summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-05-18 19:08:30 +0200
committerAndreas Kling <kling@serenityos.org>2023-05-19 06:20:14 +0200
commitf823b297b4344bc5fc1febb876918606250a3e8d (patch)
tree7e551d77995663221aa4b447673b6e97bd9e0aa0 /Userland/Libraries/LibWeb
parent819fb39a87b6c37f317c3f17fa0c9adc31370995 (diff)
downloadserenity-f823b297b4344bc5fc1febb876918606250a3e8d.zip
LibWeb: Push the realm execution context while linking modules
If linking fails, we throw a JS exception, and if there's no execution context on the VM stack at that time, we assert in VM::current_realm(). This is a hack to prevent crashing on failed module loads. Long term we need to rewrite module loading since it has been refactored to share code differently between HTML and ECMA262.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
index d12a6388e3..9bf122df4c 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
@@ -601,7 +601,7 @@ void fetch_descendants_of_and_link_a_module_script(JavaScriptModuleScript& modul
// 1. Fetch the descendants of module script, given fetch client settings object, destination, visited set, and onFetchDescendantsComplete as defined below.
// If performFetch was given, pass it along as well.
// FIXME: Pass performFetch if given.
- fetch_descendants_of_a_module_script(module_script, fetch_client_settings_object, destination, visited_set, [on_complete = move(on_complete)](auto result) {
+ fetch_descendants_of_a_module_script(module_script, fetch_client_settings_object, destination, visited_set, [&fetch_client_settings_object, on_complete = move(on_complete)](auto result) {
// onFetchDescendantsComplete given result is the following algorithm:
// 1. If result is null, then run onComplete given result, and abort these steps.
if (!result) {
@@ -609,6 +609,10 @@ void fetch_descendants_of_and_link_a_module_script(JavaScriptModuleScript& modul
return;
}
+ // FIXME: This is an ad-hoc hack to make sure that there's an execution context on the VM stack in case linking throws an exception.
+ auto& vm = fetch_client_settings_object.vm();
+ vm.push_execution_context(fetch_client_settings_object.realm_execution_context());
+
// FIXME: 2. Let parse error be the result of finding the first parse error given result.
// 3. If parse error is null, then:
@@ -628,6 +632,9 @@ void fetch_descendants_of_and_link_a_module_script(JavaScriptModuleScript& modul
TODO();
}
+ // FIXME: This undoes the ad-hoc hack above.
+ vm.pop_execution_context();
+
// 5. Run onComplete given result.
on_complete(result);
});