1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 12:08:14 +00:00

LibJS: Reduce use of Interpreter in LexicalEnvironment

This commit is contained in:
Andreas Kling 2020-09-29 16:41:28 +02:00
parent 1175ecf1dd
commit 3df604ad12
7 changed files with 22 additions and 22 deletions

View file

@ -77,10 +77,10 @@ Optional<Variable> LexicalEnvironment::get(const FlyString& name) const
return m_variables.get(name);
}
void LexicalEnvironment::set(const FlyString& name, Variable variable)
void LexicalEnvironment::set(GlobalObject& global_object, const FlyString& name, Variable variable)
{
if (type() == EnvironmentRecordType::Global)
interpreter().global_object().put(name, variable.value);
global_object.put(name, variable.value);
else
m_variables.set(name, variable);
}
@ -114,21 +114,21 @@ bool LexicalEnvironment::has_this_binding() const
ASSERT_NOT_REACHED();
}
Value LexicalEnvironment::get_this_binding() const
Value LexicalEnvironment::get_this_binding(GlobalObject& global_object) const
{
ASSERT(has_this_binding());
if (this_binding_status() == ThisBindingStatus::Uninitialized) {
vm().throw_exception<ReferenceError>(interpreter().global_object(), ErrorType::ThisHasNotBeenInitialized);
vm().throw_exception<ReferenceError>(global_object, ErrorType::ThisHasNotBeenInitialized);
return {};
}
return m_this_value;
}
void LexicalEnvironment::bind_this_value(Value this_value)
void LexicalEnvironment::bind_this_value(GlobalObject& global_object, Value this_value)
{
ASSERT(has_this_binding());
if (m_this_binding_status == ThisBindingStatus::Initialized) {
vm().throw_exception<ReferenceError>(interpreter().global_object(), ErrorType::ThisIsAlreadyInitialized);
vm().throw_exception<ReferenceError>(global_object, ErrorType::ThisIsAlreadyInitialized);
return;
}
m_this_value = this_value;

View file

@ -63,7 +63,7 @@ public:
LexicalEnvironment* parent() const { return m_parent; }
Optional<Variable> get(const FlyString&) const;
void set(const FlyString&, Variable);
void set(GlobalObject&, const FlyString&, Variable);
void clear();
@ -75,8 +75,8 @@ public:
bool has_this_binding() const;
ThisBindingStatus this_binding_status() const { return m_this_binding_status; }
Value get_this_binding() const;
void bind_this_value(Value this_value);
Value get_this_binding(GlobalObject&) const;
void bind_this_value(GlobalObject&, Value this_value);
// Not a standard operation.
void replace_this_binding(Value this_value) { m_this_value = this_value; }

View file

@ -138,7 +138,7 @@ Value ScriptFunction::call()
}
}
arguments.append({ parameter.name, value });
vm().current_environment()->set(parameter.name, { value, DeclarationKind::Var });
vm().current_environment()->set(global_object(), parameter.name, { value, DeclarationKind::Var });
}
return interpreter->execute_statement(global_object(), m_body, arguments, ScopeType::Function);
}

View file

@ -145,7 +145,7 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
return;
}
environment->set(name, { value, possible_match.value().declaration_kind });
environment->set(global_object, name, { value, possible_match.value().declaration_kind });
return;
}
}
@ -204,7 +204,7 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
Object* new_object = nullptr;
if (function.constructor_kind() == Function::ConstructorKind::Base) {
new_object = Object::create_empty(global_object);
current_environment()->bind_this_value(new_object);
current_environment()->bind_this_value(global_object, new_object);
if (exception())
return {};
auto prototype = new_target.get("prototype");
@ -222,7 +222,7 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
call_frame.this_value = this_value;
auto result = function.construct(new_target);
this_value = current_environment()->get_this_binding();
this_value = current_environment()->get_this_binding(global_object);
pop_call_frame();
call_frame_popper.disarm();
@ -280,9 +280,9 @@ String VM::join_arguments() const
return joined_arguments.build();
}
Value VM::resolve_this_binding() const
Value VM::resolve_this_binding(GlobalObject& global_object) const
{
return get_this_environment()->get_this_binding();
return get_this_environment()->get_this_binding(global_object);
}
const LexicalEnvironment* VM::get_this_environment() const
@ -313,7 +313,7 @@ Value VM::call_internal(Function& function, Value this_value, Optional<MarkedVal
call_frame.environment = function.create_environment();
ASSERT(call_frame.environment->this_binding_status() == LexicalEnvironment::ThisBindingStatus::Uninitialized);
call_frame.environment->bind_this_value(call_frame.this_value);
call_frame.environment->bind_this_value(function.global_object(), call_frame.this_value);
auto result = function.call();
pop_call_frame();

View file

@ -203,7 +203,7 @@ public:
String join_arguments() const;
Value resolve_this_binding() const;
Value resolve_this_binding(GlobalObject&) const;
const LexicalEnvironment* get_this_environment() const;
Value get_new_target() const;