1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:05:07 +00:00

LibJS: Make Function::call() not require an Interpreter&

This makes a difference inside ScriptFunction::call(), which will now
instantiate a temporary Interpreter if one is not attached to the VM.
This commit is contained in:
Andreas Kling 2020-09-27 17:24:14 +02:00
parent be31805e8b
commit 1ff9d33131
42 changed files with 167 additions and 142 deletions

View file

@ -460,36 +460,36 @@ void ProxyObject::visit_children(Cell::Visitor& visitor)
visitor.visit(&m_handler);
}
Value ProxyObject::call(Interpreter& interpreter)
Value ProxyObject::call()
{
if (!is_function()) {
interpreter.vm().throw_exception<TypeError>(global_object(), ErrorType::NotAFunction, Value(this).to_string_without_side_effects().characters());
vm().throw_exception<TypeError>(global_object(), ErrorType::NotAFunction, Value(this).to_string_without_side_effects().characters());
return {};
}
if (m_is_revoked) {
interpreter.vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
return {};
}
auto trap = m_handler.get("apply");
if (interpreter.exception())
if (vm().exception())
return {};
if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return static_cast<Function&>(m_target).call(interpreter);
return static_cast<Function&>(m_target).call();
if (!trap.is_function()) {
interpreter.vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "apply");
vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "apply");
return {};
}
MarkedValueList arguments(interpreter.heap());
MarkedValueList arguments(heap());
arguments.append(Value(&m_target));
arguments.append(Value(&m_handler));
// FIXME: Pass global object
auto arguments_array = Array::create(interpreter.global_object());
interpreter.vm().for_each_argument([&](auto& argument) {
auto arguments_array = Array::create(global_object());
vm().for_each_argument([&](auto& argument) {
arguments_array->indexed_properties().append(argument);
});
arguments.append(arguments_array);
return interpreter.call(trap.as_function(), Value(&m_handler), move(arguments));
return vm().call(trap.as_function(), Value(&m_handler), move(arguments));
}
Value ProxyObject::construct(Interpreter& interpreter, Function& new_target)