LibWeb: Forbid interleaving execution of HTML tasks with same source

From HTML spec https://html.spec.whatwg.org/#definitions-3
"... Note that in this setup, the processing model still enforces that
the user agent would never process events from any one task source out
of order."

I can't come up with an example that is fixed by this change. However,
debugging a bug caused by violating this assumption from the spec is
likely to be very painful.
This commit is contained in:
Aliaksandr Kalenik
2024-04-09 19:41:28 +02:00
committed by Andreas Kling
parent ba633882bf
commit 664611bae4
3 changed files with 46 additions and 1 deletions

View File

@@ -39,7 +39,10 @@ JS::GCPtr<Task> TaskQueue::take_first_runnable()
return nullptr;
for (size_t i = 0; i < m_tasks.size(); ++i) {
if (m_tasks[i]->is_runnable())
auto const& task = m_tasks[i];
if (m_event_loop->is_task_source_blocked(task->source()))
continue;
if (task->is_runnable())
return m_tasks.take(i);
}
return nullptr;
@@ -51,6 +54,8 @@ bool TaskQueue::has_runnable_tasks() const
return false;
for (auto& task : m_tasks) {
if (m_event_loop->is_task_source_blocked(task->source()))
continue;
if (task->is_runnable())
return true;
}