1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-22 21:57:35 +00:00

LibJS: Rename BoundFunction::m_target_function to match spec name

This commit is contained in:
Linus Groh 2021-09-25 00:16:39 +02:00
parent a08292d76c
commit 4566472ed6
6 changed files with 19 additions and 28 deletions

View file

@ -150,7 +150,7 @@ ThrowCompletionOr<Realm*> get_function_realm(GlobalObject& global_object, Functi
auto& bound_function = static_cast<BoundFunction const&>(function); auto& bound_function = static_cast<BoundFunction const&>(function);
// a. Let target be obj.[[BoundTargetFunction]]. // a. Let target be obj.[[BoundTargetFunction]].
auto& target = bound_function.target_function(); auto& target = bound_function.bound_target_function();
// b. Return ? GetFunctionRealm(target). // b. Return ? GetFunctionRealm(target).
return get_function_realm(global_object, target); return get_function_realm(global_object, target);

View file

@ -9,11 +9,11 @@
namespace JS { namespace JS {
BoundFunction::BoundFunction(GlobalObject& global_object, FunctionObject& target_function, Value bound_this, Vector<Value> arguments, i32 length, Object* constructor_prototype) BoundFunction::BoundFunction(GlobalObject& global_object, FunctionObject& bound_target_function, Value bound_this, Vector<Value> arguments, i32 length, Object* constructor_prototype)
: FunctionObject(bound_this, move(arguments), *global_object.function_prototype()) : FunctionObject(bound_this, move(arguments), *global_object.function_prototype())
, m_target_function(&target_function) , m_bound_target_function(&bound_target_function)
, m_constructor_prototype(constructor_prototype) , m_constructor_prototype(constructor_prototype)
, m_name(String::formatted("bound {}", target_function.name())) , m_name(String::formatted("bound {}", bound_target_function.name()))
, m_length(length) , m_length(length)
{ {
} }
@ -31,7 +31,7 @@ BoundFunction::~BoundFunction()
Value BoundFunction::call() Value BoundFunction::call()
{ {
return m_target_function->call(); return m_bound_target_function->call();
} }
Value BoundFunction::construct(FunctionObject& new_target) Value BoundFunction::construct(FunctionObject& new_target)
@ -41,18 +41,18 @@ Value BoundFunction::construct(FunctionObject& new_target)
if (vm().exception()) if (vm().exception())
return {}; return {};
} }
return m_target_function->construct(new_target); return m_bound_target_function->construct(new_target);
} }
FunctionEnvironment* BoundFunction::create_environment(FunctionObject& function_being_invoked) FunctionEnvironment* BoundFunction::create_environment(FunctionObject& function_being_invoked)
{ {
return m_target_function->create_environment(function_being_invoked); return m_bound_target_function->create_environment(function_being_invoked);
} }
void BoundFunction::visit_edges(Visitor& visitor) void BoundFunction::visit_edges(Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(m_target_function); visitor.visit(m_bound_target_function);
visitor.visit(m_constructor_prototype); visitor.visit(m_constructor_prototype);
} }

View file

@ -19,27 +19,18 @@ public:
virtual ~BoundFunction(); virtual ~BoundFunction();
virtual Value call() override; virtual Value call() override;
virtual Value construct(FunctionObject& new_target) override; virtual Value construct(FunctionObject& new_target) override;
virtual FunctionEnvironment* create_environment(FunctionObject&) override; virtual FunctionEnvironment* create_environment(FunctionObject&) override;
virtual const FlyString& name() const override { return m_name; }
virtual bool is_strict_mode() const override { return m_bound_target_function->is_strict_mode(); }
virtual void visit_edges(Visitor&) override; FunctionObject& bound_target_function() const { return *m_bound_target_function; }
virtual const FlyString& name() const override
{
return m_name;
}
FunctionObject& target_function() const
{
return *m_target_function;
}
virtual bool is_strict_mode() const override { return m_target_function->is_strict_mode(); }
private: private:
FunctionObject* m_target_function { nullptr }; virtual void visit_edges(Visitor&) override;
FunctionObject* m_bound_target_function { nullptr }; // [[BoundTargetFunction]]
Object* m_constructor_prototype { nullptr }; Object* m_constructor_prototype { nullptr };
FlyString m_name; FlyString m_name;
i32 m_length { 0 }; i32 m_length { 0 };

View file

@ -30,7 +30,7 @@ FunctionObject::~FunctionObject()
BoundFunction* FunctionObject::bind(Value bound_this_value, Vector<Value> arguments) BoundFunction* FunctionObject::bind(Value bound_this_value, Vector<Value> arguments)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
FunctionObject& target_function = is<BoundFunction>(*this) ? static_cast<BoundFunction&>(*this).target_function() : *this; FunctionObject& target_function = is<BoundFunction>(*this) ? static_cast<BoundFunction&>(*this).bound_target_function() : *this;
auto bound_this_object = [&vm, bound_this_value, this]() -> Value { auto bound_this_object = [&vm, bound_this_value, this]() -> Value {
if (!m_bound_this.is_empty()) if (!m_bound_this.is_empty())

View file

@ -677,7 +677,7 @@ ThrowCompletionOr<Value> VM::call_internal(FunctionObject& function, Value this_
MarkedValueList with_bound_arguments { heap() }; MarkedValueList with_bound_arguments { heap() };
append_bound_and_passed_arguments(with_bound_arguments, bound_function.bound_arguments(), move(arguments)); append_bound_and_passed_arguments(with_bound_arguments, bound_function.bound_arguments(), move(arguments));
return call_internal(bound_function.target_function(), bound_function.bound_this(), move(with_bound_arguments)); return call_internal(bound_function.bound_target_function(), bound_function.bound_this(), move(with_bound_arguments));
} }
// FIXME: prepare_for_ordinary_call() is not supposed to receive a BoundFunction, ProxyObject, etc. - ever. // FIXME: prepare_for_ordinary_call() is not supposed to receive a BoundFunction, ProxyObject, etc. - ever.

View file

@ -236,7 +236,7 @@ bool Value::is_constructor() const
if (is<NativeFunction>(as_object())) if (is<NativeFunction>(as_object()))
return static_cast<const NativeFunction&>(as_object()).has_constructor(); return static_cast<const NativeFunction&>(as_object()).has_constructor();
if (is<BoundFunction>(as_object())) if (is<BoundFunction>(as_object()))
return Value(&static_cast<const BoundFunction&>(as_object()).target_function()).is_constructor(); return Value(&static_cast<const BoundFunction&>(as_object()).bound_target_function()).is_constructor();
// ECMAScriptFunctionObject // ECMAScriptFunctionObject
return true; return true;
} }
@ -1310,7 +1310,7 @@ Value ordinary_has_instance(GlobalObject& global_object, Value lhs, Value rhs)
if (is<BoundFunction>(rhs_function)) { if (is<BoundFunction>(rhs_function)) {
auto& bound_target = static_cast<const BoundFunction&>(rhs_function); auto& bound_target = static_cast<const BoundFunction&>(rhs_function);
return instance_of(global_object, lhs, Value(&bound_target.target_function())); return instance_of(global_object, lhs, Value(&bound_target.bound_target_function()));
} }
if (!lhs.is_object()) if (!lhs.is_object())