LibWeb: Allow microtasks to run if document has been destroyed

187f8c54 made `HTML::Task` runnable for destroyed documents, and this
change aligns microtask behavior with that. This is required for an
upcoming change that switches Fetch to be unbuffered by default. During
navigation, fetching the new document is initiated by the previous
document, which means we need to allow microtasks created in the
previous document's realm to run even after that document has been
destroyed.
This commit is contained in:
Aliaksandr Kalenik 2025-11-06 17:44:41 +01:00 committed by Tim Flynn
parent cce5197f90
commit f942fef39b
Notes: github-actions[bot] 2025-11-20 11:30:58 +00:00

View file

@ -125,8 +125,14 @@ EventLoop& EnvironmentSettingsObject::responsible_event_loop()
RunScriptDecision can_run_script(JS::Realm const& realm)
{
// 1. If the global object specified by realm is a Window object whose Document object is not fully active, then return "do not run".
if (is<HTML::Window>(realm.global_object()) && !as<HTML::Window>(realm.global_object()).associated_document().is_fully_active())
if (auto const* window = as_if<HTML::Window>(realm.global_object())) {
auto const& document = window->associated_document();
// AD-HOC: We allow tasks for destroyed documents to run so that microtasks queued during the fetch of a new
// document in a navigation can still be processed, even after the previous document, the one that
// initiated the fetch, has been destroyed.
if (!document.has_been_destroyed() && !document.is_fully_active())
return RunScriptDecision::DoNotRun;
}
// 2. If scripting is disabled for realm, then return "do not run".
if (is_scripting_disabled(realm))