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

@@ -34,10 +34,6 @@ void TaskQueue::add(GC::Ref<Task> task)
if (task->document() && task->document()->is_temporary_document_for_fragment_parsing())
return;
// AD-HOC: Don't enqueue tasks for documents that haven't been browsing context associated.
if (task->document() && !task->document()->has_been_browsing_context_associated())
return;
m_tasks.append(task);
m_event_loop->schedule();
}
@@ -47,11 +43,22 @@ GC::Ptr<Task> TaskQueue::take_first_runnable()
if (m_event_loop->execution_paused())
return nullptr;
for (size_t i = 0; i < m_tasks.size(); ++i) {
if (m_event_loop->running_rendering_task() && m_tasks[i]->source() == Task::Source::Rendering)
for (size_t i = 0; i < m_tasks.size();) {
if (m_event_loop->running_rendering_task() && m_tasks[i]->source() == Task::Source::Rendering) {
++i;
continue;
}
if (m_tasks[i]->is_runnable())
return m_tasks.take(i);
// A non-runnable task with a destroyed document will never become runnable again; remove it.
if (m_tasks[i]->document() && m_tasks[i]->document()->has_been_destroyed()) {
m_tasks.remove(i);
continue;
}
++i;
}
return nullptr;
}