From 4913dac745db63746a283ca55e76c69cef16fbd6 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 25 Nov 2024 10:37:28 +1300 Subject: [PATCH] LibWeb: Get Page from principal realm during resource loading Fixes a crash for module loading for a shadow realm. --- Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 2 +- Tests/LibWeb/Text/data/external-module.mjs | 1 + .../Text/expected/HTML/ShadowRealm-importValue.txt | 1 + .../Text/input/HTML/ShadowRealm-importValue.html | 10 ++++++++++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/data/external-module.mjs create mode 100644 Tests/LibWeb/Text/expected/HTML/ShadowRealm-importValue.txt create mode 100644 Tests/LibWeb/Text/input/HTML/ShadowRealm-importValue.html diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index e333f0a7f89..ce2fae059ed 100644 --- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -2240,7 +2240,7 @@ WebIDL::ExceptionOr> nonstandard_resource_loader_file_o auto request = fetch_params.request(); - auto& page = Bindings::principal_host_defined_page(realm); + auto& page = Bindings::principal_host_defined_page(HTML::principal_realm(realm)); // NOTE: Using LoadRequest::create_for_url_on_page here will unconditionally add cookies as long as there's a page available. // However, it is up to http_network_or_cache_fetch to determine if cookies should be added to the request. diff --git a/Tests/LibWeb/Text/data/external-module.mjs b/Tests/LibWeb/Text/data/external-module.mjs new file mode 100644 index 00000000000..e9c396e5525 --- /dev/null +++ b/Tests/LibWeb/Text/data/external-module.mjs @@ -0,0 +1 @@ +export const foo = "Well hello shadows"; diff --git a/Tests/LibWeb/Text/expected/HTML/ShadowRealm-importValue.txt b/Tests/LibWeb/Text/expected/HTML/ShadowRealm-importValue.txt new file mode 100644 index 00000000000..436501b2371 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/ShadowRealm-importValue.txt @@ -0,0 +1 @@ +Well hello shadows diff --git a/Tests/LibWeb/Text/input/HTML/ShadowRealm-importValue.html b/Tests/LibWeb/Text/input/HTML/ShadowRealm-importValue.html new file mode 100644 index 00000000000..e94fde26521 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/ShadowRealm-importValue.html @@ -0,0 +1,10 @@ + +