mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:17:44 +00:00
LibJS: Track whether ScriptFunctions and FunctionExpressions are arrow
functions
This commit is contained in:
parent
5243e9974d
commit
c12125fa81
5 changed files with 13 additions and 8 deletions
|
@ -76,7 +76,7 @@ Value FunctionDeclaration::execute(Interpreter& interpreter) const
|
||||||
|
|
||||||
Value FunctionExpression::execute(Interpreter& interpreter) const
|
Value FunctionExpression::execute(Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
return ScriptFunction::create(interpreter.global_object(), name(), body(), parameters(), function_length(), interpreter.current_environment());
|
return ScriptFunction::create(interpreter.global_object(), name(), body(), parameters(), function_length(), interpreter.current_environment(), m_is_arrow_function);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ExpressionStatement::execute(Interpreter& interpreter) const
|
Value ExpressionStatement::execute(Interpreter& interpreter) const
|
||||||
|
|
|
@ -223,8 +223,9 @@ class FunctionExpression final
|
||||||
public:
|
public:
|
||||||
static bool must_have_name() { return false; }
|
static bool must_have_name() { return false; }
|
||||||
|
|
||||||
FunctionExpression(const FlyString& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables)
|
FunctionExpression(const FlyString& name, NonnullRefPtr<Statement> body, Vector<Parameter> parameters, i32 function_length, NonnullRefPtrVector<VariableDeclaration> variables, bool is_arrow_function = false)
|
||||||
: FunctionNode(name, move(body), move(parameters), function_length, move(variables))
|
: FunctionNode(name, move(body), move(parameters), function_length, move(variables))
|
||||||
|
, m_is_arrow_function(is_arrow_function)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,6 +234,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "FunctionExpression"; }
|
virtual const char* class_name() const override { return "FunctionExpression"; }
|
||||||
|
|
||||||
|
bool m_is_arrow_function;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ErrorExpression final : public Expression {
|
class ErrorExpression final : public Expression {
|
||||||
|
|
|
@ -382,7 +382,7 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
|
||||||
if (!function_body_result.is_null()) {
|
if (!function_body_result.is_null()) {
|
||||||
state_rollback_guard.disarm();
|
state_rollback_guard.disarm();
|
||||||
auto body = function_body_result.release_nonnull();
|
auto body = function_body_result.release_nonnull();
|
||||||
return create_ast_node<FunctionExpression>("", move(body), move(parameters), function_length, m_parser_state.m_var_scopes.take_last());
|
return create_ast_node<FunctionExpression>("", move(body), move(parameters), function_length, m_parser_state.m_var_scopes.take_last(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -47,18 +47,19 @@ static ScriptFunction* script_function_from(Interpreter& interpreter)
|
||||||
return static_cast<ScriptFunction*>(this_object);
|
return static_cast<ScriptFunction*>(this_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment)
|
ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, bool is_arrow_function)
|
||||||
{
|
{
|
||||||
return global_object.heap().allocate<ScriptFunction>(name, body, move(parameters), m_function_length, parent_environment, *global_object.function_prototype());
|
return global_object.heap().allocate<ScriptFunction>(name, body, move(parameters), m_function_length, parent_environment, *global_object.function_prototype(), is_arrow_function);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFunction::ScriptFunction(const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype)
|
ScriptFunction::ScriptFunction(const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_arrow_function)
|
||||||
: Function(prototype)
|
: Function(prototype)
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
, m_body(body)
|
, m_body(body)
|
||||||
, m_parameters(move(parameters))
|
, m_parameters(move(parameters))
|
||||||
, m_parent_environment(parent_environment)
|
, m_parent_environment(parent_environment)
|
||||||
, m_function_length(m_function_length)
|
, m_function_length(m_function_length)
|
||||||
|
, m_is_arrow_function(is_arrow_function)
|
||||||
{
|
{
|
||||||
define_property("prototype", Object::create_empty(interpreter(), interpreter().global_object()), 0);
|
define_property("prototype", Object::create_empty(interpreter(), interpreter().global_object()), 0);
|
||||||
define_native_property("length", length_getter, nullptr, Attribute::Configurable);
|
define_native_property("length", length_getter, nullptr, Attribute::Configurable);
|
||||||
|
|
|
@ -33,9 +33,9 @@ namespace JS {
|
||||||
|
|
||||||
class ScriptFunction final : public Function {
|
class ScriptFunction final : public Function {
|
||||||
public:
|
public:
|
||||||
static ScriptFunction* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment);
|
static ScriptFunction* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, bool is_arrow_function = false);
|
||||||
|
|
||||||
ScriptFunction(const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype);
|
ScriptFunction(const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_arrow_function = false);
|
||||||
virtual ~ScriptFunction();
|
virtual ~ScriptFunction();
|
||||||
|
|
||||||
const Statement& body() const { return m_body; }
|
const Statement& body() const { return m_body; }
|
||||||
|
@ -61,6 +61,7 @@ private:
|
||||||
const Vector<FunctionNode::Parameter> m_parameters;
|
const Vector<FunctionNode::Parameter> m_parameters;
|
||||||
LexicalEnvironment* m_parent_environment { nullptr };
|
LexicalEnvironment* m_parent_environment { nullptr };
|
||||||
i32 m_function_length;
|
i32 m_function_length;
|
||||||
|
bool m_is_arrow_function;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue