mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibJS: Don't use Optional<Value> for bound |this| values
Just use a plain Value since it already has an empty state.
This commit is contained in:
parent
698652a548
commit
a38658dc88
2 changed files with 8 additions and 12 deletions
|
@ -36,7 +36,7 @@ Function::Function(Object& prototype)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Function::Function(Object& prototype, Optional<Value> bound_this, Vector<Value> bound_arguments)
|
Function::Function(Object& prototype, Value bound_this, Vector<Value> bound_arguments)
|
||||||
: Object(&prototype)
|
: Object(&prototype)
|
||||||
, m_bound_this(bound_this)
|
, m_bound_this(bound_this)
|
||||||
, m_bound_arguments(move(bound_arguments))
|
, m_bound_arguments(move(bound_arguments))
|
||||||
|
@ -48,11 +48,9 @@ BoundFunction* Function::bind(Value bound_this_value, Vector<Value> arguments)
|
||||||
|
|
||||||
Function& target_function = is_bound_function() ? static_cast<BoundFunction&>(*this).target_function() : *this;
|
Function& target_function = is_bound_function() ? static_cast<BoundFunction&>(*this).target_function() : *this;
|
||||||
|
|
||||||
auto bound_this_object
|
auto bound_this_object = [bound_this_value, this]() -> Value {
|
||||||
= [bound_this_value, this]() -> Value {
|
if (!m_bound_this.is_empty())
|
||||||
if (bound_this().has_value()) {
|
return m_bound_this;
|
||||||
return bound_this().value();
|
|
||||||
}
|
|
||||||
switch (bound_this_value.type()) {
|
switch (bound_this_value.type()) {
|
||||||
case Value::Type::Undefined:
|
case Value::Type::Undefined:
|
||||||
case Value::Type::Null:
|
case Value::Type::Null:
|
||||||
|
@ -91,9 +89,7 @@ void Function::visit_children(Visitor& visitor)
|
||||||
{
|
{
|
||||||
Object::visit_children(visitor);
|
Object::visit_children(visitor);
|
||||||
|
|
||||||
if (m_bound_this.has_value()) {
|
visitor.visit(m_bound_this);
|
||||||
visitor.visit(m_bound_this.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto argument : m_bound_arguments) {
|
for (auto argument : m_bound_arguments) {
|
||||||
visitor.visit(argument);
|
visitor.visit(argument);
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
|
|
||||||
BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);
|
BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);
|
||||||
|
|
||||||
Optional<Value> bound_this() const
|
Value bound_this() const
|
||||||
{
|
{
|
||||||
return m_bound_this;
|
return m_bound_this;
|
||||||
}
|
}
|
||||||
|
@ -56,12 +56,12 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Function(Object& prototype);
|
explicit Function(Object& prototype);
|
||||||
explicit Function(Object& prototype, Optional<Value> bound_this, Vector<Value> bound_arguments);
|
explicit Function(Object& prototype, Value bound_this, Vector<Value> bound_arguments);
|
||||||
virtual const char* class_name() const override { return "Function"; }
|
virtual const char* class_name() const override { return "Function"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool is_function() const final { return true; }
|
virtual bool is_function() const final { return true; }
|
||||||
Optional<Value> m_bound_this;
|
Value m_bound_this;
|
||||||
Vector<Value> m_bound_arguments;
|
Vector<Value> m_bound_arguments;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue