mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibWeb: Use CSO if running script is null in HostPromiseRejectionTracker
This commit is contained in:
parent
1d5b03ce17
commit
62491cda0b
2 changed files with 39 additions and 13 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue