Skip to content

Commit

Permalink
LibJS: Don't use Optional<Value> for bound |this| values
Browse files Browse the repository at this point in the history
Just use a plain Value since it already has an empty state.
  • Loading branch information
awesomekling committed Apr 29, 2020
1 parent 698652a commit a38658d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 deletions Libraries/LibJS/Runtime/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
, m_bound_this(bound_this)
, m_bound_arguments(move(bound_arguments))
Expand All @@ -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;

auto bound_this_object
= [bound_this_value, this]() -> Value {
if (bound_this().has_value()) {
return bound_this().value();
}
auto bound_this_object = [bound_this_value, this]() -> Value {
if (!m_bound_this.is_empty())
return m_bound_this;
switch (bound_this_value.type()) {
case Value::Type::Undefined:
case Value::Type::Null:
Expand Down Expand Up @@ -91,9 +89,7 @@ void Function::visit_children(Visitor& visitor)
{
Object::visit_children(visitor);

if (m_bound_this.has_value()) {
visitor.visit(m_bound_this.value());
}
visitor.visit(m_bound_this);

for (auto argument : m_bound_arguments) {
visitor.visit(argument);
Expand Down
6 changes: 3 additions & 3 deletions Libraries/LibJS/Runtime/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Function : public Object {

BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);

Optional<Value> bound_this() const
Value bound_this() const
{
return m_bound_this;
}
Expand All @@ -56,12 +56,12 @@ class Function : public Object {

protected:
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"; }

private:
virtual bool is_function() const final { return true; }
Optional<Value> m_bound_this;
Value m_bound_this;
Vector<Value> m_bound_arguments;
};

Expand Down

0 comments on commit a38658d

Please sign in to comment.