From 6a55865bf61ba0ad8aebd1b72ea0be82d849600d Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 3 Nov 2024 20:56:30 +1300 Subject: [PATCH] LibJS: Use GetShadowRealmContext for ShadowRealmImportValue Removing one user of the ExecutionContext slot of ShadowRealm. --- Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp | 13 ++++++------- Userland/Libraries/LibJS/Runtime/ShadowRealm.h | 2 +- .../LibJS/Runtime/ShadowRealmPrototype.cpp | 7 ++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index 05e0ed4c00..316e6f4140 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -211,14 +211,12 @@ ThrowCompletionOr perform_shadow_realm_eval(VM& vm, StringView source_tex } // 3.1.4 ShadowRealmImportValue ( specifierString: a String, exportNameString: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, evalContext: an execution context, ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue -ThrowCompletionOr shadow_realm_import_value(VM& vm, ByteString specifier_string, ByteString export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context) +ThrowCompletionOr shadow_realm_import_value(VM& vm, ByteString specifier_string, ByteString export_name_string, Realm& caller_realm, Realm& eval_realm) { - // FIXME: evalRealm isn't being used anywhere in this AO (spec issue) - (void)eval_realm; - auto& realm = *vm.current_realm(); - // 1. Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]]. + // 1. Let evalContext be GetShadowRealmContext(evalRealm, true). + auto eval_context = get_shadow_realm_context(eval_realm, true); // 2. Let innerCapability be ! NewPromiseCapability(%Promise%). auto inner_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); @@ -228,10 +226,11 @@ ThrowCompletionOr shadow_realm_import_value(VM& vm, ByteString specifier_ // NOTE: We don't support this concept yet. // 5. Push evalContext onto the execution context stack; evalContext is now the running execution context. - TRY(vm.push_execution_context(eval_context, {})); + TRY(vm.push_execution_context(*eval_context, {})); // 6. Let referrer be the Realm component of evalContext. - auto referrer = JS::NonnullGCPtr { *eval_context.realm }; + auto referrer = JS::NonnullGCPtr { *eval_context->realm }; + // 7. Perform HostLoadImportedModule(referrer, specifierString, empty, innerCapability). vm.host_load_imported_module(referrer, ModuleRequest { specifier_string }, nullptr, inner_capability); diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.h b/Userland/Libraries/LibJS/Runtime/ShadowRealm.h index b15b392890..e13bdc51af 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.h +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.h @@ -40,7 +40,7 @@ private: ThrowCompletionOr copy_name_and_length(VM&, FunctionObject& function, FunctionObject& target, Optional prefix = {}, Optional arg_count = {}); ThrowCompletionOr perform_shadow_realm_eval(VM&, StringView source_text, Realm& caller_realm, Realm& eval_realm); -ThrowCompletionOr shadow_realm_import_value(VM&, ByteString specifier_string, ByteString export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context); +ThrowCompletionOr shadow_realm_import_value(VM&, ByteString specifier_string, ByteString export_name_string, Realm& caller_realm, Realm& eval_realm); ThrowCompletionOr get_wrapped_value(VM&, Realm& caller_realm, Value); NonnullOwnPtr get_shadow_realm_context(Realm& shadow_realm, bool strict_eval); diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp index 86d46a284f..c239fd67ab 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp @@ -77,11 +77,8 @@ JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::import_value) // 6. Let evalRealm be O.[[ShadowRealm]]. auto& eval_realm = object->shadow_realm(); - // 7. Let evalContext be O.[[ExecutionContext]]. - auto& eval_context = object->execution_context(); - - // 8. Return ? ShadowRealmImportValue(specifierString, exportNameString, callerRealm, evalRealm, evalContext). - return shadow_realm_import_value(vm, move(specifier_string), export_name.as_string().byte_string(), *caller_realm, eval_realm, eval_context); + // 7. Return ShadowRealmImportValue(specifierString, exportName, callerRealm, evalRealm). + return shadow_realm_import_value(vm, move(specifier_string), export_name.as_string().byte_string(), *caller_realm, eval_realm); } }