1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 00:58:12 +00:00

LibJS: FunctionEnvironment.[[FunctionObject]] is the *invoked* function

We were setting the wrong [[FunctionObject]] on the environment when
going through ProxyObject and BoundFunction.
This commit is contained in:
Andreas Kling 2021-06-25 20:14:17 +02:00
parent 08d2ea3fac
commit b650d11dd3
10 changed files with 14 additions and 14 deletions

View file

@ -44,9 +44,9 @@ Value BoundFunction::construct(Function& new_target)
return m_target_function->construct(new_target); return m_target_function->construct(new_target);
} }
FunctionEnvironmentRecord* BoundFunction::create_environment_record() FunctionEnvironmentRecord* BoundFunction::create_environment_record(Function& function_being_invoked)
{ {
return m_target_function->create_environment_record(); return m_target_function->create_environment_record(function_being_invoked);
} }
void BoundFunction::visit_edges(Visitor& visitor) void BoundFunction::visit_edges(Visitor& visitor)

View file

@ -22,7 +22,7 @@ public:
virtual Value construct(Function& new_target) override; virtual Value construct(Function& new_target) override;
virtual FunctionEnvironmentRecord* create_environment_record() override; virtual FunctionEnvironmentRecord* create_environment_record(Function&) override;
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;

View file

@ -26,7 +26,7 @@ public:
virtual Value call() = 0; virtual Value call() = 0;
virtual Value construct(Function& new_target) = 0; virtual Value construct(Function& new_target) = 0;
virtual const FlyString& name() const = 0; virtual const FlyString& name() const = 0;
virtual FunctionEnvironmentRecord* create_environment_record() = 0; virtual FunctionEnvironmentRecord* create_environment_record(Function&) = 0;
BoundFunction* bind(Value bound_this_value, Vector<Value> arguments); BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);

View file

@ -47,7 +47,7 @@ Value NativeFunction::construct(Function&)
return {}; return {};
} }
FunctionEnvironmentRecord* NativeFunction::create_environment_record() FunctionEnvironmentRecord* NativeFunction::create_environment_record(Function&)
{ {
return nullptr; return nullptr;
} }

View file

@ -34,7 +34,7 @@ protected:
explicit NativeFunction(Object& prototype); explicit NativeFunction(Object& prototype);
private: private:
virtual FunctionEnvironmentRecord* create_environment_record() override final; virtual FunctionEnvironmentRecord* create_environment_record(Function&) override final;
virtual bool is_native_function() const final { return true; } virtual bool is_native_function() const final { return true; }
FlyString m_name; FlyString m_name;

View file

@ -478,10 +478,10 @@ const FlyString& ProxyObject::name() const
return static_cast<Function&>(m_target).name(); return static_cast<Function&>(m_target).name();
} }
FunctionEnvironmentRecord* ProxyObject::create_environment_record() FunctionEnvironmentRecord* ProxyObject::create_environment_record(Function& function_being_invoked)
{ {
VERIFY(is_function()); VERIFY(is_function());
return static_cast<Function&>(m_target).create_environment_record(); return static_cast<Function&>(m_target).create_environment_record(function_being_invoked);
} }
} }

View file

@ -22,7 +22,7 @@ public:
virtual Value call() override; virtual Value call() override;
virtual Value construct(Function& new_target) override; virtual Value construct(Function& new_target) override;
virtual const FlyString& name() const override; virtual const FlyString& name() const override;
virtual FunctionEnvironmentRecord* create_environment_record() override; virtual FunctionEnvironmentRecord* create_environment_record(Function&) override;
const Object& target() const { return m_target; } const Object& target() const { return m_target; }
const Object& handler() const { return m_handler; } const Object& handler() const { return m_handler; }

View file

@ -94,7 +94,7 @@ void ScriptFunction::visit_edges(Visitor& visitor)
visitor.visit(m_parent_scope); visitor.visit(m_parent_scope);
} }
FunctionEnvironmentRecord* ScriptFunction::create_environment_record() FunctionEnvironmentRecord* ScriptFunction::create_environment_record(Function& function_being_invoked)
{ {
HashMap<FlyString, Variable> variables; HashMap<FlyString, Variable> variables;
for (auto& parameter : m_parameters) { for (auto& parameter : m_parameters) {
@ -124,7 +124,7 @@ FunctionEnvironmentRecord* ScriptFunction::create_environment_record()
} }
auto* environment = heap().allocate<FunctionEnvironmentRecord>(global_object(), m_parent_scope, variables); auto* environment = heap().allocate<FunctionEnvironmentRecord>(global_object(), m_parent_scope, variables);
environment->set_function_object(*this); environment->set_function_object(function_being_invoked);
if (m_is_arrow_function) { if (m_is_arrow_function) {
if (is<FunctionEnvironmentRecord>(m_parent_scope)) if (is<FunctionEnvironmentRecord>(m_parent_scope))
environment->set_new_target(static_cast<FunctionEnvironmentRecord*>(m_parent_scope)->new_target()); environment->set_new_target(static_cast<FunctionEnvironmentRecord*>(m_parent_scope)->new_target());

View file

@ -41,7 +41,7 @@ protected:
virtual bool is_strict_mode() const final { return m_is_strict; } virtual bool is_strict_mode() const final { return m_is_strict; }
private: private:
virtual FunctionEnvironmentRecord* create_environment_record() override; virtual FunctionEnvironmentRecord* create_environment_record(Function&) override;
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
Value execute_function_body(); Value execute_function_body();

View file

@ -425,7 +425,7 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
callee_context.arguments = function.bound_arguments(); callee_context.arguments = function.bound_arguments();
if (arguments.has_value()) if (arguments.has_value())
callee_context.arguments.extend(arguments.value().values()); callee_context.arguments.extend(arguments.value().values());
auto* environment = function.create_environment_record(); auto* environment = function.create_environment_record(function);
callee_context.lexical_environment = environment; callee_context.lexical_environment = environment;
callee_context.variable_environment = environment; callee_context.variable_environment = environment;
if (environment) if (environment)
@ -529,7 +529,7 @@ Value VM::call_internal(Function& function, Value this_value, Optional<MarkedVal
callee_context.arguments = function.bound_arguments(); callee_context.arguments = function.bound_arguments();
if (arguments.has_value()) if (arguments.has_value())
callee_context.arguments.extend(arguments.value().values()); callee_context.arguments.extend(arguments.value().values());
auto* environment = function.create_environment_record(); auto* environment = function.create_environment_record(function);
callee_context.lexical_environment = environment; callee_context.lexical_environment = environment;
callee_context.variable_environment = environment; callee_context.variable_environment = environment;