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:
Jelle Raaijmakers
2026-03-19 20:21:11 +01:00
committed by Andreas Kling
parent 71ba774083
commit c8baa6e179
Notes: github-actions[bot] 2026-03-19 20:25:47 +00:00
6 changed files with 19 additions and 36 deletions

View File

@@ -4532,9 +4532,7 @@ void Document::destroy()
return task.document() == this;
});
// AD-HOC: Mark this document as destroyed. This makes any tasks scheduled for this document in the
// future immediately runnable instead of blocking on the document becoming fully active.
// This is important because otherwise those tasks will get stuck in the task queue forever.
// AD-HOC: Mark this document as destroyed so we can remove tasks from the queue that will never be able to run.
m_has_been_destroyed = true;
// 8. Set document's browsing context to null.
@@ -4744,8 +4742,6 @@ GC::Ptr<HTML::HTMLParser> Document::active_parser()
void Document::set_browsing_context(GC::Ptr<HTML::BrowsingContext> browsing_context)
{
if (browsing_context)
m_has_been_browsing_context_associated = true;
m_browsing_context = browsing_context;
}