LibWeb: Run queued HTML tasks after associated document is destroyed

Before this change, tasks associated with a destroyed document would get
stuck in the task queue forever, since document-associated tasks are not
allowed to run when their document isn't fully active (and destroyed
documents never become fully active again). This caused everything
captured by task callbacks to leak.

We now treat tasks for destroyed documents as runnable immediately,
which gets them out of the queue.

This fixes another massive GC leak on Speedometer.
This commit is contained in:
Andreas Kling 2025-02-07 11:28:08 +01:00 committed by Andreas Kling
commit 187f8c5460
Notes: github-actions[bot] 2025-02-07 15:54:13 +00:00
3 changed files with 18 additions and 1 deletions

View file

@ -560,6 +560,8 @@ public:
Vector<GC::Root<HTML::Navigable>> inclusive_ancestor_navigables();
Vector<GC::Root<HTML::Navigable>> document_tree_child_navigables();
[[nodiscard]] bool has_been_destroyed() const { return m_has_been_destroyed; }
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document
void destroy();
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document-and-its-descendants
@ -873,6 +875,8 @@ private:
GC::Ptr<HTML::HTMLParser> m_parser;
bool m_active_parser_was_aborted { false };
bool m_has_been_destroyed { false };
String m_source;
GC::Ptr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script;