From 9d69563da40aeb571f43f91fc64c0dfd4ebb350d Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 13 Apr 2024 06:09:34 +0200 Subject: [PATCH] LibWeb: Revert blocking of task by source in EventLoop This reverts commit 664611bae41a20d3bf740da12fdf19322f6574f1. It seems like the HTML spec has been misinterpreted and this text: "... 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." does not mean we can't interrupt execution of task by a task with the same task source. It just says they should be processed in the order they were added. Fixes hanging while navigating from PR list to PR page on GitHub. --- .../LibWeb/HTML/EventLoop/EventLoop.cpp | 34 ------------------- .../LibWeb/HTML/EventLoop/EventLoop.h | 6 ---- .../LibWeb/HTML/EventLoop/TaskQueue.cpp | 7 +--- 3 files changed, 1 insertion(+), 46 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index 09285c391b2..cdfe2ce60d0 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -27,9 +27,6 @@ EventLoop::EventLoop() { m_task_queue = heap().allocate_without_realm(*this); m_microtask_queue = heap().allocate_without_realm(*this); - - for (size_t i = 0; i < m_blocked_task_sources.size(); ++i) - m_blocked_task_sources[i] = false; } EventLoop::~EventLoop() = default; @@ -62,31 +59,6 @@ EventLoop& main_thread_event_loop() return *static_cast(Bindings::main_thread_vm().custom_data())->event_loop; } -bool EventLoop::is_task_source_blocked(Task::Source source) const -{ - if (source == Task::Source::Unspecified) - return false; - if (static_cast(to_underlying(source)) < m_blocked_task_sources.size()) - return m_blocked_task_sources[to_underlying(source)]; - return false; -} - -void EventLoop::block_task_source(Task::Source source) -{ - if (source == Task::Source::Unspecified) - return; - if (static_cast(to_underlying(source)) < m_blocked_task_sources.size()) - m_blocked_task_sources[to_underlying(source)] = true; -} - -void EventLoop::unblock_task_source(Task::Source source) -{ - if (source == Task::Source::Unspecified) - return; - if (static_cast(to_underlying(source)) < m_blocked_task_sources.size()) - m_blocked_task_sources[to_underlying(source)] = false; -} - // https://html.spec.whatwg.org/multipage/webappapis.html#spin-the-event-loop void EventLoop::spin_until(JS::SafeFunction goal_condition) { @@ -147,13 +119,11 @@ void EventLoop::spin_processing_tasks_with_source_until(Task::Source source, JS: return task.source() == source && task.is_runnable(); }); - block_task_source(source); for (auto& task : tasks) { m_currently_running_task = task.ptr(); task->execute(); m_currently_running_task = nullptr; } - unblock_task_source(source); } // FIXME: Remove the platform event loop plugin so that this doesn't look out of place @@ -191,8 +161,6 @@ void EventLoop::process() oldest_task = task_queue.take_first_runnable(); if (oldest_task) { - block_task_source(oldest_task->source()); - // 5. Set the event loop's currently running task to oldestTask. m_currently_running_task = oldest_task.ptr(); @@ -201,8 +169,6 @@ void EventLoop::process() // 7. Set the event loop's currently running task back to null. m_currently_running_task = nullptr; - - unblock_task_source(oldest_task->source()); } // 8. Microtasks: Perform a microtask checkpoint. diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h index dae3a3b521e..ebb4a794cdb 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h @@ -39,10 +39,6 @@ public: TaskQueue& microtask_queue() { return *m_microtask_queue; } TaskQueue const& microtask_queue() const { return *m_microtask_queue; } - bool is_task_source_blocked(Task::Source source) const; - void block_task_source(Task::Source source); - void unblock_task_source(Task::Source source); - void spin_until(NOESCAPE JS::SafeFunction goal_condition); void spin_processing_tasks_with_source_until(Task::Source, NOESCAPE JS::SafeFunction goal_condition); void process(); @@ -117,8 +113,6 @@ private: bool m_execution_paused { false }; bool m_skip_event_loop_processing_steps { false }; - - Array m_blocked_task_sources; }; EventLoop& main_thread_event_loop(); diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp index bee975f1e9b..8cea970cc5f 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp @@ -39,10 +39,7 @@ JS::GCPtr TaskQueue::take_first_runnable() return nullptr; for (size_t i = 0; i < m_tasks.size(); ++i) { - auto const& task = m_tasks[i]; - if (m_event_loop->is_task_source_blocked(task->source())) - continue; - if (task->is_runnable()) + if (m_tasks[i]->is_runnable()) return m_tasks.take(i); } return nullptr; @@ -54,8 +51,6 @@ 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; }