1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:57:45 +00:00

LibJS: Use an enum class instead of 'bool is_generator'

This avoid confusion in the order of the multiple boolean parameters
that exist.
This commit is contained in:
Ali Mohammad Pur 2021-06-11 03:38:05 +04:30 committed by Ali Mohammad Pur
parent 5ffe23e4f3
commit 8b3f8879c1
9 changed files with 46 additions and 29 deletions

View file

@ -26,6 +26,11 @@ class VariableDeclaration;
class FunctionDeclaration;
class Identifier;
enum class FunctionKind {
Generator,
Regular,
};
template<class T, class... Args>
static inline NonnullRefPtr<T>
create_ast_node(SourceRange range, Args&&... args)
@ -228,16 +233,16 @@ public:
i32 function_length() const { return m_function_length; }
bool is_strict_mode() const { return m_is_strict_mode; }
bool is_arrow_function() const { return m_is_arrow_function; }
bool is_generator() const { return m_is_generator; }
FunctionKind kind() const { return m_kind; }
protected:
FunctionNode(FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode, bool is_arrow_function)
FunctionNode(FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, FunctionKind kind, bool is_strict_mode, bool is_arrow_function)
: m_name(name)
, m_body(move(body))
, m_parameters(move(parameters))
, m_variables(move(variables))
, m_function_length(function_length)
, m_is_generator(is_generator)
, m_kind(kind)
, m_is_strict_mode(is_strict_mode)
, m_is_arrow_function(is_arrow_function)
{
@ -260,7 +265,7 @@ private:
Vector<Parameter> const m_parameters;
NonnullRefPtrVector<VariableDeclaration> m_variables;
const i32 m_function_length;
bool m_is_generator;
FunctionKind m_kind;
bool m_is_strict_mode;
bool m_is_arrow_function { false };
};
@ -271,9 +276,9 @@ class FunctionDeclaration final
public:
static bool must_have_name() { return true; }
FunctionDeclaration(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode = false)
FunctionDeclaration(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, FunctionKind kind, bool is_strict_mode = false)
: Declaration(move(source_range))
, FunctionNode(name, move(body), move(parameters), function_length, move(variables), is_generator, is_strict_mode, false)
, FunctionNode(name, move(body), move(parameters), function_length, move(variables), kind, is_strict_mode, false)
{
}
@ -288,9 +293,9 @@ class FunctionExpression final
public:
static bool must_have_name() { return false; }
FunctionExpression(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode, bool is_arrow_function = false)
FunctionExpression(SourceRange source_range, FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, FunctionKind kind, bool is_strict_mode, bool is_arrow_function = false)
: Expression(source_range)
, FunctionNode(name, move(body), move(parameters), function_length, move(variables), is_generator, is_strict_mode, is_arrow_function)
, FunctionNode(name, move(body), move(parameters), function_length, move(variables), kind, is_strict_mode, is_arrow_function)
{
}