From a746739cb015ec2fb6e955be93e75688d6977b5b Mon Sep 17 00:00:00 2001 From: davidot Date: Wed, 14 Dec 2022 13:26:10 +0100 Subject: LibJS: Add an initialize binding hint to all initialize_binding methods This will allow us to specify things like SyncDispose and perhaps AsyncDispose in the future. --- Userland/Libraries/LibJS/AST.cpp | 6 +++--- .../Libraries/LibJS/Runtime/AbstractOperations.cpp | 18 +++++++++-------- .../LibJS/Runtime/DeclarativeEnvironment.cpp | 23 +++++++++++----------- .../LibJS/Runtime/DeclarativeEnvironment.h | 3 +-- .../LibJS/Runtime/ECMAScriptFunctionObject.cpp | 10 +++++----- Userland/Libraries/LibJS/Runtime/Environment.h | 7 ++++++- .../Libraries/LibJS/Runtime/GlobalEnvironment.cpp | 20 ++++++++++--------- .../Libraries/LibJS/Runtime/GlobalEnvironment.h | 2 +- .../Libraries/LibJS/Runtime/ObjectEnvironment.cpp | 7 +++++-- .../Libraries/LibJS/Runtime/ObjectEnvironment.h | 2 +- Userland/Libraries/LibJS/Runtime/Reference.cpp | 5 +++-- Userland/Libraries/LibJS/Runtime/Reference.h | 2 +- Userland/Libraries/LibJS/SourceTextModule.cpp | 16 +++++++-------- Userland/Libraries/LibJS/SyntheticModule.cpp | 4 ++-- 14 files changed, 68 insertions(+), 57 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index dc4b5b0a8e..5c67c1ea44 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -323,7 +323,7 @@ Value FunctionExpression::instantiate_ordinary_function_expression(Interpreter& // FIXME: 7. Perform MakeConstructor(closure). if (has_own_name) - MUST(environment->initialize_binding(vm, name(), closure)); + MUST(environment->initialize_binding(vm, name(), closure, Environment::InitializeBindingHint::Normal)); return closure; } @@ -1973,7 +1973,7 @@ ThrowCompletionOr ClassExpression::class_definition_e restore_environment.disarm(); if (!binding_name.is_null()) - MUST(class_environment->initialize_binding(vm, binding_name, class_constructor)); + MUST(class_environment->initialize_binding(vm, binding_name, class_constructor, Environment::InitializeBindingHint::Normal)); for (auto& field : instance_fields) class_constructor->add_field(field); @@ -3864,7 +3864,7 @@ Completion TryStatement::execute(Interpreter& interpreter) const // 5. Let status be Completion(BindingInitialization of CatchParameter with arguments thrownValue and catchEnv). auto status = m_handler->parameter().visit( [&](DeprecatedFlyString const& parameter) { - return catch_environment->initialize_binding(vm, parameter, thrown_value); + return catch_environment->initialize_binding(vm, parameter, thrown_value, Environment::InitializeBindingHint::Normal); }, [&](NonnullRefPtr const& pattern) { return vm.binding_initialization(pattern, thrown_value, catch_environment); diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index b904fec612..dcfe8bec7d 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -205,8 +205,9 @@ ThrowCompletionOr initialize_bound_name(VM& vm, DeprecatedFlyString const& { // 1. If environment is not undefined, then if (environment) { - // a. Perform ! environment.InitializeBinding(name, value). - MUST(environment->initialize_binding(vm, name, value)); + // FIXME: The normal is not included in the explicit resource management spec yet, so there is no spec link for it. + // a. Perform ! environment.InitializeBinding(name, value, normal). + MUST(environment->initialize_binding(vm, name, value, Environment::InitializeBindingHint::Normal)); // b. Return unused. return {}; @@ -729,6 +730,7 @@ ThrowCompletionOr perform_eval(VM& vm, Value x, CallerMode strict_caller, } // 19.2.1.3 EvalDeclarationInstantiation ( body, varEnv, lexEnv, privateEnv, strict ), https://tc39.es/ecma262/#sec-evaldeclarationinstantiation +// 9.1.1.1 EvalDeclarationInstantiation ( body, varEnv, lexEnv, privateEnv, strict ), https://tc39.es/proposal-explicit-resource-management/#sec-evaldeclarationinstantiation ThrowCompletionOr eval_declaration_instantiation(VM& vm, Program const& program, Environment* variable_environment, Environment* lexical_environment, PrivateEnvironment* private_environment, bool strict) { auto& realm = *vm.current_realm(); @@ -903,9 +905,9 @@ ThrowCompletionOr eval_declaration_instantiation(VM& vm, Program const& pr // ii. If bindingExists is false, then 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(vm, function_name, true)); - MUST(variable_environment->initialize_binding(vm, function_name, js_undefined())); + // ii. Perform ! varEnv.InitializeBinding(F, undefined, normal). + MUST(variable_environment->initialize_binding(vm, function_name, js_undefined(), Environment::InitializeBindingHint::Normal)); } } } @@ -1003,8 +1005,8 @@ ThrowCompletionOr eval_declaration_instantiation(VM& vm, Program const& pr // 2. Perform ! varEnv.CreateMutableBinding(fn, true). MUST(variable_environment->create_mutable_binding(vm, declaration.name(), true)); - // 3. Perform ! varEnv.InitializeBinding(fn, fo). - MUST(variable_environment->initialize_binding(vm, declaration.name(), function)); + // 3. Perform ! varEnv.InitializeBinding(fn, fo, normal). + MUST(variable_environment->initialize_binding(vm, declaration.name(), function, Environment::InitializeBindingHint::Normal)); } // iii. Else, else { @@ -1033,8 +1035,8 @@ ThrowCompletionOr eval_declaration_instantiation(VM& vm, Program const& pr // 2. Perform ! varEnv.CreateMutableBinding(vn, true). MUST(variable_environment->create_mutable_binding(vm, var_name, true)); - // 3. Perform ! varEnv.InitializeBinding(vn, undefined). - MUST(variable_environment->initialize_binding(vm, var_name, js_undefined())); + // 3. Perform ! varEnv.InitializeBinding(vn, undefined, normal). + MUST(variable_environment->initialize_binding(vm, var_name, js_undefined(), Environment::InitializeBindingHint::Normal)); } } } diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp index d427780ed9..08904e5ad4 100644 --- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.cpp @@ -96,26 +96,25 @@ ThrowCompletionOr DeclarativeEnvironment::create_immutable_binding(VM&, De } // 9.1.1.1.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-declarative-environment-records-initializebinding-n-v -ThrowCompletionOr DeclarativeEnvironment::initialize_binding(VM& vm, DeprecatedFlyString const& name, Value value) +// 4.1.1.1.1 InitializeBinding ( N, V, hint ), https://tc39.es/proposal-explicit-resource-management/#sec-declarative-environment-records +ThrowCompletionOr DeclarativeEnvironment::initialize_binding(VM&, DeprecatedFlyString const& name, Value value, Environment::InitializeBindingHint) { auto binding_and_index = find_binding_and_index(name); VERIFY(binding_and_index.has_value()); + auto& binding = binding_and_index->binding(); - return initialize_binding_direct(vm, binding_and_index->binding(), value); -} - -ThrowCompletionOr DeclarativeEnvironment::initialize_binding_direct(VM&, Binding& binding, Value value) -{ // 1. Assert: envRec must have an uninitialized binding for N. VERIFY(binding.initialized == false); - // 2. Set the bound value for N in envRec to V. + // FIXME: 2. If hint is not normal, perform ? AddDisposableResource(envRec, V, hint). + + // 3. Set the bound value for N in envRec to V. binding.value = value; - // 3. Record that the binding for N in envRec has been initialized. + // 4. Record that the binding for N in envRec has been initialized. binding.initialized = true; - // 4. Return unused. + // 5. Return unused. return {}; } @@ -132,8 +131,8 @@ ThrowCompletionOr DeclarativeEnvironment::set_mutable_binding(VM& vm, Depr // b. Perform ! envRec.CreateMutableBinding(N, true). MUST(create_mutable_binding(vm, name, true)); - // c. Perform ! envRec.InitializeBinding(N, V). - MUST(initialize_binding(vm, name, value)); + // c. Perform ! envRec.InitializeBinding(N, V, normal). + MUST(initialize_binding(vm, name, value, Environment::InitializeBindingHint::Normal)); // d. Return unused. return {}; @@ -220,7 +219,7 @@ ThrowCompletionOr DeclarativeEnvironment::initialize_or_set_mutable_bindin VERIFY(binding_and_index.has_value()); if (!binding_and_index->binding().initialized) - TRY(initialize_binding(vm, name, value)); + TRY(initialize_binding(vm, name, value, Environment::InitializeBindingHint::Normal)); else TRY(set_mutable_binding(vm, name, value, false)); return {}; diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h index c4c844e0a8..5d792edfed 100644 --- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h @@ -34,7 +34,7 @@ public: virtual ThrowCompletionOr has_binding(DeprecatedFlyString const& name, Optional* = nullptr) const override; virtual ThrowCompletionOr create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted) override; virtual ThrowCompletionOr create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict) override; - virtual ThrowCompletionOr initialize_binding(VM&, DeprecatedFlyString const& name, Value) override; + virtual ThrowCompletionOr initialize_binding(VM&, DeprecatedFlyString const& name, Value, InitializeBindingHint) override; virtual ThrowCompletionOr set_mutable_binding(VM&, DeprecatedFlyString const& name, Value, bool strict) override; virtual ThrowCompletionOr get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override; virtual ThrowCompletionOr delete_binding(VM&, DeprecatedFlyString const& name) override; @@ -60,7 +60,6 @@ public: void shrink_to_fit(); private: - ThrowCompletionOr initialize_binding_direct(VM&, Binding&, Value); ThrowCompletionOr get_binding_value_direct(VM&, Binding&, bool strict); ThrowCompletionOr set_mutable_binding_direct(VM&, Binding&, Value, bool strict); diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 2c7c270886..ab5b4bff95 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -407,7 +407,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia MUST(environment->create_mutable_binding(vm, parameter_name, false)); if (has_duplicates) - MUST(environment->initialize_binding(vm, parameter_name, js_undefined())); + MUST(environment->initialize_binding(vm, parameter_name, js_undefined(), Environment::InitializeBindingHint::Normal)); } if (arguments_object_needed) { @@ -422,7 +422,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia else MUST(environment->create_mutable_binding(vm, vm.names.arguments.as_string(), false)); - MUST(environment->initialize_binding(vm, vm.names.arguments.as_string(), arguments_object)); + MUST(environment->initialize_binding(vm, vm.names.arguments.as_string(), arguments_object, Environment::InitializeBindingHint::Normal)); parameter_names.set(vm.names.arguments.as_string()); } @@ -488,7 +488,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia 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(vm, name, false)); - MUST(environment->initialize_binding(vm, name, js_undefined())); + MUST(environment->initialize_binding(vm, name, js_undefined(), Environment::InitializeBindingHint::Normal)); } }); } @@ -509,7 +509,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia else initial_value = MUST(environment->get_binding_value(vm, name, false)); - MUST(var_environment->initialize_binding(vm, name, initial_value)); + MUST(var_environment->initialize_binding(vm, name, initial_value, Environment::InitializeBindingHint::Normal)); }); } } @@ -523,7 +523,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia // 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(vm, function_name, false)); - MUST(var_environment->initialize_binding(vm, function_name, js_undefined())); + MUST(var_environment->initialize_binding(vm, function_name, js_undefined(), Environment::InitializeBindingHint::Normal)); instantiated_var_names.set(function_name); } diff --git a/Userland/Libraries/LibJS/Runtime/Environment.h b/Userland/Libraries/LibJS/Runtime/Environment.h index 74388d7429..e33fa08b2e 100644 --- a/Userland/Libraries/LibJS/Runtime/Environment.h +++ b/Userland/Libraries/LibJS/Runtime/Environment.h @@ -23,6 +23,11 @@ class Environment : public Cell { JS_CELL(Environment, Cell); public: + enum class InitializeBindingHint { + Normal, + SyncDispose, + }; + virtual bool has_this_binding() const { return false; } virtual ThrowCompletionOr get_this_binding(VM&) const { return Value {}; } @@ -31,7 +36,7 @@ public: virtual ThrowCompletionOr has_binding([[maybe_unused]] DeprecatedFlyString const& name, [[maybe_unused]] Optional* out_index = nullptr) const { return false; } virtual ThrowCompletionOr create_mutable_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, [[maybe_unused]] bool can_be_deleted) { return {}; } virtual ThrowCompletionOr create_immutable_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, [[maybe_unused]] bool strict) { return {}; } - virtual ThrowCompletionOr initialize_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, Value) { return {}; } + virtual ThrowCompletionOr initialize_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, Value, InitializeBindingHint) { return {}; } virtual ThrowCompletionOr set_mutable_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, Value, [[maybe_unused]] bool strict) { return {}; } virtual ThrowCompletionOr get_binding_value(VM&, [[maybe_unused]] DeprecatedFlyString const& name, [[maybe_unused]] bool strict) { return Value {}; } virtual ThrowCompletionOr delete_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name) { return false; } diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp index 2fada09a3d..b2fba47a28 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.cpp @@ -78,20 +78,22 @@ ThrowCompletionOr GlobalEnvironment::create_immutable_binding(VM& vm, Depr 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 GlobalEnvironment::initialize_binding(VM& vm, DeprecatedFlyString const& name, Value value) +// 9.1.1.4.4 InitializeBinding ( N, V, hint ), https://tc39.es/ecma262/#sec-global-environment-records-initializebinding-n-v +ThrowCompletionOr GlobalEnvironment::initialize_binding(VM& vm, DeprecatedFlyString const& name, Value value, InitializeBindingHint hint) { // 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(vm, name, value)); + // a. Return ! DclRec.InitializeBinding(N, V, hint). + return MUST(m_declarative_record->initialize_binding(vm, name, value, hint)); } // 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(vm, name, value); + // 4. Assert: hint is normal. + VERIFY(hint == Environment::InitializeBindingHint::Normal); + // 5. Let ObjRec be envRec.[[ObjectRecord]]. + // 6. Return ? ObjRec.InitializeBinding(N, V, normal). + return m_object_record->initialize_binding(vm, name, value, Environment::InitializeBindingHint::Normal); } // 9.1.1.4.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-global-environment-records-setmutablebinding-n-v-s @@ -263,8 +265,8 @@ ThrowCompletionOr GlobalEnvironment::create_global_var_binding(DeprecatedF // a. Perform ? ObjRec.CreateMutableBinding(N, D). TRY(m_object_record->create_mutable_binding(vm, name, can_be_deleted)); - // b. Perform ? ObjRec.InitializeBinding(N, undefined). - TRY(m_object_record->initialize_binding(vm, name, js_undefined())); + // b. Perform ? ObjRec.InitializeBinding(N, undefined, normal). + TRY(m_object_record->initialize_binding(vm, name, js_undefined(), Environment::InitializeBindingHint::Normal)); } // 6. Let varDeclaredNames be envRec.[[VarNames]]. diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h index 65ed843725..1bae539f6c 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h @@ -20,7 +20,7 @@ public: virtual ThrowCompletionOr has_binding(DeprecatedFlyString const& name, Optional* = nullptr) const override; virtual ThrowCompletionOr create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted) override; virtual ThrowCompletionOr create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict) override; - virtual ThrowCompletionOr initialize_binding(VM&, DeprecatedFlyString const& name, Value) override; + virtual ThrowCompletionOr initialize_binding(VM&, DeprecatedFlyString const& name, Value, Environment::InitializeBindingHint) override; virtual ThrowCompletionOr set_mutable_binding(VM&, DeprecatedFlyString const& name, Value, bool strict) override; virtual ThrowCompletionOr get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override; virtual ThrowCompletionOr delete_binding(VM&, DeprecatedFlyString const& name) override; diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp index cdc4f1e74b..4e477d8033 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp @@ -77,9 +77,12 @@ ThrowCompletionOr ObjectEnvironment::create_immutable_binding(VM&, Depreca } // 9.1.1.2.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-object-environment-records-initializebinding-n-v -ThrowCompletionOr ObjectEnvironment::initialize_binding(VM& vm, DeprecatedFlyString const& name, Value value) +ThrowCompletionOr ObjectEnvironment::initialize_binding(VM& vm, DeprecatedFlyString const& name, Value value, Environment::InitializeBindingHint hint) { - // 1. Perform ? envRec.SetMutableBinding(N, V, false). + // 1. Assert: hint is normal. + VERIFY(hint == Environment::InitializeBindingHint::Normal); + + // 2. Perform ? envRec.SetMutableBinding(N, V, false). TRY(set_mutable_binding(vm, name, value, false)); // 2. Return unused. diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h index bd3bbc7729..5998b1a636 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h @@ -22,7 +22,7 @@ public: virtual ThrowCompletionOr has_binding(DeprecatedFlyString const& name, Optional* = nullptr) const override; virtual ThrowCompletionOr create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted) override; virtual ThrowCompletionOr create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict) override; - virtual ThrowCompletionOr initialize_binding(VM&, DeprecatedFlyString const& name, Value) override; + virtual ThrowCompletionOr initialize_binding(VM&, DeprecatedFlyString const& name, Value, Environment::InitializeBindingHint) override; virtual ThrowCompletionOr set_mutable_binding(VM&, DeprecatedFlyString const& name, Value, bool strict) override; virtual ThrowCompletionOr get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override; virtual ThrowCompletionOr delete_binding(VM&, DeprecatedFlyString const& name) override; diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp index 06a16337a2..4d21d76705 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.cpp +++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp @@ -231,11 +231,12 @@ DeprecatedString Reference::to_deprecated_string() const } // 6.2.4.8 InitializeReferencedBinding ( V, W ), https://tc39.es/ecma262/#sec-object.prototype.hasownproperty -ThrowCompletionOr Reference::initialize_referenced_binding(VM& vm, Value value) const +// 1.2.1.1 InitializeReferencedBinding ( V, W, hint ), https://tc39.es/proposal-explicit-resource-management/#sec-initializereferencedbinding +ThrowCompletionOr Reference::initialize_referenced_binding(VM& vm, Value value, Environment::InitializeBindingHint hint) const { VERIFY(!is_unresolvable()); VERIFY(m_base_type == BaseType::Environment); - return m_base_environment->initialize_binding(vm, m_name.as_string(), value); + return m_base_environment->initialize_binding(vm, m_name.as_string(), value, hint); } // 6.2.4.9 MakePrivateReference ( baseValue, privateIdentifier ), https://tc39.es/ecma262/#sec-makeprivatereference diff --git a/Userland/Libraries/LibJS/Runtime/Reference.h b/Userland/Libraries/LibJS/Runtime/Reference.h index f0d716b296..8c278cda6f 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.h +++ b/Userland/Libraries/LibJS/Runtime/Reference.h @@ -121,7 +121,7 @@ public: return m_base_type == BaseType::Environment; } - ThrowCompletionOr initialize_referenced_binding(VM&, Value value) const; + ThrowCompletionOr initialize_referenced_binding(VM&, Value value, Environment::InitializeBindingHint hint = Environment::InitializeBindingHint::Normal) const; ThrowCompletionOr put_value(VM&, Value); ThrowCompletionOr get_value(VM&) const; diff --git a/Userland/Libraries/LibJS/SourceTextModule.cpp b/Userland/Libraries/LibJS/SourceTextModule.cpp index 2664002911..3afb59c0dd 100644 --- a/Userland/Libraries/LibJS/SourceTextModule.cpp +++ b/Userland/Libraries/LibJS/SourceTextModule.cpp @@ -367,8 +367,8 @@ ThrowCompletionOr SourceTextModule::initialize_environment(VM& vm) // ii. Perform ! env.CreateImmutableBinding(in.[[LocalName]], true). MUST(environment->create_immutable_binding(vm, import_entry.local_name, true)); - // iii. Perform ! env.InitializeBinding(in.[[LocalName]], namespace). - MUST(environment->initialize_binding(vm, import_entry.local_name, namespace_)); + // iii. Perform ! env.InitializeBinding(in.[[LocalName]], namespace, normal). + MUST(environment->initialize_binding(vm, import_entry.local_name, namespace_, Environment::InitializeBindingHint::Normal)); } // d. Else, else { @@ -387,8 +387,8 @@ ThrowCompletionOr SourceTextModule::initialize_environment(VM& vm) // 2. Perform ! env.CreateImmutableBinding(in.[[LocalName]], true). MUST(environment->create_immutable_binding(vm, import_entry.local_name, true)); - // 3. Perform ! env.InitializeBinding(in.[[LocalName]], namespace). - MUST(environment->initialize_binding(vm, import_entry.local_name, namespace_)); + // 3. Perform ! env.InitializeBinding(in.[[LocalName]], namespace, normal). + MUST(environment->initialize_binding(vm, import_entry.local_name, namespace_, Environment::InitializeBindingHint::Normal)); } // iv. Else, else { @@ -442,8 +442,8 @@ ThrowCompletionOr SourceTextModule::initialize_environment(VM& vm) // 1. Perform ! env.CreateMutableBinding(dn, false). MUST(environment->create_mutable_binding(vm, name, false)); - // 2. Perform ! env.InitializeBinding(dn, undefined). - MUST(environment->initialize_binding(vm, name, js_undefined())); + // 2. Perform ! env.InitializeBinding(dn, undefined, normal). + MUST(environment->initialize_binding(vm, name, js_undefined(), Environment::InitializeBindingHint::Normal)); // 3. Append dn to declaredVarNames. declared_var_names.empend(name); @@ -484,8 +484,8 @@ ThrowCompletionOr SourceTextModule::initialize_environment(VM& vm) function_name = "default"sv; auto function = ECMAScriptFunctionObject::create(realm(), function_name, function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(), function_declaration.might_need_arguments_object(), function_declaration.contains_direct_call_to_eval()); - // 2. Perform ! env.InitializeBinding(dn, fo). - MUST(environment->initialize_binding(vm, name, function)); + // 2. Perform ! env.InitializeBinding(dn, fo, normal). + MUST(environment->initialize_binding(vm, name, function, Environment::InitializeBindingHint::Normal)); } }); }); diff --git a/Userland/Libraries/LibJS/SyntheticModule.cpp b/Userland/Libraries/LibJS/SyntheticModule.cpp index 7e94f5a8a6..332337343a 100644 --- a/Userland/Libraries/LibJS/SyntheticModule.cpp +++ b/Userland/Libraries/LibJS/SyntheticModule.cpp @@ -61,8 +61,8 @@ ThrowCompletionOr SyntheticModule::link(VM& vm) // a. Perform ! envRec.CreateMutableBinding(exportName, false). MUST(environment->create_mutable_binding(vm, export_name, false)); - // b. Perform ! envRec.InitializeBinding(exportName, undefined). - MUST(environment->initialize_binding(vm, export_name, js_undefined())); + // b. Perform ! envRec.InitializeBinding(exportName, undefined, normal). + MUST(environment->initialize_binding(vm, export_name, js_undefined(), Environment::InitializeBindingHint::Normal)); } // 6. Return unused. -- cgit v1.2.3