LibWeb: Prevent running permanently unrunnable tasks in EventLoop

In `::spin_processing_tasks_with_source_until()`, we would first take a
set of tasks based on a filter, and then run them one by one. If there
was more than one task matched and put in that vector, they could
interfere with each other's runnability by making later tasks
permanently unrunnable.

The `::take_tasks_matching()` API is a footgun - remove it in favor of
an API that takes tasks one by one, performing the runnability check
just in time.
This commit is contained in:
Jelle Raaijmakers
2026-03-26 16:14:14 +01:00
committed by Jelle Raaijmakers
parent f5d76ec2d0
commit a5000d07c0
Notes: github-actions[bot] 2026-03-26 17:49:49 +00:00
4 changed files with 22 additions and 29 deletions

View File

@@ -617,17 +617,15 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::load_element()
// any ongoing fetch operation. Therefore, all resource selection algorithms will be cancelled before a new
// one begins.
// 2. Let pending tasks be a list of all tasks from the media element's media element event task source in one of the task queues.
[[maybe_unused]] auto pending_tasks = HTML::main_thread_event_loop().task_queue().take_tasks_matching([&](auto& task) {
// 2. Let pending tasks be a list of all tasks from the media element's media element event task source in one of
// the task queues.
// FIXME: 3. For each task in pending tasks that would resolve pending play promises or reject pending play promises,
// immediately resolve or reject those promises in the order the corresponding tasks were queued.
// 4. Remove each task in pending tasks from its task queue
main_thread_event_loop().task_queue().remove_tasks_matching([&](auto& task) {
return task.source() == media_element_event_task_source();
});
// FIXME: 3. For each task in pending tasks that would resolve pending play promises or reject pending play promises, immediately resolve or
// reject those promises in the order the corresponding tasks were queued.
// 4. Remove each task in pending tasks from its task queue
// NOTE: We performed this step along with step 2.
// 5. If the media element's networkState is set to NETWORK_LOADING or NETWORK_IDLE, queue a media element task given the media element to
// fire an event named abort at the media element.
if (m_network_state == NetworkState::Loading || m_network_state == NetworkState::Idle) {