diff --git a/Userland/Libraries/LibWeb/Animations/Animation.h b/Userland/Libraries/LibWeb/Animations/Animation.h index c06e5010e65..134346e0cab 100644 --- a/Userland/Libraries/LibWeb/Animations/Animation.h +++ b/Userland/Libraries/LibWeb/Animations/Animation.h @@ -192,7 +192,7 @@ private: // https://www.w3.org/TR/web-animations-1/#pending-pause-task TaskState m_pending_pause_task { TaskState::None }; - Optional m_pending_finish_microtask_id; + Optional m_pending_finish_microtask_id; Optional m_saved_play_time; Optional m_saved_pause_time; diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 4a70684f513..f9d034dea12 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -894,7 +894,7 @@ void Element::make_html_uppercased_qualified_name() } // https://html.spec.whatwg.org/multipage/webappapis.html#queue-an-element-task -int Element::queue_an_element_task(HTML::Task::Source source, Function steps) +HTML::TaskID Element::queue_an_element_task(HTML::Task::Source source, Function steps) { return queue_a_task(source, HTML::main_thread_event_loop(), document(), JS::create_heap_function(heap(), move(steps))); } diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 13fe0256372..eabd7fcd0d5 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -227,7 +227,7 @@ public: [[nodiscard]] HashMap const& custom_properties(Optional) const; // NOTE: The function is wrapped in a JS::HeapFunction immediately. - int queue_an_element_task(HTML::Task::Source, Function); + HTML::TaskID queue_an_element_task(HTML::Task::Source, Function); bool is_void_element() const; bool serializes_as_void() const; diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp index 047d77efeb8..eefa688233e 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp @@ -110,7 +110,7 @@ void FetchController::stop_fetch() auto ongoing_fetch_tasks = move(m_ongoing_fetch_tasks); HTML::main_thread_event_loop().task_queue().remove_tasks_matching([&](auto const& task) { - return ongoing_fetch_tasks.remove_all_matching([&](u64, int task_id) { + return ongoing_fetch_tasks.remove_all_matching([&](u64, HTML::TaskID task_id) { return task.id() == task_id; }); }); @@ -121,7 +121,7 @@ void FetchController::stop_fetch() } } -void FetchController::fetch_task_queued(u64 fetch_task_id, int event_id) +void FetchController::fetch_task_queued(u64 fetch_task_id, HTML::TaskID event_id) { m_ongoing_fetch_tasks.set(fetch_task_id, event_id); } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h index 879bd7f3876..46e8f3169bb 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace Web::Fetch::Infrastructure { @@ -50,7 +51,7 @@ public: void stop_fetch(); u64 next_fetch_task_id() { return m_next_fetch_task_id++; } - void fetch_task_queued(u64 fetch_task_id, int event_id); + void fetch_task_queued(u64 fetch_task_id, HTML::TaskID event_id); void fetch_task_complete(u64 fetch_task_id); private: @@ -84,7 +85,7 @@ private: JS::GCPtr m_fetch_params; - HashMap m_ongoing_fetch_tasks; + HashMap m_ongoing_fetch_tasks; u64 m_next_fetch_task_id { 0 }; }; diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.cpp index 38af834ffe3..bd223000c2b 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.cpp @@ -11,7 +11,7 @@ namespace Web::Fetch::Infrastructure { // https://fetch.spec.whatwg.org/#queue-a-fetch-task -int queue_fetch_task(JS::Object& task_destination, JS::NonnullGCPtr> algorithm) +HTML::TaskID queue_fetch_task(JS::Object& task_destination, JS::NonnullGCPtr> algorithm) { // FIXME: 1. If taskDestination is a parallel queue, then enqueue algorithm to taskDestination. @@ -21,18 +21,18 @@ int queue_fetch_task(JS::Object& task_destination, JS::NonnullGCPtr fetch_controller, JS::Object& task_destination, JS::NonnullGCPtr> algorithm) +HTML::TaskID queue_fetch_task(JS::NonnullGCPtr fetch_controller, JS::Object& task_destination, JS::NonnullGCPtr> algorithm) { auto fetch_task_id = fetch_controller->next_fetch_task_id(); auto& heap = task_destination.heap(); - int event_id = queue_fetch_task(task_destination, JS::create_heap_function(heap, [fetch_controller, fetch_task_id, algorithm]() { + auto html_task_id = queue_fetch_task(task_destination, JS::create_heap_function(heap, [fetch_controller, fetch_task_id, algorithm]() { fetch_controller->fetch_task_complete(fetch_task_id); algorithm->function()(); })); - fetch_controller->fetch_task_queued(fetch_task_id, event_id); - return event_id; + fetch_controller->fetch_task_queued(fetch_task_id, html_task_id); + return html_task_id; } } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.h index 1c094f43b50..539cd86ba56 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/Task.h @@ -11,13 +11,14 @@ #include #include #include +#include namespace Web::Fetch::Infrastructure { // FIXME: 'or a parallel queue' using TaskDestination = Variant>; -int queue_fetch_task(JS::Object&, JS::NonnullGCPtr>); -int queue_fetch_task(JS::NonnullGCPtr, JS::Object&, JS::NonnullGCPtr>); +HTML::TaskID queue_fetch_task(JS::Object&, JS::NonnullGCPtr>); +HTML::TaskID queue_fetch_task(JS::NonnullGCPtr, JS::Object&, JS::NonnullGCPtr>); } diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index c974232665f..0a29e967c27 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -384,7 +384,7 @@ void EventLoop::process() } // https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task -int queue_a_task(HTML::Task::Source source, JS::GCPtr event_loop, JS::GCPtr document, JS::NonnullGCPtr> steps) +TaskID queue_a_task(HTML::Task::Source source, JS::GCPtr event_loop, JS::GCPtr document, JS::NonnullGCPtr> steps) { // 1. If event loop was not given, set event loop to the implied event loop. if (!event_loop) @@ -409,7 +409,7 @@ int queue_a_task(HTML::Task::Source source, JS::GCPtr event_loop, JS: } // https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-global-task -int queue_global_task(HTML::Task::Source source, JS::Object& global_object, JS::NonnullGCPtr> steps) +TaskID queue_global_task(HTML::Task::Source source, JS::Object& global_object, JS::NonnullGCPtr> steps) { // 1. Let event loop be global's relevant agent's event loop. auto& global_custom_data = verify_cast(*global_object.vm().custom_data()); diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h index 206e708d468..d50a0d894fc 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h @@ -116,8 +116,8 @@ private: }; EventLoop& main_thread_event_loop(); -int queue_a_task(HTML::Task::Source, JS::GCPtr, JS::GCPtr, JS::NonnullGCPtr> steps); -int queue_global_task(HTML::Task::Source, JS::Object&, JS::NonnullGCPtr> steps); +TaskID queue_a_task(HTML::Task::Source, JS::GCPtr, JS::GCPtr, JS::NonnullGCPtr> steps); +TaskID queue_global_task(HTML::Task::Source, JS::Object&, JS::NonnullGCPtr> steps); void queue_a_microtask(DOM::Document const*, JS::NonnullGCPtr> steps); void perform_a_microtask_checkpoint(); diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp index 9be925bb902..a78f3ab8bd8 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp @@ -13,7 +13,12 @@ namespace Web::HTML { JS_DEFINE_ALLOCATOR(Task); static IDAllocator s_unique_task_source_allocator { static_cast(Task::Source::UniqueTaskSourceStart) }; -static IDAllocator s_task_id_allocator; + +[[nodiscard]] static TaskID allocate_task_id() +{ + static u64 next_task_id = 1; + return next_task_id++; +} JS::NonnullGCPtr Task::create(JS::VM& vm, Source source, JS::GCPtr document, JS::NonnullGCPtr> steps) { @@ -21,7 +26,7 @@ JS::NonnullGCPtr Task::create(JS::VM& vm, Source source, JS::GCPtr document, JS::NonnullGCPtr> steps) - : m_id(s_task_id_allocator.allocate()) + : m_id(allocate_task_id()) , m_source(source) , m_steps(steps) , m_document(document) @@ -30,11 +35,6 @@ Task::Task(Source source, JS::GCPtr document, JS::NonnullGC Task::~Task() = default; -void Task::finalize() -{ - s_unique_task_source_allocator.deallocate(m_id); -} - void Task::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h index 5460dcfc45a..e26c57ffe3a 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -15,6 +16,8 @@ namespace Web::HTML { struct UniqueTaskSource; +AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, TaskID, Comparison); + class Task final : public JS::Cell { JS_CELL(Task, JS::Cell); JS_DECLARE_ALLOCATOR(Task); @@ -69,9 +72,8 @@ public: static JS::NonnullGCPtr create(JS::VM&, Source, JS::GCPtr, JS::NonnullGCPtr> steps); virtual ~Task() override; - virtual void finalize() override; - int id() const { return m_id; } + [[nodiscard]] TaskID id() const { return m_id; } Source source() const { return m_source; } void execute(); @@ -84,7 +86,7 @@ private: virtual void visit_edges(Visitor&) override; - int m_id { 0 }; + TaskID m_id {}; Source m_source { Source::Unspecified }; JS::NonnullGCPtr> m_steps; JS::GCPtr m_document; diff --git a/Userland/Libraries/LibWeb/HTML/ToggleTaskTracker.h b/Userland/Libraries/LibWeb/HTML/ToggleTaskTracker.h index 267da119eab..54c9045d81b 100644 --- a/Userland/Libraries/LibWeb/HTML/ToggleTaskTracker.h +++ b/Userland/Libraries/LibWeb/HTML/ToggleTaskTracker.h @@ -16,7 +16,7 @@ namespace Web::HTML { struct ToggleTaskTracker { // https://html.spec.whatwg.org/multipage/interaction.html#toggle-task-task // NOTE: We store the task's ID rather than the task itself to avoid ownership issues. - Optional task_id; + Optional task_id; // https://html.spec.whatwg.org/multipage/interaction.html#toggle-task-old-state String old_state;