summaryrefslogtreecommitdiff
path: root/Libraries/LibJS
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-29 16:41:28 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-29 16:41:28 +0200
commit3df604ad120fe37cb137542a841a29328d03ddf7 (patch)
tree38698eeafd704718aef35eff31a419edff8d2e1f /Libraries/LibJS
parent1175ecf1dd520262dbb383decedae2cdebfbd0cc (diff)
downloadserenity-3df604ad120fe37cb137542a841a29328d03ddf7.zip
LibJS: Reduce use of Interpreter in LexicalEnvironment
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r--Libraries/LibJS/AST.cpp8
-rw-r--r--Libraries/LibJS/Interpreter.cpp2
-rw-r--r--Libraries/LibJS/Runtime/LexicalEnvironment.cpp12
-rw-r--r--Libraries/LibJS/Runtime/LexicalEnvironment.h6
-rw-r--r--Libraries/LibJS/Runtime/ScriptFunction.cpp2
-rw-r--r--Libraries/LibJS/Runtime/VM.cpp12
-rw-r--r--Libraries/LibJS/Runtime/VM.h2
7 files changed, 22 insertions, 22 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp
index 5002901df4..39485a8203 100644
--- a/Libraries/LibJS/AST.cpp
+++ b/Libraries/LibJS/AST.cpp
@@ -208,7 +208,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
if (interpreter.exception())
return {};
- interpreter.current_environment()->bind_this_value(result);
+ interpreter.current_environment()->bind_this_value(global_object, result);
} else {
result = interpreter.call(function, this_value, move(arguments));
}
@@ -761,7 +761,7 @@ Value ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& global_o
if (interpreter.exception())
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();
}
@@ -1181,9 +1181,9 @@ Value SpreadExpression::execute(Interpreter& interpreter, GlobalObject& global_o
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
diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp
index 1690be3483..119919acc0 100644
--- a/Libraries/LibJS/Interpreter.cpp
+++ b/Libraries/LibJS/Interpreter.cpp
@@ -72,7 +72,7 @@ Value Interpreter::run(GlobalObject& global_object, const Program& program)
global_call_frame.this_value = &global_object;
global_call_frame.function_name = "(global execution context)";
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())
return {};
vm().call_stack().append(move(global_call_frame));
diff --git a/Libraries/LibJS/Runtime/LexicalEnvironment.cpp b/Libraries/LibJS/Runtime/LexicalEnvironment.cpp
index 47a78e0d44..c60b444aca 100644
--- a/Libraries/LibJS/Runtime/LexicalEnvironment.cpp
+++ b/Libraries/LibJS/Runtime/LexicalEnvironment.cpp
@@ -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;
diff --git a/Libraries/LibJS/Runtime/LexicalEnvironment.h b/Libraries/LibJS/Runtime/LexicalEnvironment.h
index a6d2173f2c..8607e02917 100644
--- a/Libraries/LibJS/Runtime/LexicalEnvironment.h
+++ b/Libraries/LibJS/Runtime/LexicalEnvironment.h
@@ -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; }
diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp
index 879b9f64a3..aea79317e8 100644
--- a/Libraries/LibJS/Runtime/ScriptFunction.cpp
+++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp
@@ -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);
}
diff --git a/Libraries/LibJS/Runtime/VM.cpp b/Libraries/LibJS/Runtime/VM.cpp
index 273ba911a9..41919e2fbd 100644
--- a/Libraries/LibJS/Runtime/VM.cpp
+++ b/Libraries/LibJS/Runtime/VM.cpp
@@ -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();
diff --git a/Libraries/LibJS/Runtime/VM.h b/Libraries/LibJS/Runtime/VM.h
index 0fe2de9ef6..a602febae7 100644
--- a/Libraries/LibJS/Runtime/VM.h
+++ b/Libraries/LibJS/Runtime/VM.h
@@ -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;