Skip to content

Commit f942fef

Browse files
kalenikaliaksandrtrflynn89
authored andcommitted
LibWeb: Allow microtasks to run if document has been destroyed
187f8c5 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.
1 parent cce5197 commit f942fef

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Libraries/LibWeb/HTML/Scripting/Environments.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,14 @@ EventLoop& EnvironmentSettingsObject::responsible_event_loop()
125125
RunScriptDecision can_run_script(JS::Realm const& realm)
126126
{
127127
// 1. If the global object specified by realm is a Window object whose Document object is not fully active, then return "do not run".
128-
if (is<HTML::Window>(realm.global_object()) && !as<HTML::Window>(realm.global_object()).associated_document().is_fully_active())
129-
return RunScriptDecision::DoNotRun;
128+
if (auto const* window = as_if<HTML::Window>(realm.global_object())) {
129+
auto const& document = window->associated_document();
130+
// AD-HOC: We allow tasks for destroyed documents to run so that microtasks queued during the fetch of a new
131+
// document in a navigation can still be processed, even after the previous document, the one that
132+
// initiated the fetch, has been destroyed.
133+
if (!document.has_been_destroyed() && !document.is_fully_active())
134+
return RunScriptDecision::DoNotRun;
135+
}
130136

131137
// 2. If scripting is disabled for realm, then return "do not run".
132138
if (is_scripting_disabled(realm))

0 commit comments

Comments
 (0)