mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibJS: Remove Interpreter& argument to Function::construct()
This is no longer needed, we can get everything we need from the VM.
This commit is contained in:
parent
340a115dfe
commit
f79d4c7347
Notes:
sideshowbarker
2024-07-19 02:10:32 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f79d4c7347c
36 changed files with 73 additions and 61 deletions
|
@ -81,7 +81,7 @@ Value ArrayConstructor::call()
|
|||
return array;
|
||||
}
|
||||
|
||||
Value ArrayConstructor::construct(Interpreter&, Function&)
|
||||
Value ArrayConstructor::construct(Function&)
|
||||
{
|
||||
return call();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~ArrayConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -72,9 +72,9 @@ Value BigIntConstructor::call()
|
|||
return bigint;
|
||||
}
|
||||
|
||||
Value BigIntConstructor::construct(Interpreter& interpreter, Function&)
|
||||
Value BigIntConstructor::construct(Function&)
|
||||
{
|
||||
interpreter.vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, "BigInt");
|
||||
vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, "BigInt");
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~BigIntConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -54,9 +54,9 @@ Value BooleanConstructor::call()
|
|||
return Value(vm().argument(0).to_boolean());
|
||||
}
|
||||
|
||||
Value BooleanConstructor::construct(Interpreter& interpreter, Function&)
|
||||
Value BooleanConstructor::construct(Function&)
|
||||
{
|
||||
return BooleanObject::create(global_object(), interpreter.argument(0).to_boolean());
|
||||
return BooleanObject::create(global_object(), vm().argument(0).to_boolean());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~BooleanConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -54,14 +54,14 @@ Value BoundFunction::call()
|
|||
return m_target_function->call();
|
||||
}
|
||||
|
||||
Value BoundFunction::construct(Interpreter& interpreter, Function& new_target)
|
||||
Value BoundFunction::construct(Function& new_target)
|
||||
{
|
||||
if (auto this_value = vm().this_value(global_object()); m_constructor_prototype && this_value.is_object()) {
|
||||
this_value.as_object().set_prototype(m_constructor_prototype);
|
||||
if (interpreter.exception())
|
||||
if (vm().exception())
|
||||
return {};
|
||||
}
|
||||
return m_target_function->construct(interpreter, new_target);
|
||||
return m_target_function->construct(new_target);
|
||||
}
|
||||
|
||||
LexicalEnvironment* BoundFunction::create_environment()
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
|
||||
virtual Value call() override;
|
||||
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
virtual LexicalEnvironment* create_environment() override;
|
||||
|
||||
|
|
|
@ -159,13 +159,13 @@ DateConstructor::~DateConstructor()
|
|||
|
||||
Value DateConstructor::call()
|
||||
{
|
||||
auto date = construct(interpreter(), *this);
|
||||
auto date = construct(*this);
|
||||
if (!date.is_object())
|
||||
return {};
|
||||
return js_string(heap(), static_cast<Date&>(date.as_object()).string());
|
||||
}
|
||||
|
||||
Value DateConstructor::construct(Interpreter&, Function&)
|
||||
Value DateConstructor::construct(Function&)
|
||||
{
|
||||
if (vm().argument_count() == 0) {
|
||||
struct timeval tv;
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~DateConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -49,15 +49,16 @@ ErrorConstructor::~ErrorConstructor()
|
|||
|
||||
Value ErrorConstructor::call()
|
||||
{
|
||||
return construct(interpreter(), *this);
|
||||
return construct(*this);
|
||||
}
|
||||
|
||||
Value ErrorConstructor::construct(Interpreter& interpreter, Function&)
|
||||
Value ErrorConstructor::construct(Function&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
String message = "";
|
||||
if (!interpreter.call_frame().arguments.is_empty() && !interpreter.call_frame().arguments[0].is_undefined()) {
|
||||
message = interpreter.call_frame().arguments[0].to_string(global_object());
|
||||
if (interpreter.exception())
|
||||
if (!vm.call_frame().arguments.is_empty() && !vm.call_frame().arguments[0].is_undefined()) {
|
||||
message = vm.call_frame().arguments[0].to_string(global_object());
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
return Error::create(global_object(), "Error", message);
|
||||
|
@ -77,9 +78,9 @@ Value ErrorConstructor::construct(Interpreter& interpreter, Function&)
|
|||
ConstructorName::~ConstructorName() { } \
|
||||
Value ConstructorName::call() \
|
||||
{ \
|
||||
return construct(interpreter(), *this); \
|
||||
return construct(*this); \
|
||||
} \
|
||||
Value ConstructorName::construct(Interpreter&, Function&) \
|
||||
Value ConstructorName::construct(Function&) \
|
||||
{ \
|
||||
String message = ""; \
|
||||
if (!vm().call_frame().arguments.is_empty() && !vm().call_frame().arguments[0].is_undefined()) { \
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
virtual ~ErrorConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
@ -55,7 +55,7 @@ private:
|
|||
virtual void initialize(GlobalObject&) override; \
|
||||
virtual ~ConstructorName() override; \
|
||||
virtual Value call() override; \
|
||||
virtual Value construct(Interpreter&, Function& new_target) override; \
|
||||
virtual Value construct(Function& new_target) override; \
|
||||
\
|
||||
private: \
|
||||
virtual bool has_constructor() const override { return true; } \
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
virtual void initialize(GlobalObject&) override { }
|
||||
|
||||
virtual Value call() = 0;
|
||||
virtual Value construct(Interpreter&, Function& new_target) = 0;
|
||||
virtual Value construct(Function& new_target) = 0;
|
||||
virtual const FlyString& name() const = 0;
|
||||
virtual LexicalEnvironment* create_environment() = 0;
|
||||
|
||||
|
|
|
@ -53,10 +53,10 @@ FunctionConstructor::~FunctionConstructor()
|
|||
|
||||
Value FunctionConstructor::call()
|
||||
{
|
||||
return construct(interpreter(), *this);
|
||||
return construct(*this);
|
||||
}
|
||||
|
||||
Value FunctionConstructor::construct(Interpreter& interpreter, Function&)
|
||||
Value FunctionConstructor::construct(Function&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
String parameters_source = "";
|
||||
|
@ -88,7 +88,17 @@ Value FunctionConstructor::construct(Interpreter& interpreter, Function&)
|
|||
vm.throw_exception<SyntaxError>(global_object(), error.to_string());
|
||||
return {};
|
||||
}
|
||||
return function_expression->execute(interpreter, global_object());
|
||||
|
||||
OwnPtr<Interpreter> local_interpreter;
|
||||
Interpreter* interpreter = vm.interpreter_if_exists();
|
||||
|
||||
if (!interpreter) {
|
||||
local_interpreter = Interpreter::create_with_existing_global_object(global_object());
|
||||
interpreter = local_interpreter.ptr();
|
||||
}
|
||||
|
||||
VM::InterpreterExecutionScope scope(*interpreter);
|
||||
return function_expression->execute(*interpreter, global_object());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~FunctionConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -63,7 +63,7 @@ Value NativeFunction::call()
|
|||
return m_native_function(vm(), global_object());
|
||||
}
|
||||
|
||||
Value NativeFunction::construct(Interpreter&, Function&)
|
||||
Value NativeFunction::construct(Function&)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
virtual ~NativeFunction() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
virtual const FlyString& name() const override { return m_name; };
|
||||
virtual bool has_constructor() const { return false; }
|
||||
|
|
|
@ -72,7 +72,7 @@ Value NumberConstructor::call()
|
|||
return vm().argument(0).to_number(global_object());
|
||||
}
|
||||
|
||||
Value NumberConstructor::construct(Interpreter&, Function&)
|
||||
Value NumberConstructor::construct(Function&)
|
||||
{
|
||||
double number = 0;
|
||||
if (vm().argument_count()) {
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~NumberConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -69,7 +69,7 @@ Value ObjectConstructor::call()
|
|||
return Object::create_empty(global_object());
|
||||
}
|
||||
|
||||
Value ObjectConstructor::construct(Interpreter&, Function&)
|
||||
Value ObjectConstructor::construct(Function&)
|
||||
{
|
||||
return call();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~ObjectConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -55,22 +55,23 @@ Value ProxyConstructor::call()
|
|||
return {};
|
||||
}
|
||||
|
||||
Value ProxyConstructor::construct(Interpreter& interpreter, Function&)
|
||||
Value ProxyConstructor::construct(Function&)
|
||||
{
|
||||
if (interpreter.argument_count() < 2) {
|
||||
interpreter.vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyTwoArguments);
|
||||
auto& vm = this->vm();
|
||||
if (vm.argument_count() < 2) {
|
||||
vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyTwoArguments);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto target = interpreter.argument(0);
|
||||
auto handler = interpreter.argument(1);
|
||||
auto target = vm.argument(0);
|
||||
auto handler = vm.argument(1);
|
||||
|
||||
if (!target.is_object()) {
|
||||
interpreter.vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyConstructorBadType, "target", target.to_string_without_side_effects().characters());
|
||||
vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyConstructorBadType, "target", target.to_string_without_side_effects().characters());
|
||||
return {};
|
||||
}
|
||||
if (!handler.is_object()) {
|
||||
interpreter.vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyConstructorBadType, "handler", handler.to_string_without_side_effects().characters());
|
||||
vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyConstructorBadType, "handler", handler.to_string_without_side_effects().characters());
|
||||
return {};
|
||||
}
|
||||
return ProxyObject::create(global_object(), target.as_object(), handler.as_object());
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~ProxyConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -492,7 +492,7 @@ Value ProxyObject::call()
|
|||
return vm().call(trap.as_function(), Value(&m_handler), move(arguments));
|
||||
}
|
||||
|
||||
Value ProxyObject::construct(Interpreter& interpreter, Function& new_target)
|
||||
Value ProxyObject::construct(Function& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
if (!is_function()) {
|
||||
|
@ -507,7 +507,7 @@ Value ProxyObject::construct(Interpreter& interpreter, Function& new_target)
|
|||
if (vm.exception())
|
||||
return {};
|
||||
if (trap.is_empty() || trap.is_undefined() || trap.is_null())
|
||||
return static_cast<Function&>(m_target).construct(interpreter, new_target);
|
||||
return static_cast<Function&>(m_target).construct(new_target);
|
||||
if (!trap.is_function()) {
|
||||
vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "construct");
|
||||
return {};
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
virtual ~ProxyObject() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
virtual const FlyString& name() const override;
|
||||
virtual LexicalEnvironment* create_environment() override;
|
||||
|
||||
|
|
|
@ -50,10 +50,10 @@ RegExpConstructor::~RegExpConstructor()
|
|||
|
||||
Value RegExpConstructor::call()
|
||||
{
|
||||
return construct(interpreter(), *this);
|
||||
return construct(*this);
|
||||
}
|
||||
|
||||
Value RegExpConstructor::construct(Interpreter&, Function&)
|
||||
Value RegExpConstructor::construct(Function&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
if (!vm.argument_count())
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~RegExpConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -143,7 +143,7 @@ Value ScriptFunction::call()
|
|||
return interpreter->execute_statement(global_object(), m_body, arguments, ScopeType::Function);
|
||||
}
|
||||
|
||||
Value ScriptFunction::construct(Interpreter&, Function&)
|
||||
Value ScriptFunction::construct(Function&)
|
||||
{
|
||||
if (m_is_arrow_function) {
|
||||
vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, m_name.characters());
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
const Vector<FunctionNode::Parameter>& parameters() const { return m_parameters; };
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
virtual const FlyString& name() const override { return m_name; };
|
||||
void set_name(const FlyString& name) { m_name = name; };
|
||||
|
|
|
@ -67,7 +67,7 @@ Value StringConstructor::call()
|
|||
return string;
|
||||
}
|
||||
|
||||
Value StringConstructor::construct(Interpreter&, Function&)
|
||||
Value StringConstructor::construct(Function&)
|
||||
{
|
||||
PrimitiveString* primitive_string = nullptr;
|
||||
if (!vm().argument_count())
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~StringConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -63,9 +63,9 @@ Value SymbolConstructor::call()
|
|||
return js_symbol(heap(), vm().argument(0).to_string(global_object()), false);
|
||||
}
|
||||
|
||||
Value SymbolConstructor::construct(Interpreter& interpreter, Function&)
|
||||
Value SymbolConstructor::construct(Function&)
|
||||
{
|
||||
interpreter.vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, "Symbol");
|
||||
vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, "Symbol");
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual ~SymbolConstructor() override;
|
||||
|
||||
virtual Value call() override;
|
||||
virtual Value construct(Interpreter&, Function& new_target) override;
|
||||
virtual Value construct(Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
|
@ -220,7 +220,7 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
|
|||
// If we are a Derived constructor, |this| has not been constructed before super is called.
|
||||
Value this_value = function.constructor_kind() == Function::ConstructorKind::Base ? new_object : Value {};
|
||||
call_frame.this_value = this_value;
|
||||
auto result = function.construct(interpreter(), new_target);
|
||||
auto result = function.construct(new_target);
|
||||
|
||||
this_value = current_environment()->get_this_binding();
|
||||
pop_call_frame();
|
||||
|
|
|
@ -58,13 +58,13 @@ XMLHttpRequestConstructor::~XMLHttpRequestConstructor()
|
|||
|
||||
JS::Value XMLHttpRequestConstructor::call()
|
||||
{
|
||||
return construct(interpreter(), *this);
|
||||
return construct(*this);
|
||||
}
|
||||
|
||||
JS::Value XMLHttpRequestConstructor::construct(JS::Interpreter& interpreter, Function&)
|
||||
JS::Value XMLHttpRequestConstructor::construct(Function&)
|
||||
{
|
||||
auto& window = static_cast<WindowObject&>(global_object());
|
||||
return interpreter.heap().allocate<XMLHttpRequestWrapper>(window, window, XMLHttpRequest::create(window.impl()));
|
||||
return heap().allocate<XMLHttpRequestWrapper>(window, window, XMLHttpRequest::create(window.impl()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
virtual ~XMLHttpRequestConstructor() override;
|
||||
|
||||
virtual JS::Value call() override;
|
||||
virtual JS::Value construct(JS::Interpreter& interpreter, Function& new_target) override;
|
||||
virtual JS::Value construct(JS::Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
|
|
Loading…
Reference in a new issue