From d5aaff818eeb119d06fd592828371d3a2c670143 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 28 Nov 2024 03:14:47 +1300 Subject: [PATCH] LibWeb: Adjust 'resolve a module specifier' to shadow realm proposal --- Libraries/LibWeb/HTML/Scripting/Fetching.cpp | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp index ad5e1a1bb3b..edb827c51ec 100644 --- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp +++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2022-2023, networkException * Copyright (c) 2024, Tim Ledbetter + * Copyright (c) 2024, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -9,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -84,36 +87,38 @@ ByteString module_type_from_module_request(JS::ModuleRequest const& module_reque // https://whatpr.org/html/9893/webappapis.html#resolve-a-module-specifier WebIDL::ExceptionOr resolve_module_specifier(Optional referring_script, ByteString const& specifier) { - // 1. Let settingsObject and baseURL be null. - GC::Ptr settings_object; + auto& vm = Bindings::main_thread_vm(); + + // 1. Let realm and baseURL be null. + GC::Ptr realm; Optional base_url; // 2. If referringScript is not null, then: if (referring_script.has_value()) { - // 1. Set settingsObject to referringScript's settings object. - settings_object = referring_script->settings_object(); + // 1. Set realm to referringScript's realm. + realm = referring_script->realm(); // 2. Set baseURL to referringScript's base URL. base_url = referring_script->base_url(); } // 3. Otherwise: else { - // 1. Assert: there is a current principal settings object. - // NOTE: This is handled by the current_principal_settings_object() accessor. + // 1. Assert: there is a current realm. + VERIFY(vm.current_realm()); - // 2. Set settingsObject to the current principal settings object. - settings_object = current_principal_settings_object(); + // 2. Set realm to the current realm. + realm = *vm.current_realm(); - // 3. Set baseURL to settingsObject's API base URL. - base_url = settings_object->api_base_url(); + // 3. Set baseURL to realm's principal realm's settings object's API base URL. + base_url = Bindings::principal_host_defined_environment_settings_object(HTML::principal_realm(*realm)).api_base_url(); } // 4. Let importMap be an empty import map. ImportMap import_map; - // 5. If settingsObject's global object implements Window, then set importMap to settingsObject's global object's import map. - if (is(settings_object->global_object())) - import_map = verify_cast(settings_object->global_object()).import_map(); + // 5. If realm's global object implements Window, then set importMap to settingsObject's global object's import map. + if (is(realm->global_object())) + import_map = verify_cast(realm->global_object()).import_map(); // 6. Let baseURLString be baseURL, serialized. auto base_url_string = base_url->serialize();