mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
LibJS: NewExpression doesn't need compute_this_and_callee()
Now that NewExpression is separated from CallExpression, it doesn't have to use the ad-hoc compute_this_and_callee() logic.
This commit is contained in:
parent
814549b846
commit
d81f4d5228
2 changed files with 8 additions and 12 deletions
|
@ -115,11 +115,6 @@ CallExpression::ThisAndCallee CallExpression::compute_this_and_callee(Interprete
|
||||||
{
|
{
|
||||||
auto& vm = interpreter.vm();
|
auto& vm = interpreter.vm();
|
||||||
|
|
||||||
if (is<NewExpression>(*this)) {
|
|
||||||
// Computing |this| is irrelevant for "new" expression.
|
|
||||||
return { js_undefined(), m_callee->execute(interpreter, global_object) };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is<SuperExpression>(*m_callee)) {
|
if (is<SuperExpression>(*m_callee)) {
|
||||||
// If we are calling super, |this| has not been initialized yet, and would not be meaningful to provide.
|
// 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();
|
auto new_target = vm.get_new_target();
|
||||||
|
@ -197,12 +192,12 @@ Value NewExpression::execute(Interpreter& interpreter, GlobalObject& global_obje
|
||||||
InterpreterNodeScope node_scope { interpreter, *this };
|
InterpreterNodeScope node_scope { interpreter, *this };
|
||||||
auto& vm = interpreter.vm();
|
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())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (!callee.is_function() || (is<NativeFunction>(callee.as_object()) && !static_cast<NativeFunction&>(callee.as_object()).has_constructor())) {
|
if (!callee_value.is_function() || (is<NativeFunction>(callee_value.as_object()) && !static_cast<NativeFunction&>(callee_value.as_object()).has_constructor())) {
|
||||||
throw_type_error_for_callee(interpreter, global_object, callee, "constructor"sv);
|
throw_type_error_for_callee(interpreter, global_object, callee_value, "constructor"sv);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +206,7 @@ Value NewExpression::execute(Interpreter& interpreter, GlobalObject& global_obje
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto& function = callee.as_function();
|
auto& function = callee_value.as_function();
|
||||||
return vm.construct(function, function, move(arg_list));
|
return vm.construct(function, function, move(arg_list));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -927,15 +927,16 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void throw_type_error_for_callee(Interpreter&, GlobalObject&, Value callee_value, StringView call_type) const;
|
void throw_type_error_for_callee(Interpreter&, GlobalObject&, Value callee_value, StringView call_type) const;
|
||||||
|
|
||||||
|
NonnullRefPtr<Expression> m_callee;
|
||||||
|
Vector<Argument> const m_arguments;
|
||||||
|
|
||||||
|
private:
|
||||||
struct ThisAndCallee {
|
struct ThisAndCallee {
|
||||||
Value this_value;
|
Value this_value;
|
||||||
Value callee;
|
Value callee;
|
||||||
};
|
};
|
||||||
|
|
||||||
ThisAndCallee compute_this_and_callee(Interpreter&, GlobalObject&) const;
|
ThisAndCallee compute_this_and_callee(Interpreter&, GlobalObject&) const;
|
||||||
|
|
||||||
NonnullRefPtr<Expression> m_callee;
|
|
||||||
Vector<Argument> const m_arguments;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class NewExpression final : public CallExpression {
|
class NewExpression final : public CallExpression {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue