mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
LibWeb: Remove tasks for destroyed documents instead of running them
Previously, destroyed-document tasks were forced to be runnable to prevent them from leaking in the task queue. Instead, discard them during task selection so their callbacks never run with stale state. This used to cause issues with a couple of `spin_until()`s in the past, but since we've removed some of them that had to do with the document lifecycle, let's see if we can stick closer to the spec now.
This commit is contained in:
committed by
Andreas Kling
parent
71ba774083
commit
c8baa6e179
Notes:
github-actions[bot]
2026-03-19 20:25:47 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/c8baa6e179a Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8513
@@ -126,13 +126,10 @@ EventLoop& EnvironmentSettingsObject::responsible_event_loop()
|
||||
// https://whatpr.org/html/9893/webappapis.html#check-if-we-can-run-script
|
||||
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 (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())
|
||||
// 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 (auto const* window = as_if<Window>(realm.global_object())) {
|
||||
if (!window->associated_document().is_fully_active())
|
||||
return RunScriptDecision::DoNotRun;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user