diff --git a/Libraries/LibJS/Runtime/Function.cpp b/Libraries/LibJS/Runtime/Function.cpp index d5b05f7251..605c98141e 100644 --- a/Libraries/LibJS/Runtime/Function.cpp +++ b/Libraries/LibJS/Runtime/Function.cpp @@ -36,7 +36,7 @@ Function::Function(Object& prototype) { } -Function::Function(Object& prototype, Optional bound_this, Vector bound_arguments) +Function::Function(Object& prototype, Value bound_this, Vector bound_arguments) : Object(&prototype) , m_bound_this(bound_this) , m_bound_arguments(move(bound_arguments)) @@ -48,11 +48,9 @@ BoundFunction* Function::bind(Value bound_this_value, Vector arguments) Function& target_function = is_bound_function() ? static_cast(*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: @@ -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); diff --git a/Libraries/LibJS/Runtime/Function.h b/Libraries/LibJS/Runtime/Function.h index eb1cd2b9f2..7c6f66e987 100644 --- a/Libraries/LibJS/Runtime/Function.h +++ b/Libraries/LibJS/Runtime/Function.h @@ -44,7 +44,7 @@ public: BoundFunction* bind(Value bound_this_value, Vector arguments); - Optional bound_this() const + Value bound_this() const { return m_bound_this; } @@ -56,12 +56,12 @@ public: protected: explicit Function(Object& prototype); - explicit Function(Object& prototype, Optional bound_this, Vector bound_arguments); + explicit Function(Object& prototype, Value bound_this, Vector bound_arguments); virtual const char* class_name() const override { return "Function"; } private: virtual bool is_function() const final { return true; } - Optional m_bound_this; + Value m_bound_this; Vector m_bound_arguments; };