mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:28:11 +00:00
LibJS: Reduce use of Interpreter in LexicalEnvironment
This commit is contained in:
parent
1175ecf1dd
commit
3df604ad12
7 changed files with 22 additions and 22 deletions
|
@ -208,7 +208,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
interpreter.current_environment()->bind_this_value(result);
|
interpreter.current_environment()->bind_this_value(global_object, result);
|
||||||
} else {
|
} else {
|
||||||
result = interpreter.call(function, this_value, move(arguments));
|
result = interpreter.call(function, this_value, move(arguments));
|
||||||
}
|
}
|
||||||
|
@ -761,7 +761,7 @@ Value ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& global_o
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
interpreter.current_environment()->set(m_class_expression->name(), { class_constructor, DeclarationKind::Let });
|
interpreter.current_environment()->set(global_object, m_class_expression->name(), { class_constructor, DeclarationKind::Let });
|
||||||
|
|
||||||
return js_undefined();
|
return js_undefined();
|
||||||
}
|
}
|
||||||
|
@ -1181,9 +1181,9 @@ Value SpreadExpression::execute(Interpreter& interpreter, GlobalObject& global_o
|
||||||
return m_target->execute(interpreter, global_object);
|
return m_target->execute(interpreter, global_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ThisExpression::execute(Interpreter& interpreter, GlobalObject&) const
|
Value ThisExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const
|
||||||
{
|
{
|
||||||
return interpreter.vm().resolve_this_binding();
|
return interpreter.vm().resolve_this_binding(global_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThisExpression::dump(int indent) const
|
void ThisExpression::dump(int indent) const
|
||||||
|
|
|
@ -72,7 +72,7 @@ Value Interpreter::run(GlobalObject& global_object, const Program& program)
|
||||||
global_call_frame.this_value = &global_object;
|
global_call_frame.this_value = &global_object;
|
||||||
global_call_frame.function_name = "(global execution context)";
|
global_call_frame.function_name = "(global execution context)";
|
||||||
global_call_frame.environment = heap().allocate<LexicalEnvironment>(global_object, LexicalEnvironment::EnvironmentRecordType::Global);
|
global_call_frame.environment = heap().allocate<LexicalEnvironment>(global_object, LexicalEnvironment::EnvironmentRecordType::Global);
|
||||||
global_call_frame.environment->bind_this_value(&global_object);
|
global_call_frame.environment->bind_this_value(global_object, &global_object);
|
||||||
if (vm().exception())
|
if (vm().exception())
|
||||||
return {};
|
return {};
|
||||||
vm().call_stack().append(move(global_call_frame));
|
vm().call_stack().append(move(global_call_frame));
|
||||||
|
|
|
@ -77,10 +77,10 @@ Optional<Variable> LexicalEnvironment::get(const FlyString& name) const
|
||||||
return m_variables.get(name);
|
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)
|
if (type() == EnvironmentRecordType::Global)
|
||||||
interpreter().global_object().put(name, variable.value);
|
global_object.put(name, variable.value);
|
||||||
else
|
else
|
||||||
m_variables.set(name, variable);
|
m_variables.set(name, variable);
|
||||||
}
|
}
|
||||||
|
@ -114,21 +114,21 @@ bool LexicalEnvironment::has_this_binding() const
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value LexicalEnvironment::get_this_binding() const
|
Value LexicalEnvironment::get_this_binding(GlobalObject& global_object) const
|
||||||
{
|
{
|
||||||
ASSERT(has_this_binding());
|
ASSERT(has_this_binding());
|
||||||
if (this_binding_status() == ThisBindingStatus::Uninitialized) {
|
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 {};
|
||||||
}
|
}
|
||||||
return m_this_value;
|
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());
|
ASSERT(has_this_binding());
|
||||||
if (m_this_binding_status == ThisBindingStatus::Initialized) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
m_this_value = this_value;
|
m_this_value = this_value;
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
LexicalEnvironment* parent() const { return m_parent; }
|
LexicalEnvironment* parent() const { return m_parent; }
|
||||||
|
|
||||||
Optional<Variable> get(const FlyString&) const;
|
Optional<Variable> get(const FlyString&) const;
|
||||||
void set(const FlyString&, Variable);
|
void set(GlobalObject&, const FlyString&, Variable);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
@ -75,8 +75,8 @@ public:
|
||||||
|
|
||||||
bool has_this_binding() const;
|
bool has_this_binding() const;
|
||||||
ThisBindingStatus this_binding_status() const { return m_this_binding_status; }
|
ThisBindingStatus this_binding_status() const { return m_this_binding_status; }
|
||||||
Value get_this_binding() const;
|
Value get_this_binding(GlobalObject&) const;
|
||||||
void bind_this_value(Value this_value);
|
void bind_this_value(GlobalObject&, Value this_value);
|
||||||
|
|
||||||
// Not a standard operation.
|
// Not a standard operation.
|
||||||
void replace_this_binding(Value this_value) { m_this_value = this_value; }
|
void replace_this_binding(Value this_value) { m_this_value = this_value; }
|
||||||
|
|
|
@ -138,7 +138,7 @@ Value ScriptFunction::call()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arguments.append({ parameter.name, value });
|
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);
|
return interpreter->execute_statement(global_object(), m_body, arguments, ScopeType::Function);
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,7 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
environment->set(name, { value, possible_match.value().declaration_kind });
|
environment->set(global_object, name, { value, possible_match.value().declaration_kind });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
|
||||||
Object* new_object = nullptr;
|
Object* new_object = nullptr;
|
||||||
if (function.constructor_kind() == Function::ConstructorKind::Base) {
|
if (function.constructor_kind() == Function::ConstructorKind::Base) {
|
||||||
new_object = Object::create_empty(global_object);
|
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())
|
if (exception())
|
||||||
return {};
|
return {};
|
||||||
auto prototype = new_target.get("prototype");
|
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;
|
call_frame.this_value = this_value;
|
||||||
auto result = function.construct(new_target);
|
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();
|
pop_call_frame();
|
||||||
call_frame_popper.disarm();
|
call_frame_popper.disarm();
|
||||||
|
|
||||||
|
@ -280,9 +280,9 @@ String VM::join_arguments() const
|
||||||
return joined_arguments.build();
|
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
|
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();
|
call_frame.environment = function.create_environment();
|
||||||
|
|
||||||
ASSERT(call_frame.environment->this_binding_status() == LexicalEnvironment::ThisBindingStatus::Uninitialized);
|
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();
|
auto result = function.call();
|
||||||
pop_call_frame();
|
pop_call_frame();
|
||||||
|
|
|
@ -203,7 +203,7 @@ public:
|
||||||
|
|
||||||
String join_arguments() const;
|
String join_arguments() const;
|
||||||
|
|
||||||
Value resolve_this_binding() const;
|
Value resolve_this_binding(GlobalObject&) const;
|
||||||
const LexicalEnvironment* get_this_environment() const;
|
const LexicalEnvironment* get_this_environment() const;
|
||||||
Value get_new_target() const;
|
Value get_new_target() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue