diff options
author | Andreas Kling <kling@serenityos.org> | 2021-06-11 10:45:49 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-11 10:45:49 +0200 |
commit | 749a3b9245d83101ea6ef19c7a4be2ed454ed292 (patch) | |
tree | c548d03bec0e8629d1c86209ae0adf8a940a486b /Userland/Libraries | |
parent | 17da54d49c0ffb502372dc9cf55c5882fdf5c190 (diff) | |
download | serenity-749a3b9245d83101ea6ef19c7a4be2ed454ed292.zip |
LibJS: Move is_arrow_function() from FunctionExpression to FunctionNode
This will make it easier to write bytecode generation for function
expressions in just a moment.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/AST.h | 11 |
2 files changed, 7 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index e8ea55f124..6aa1714a35 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -100,7 +100,7 @@ Value FunctionDeclaration::execute(Interpreter& interpreter, GlobalObject&) cons Value FunctionExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const { InterpreterNodeScope node_scope { interpreter, *this }; - return ScriptFunction::create(global_object, name(), body(), parameters(), function_length(), interpreter.current_scope(), is_generator(), is_strict_mode() || interpreter.vm().in_strict_mode(), m_is_arrow_function); + return ScriptFunction::create(global_object, name(), body(), parameters(), function_length(), interpreter.current_scope(), is_generator(), is_strict_mode() || interpreter.vm().in_strict_mode(), is_arrow_function()); } Value ExpressionStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index 4e1676c569..ebc5967c03 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -227,10 +227,11 @@ public: Vector<Parameter> const& parameters() const { return m_parameters; }; 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; } protected: - FunctionNode(FlyString const& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_generator, bool is_strict_mode) + 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) : m_name(name) , m_body(move(body)) , m_parameters(move(parameters)) @@ -238,6 +239,7 @@ protected: , m_function_length(function_length) , m_is_generator(is_generator) , m_is_strict_mode(is_strict_mode) + , m_is_arrow_function(is_arrow_function) { } @@ -260,6 +262,7 @@ private: const i32 m_function_length; bool m_is_generator; bool m_is_strict_mode; + bool m_is_arrow_function { false }; }; class FunctionDeclaration final @@ -270,7 +273,7 @@ public: 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) : Declaration(move(source_range)) - , FunctionNode(name, move(body), move(parameters), function_length, move(variables), is_generator, is_strict_mode) + , FunctionNode(name, move(body), move(parameters), function_length, move(variables), is_generator, is_strict_mode, false) { } @@ -287,8 +290,7 @@ public: 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) : Expression(source_range) - , FunctionNode(name, move(body), move(parameters), function_length, move(variables), is_generator, is_strict_mode) - , m_is_arrow_function(is_arrow_function) + , FunctionNode(name, move(body), move(parameters), function_length, move(variables), is_generator, is_strict_mode, is_arrow_function) { } @@ -308,7 +310,6 @@ public: private: bool m_cannot_auto_rename { false }; - bool m_is_arrow_function { false }; }; class ErrorExpression final : public Expression { |