summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-06-27 19:53:30 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-29 21:21:50 +0100
commit62491cda0b9e8aa55067aa794d58a79b965f6f46 (patch)
tree3a260b6867b5f9ff31aaa7015a9ae4fb2f643293 /Userland/Libraries
parent1d5b03ce171df7a5a3aae3f4048ac3419e21fd74 (diff)
downloadserenity-62491cda0b9e8aa55067aa794d58a79b965f6f46.zip
LibWeb: Use CSO if running script is null in HostPromiseRejectionTracker
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
index e1209646bb..9329b77ea6 100644
--- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
@@ -55,8 +55,7 @@ JS::VM& main_thread_vm()
vm->host_promise_rejection_tracker = [](JS::Promise& promise, JS::Promise::RejectionOperation operation) {
// 1. Let script be the running script.
// The running script is the script in the [[HostDefined]] field in the ScriptOrModule component of the running JavaScript execution context.
- // FIXME: This currently assumes there's only a ClassicScript.
- HTML::ClassicScript* script { nullptr };
+ HTML::Script* script { nullptr };
vm->running_execution_context().script_or_module.visit(
[&script](WeakPtr<JS::Script>& js_script) {
script = verify_cast<HTML::ClassicScript>(js_script->host_defined());
@@ -67,19 +66,17 @@ JS::VM& main_thread_vm()
[](Empty) {
});
- // If there's no script, we're out of luck. Return.
- // FIXME: This can happen from JS::NativeFunction, which makes its callee contexts [[ScriptOrModule]] null.
- if (!script) {
- dbgln("FIXME: Unable to process unhandled promise rejection in host_promise_rejection_tracker as the running script is null.");
- return;
+ // 2. If script is a classic script and script's muted errors is true, then return.
+ // NOTE: is<T>() returns false if nullptr is passed.
+ if (is<HTML::ClassicScript>(script)) {
+ auto const& classic_script = static_cast<HTML::ClassicScript const&>(*script);
+ if (classic_script.muted_errors() == HTML::ClassicScript::MutedErrors::Yes)
+ return;
}
- // 2. If script's muted errors is true, terminate these steps.
- if (script->muted_errors() == HTML::ClassicScript::MutedErrors::Yes)
- return;
-
- // 3. Let settings object be script's settings object.
- auto& settings_object = script->settings_object();
+ // 3. Let settings object be the current settings object.
+ // 4. If script is not null, then set settings object to script's settings object.
+ auto& settings_object = script ? script->settings_object() : HTML::current_settings_object();
switch (operation) {
case JS::Promise::RejectionOperation::Reject: