diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 20e8294fbd..dff0d4da50 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -115,11 +115,6 @@ CallExpression::ThisAndCallee CallExpression::compute_this_and_callee(Interprete { auto& vm = interpreter.vm(); - if (is(*this)) { - // Computing |this| is irrelevant for "new" expression. - return { js_undefined(), m_callee->execute(interpreter, global_object) }; - } - if (is(*m_callee)) { // If we are calling super, |this| has not been initialized yet, and would not be meaningful to provide. auto new_target = vm.get_new_target(); @@ -197,12 +192,12 @@ Value NewExpression::execute(Interpreter& interpreter, GlobalObject& global_obje InterpreterNodeScope node_scope { interpreter, *this }; auto& vm = interpreter.vm(); - auto [this_value, callee] = compute_this_and_callee(interpreter, global_object); + auto callee_value = m_callee->execute(interpreter, global_object); if (vm.exception()) return {}; - if (!callee.is_function() || (is(callee.as_object()) && !static_cast(callee.as_object()).has_constructor())) { - throw_type_error_for_callee(interpreter, global_object, callee, "constructor"sv); + if (!callee_value.is_function() || (is(callee_value.as_object()) && !static_cast(callee_value.as_object()).has_constructor())) { + throw_type_error_for_callee(interpreter, global_object, callee_value, "constructor"sv); return {}; } @@ -211,7 +206,7 @@ Value NewExpression::execute(Interpreter& interpreter, GlobalObject& global_obje if (interpreter.exception()) return {}; - auto& function = callee.as_function(); + auto& function = callee_value.as_function(); return vm.construct(function, function, move(arg_list)); } diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index 7009e8314b..3c7c3efe19 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -927,15 +927,16 @@ public: protected: void throw_type_error_for_callee(Interpreter&, GlobalObject&, Value callee_value, StringView call_type) const; + NonnullRefPtr m_callee; + Vector const m_arguments; + +private: struct ThisAndCallee { Value this_value; Value callee; }; ThisAndCallee compute_this_and_callee(Interpreter&, GlobalObject&) const; - - NonnullRefPtr m_callee; - Vector const m_arguments; }; class NewExpression final : public CallExpression {