mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user