summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-08-21 15:12:43 +0100
committerLinus Groh <mail@linusgroh.de>2022-08-23 13:58:30 +0100
commit275a7a0c0a2de638639e0a401c5d67fae8b9fedf (patch)
tree4bb5d1e8444e9a51835e76cb65ba065e6f466953 /Userland/Libraries/LibJS/Runtime
parenta022e548b808df91c471cb55f0245e15957e89c4 (diff)
downloadserenity-275a7a0c0a2de638639e0a401c5d67fae8b9fedf.zip
LibJS: Replace GlobalObject with VM in Environment AOs [Part 5/19]
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp28
-rw-r--r--Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp44
-rw-r--r--Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h22
-rw-r--r--Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp34
-rw-r--r--Userland/Libraries/LibJS/Runtime/Environment.h14
-rw-r--r--Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h4
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp44
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h14
-rw-r--r--Userland/Libraries/LibJS/Runtime/ModuleEnvironment.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/ModuleEnvironment.h6
-rw-r--r--Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp14
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Reference.cpp20
-rw-r--r--Userland/Libraries/LibJS/Runtime/Reference.h8
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.cpp9
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.h2
18 files changed, 158 insertions, 147 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
index a4871c14b5..6a6a289ad8 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
@@ -218,7 +218,7 @@ ThrowCompletionOr<void> initialize_bound_name(GlobalObject& global_object, FlySt
// 1. If environment is not undefined, then
if (environment) {
// a. Perform ! environment.InitializeBinding(name, value).
- MUST(environment->initialize_binding(global_object, name, value));
+ MUST(environment->initialize_binding(vm, name, value));
// b. Return unused.
return {};
@@ -897,8 +897,8 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
if (!MUST(variable_environment->has_binding(function_name))) {
// i. Perform ! varEnv.CreateMutableBinding(F, true).
// ii. Perform ! varEnv.InitializeBinding(F, undefined).
- MUST(variable_environment->create_mutable_binding(global_object, function_name, true));
- MUST(variable_environment->initialize_binding(global_object, function_name, js_undefined()));
+ MUST(variable_environment->create_mutable_binding(vm, function_name, true));
+ MUST(variable_environment->initialize_binding(vm, function_name, js_undefined()));
}
}
}
@@ -960,12 +960,12 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
// i. If IsConstantDeclaration of d is true, then
if (declaration.is_constant_declaration()) {
// 1. Perform ? lexEnv.CreateImmutableBinding(dn, true).
- TRY(lexical_environment->create_immutable_binding(global_object, name, true));
+ TRY(lexical_environment->create_immutable_binding(vm, name, true));
}
// ii. Else,
else {
// 1. Perform ? lexEnv.CreateMutableBinding(dn, false).
- TRY(lexical_environment->create_mutable_binding(global_object, name, false));
+ TRY(lexical_environment->create_mutable_binding(vm, name, false));
}
return {};
});
@@ -991,15 +991,15 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
if (!binding_exists) {
// 1. NOTE: The following invocation cannot return an abrupt completion because of the validation preceding step 14.
// 2. Perform ! varEnv.CreateMutableBinding(fn, true).
- MUST(variable_environment->create_mutable_binding(global_object, declaration.name(), true));
+ MUST(variable_environment->create_mutable_binding(vm, declaration.name(), true));
// 3. Perform ! varEnv.InitializeBinding(fn, fo).
- MUST(variable_environment->initialize_binding(global_object, declaration.name(), function));
+ MUST(variable_environment->initialize_binding(vm, declaration.name(), function));
}
// iii. Else,
else {
// 1. Perform ! varEnv.SetMutableBinding(fn, fo, false).
- MUST(variable_environment->set_mutable_binding(global_object, declaration.name(), function, false));
+ MUST(variable_environment->set_mutable_binding(vm, declaration.name(), function, false));
}
}
}
@@ -1021,10 +1021,10 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, GlobalObject& glo
if (!binding_exists) {
// 1. NOTE: The following invocation cannot return an abrupt completion because of the validation preceding step 14.
// 2. Perform ! varEnv.CreateMutableBinding(vn, true).
- MUST(variable_environment->create_mutable_binding(global_object, var_name, true));
+ MUST(variable_environment->create_mutable_binding(vm, var_name, true));
// 3. Perform ! varEnv.InitializeBinding(vn, undefined).
- MUST(variable_environment->initialize_binding(global_object, var_name, js_undefined()));
+ MUST(variable_environment->initialize_binding(vm, var_name, js_undefined()));
}
}
}
@@ -1134,11 +1134,11 @@ Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObje
// 3. Perform ! map.[[DefineOwnProperty]](! ToString(𝔽(index)), PropertyDescriptor { [[Set]]: p, [[Get]]: g, [[Enumerable]]: false, [[Configurable]]: true }).
object->parameter_map().define_native_accessor(
PropertyKey { index },
- [&environment, name](VM&, GlobalObject& global_object_getter) -> ThrowCompletionOr<Value> {
- return MUST(environment.get_binding_value(global_object_getter, name, false));
+ [&environment, name](VM& vm, GlobalObject&) -> ThrowCompletionOr<Value> {
+ return MUST(environment.get_binding_value(vm, name, false));
},
- [&environment, name](VM& vm, GlobalObject& global_object_setter) {
- MUST(environment.set_mutable_binding(global_object_setter, name, vm.argument(0), false));
+ [&environment, name](VM& vm, GlobalObject&) {
+ MUST(environment.set_mutable_binding(vm, name, vm.argument(0), false));
return js_undefined();
},
Attribute::Configurable);
diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp
index c16e16a329..616143ffae 100644
--- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp
@@ -56,7 +56,7 @@ ThrowCompletionOr<bool> DeclarativeEnvironment::has_binding(FlyString const& nam
}
// 9.1.1.1.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-declarative-environment-records-createmutablebinding-n-d
-ThrowCompletionOr<void> DeclarativeEnvironment::create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted)
+ThrowCompletionOr<void> DeclarativeEnvironment::create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted)
{
// 1. Assert: envRec does not already have a binding for N.
// NOTE: We skip this to avoid O(n) traversal of m_bindings.
@@ -76,7 +76,7 @@ ThrowCompletionOr<void> DeclarativeEnvironment::create_mutable_binding(GlobalObj
}
// 9.1.1.1.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-createimmutablebinding-n-s
-ThrowCompletionOr<void> DeclarativeEnvironment::create_immutable_binding(GlobalObject&, FlyString const& name, bool strict)
+ThrowCompletionOr<void> DeclarativeEnvironment::create_immutable_binding(VM&, FlyString const& name, bool strict)
{
// 1. Assert: envRec does not already have a binding for N.
// NOTE: We skip this to avoid O(n) traversal of m_bindings.
@@ -96,15 +96,15 @@ ThrowCompletionOr<void> DeclarativeEnvironment::create_immutable_binding(GlobalO
}
// 9.1.1.1.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-declarative-environment-records-initializebinding-n-v
-ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding(GlobalObject& global_object, FlyString const& name, Value value)
+ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding(VM& vm, FlyString const& name, Value value)
{
auto index = find_binding_index(name);
VERIFY(index.has_value());
- return initialize_binding_direct(global_object, *index, value);
+ return initialize_binding_direct(vm, *index, value);
}
-ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding_direct(GlobalObject&, size_t index, Value value)
+ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding_direct(VM&, size_t index, Value value)
{
auto& binding = m_bindings[index];
@@ -122,63 +122,63 @@ ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding_direct(Global
}
// 9.1.1.1.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-setmutablebinding-n-v-s
-ThrowCompletionOr<void> DeclarativeEnvironment::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict)
+ThrowCompletionOr<void> DeclarativeEnvironment::set_mutable_binding(VM& vm, FlyString const& name, Value value, bool strict)
{
// 1. If envRec does not have a binding for N, then
auto index = find_binding_index(name);
if (!index.has_value()) {
// a. If S is true, throw a ReferenceError exception.
if (strict)
- return vm().throw_completion<ReferenceError>(ErrorType::UnknownIdentifier, name);
+ return vm.throw_completion<ReferenceError>(ErrorType::UnknownIdentifier, name);
// b. Perform ! envRec.CreateMutableBinding(N, true).
- MUST(create_mutable_binding(global_object, name, true));
+ MUST(create_mutable_binding(vm, name, true));
// c. Perform ! envRec.InitializeBinding(N, V).
- MUST(initialize_binding(global_object, name, value));
+ MUST(initialize_binding(vm, name, value));
// d. Return unused.
return {};
}
// 2-5. (extracted into a non-standard function below)
- TRY(set_mutable_binding_direct(global_object, *index, value, strict));
+ TRY(set_mutable_binding_direct(vm, *index, value, strict));
// 6. Return unused.
return {};
}
-ThrowCompletionOr<void> DeclarativeEnvironment::set_mutable_binding_direct(GlobalObject&, size_t index, Value value, bool strict)
+ThrowCompletionOr<void> DeclarativeEnvironment::set_mutable_binding_direct(VM& vm, size_t index, Value value, bool strict)
{
auto& binding = m_bindings[index];
if (binding.strict)
strict = true;
if (!binding.initialized)
- return vm().throw_completion<ReferenceError>(ErrorType::BindingNotInitialized, binding.name);
+ return vm.throw_completion<ReferenceError>(ErrorType::BindingNotInitialized, binding.name);
if (binding.mutable_) {
binding.value = value;
} else {
if (strict)
- return vm().throw_completion<TypeError>(ErrorType::InvalidAssignToConst);
+ return vm.throw_completion<TypeError>(ErrorType::InvalidAssignToConst);
}
return {};
}
// 9.1.1.1.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-getbindingvalue-n-s
-ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value(GlobalObject& global_object, FlyString const& name, bool strict)
+ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value(VM& vm, FlyString const& name, bool strict)
{
// 1. Assert: envRec has a binding for N.
auto index = find_binding_index(name);
VERIFY(index.has_value());
// 2-3. (extracted into a non-standard function below)
- return get_binding_value_direct(global_object, *index, strict);
+ return get_binding_value_direct(vm, *index, strict);
}
-ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value_direct(GlobalObject&, size_t index, bool)
+ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value_direct(VM&, size_t index, bool)
{
auto& binding = m_bindings[index];
@@ -191,7 +191,7 @@ ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value_direct(Global
}
// 9.1.1.1.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-declarative-environment-records-deletebinding-n
-ThrowCompletionOr<bool> DeclarativeEnvironment::delete_binding(GlobalObject&, FlyString const& name)
+ThrowCompletionOr<bool> DeclarativeEnvironment::delete_binding(VM&, FlyString const& name)
{
// 1. Assert: envRec has a binding for the name that is the value of N.
auto index = find_binding_index(name);
@@ -211,21 +211,21 @@ ThrowCompletionOr<bool> DeclarativeEnvironment::delete_binding(GlobalObject&, Fl
return true;
}
-ThrowCompletionOr<void> DeclarativeEnvironment::initialize_or_set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value)
+ThrowCompletionOr<void> DeclarativeEnvironment::initialize_or_set_mutable_binding(VM& vm, FlyString const& name, Value value)
{
auto index = find_binding_index(name);
VERIFY(index.has_value());
auto& binding = m_bindings[*index];
if (!binding.initialized)
- TRY(initialize_binding(global_object, name, value));
+ TRY(initialize_binding(vm, name, value));
else
- TRY(set_mutable_binding(global_object, name, value, false));
+ TRY(set_mutable_binding(vm, name, value, false));
return {};
}
-void DeclarativeEnvironment::initialize_or_set_mutable_binding(Badge<ScopeNode>, GlobalObject& global_object, FlyString const& name, Value value)
+void DeclarativeEnvironment::initialize_or_set_mutable_binding(Badge<ScopeNode>, VM& vm, FlyString const& name, Value value)
{
- MUST(initialize_or_set_mutable_binding(global_object, name, value));
+ MUST(initialize_or_set_mutable_binding(vm, name, value));
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h
index 53ff5a7a5d..8191663aba 100644
--- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h
+++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h
@@ -35,15 +35,15 @@ public:
virtual ~DeclarativeEnvironment() override = default;
virtual ThrowCompletionOr<bool> has_binding(FlyString const& name, Optional<size_t>* = nullptr) const override;
- virtual ThrowCompletionOr<void> create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted) override;
- virtual ThrowCompletionOr<void> create_immutable_binding(GlobalObject&, FlyString const& name, bool strict) override;
- virtual ThrowCompletionOr<void> initialize_binding(GlobalObject&, FlyString const& name, Value) override;
- virtual ThrowCompletionOr<void> set_mutable_binding(GlobalObject&, FlyString const& name, Value, bool strict) override;
- virtual ThrowCompletionOr<Value> get_binding_value(GlobalObject&, FlyString const& name, bool strict) override;
- virtual ThrowCompletionOr<bool> delete_binding(GlobalObject&, FlyString const& name) override;
+ virtual ThrowCompletionOr<void> create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted) override;
+ virtual ThrowCompletionOr<void> create_immutable_binding(VM&, FlyString const& name, bool strict) override;
+ virtual ThrowCompletionOr<void> initialize_binding(VM&, FlyString const& name, Value) override;
+ virtual ThrowCompletionOr<void> set_mutable_binding(VM&, FlyString const& name, Value, bool strict) override;
+ virtual ThrowCompletionOr<Value> get_binding_value(VM&, FlyString const& name, bool strict) override;
+ virtual ThrowCompletionOr<bool> delete_binding(VM&, FlyString const& name) override;
- void initialize_or_set_mutable_binding(Badge<ScopeNode>, GlobalObject& global_object, FlyString const& name, Value value);
- ThrowCompletionOr<void> initialize_or_set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value);
+ void initialize_or_set_mutable_binding(Badge<ScopeNode>, VM&, FlyString const& name, Value value);
+ ThrowCompletionOr<void> initialize_or_set_mutable_binding(VM&, FlyString const& name, Value value);
// This is not a method defined in the spec! Do not use this in any LibJS (or other spec related) code.
[[nodiscard]] Vector<FlyString> bindings() const
@@ -57,9 +57,9 @@ public:
return names;
}
- ThrowCompletionOr<void> initialize_binding_direct(GlobalObject&, size_t index, Value);
- ThrowCompletionOr<Value> get_binding_value_direct(GlobalObject&, size_t index, bool strict);
- ThrowCompletionOr<void> set_mutable_binding_direct(GlobalObject&, size_t index, Value, bool strict);
+ ThrowCompletionOr<void> initialize_binding_direct(VM&, size_t index, Value);
+ ThrowCompletionOr<Value> get_binding_value_direct(VM&, size_t index, bool strict);
+ ThrowCompletionOr<void> set_mutable_binding_direct(VM&, size_t index, Value, bool strict);
protected:
virtual void visit_edges(Visitor&) override;
diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
index 8041a8bb21..c1fcfef03a 100644
--- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
@@ -283,7 +283,7 @@ ThrowCompletionOr<Object*> ECMAScriptFunctionObject::internal_construct(MarkedVe
}
// 12. Let thisBinding be ? constructorEnv.GetThisBinding().
- auto this_binding = TRY(constructor_env->get_this_binding(global_object));
+ auto this_binding = TRY(constructor_env->get_this_binding(vm));
// 13. Assert: Type(thisBinding) is Object.
VERIFY(this_binding.is_object());
@@ -401,9 +401,9 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
if (MUST(environment->has_binding(parameter_name)))
continue;
- MUST(environment->create_mutable_binding(global_object, parameter_name, false));
+ MUST(environment->create_mutable_binding(vm, parameter_name, false));
if (has_duplicates)
- MUST(environment->initialize_binding(global_object, parameter_name, js_undefined()));
+ MUST(environment->initialize_binding(vm, parameter_name, js_undefined()));
}
if (arguments_object_needed) {
@@ -414,11 +414,11 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
arguments_object = create_mapped_arguments_object(global_object, *this, formal_parameters(), vm.running_execution_context().arguments, *environment);
if (is_strict_mode())
- MUST(environment->create_immutable_binding(global_object, vm.names.arguments.as_string(), false));
+ MUST(environment->create_immutable_binding(vm, vm.names.arguments.as_string(), false));
else
- MUST(environment->create_mutable_binding(global_object, vm.names.arguments.as_string(), false));
+ MUST(environment->create_mutable_binding(vm, vm.names.arguments.as_string(), false));
- MUST(environment->initialize_binding(global_object, vm.names.arguments.as_string(), arguments_object));
+ MUST(environment->initialize_binding(vm, vm.names.arguments.as_string(), arguments_object));
parameter_names.set(vm.names.arguments.as_string());
}
@@ -483,8 +483,8 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
if (scope_body) {
scope_body->for_each_var_declared_name([&](auto const& name) {
if (!parameter_names.contains(name) && instantiated_var_names.set(name) == AK::HashSetResult::InsertedNewEntry) {
- MUST(environment->create_mutable_binding(global_object, name, false));
- MUST(environment->initialize_binding(global_object, name, js_undefined()));
+ MUST(environment->create_mutable_binding(vm, name, false));
+ MUST(environment->initialize_binding(vm, name, js_undefined()));
}
});
}
@@ -497,15 +497,15 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
scope_body->for_each_var_declared_name([&](auto const& name) {
if (instantiated_var_names.set(name) != AK::HashSetResult::InsertedNewEntry)
return;
- MUST(var_environment->create_mutable_binding(global_object, name, false));
+ MUST(var_environment->create_mutable_binding(vm, name, false));
Value initial_value;
if (!parameter_names.contains(name) || function_names.contains(name))
initial_value = js_undefined();
else
- initial_value = MUST(environment->get_binding_value(global_object, name, false));
+ initial_value = MUST(environment->get_binding_value(vm, name, false));
- MUST(var_environment->initialize_binding(global_object, name, initial_value));
+ MUST(var_environment->initialize_binding(vm, name, initial_value));
});
}
}
@@ -518,8 +518,8 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
return;
// The spec says 'initializedBindings' here but that does not exist and it then adds it to 'instantiatedVarNames' so it probably means 'instantiatedVarNames'.
if (!instantiated_var_names.contains(function_name) && function_name != vm.names.arguments.as_string()) {
- MUST(var_environment->create_mutable_binding(global_object, function_name, false));
- MUST(var_environment->initialize_binding(global_object, function_name, js_undefined()));
+ MUST(var_environment->create_mutable_binding(vm, function_name, false));
+ MUST(var_environment->initialize_binding(vm, function_name, js_undefined()));
instantiated_var_names.set(function_name);
}
@@ -560,9 +560,9 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
scope_body->for_each_lexically_scoped_declaration([&](Declaration const& declaration) {
declaration.for_each_bound_name([&](auto const& name) {
if (declaration.is_constant_declaration())
- MUST(lex_environment->create_immutable_binding(global_object, name, true));
+ MUST(lex_environment->create_immutable_binding(vm, name, true));
else
- MUST(lex_environment->create_mutable_binding(global_object, name, false));
+ MUST(lex_environment->create_mutable_binding(vm, name, false));
});
});
}
@@ -570,7 +570,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
auto* private_environment = callee_context.private_environment;
for (auto& declaration : functions_to_initialize) {
auto* function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), lex_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object(), declaration.contains_direct_call_to_eval());
- MUST(var_environment->set_mutable_binding(global_object, declaration.name(), function, false));
+ MUST(var_environment->set_mutable_binding(vm, declaration.name(), function, false));
}
return {};
@@ -692,7 +692,7 @@ void ECMAScriptFunctionObject::ordinary_call_bind_this(ExecutionContext& callee_
// 7. Assert: localEnv is a function Environment Record.
// 8. Assert: The next step never returns an abrupt completion because localEnv.[[ThisBindingStatus]] is not initialized.
// 9. Perform ! localEnv.BindThisValue(thisValue).
- MUST(verify_cast<FunctionEnvironment>(local_env)->bind_this_value(global_object(), this_value));
+ MUST(verify_cast<FunctionEnvironment>(local_env)->bind_this_value(vm, this_value));
// 10. Return unused.
}
diff --git a/Userland/Libraries/LibJS/Runtime/Environment.h b/Userland/Libraries/LibJS/Runtime/Environment.h
index 3fbc9643c3..6ff74a4a74 100644
--- a/Userland/Libraries/LibJS/Runtime/Environment.h
+++ b/Userland/Libraries/LibJS/Runtime/Environment.h
@@ -25,17 +25,17 @@ public: \
class Environment : public Cell {
public:
virtual bool has_this_binding() const { return false; }
- virtual ThrowCompletionOr<Value> get_this_binding(GlobalObject&) const { return Value {}; }
+ virtual ThrowCompletionOr<Value> get_this_binding(VM&) const { return Value {}; }
virtual Object* with_base_object() const { return nullptr; }
virtual ThrowCompletionOr<bool> has_binding([[maybe_unused]] FlyString const& name, [[maybe_unused]] Optional<size_t>* out_index = nullptr) const { return false; }
- virtual ThrowCompletionOr<void> create_mutable_binding(GlobalObject&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool can_be_deleted) { return {}; }
- virtual ThrowCompletionOr<void> create_immutable_binding(GlobalObject&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool strict) { return {}; }
- virtual ThrowCompletionOr<void> initialize_binding(GlobalObject&, [[maybe_unused]] FlyString const& name, Value) { return {}; }
- virtual ThrowCompletionOr<void> set_mutable_binding(GlobalObject&, [[maybe_unused]] FlyString const& name, Value, [[maybe_unused]] bool strict) { return {}; }
- virtual ThrowCompletionOr<Value> get_binding_value(GlobalObject&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool strict) { return Value {}; }
- virtual ThrowCompletionOr<bool> delete_binding(GlobalObject&, [[maybe_unused]] FlyString const& name) { return false; }
+ virtual ThrowCompletionOr<void> create_mutable_binding(VM&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool can_be_deleted) { return {}; }
+ virtual ThrowCompletionOr<void> create_immutable_binding(VM&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool strict) { return {}; }
+ virtual ThrowCompletionOr<void> initialize_binding(VM&, [[maybe_unused]] FlyString const& name, Value) { return {}; }
+ virtual ThrowCompletionOr<void> set_mutable_binding(VM&, [[maybe_unused]] FlyString const& name, Value, [[maybe_unused]] bool strict) { return {}; }
+ virtual ThrowCompletionOr<Value> get_binding_value(VM&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool strict) { return Value {}; }
+ virtual ThrowCompletionOr<bool> delete_binding(VM&, [[maybe_unused]] FlyString const& name) { return false; }
// [[OuterEnv]]
Environment* outer_environment() { return m_outer_environment; }
diff --git a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp
index e212a2aa58..1383383885 100644
--- a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp
+++ b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp
@@ -61,21 +61,21 @@ bool FunctionEnvironment::has_super_binding() const
}
// 9.1.1.3.4 GetThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-getthisbinding
-ThrowCompletionOr<Value> FunctionEnvironment::get_this_binding(GlobalObject&) const
+ThrowCompletionOr<Value> FunctionEnvironment::get_this_binding(VM& vm) const
{
// 1. Assert: envRec.[[ThisBindingStatus]] is not lexical.
VERIFY(m_this_binding_status != ThisBindingStatus::Lexical);
// 2. If envRec.[[ThisBindingStatus]] is uninitialized, throw a ReferenceError exception.
if (m_this_binding_status == ThisBindingStatus::Uninitialized)
- return vm().throw_completion<ReferenceError>(ErrorType::ThisHasNotBeenInitialized);
+ return vm.throw_completion<ReferenceError>(ErrorType::ThisHasNotBeenInitialized);
// 3. Return envRec.[[ThisValue]].
return m_this_value;
}
// 9.1.1.3.1 BindThisValue ( V ), https://tc39.es/ecma262/#sec-bindthisvalue
-ThrowCompletionOr<Value> FunctionEnvironment::bind_this_value(GlobalObject&, Value this_value)
+ThrowCompletionOr<Value> FunctionEnvironment::bind_this_value(VM& vm, Value this_value)
{
VERIFY(!this_value.is_empty());
@@ -84,7 +84,7 @@ ThrowCompletionOr<Value> FunctionEnvironment::bind_this_value(GlobalObject&, Val
// 2. If envRec.[[ThisBindingStatus]] is initialized, throw a ReferenceError exception.
if (m_this_binding_status == ThisBindingStatus::Initialized)
- return vm().throw_completion<ReferenceError>(ErrorType::ThisIsAlreadyInitialized);
+ return vm.throw_completion<ReferenceError>(ErrorType::ThisIsAlreadyInitialized);
// 3. Set envRec.[[ThisValue]] to V.
m_this_value = this_value;
diff --git a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h
index 2879851a3c..8501a75239 100644
--- a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h
+++ b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h
@@ -43,8 +43,8 @@ public:
ThrowCompletionOr<Value> get_super_base() const;
bool has_super_binding() const;
virtual bool has_this_binding() const override;
- virtual ThrowCompletionOr<Value> get_this_binding(GlobalObject&) const override;
- ThrowCompletionOr<Value> bind_this_value(GlobalObject&, Value);
+ virtual ThrowCompletionOr<Value> get_this_binding(VM&) const override;
+ ThrowCompletionOr<Value> bind_this_value(VM&, Value);
private:
virtual bool is_function_environment() const override { return true; }
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp
index 7fbb21e3ff..797c252f2d 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp
@@ -32,7 +32,7 @@ void GlobalEnvironment::visit_edges(Cell::Visitor& visitor)
}
// 9.1.1.4.11 GetThisBinding ( ), https://tc39.es/ecma262/#sec-global-environment-records-getthisbinding
-ThrowCompletionOr<Value> GlobalEnvironment::get_this_binding(GlobalObject&) const
+ThrowCompletionOr<Value> GlobalEnvironment::get_this_binding(VM&) const
{
// 1. Return envRec.[[GlobalThisValue]].
return m_global_this_value;
@@ -52,83 +52,83 @@ ThrowCompletionOr<bool> GlobalEnvironment::has_binding(FlyString const& name, Op
}
// 9.1.1.4.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-global-environment-records-createmutablebinding-n-d
-ThrowCompletionOr<void> GlobalEnvironment::create_mutable_binding(GlobalObject& global_object, FlyString const& name, bool can_be_deleted)
+ThrowCompletionOr<void> GlobalEnvironment::create_mutable_binding(VM& vm, FlyString const& name, bool can_be_deleted)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, throw a TypeError exception.
if (MUST(m_declarative_record->has_binding(name)))
- return vm().throw_completion<TypeError>(ErrorType::GlobalEnvironmentAlreadyHasBinding, name);
+ return vm.throw_completion<TypeError>(ErrorType::GlobalEnvironmentAlreadyHasBinding, name);
// 3. Return ! DclRec.CreateMutableBinding(N, D).
- return MUST(m_declarative_record->create_mutable_binding(global_object, name, can_be_deleted));
+ return MUST(m_declarative_record->create_mutable_binding(vm, name, can_be_deleted));
}
// 9.1.1.4.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-global-environment-records-createimmutablebinding-n-s
-ThrowCompletionOr<void> GlobalEnvironment::create_immutable_binding(GlobalObject& global_object, FlyString const& name, bool strict)
+ThrowCompletionOr<void> GlobalEnvironment::create_immutable_binding(VM& vm, FlyString const& name, bool strict)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, throw a TypeError exception.
if (MUST(m_declarative_record->has_binding(name)))
- return vm().throw_completion<TypeError>(ErrorType::GlobalEnvironmentAlreadyHasBinding, name);
+ return vm.throw_completion<TypeError>(ErrorType::GlobalEnvironmentAlreadyHasBinding, name);
// 3. Return ! DclRec.CreateImmutableBinding(N, S).
- return MUST(m_declarative_record->create_immutable_binding(global_object, name, strict));
+ return MUST(m_declarative_record->create_immutable_binding(vm, name, strict));
}
// 9.1.1.4.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-global-environment-records-initializebinding-n-v
-ThrowCompletionOr<void> GlobalEnvironment::initialize_binding(GlobalObject& global_object, FlyString const& name, Value value)
+ThrowCompletionOr<void> GlobalEnvironment::initialize_binding(VM& vm, FlyString const& name, Value value)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, then
if (MUST(m_declarative_record->has_binding(name))) {
// a. Return ! DclRec.InitializeBinding(N, V).
- return MUST(m_declarative_record->initialize_binding(global_object, name, value));
+ return MUST(m_declarative_record->initialize_binding(vm, name, value));
}
// 3. Assert: If the binding exists, it must be in the object Environment Record.
// 4. Let ObjRec be envRec.[[ObjectRecord]].
// 5. Return ? ObjRec.InitializeBinding(N, V).
- return m_object_record->initialize_binding(global_object, name, value);
+ return m_object_record->initialize_binding(vm, name, value);
}
// 9.1.1.4.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-global-environment-records-setmutablebinding-n-v-s
-ThrowCompletionOr<void> GlobalEnvironment::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict)
+ThrowCompletionOr<void> GlobalEnvironment::set_mutable_binding(VM& vm, FlyString const& name, Value value, bool strict)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, then
if (MUST(m_declarative_record->has_binding(name))) {
// a. Return ? DclRec.SetMutableBinding(N, V, S).
- return m_declarative_record->set_mutable_binding(global_object, name, value, strict);
+ return m_declarative_record->set_mutable_binding(vm, name, value, strict);
}
// 3. Let ObjRec be envRec.[[ObjectRecord]].
// 4. Return ? ObjRec.SetMutableBinding(N, V, S).
- return m_object_record->set_mutable_binding(global_object, name, value, strict);
+ return m_object_record->set_mutable_binding(vm, name, value, strict);
}
// 9.1.1.4.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-global-environment-records-getbindingvalue-n-s
-ThrowCompletionOr<Value> GlobalEnvironment::get_binding_value(GlobalObject& global_object, FlyString const& name, bool strict)
+ThrowCompletionOr<Value> GlobalEnvironment::get_binding_value(VM& vm, FlyString const& name, bool strict)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, then
if (MUST(m_declarative_record->has_binding(name))) {
// a. Return ? DclRec.GetBindingValue(N, S).
- return m_declarative_record->get_binding_value(global_object, name, strict);
+ return m_declarative_record->get_binding_value(vm, name, strict);
}
// 3. Let ObjRec be envRec.[[ObjectRecord]].
// 4. Return ? ObjRec.GetBindingValue(N, S).
- return m_object_record->get_binding_value(global_object, name, strict);
+ return m_object_record->get_binding_value(vm, name, strict);
}
// 9.1.1.4.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-deletebinding-n
-ThrowCompletionOr<bool> GlobalEnvironment::delete_binding(GlobalObject& global_object, FlyString const& name)
+ThrowCompletionOr<bool> GlobalEnvironment::delete_binding(VM& vm, FlyString const& name)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, then
if (MUST(m_declarative_record->has_binding(name))) {
// a. Return ! DclRec.DeleteBinding(N).
- return MUST(m_declarative_record->delete_binding(global_object, name));
+ return MUST(m_declarative_record->delete_binding(vm, name));
}
// 3. Let ObjRec be envRec.[[ObjectRecord]].
@@ -140,7 +140,7 @@ ThrowCompletionOr<bool> GlobalEnvironment::delete_binding(GlobalObject& global_o
// 6. If existingProp is true, then
if (existing_prop) {
// a. Let status be ? ObjRec.DeleteBinding(N).
- bool status = TRY(m_object_record->delete_binding(global_object, name));
+ bool status = TRY(m_object_record->delete_binding(vm, name));
// b. If status is true, then
if (status) {
@@ -243,6 +243,8 @@ ThrowCompletionOr<bool> GlobalEnvironment::can_declare_global_function(FlyString
// 9.1.1.4.17 CreateGlobalVarBinding ( N, D ), https://tc39.es/ecma262/#sec-createglobalvarbinding
ThrowCompletionOr<void> GlobalEnvironment::create_global_var_binding(FlyString const& name, bool can_be_deleted)
{
+ auto& vm = this->vm();
+
// 1. Let ObjRec be envRec.[[ObjectRecord]].
// 2. Let globalObject be ObjRec.[[BindingObject]].
auto& global_object = verify_cast<GlobalObject>(m_object_record->binding_object());
@@ -256,10 +258,10 @@ ThrowCompletionOr<void> GlobalEnvironment::create_global_var_binding(FlyString c
// 5. If hasProperty is false and extensible is true, then
if (!has_property && extensible) {
// a. Perform ? ObjRec.CreateMutableBinding(N, D).
- TRY(m_object_record->create_mutable_binding(global_object, name, can_be_deleted));
+ TRY(m_object_record->create_mutable_binding(vm, name, can_be_deleted));
// b. Perform ? ObjRec.InitializeBinding(N, undefined).
- TRY(m_object_record->initialize_binding(global_object, name, js_undefined()));
+ TRY(m_object_record->initialize_binding(vm, name, js_undefined()));
}
// 6. Let varDeclaredNames be envRec.[[VarNames]].
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h
index 51a20f7b2b..08e1557766 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h
+++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h
@@ -17,15 +17,15 @@ public:
GlobalEnvironment(GlobalObject&, Object& this_value);
virtual bool has_this_binding() const final { return true; }
- virtual ThrowCompletionOr<Value> get_this_binding(GlobalObject&) const final;
+ virtual ThrowCompletionOr<Value> get_this_binding(VM&) const final;
virtual ThrowCompletionOr<bool> has_binding(FlyString const& name, Optional<size_t>* = nullptr) const override;
- virtual ThrowCompletionOr<void> create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted) override;
- virtual ThrowCompletionOr<void> create_immutable_binding(GlobalObject&, FlyString const& name, bool strict) override;
- virtual ThrowCompletionOr<void> initialize_binding(GlobalObject&, FlyString const& name, Value) override;
- virtual ThrowCompletionOr<void> set_mutable_binding(GlobalObject&, FlyString const& name, Value, bool strict) override;
- virtual ThrowCompletionOr<Value> get_binding_value(GlobalObject&, FlyString const& name, bool strict) override;
- virtual ThrowCompletionOr<bool> delete_binding(GlobalObject&, FlyString const& name) override;
+ virtual ThrowCompletionOr<void> create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted) override;
+ virtual ThrowCompletionOr<void> create_immutable_binding(VM&, FlyString const& name, bool strict) override;
+ virtual ThrowCompletionOr<void> initialize_binding(VM&, FlyString const& name, Value) override;
+ virtual ThrowCompletionOr<void> set_mutable_binding(VM&, FlyString const& name, Value, bool strict) override;
+ virtual ThrowCompletionOr<Value> get_binding_value(VM&, FlyString const& name, bool strict) override;
+ virtual ThrowCompletionOr<bool> delete_binding(VM&, FlyString const& name) override;
ObjectEnvironment& object_record() { return *m_object_record; }
Object& global_this_value() { return *m_global_this_value; }
diff --git a/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.cpp
index 8620c15fd2..47d4d1ddb8 100644
--- a/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.cpp
@@ -18,7 +18,7 @@ ModuleEnvironment::ModuleEnvironment(Environment* outer_environment)
}
// 9.1.1.5.1 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-module-environment-records-getbindingvalue-n-s
-ThrowCompletionOr<Value> ModuleEnvironment::get_binding_value(GlobalObject& global_object, FlyString const& name, bool strict)
+ThrowCompletionOr<Value> ModuleEnvironment::get_binding_value(VM& vm, FlyString const& name, bool strict)
{
// 1. Assert: S is true.
VERIFY(strict);
@@ -36,16 +36,16 @@ ThrowCompletionOr<Value> ModuleEnvironment::get_binding_value(GlobalObject& glob
// c. If targetEnv is empty, throw a ReferenceError exception.
if (!target_env)
- return vm().throw_completion<ReferenceError>(ErrorType::ModuleNoEnvironment);
+ return vm.throw_completion<ReferenceError>(ErrorType::ModuleNoEnvironment);
// d. Return ? targetEnv.GetBindingValue(N2, true).
- return target_env->get_binding_value(global_object, indirect_binding->binding_name, true);
+ return target_env->get_binding_value(vm, indirect_binding->binding_name, true);
}
// 4. If the binding for N in envRec is an uninitialized binding, throw a ReferenceError exception.
// 5. Return the value currently bound to N in envRec.
// Note: Step 4 & 5 are the steps performed by declarative environment GetBindingValue
- return DeclarativeEnvironment::get_binding_value(global_object, name, strict);
+ return DeclarativeEnvironment::get_binding_value(vm, name, strict);
}
// Not defined in the spec, see comment in the header.
@@ -60,14 +60,14 @@ ThrowCompletionOr<bool> ModuleEnvironment::has_binding(FlyString const& name, Op
}
// 9.1.1.5.2 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-module-environment-records-deletebinding-n
-ThrowCompletionOr<bool> ModuleEnvironment::delete_binding(GlobalObject&, FlyString const&)
+ThrowCompletionOr<bool> ModuleEnvironment::delete_binding(VM&, FlyString const&)
{
// The DeleteBinding concrete method of a module Environment Record is never used within this specification.
VERIFY_NOT_REACHED();
}
// 9.1.1.5.4 GetThisBinding ( ), https://tc39.es/ecma262/#sec-module-environment-records-getthisbinding
-ThrowCompletionOr<Value> ModuleEnvironment::get_this_binding(GlobalObject&) const
+ThrowCompletionOr<Value> ModuleEnvironment::get_this_binding(VM&) const
{
// 1. Return undefined.
return js_undefined();
diff --git a/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.h b/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.h
index 67473443a8..8670a915df 100644
--- a/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.h
+++ b/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.h
@@ -23,10 +23,10 @@ public:
// in Table 18 and share the same specifications for all of those methods except for
// GetBindingValue, DeleteBinding, HasThisBinding and GetThisBinding.
// In addition, module Environment Records support the methods listed in Table 24.
- virtual ThrowCompletionOr<Value> get_binding_value(GlobalObject&, FlyString const& name, bool strict) override;
- virtual ThrowCompletionOr<bool> delete_binding(GlobalObject&, FlyString const& name) override;
+ virtual ThrowCompletionOr<Value> get_binding_value(VM&, FlyString const& name, bool strict) override;
+ virtual ThrowCompletionOr<bool> delete_binding(VM&, FlyString const& name) override;
virtual bool has_this_binding() const final { return true; }
- virtual ThrowCompletionOr<Value> get_this_binding(GlobalObject&) const final;
+ virtual ThrowCompletionOr<Value> get_this_binding(VM&) const final;
ThrowCompletionOr<void> create_import_binding(FlyString name, Module* module, FlyString binding_name);
// Note: Although the spec does not explicitly say this we also have to implement HasBinding as
diff --git a/Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp b/Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp
index a54ebbd9bb..efab770e2f 100644
--- a/Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp
@@ -136,6 +136,8 @@ ThrowCompletionOr<bool> ModuleNamespaceObject::internal_has_property(PropertyKey
// 10.4.6.8 [[Get]] ( P, Receiver ), https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-get-p-receiver
ThrowCompletionOr<Value> ModuleNamespaceObject::internal_get(PropertyKey const& property_key, Value receiver) const
{
+ auto& vm = this->vm();
+
// 1. If Type(P) is Symbol, then
if (property_key.is_symbol()) {
// a. Return ! OrdinaryGet(O, P, Receiver).
@@ -150,7 +152,7 @@ ThrowCompletionOr<Value> ModuleNamespaceObject::internal_get(PropertyKey const&
// 4. Let m be O.[[Module]].
// 5. Let binding be ! m.ResolveExport(P).
- auto binding = MUST(m_module->resolve_export(vm(), property_key.to_string()));
+ auto binding = MUST(m_module->resolve_export(vm, property_key.to_string()));
// 6. Assert: binding is a ResolvedBinding Record.
VERIFY(binding.is_valid());
@@ -164,7 +166,7 @@ ThrowCompletionOr<Value> ModuleNamespaceObject::internal_get(PropertyKey const&
// 9. If binding.[[BindingName]] is namespace, then
if (binding.is_namespace()) {
// a. Return ? GetModuleNamespace(targetModule).
- return TRY(target_module->get_module_namespace(vm()));
+ return TRY(target_module->get_module_namespace(vm));
}
// 10. Let targetEnv be targetModule.[[Environment]].
@@ -172,10 +174,10 @@ ThrowCompletionOr<Value> ModuleNamespaceObject::internal_get(PropertyKey const&
// 11. If targetEnv is empty, throw a ReferenceError exception.
if (!target_environment)
- return vm().throw_completion<ReferenceError>(ErrorType::ModuleNoEnvironment);
+ return vm.throw_completion<ReferenceError>(ErrorType::ModuleNoEnvironment);
// 12. Return ? targetEnv.GetBindingValue(binding.[[BindingName]], true).
- return target_environment->get_binding_value(global_object(), binding.export_name, true);
+ return target_environment->get_binding_value(vm, binding.export_name, true);
}
// 10.4.6.9 [[Set]] ( P, V, Receiver ), https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-set-p-v-receiver
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp
index f629b70eea..10fa8722c8 100644
--- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp
@@ -60,7 +60,7 @@ ThrowCompletionOr<bool> ObjectEnvironment::has_binding(FlyString const& name, Op
}
// 9.1.1.2.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-object-environment-records-createmutablebinding-n-d
-ThrowCompletionOr<void> ObjectEnvironment::create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted)
+ThrowCompletionOr<void> ObjectEnvironment::create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted)
{
// 1. Let bindingObject be envRec.[[BindingObject]].
// 2. Perform ? DefinePropertyOrThrow(bindingObject, N, PropertyDescriptor { [[Value]]: undefined, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: D }).
@@ -71,24 +71,24 @@ ThrowCompletionOr<void> ObjectEnvironment::create_mutable_binding(GlobalObject&,
}
// 9.1.1.2.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-createimmutablebinding-n-s
-ThrowCompletionOr<void> ObjectEnvironment::create_immutable_binding(GlobalObject&, FlyString const&, bool)
+ThrowCompletionOr<void> ObjectEnvironment::create_immutable_binding(VM&, FlyString const&, bool)
{
// "The CreateImmutableBinding concrete method of an object Environment Record is never used within this specification."
VERIFY_NOT_REACHED();
}
// 9.1.1.2.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-object-environment-records-initializebinding-n-v
-ThrowCompletionOr<void> ObjectEnvironment::initialize_binding(GlobalObject& global_object, FlyString const& name, Value value)
+ThrowCompletionOr<void> ObjectEnvironment::initialize_binding(VM& vm, FlyString const& name, Value value)
{
// 1. Perform ? envRec.SetMutableBinding(N, V, false).
- TRY(set_mutable_binding(global_object, name, value, false));
+ TRY(set_mutable_binding(vm, name, value, false));
// 2. Return unused.
return {};
}
// 9.1.1.2.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-object-environment-records-setmutablebinding-n-v-s
-ThrowCompletionOr<void> ObjectEnvironment::set_mutable_binding(GlobalObject&, FlyString const& name, Value value, bool strict)
+ThrowCompletionOr<void> ObjectEnvironment::set_mutable_binding(VM&, FlyString const& name, Value value, bool strict)
{
auto& vm = this->vm();
@@ -123,7 +123,7 @@ ThrowCompletionOr<void> ObjectEnvironment::set_mutable_binding(GlobalObject&, Fl
}
// 9.1.1.2.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-getbindingvalue-n-s
-ThrowCompletionOr<Value> ObjectEnvironment::get_binding_value(GlobalObject&, FlyString const& name, bool strict)
+ThrowCompletionOr<Value> ObjectEnvironment::get_binding_value(VM&, FlyString const& name, bool strict)
{
auto& vm = this->vm();
@@ -144,7 +144,7 @@ ThrowCompletionOr<Value> ObjectEnvironment::get_binding_value(GlobalObject&, Fly
}
// 9.1.1.2.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-deletebinding-n
-ThrowCompletionOr<bool> ObjectEnvironment::delete_binding(GlobalObject&, FlyString const& name)
+ThrowCompletionOr<bool> ObjectEnvironment::delete_binding(VM&, FlyString const& name)
{
// 1. Let bindingObject be envRec.[[BindingObject]].
// 2. Return ? bindingObject.[[Delete]](N).
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h
index 6d451b5057..ec5fa7dae5 100644
--- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h
+++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h
@@ -21,12 +21,12 @@ public:
ObjectEnvironment(Object& binding_object, IsWithEnvironment, Environment* outer_environment);
virtual ThrowCompletionOr<bool> has_binding(FlyString const& name, Optional<size_t>* = nullptr) const override;
- virtual ThrowCompletionOr<void> create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted) override;
- virtual ThrowCompletionOr<void> create_immutable_binding(GlobalObject&, FlyString const& name, bool strict) override;
- virtual ThrowCompletionOr<void> initialize_binding(GlobalObject&, FlyString const& name, Value) override;
- virtual ThrowCompletionOr<void> set_mutable_binding(GlobalObject&, FlyString const& name, Value, bool strict) override;
- virtual ThrowCompletionOr<Value> get_binding_value(GlobalObject&, FlyString const& name, bool strict) override;
- virtual ThrowCompletionOr<bool> delete_binding(GlobalObject&, FlyString const& name) override;
+ virtual ThrowCompletionOr<void> create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted) override;
+ virtual ThrowCompletionOr<void> create_immutable_binding(VM&, FlyString const& name, bool strict) override;
+ virtual ThrowCompletionOr<void> initialize_binding(VM&, FlyString const& name, Value) override;
+ virtual ThrowCompletionOr<void> set_mutable_binding(VM&, FlyString const& name, Value, bool strict) override;
+ virtual ThrowCompletionOr<Value> get_binding_value(VM&, FlyString const& name, bool strict) override;
+ virtual ThrowCompletionOr<bool> delete_binding(VM&, FlyString const& name) override;
// 9.1.1.2.10 WithBaseObject ( ), https://tc39.es/ecma262/#sec-object-environment-records-withbaseobject
virtual Object* with_base_object() const override
diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp
index d4a82f3fa3..ccaeacfa6a 100644
--- a/Userland/Libraries/LibJS/Runtime/Reference.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp
@@ -69,9 +69,9 @@ ThrowCompletionOr<void> Reference::put_value(GlobalObject& global_object, Value
// c. Return ? base.SetMutableBinding(V.[[ReferencedName]], W, V.[[Strict]]) (see 9.1).
if (m_environment_coordinate.has_value())
- return static_cast<DeclarativeEnvironment*>(m_base_environment)->set_mutable_binding_direct(global_object, m_environment_coordinate->index, value, m_strict);
+ return static_cast<DeclarativeEnvironment*>(m_base_environment)->set_mutable_binding_direct(vm, m_environment_coordinate->index, value, m_strict);
else
- return m_base_environment->set_mutable_binding(global_object, m_name.as_string(), value, m_strict);
+ return m_base_environment->set_mutable_binding(vm, m_name.as_string(), value, m_strict);
}
Completion Reference::throw_reference_error(GlobalObject& global_object) const
@@ -140,8 +140,8 @@ ThrowCompletionOr<Value> Reference::get_value(GlobalObject& global_object) const
// c. Return ? base.GetBindingValue(V.[[ReferencedName]], V.[[Strict]]) (see 9.1).
if (m_environment_coordinate.has_value())
- return static_cast<DeclarativeEnvironment*>(m_base_environment)->get_binding_value_direct(global_object, m_environment_coordinate->index, m_strict);
- return m_base_environment->get_binding_value(global_object, m_name.as_string(), m_strict);
+ return static_cast<DeclarativeEnvironment*>(m_base_environment)->get_binding_value_direct(vm, m_environment_coordinate->index, m_strict);
+ return m_base_environment->get_binding_value(vm, m_name.as_string(), m_strict);
}
// 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation
@@ -195,7 +195,7 @@ ThrowCompletionOr<bool> Reference::delete_(GlobalObject& global_object)
VERIFY(m_base_type == BaseType::Environment);
// c. Return ? base.DeleteBinding(ref.[[ReferencedName]]).
- return m_base_environment->delete_binding(global_object, m_name.as_string());
+ return m_base_environment->delete_binding(vm, m_name.as_string());
}
String Reference::to_string() const
@@ -234,6 +234,16 @@ String Reference::to_string() const
return builder.to_string();
}
+// 6.2.4.8 InitializeReferencedBinding ( V, W ), https://tc39.es/ecma262/#sec-object.prototype.hasownproperty
+ThrowCompletionOr<void> Reference::initialize_referenced_binding(GlobalObject& global_object, Value value) const
+{
+ auto& vm = global_object.vm();
+
+ VERIFY(!is_unresolvable());
+ VERIFY(m_base_type == BaseType::Environment);
+ return m_base_environment->initialize_binding(vm, m_name.as_string(), value);
+}
+
// 6.2.4.9 MakePrivateReference ( baseValue, privateIdentifier ), https://tc39.es/ecma262/#sec-makeprivatereference
Reference make_private_reference(VM& vm, Value base_value, FlyString const& private_identifier)
{
diff --git a/Userland/Libraries/LibJS/Runtime/Reference.h b/Userland/Libraries/LibJS/Runtime/Reference.h
index 08c618995e..ecd23e660a 100644
--- a/Userland/Libraries/LibJS/Runtime/Reference.h
+++ b/Userland/Libraries/LibJS/Runtime/Reference.h
@@ -121,13 +121,7 @@ public:
return m_base_type == BaseType::Environment;
}
- // 6.2.4.8 InitializeReferencedBinding ( V, W ), https://tc39.es/ecma262/#sec-object.prototype.hasownproperty
- ThrowCompletionOr<void> initialize_referenced_binding(GlobalObject& global_object, Value value) const
- {
- VERIFY(!is_unresolvable());
- VERIFY(m_base_type == BaseType::Environment);
- return m_base_environment->initialize_binding(global_object, m_name.as_string(), value);
- }
+ ThrowCompletionOr<void> initialize_referenced_binding(GlobalObject& global_object, Value value) const;
ThrowCompletionOr<void> put_value(GlobalObject&, Value);
ThrowCompletionOr<Value> get_value(GlobalObject&) const;
diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp
index f3c733c17b..7593cf46a9 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.cpp
+++ b/Userland/Libraries/LibJS/Runtime/VM.cpp
@@ -606,12 +606,15 @@ ThrowCompletionOr<void> VM::initialize_instance_elements(Object& object, ECMAScr
}
// 9.4.4 ResolveThisBinding ( ), https://tc39.es/ecma262/#sec-resolvethisbinding
-ThrowCompletionOr<Value> VM::resolve_this_binding(GlobalObject& global_object)
+ThrowCompletionOr<Value> VM::resolve_this_binding()
{
+ auto& vm = *this;
+
// 1. Let envRec be GetThisEnvironment().
- auto& environment = get_this_environment(*this);
+ auto& environment = get_this_environment(vm);
+
// 2. Return ? envRec.GetThisBinding().
- return TRY(environment.get_this_binding(global_object));
+ return TRY(environment.get_this_binding(vm));
}
String VM::join_arguments(size_t start_index) const
diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h
index d5175be6fe..f3976931d7 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.h
+++ b/Userland/Libraries/LibJS/Runtime/VM.h
@@ -153,7 +153,7 @@ public:
return running_execution_context().this_value;
}
- ThrowCompletionOr<Value> resolve_this_binding(GlobalObject&);
+ ThrowCompletionOr<Value> resolve_this_binding();
StackInfo const& stack_info() const { return m_stack_info; };