mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-12 02:30:30 +09:00
LibWeb: Put setting object's promise's in WindowOrWorkerGlobalScope
This aligns with an update to the HTML specification which instead stores these promises on the global object instead of the settings object. It also makes progress towards implementing the ShadowRealm proposal as these promises are not present in the 'synthetic' realm for that proposal.
This commit is contained in:
parent
d1fc76bffd
commit
1096b64936
Notes:
github-actions[bot]
2024-10-23 17:30:50 +00:00
Author: https://github.com/shannonbooth
Commit: 1096b64936
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1927
Reviewed-by: https://github.com/ADKaster ✅
6 changed files with 129 additions and 119 deletions
|
@ -54,7 +54,6 @@ void EnvironmentSettingsObject::visit_edges(Cell::Visitor& visitor)
|
|||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_responsible_event_loop);
|
||||
visitor.visit(m_module_map);
|
||||
visitor.ignore(m_outstanding_rejected_promises_weak_set);
|
||||
m_realm_execution_context->visit_edges(visitor);
|
||||
visitor.visit(m_fetch_group);
|
||||
visitor.visit(m_storage_manager);
|
||||
|
@ -208,89 +207,6 @@ void EnvironmentSettingsObject::clean_up_after_running_callback()
|
|||
event_loop.pop_backup_incumbent_settings_object_stack({});
|
||||
}
|
||||
|
||||
void EnvironmentSettingsObject::push_onto_outstanding_rejected_promises_weak_set(JS::Promise* promise)
|
||||
{
|
||||
m_outstanding_rejected_promises_weak_set.append(promise);
|
||||
}
|
||||
|
||||
bool EnvironmentSettingsObject::remove_from_outstanding_rejected_promises_weak_set(JS::Promise* promise)
|
||||
{
|
||||
return m_outstanding_rejected_promises_weak_set.remove_first_matching([&](JS::Promise* promise_in_set) {
|
||||
return promise == promise_in_set;
|
||||
});
|
||||
}
|
||||
|
||||
void EnvironmentSettingsObject::push_onto_about_to_be_notified_rejected_promises_list(JS::NonnullGCPtr<JS::Promise> promise)
|
||||
{
|
||||
m_about_to_be_notified_rejected_promises_list.append(JS::make_handle(promise));
|
||||
}
|
||||
|
||||
bool EnvironmentSettingsObject::remove_from_about_to_be_notified_rejected_promises_list(JS::NonnullGCPtr<JS::Promise> promise)
|
||||
{
|
||||
return m_about_to_be_notified_rejected_promises_list.remove_first_matching([&](auto& promise_in_list) {
|
||||
return promise == promise_in_list;
|
||||
});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#notify-about-rejected-promises
|
||||
void EnvironmentSettingsObject::notify_about_rejected_promises(Badge<EventLoop>)
|
||||
{
|
||||
// 1. Let list be a copy of settings object's about-to-be-notified rejected promises list.
|
||||
auto list = m_about_to_be_notified_rejected_promises_list;
|
||||
|
||||
// 2. If list is empty, return.
|
||||
if (list.is_empty())
|
||||
return;
|
||||
|
||||
// 3. Clear settings object's about-to-be-notified rejected promises list.
|
||||
m_about_to_be_notified_rejected_promises_list.clear();
|
||||
|
||||
// 4. Let global be settings object's global object.
|
||||
// We need this as an event target for the unhandledrejection event below
|
||||
auto& global = verify_cast<DOM::EventTarget>(global_object());
|
||||
|
||||
// 5. Queue a global task on the DOM manipulation task source given global to run the following substep:
|
||||
queue_global_task(Task::Source::DOMManipulation, global, JS::create_heap_function(heap(), [this, &global, list = move(list)] {
|
||||
auto& realm = global.realm();
|
||||
|
||||
// 1. For each promise p in list:
|
||||
for (auto const& promise : list) {
|
||||
|
||||
// 1. If p's [[PromiseIsHandled]] internal slot is true, continue to the next iteration of the loop.
|
||||
if (promise->is_handled())
|
||||
continue;
|
||||
|
||||
// 2. Let notHandled be the result of firing an event named unhandledrejection at global, using PromiseRejectionEvent, with the cancelable attribute initialized to true,
|
||||
// the promise attribute initialized to p, and the reason attribute initialized to the value of p's [[PromiseResult]] internal slot.
|
||||
PromiseRejectionEventInit event_init {
|
||||
{
|
||||
.bubbles = false,
|
||||
.cancelable = true,
|
||||
.composed = false,
|
||||
},
|
||||
// Sadly we can't use .promise and .reason here, as we can't use the designator on the initialization of DOM::EventInit above.
|
||||
/* .promise = */ JS::make_handle(*promise),
|
||||
/* .reason = */ promise->result(),
|
||||
};
|
||||
|
||||
auto promise_rejection_event = PromiseRejectionEvent::create(realm, HTML::EventNames::unhandledrejection, event_init);
|
||||
|
||||
bool not_handled = global.dispatch_event(*promise_rejection_event);
|
||||
|
||||
// 3. If notHandled is false, then the promise rejection is handled. Otherwise, the promise rejection is not handled.
|
||||
|
||||
// 4. If p's [[PromiseIsHandled]] internal slot is false, add p to settings object's outstanding rejected promises weak set.
|
||||
if (!promise->is_handled())
|
||||
m_outstanding_rejected_promises_weak_set.append(*promise);
|
||||
|
||||
// This algorithm results in promise rejections being marked as handled or not handled. These concepts parallel handled and not handled script errors.
|
||||
// If a rejection is still not handled after this, then the rejection may be reported to a developer console.
|
||||
if (not_handled)
|
||||
HTML::report_exception_to_console(promise->result(), realm, ErrorInPromise::Yes);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-script
|
||||
bool EnvironmentSettingsObject::is_scripting_enabled() const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue