diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 79b1de2931..20dab940d9 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -759,10 +759,14 @@ void Element::make_html_uppercased_qualified_name() } // https://html.spec.whatwg.org/multipage/webappapis.html#queue-an-element-task -void Element::queue_an_element_task(HTML::Task::Source source, JS::SafeFunction steps) +int Element::queue_an_element_task(HTML::Task::Source source, JS::SafeFunction steps) { auto task = HTML::Task::create(source, &document(), move(steps)); + auto id = task->id(); + HTML::main_thread_event_loop().task_queue().add(move(task)); + + return id; } // https://html.spec.whatwg.org/multipage/syntax.html#void-elements diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 208d940926..68d06de00f 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -197,7 +197,7 @@ public: void set_custom_properties(Optional, HashMap custom_properties); [[nodiscard]] HashMap const& custom_properties(Optional) const; - void queue_an_element_task(HTML::Task::Source, JS::SafeFunction); + int queue_an_element_task(HTML::Task::Source, JS::SafeFunction); bool is_void_element() const; bool serializes_as_void() const; diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp index 60471f68d2..b77c779232 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp @@ -11,15 +11,20 @@ namespace Web::HTML { static IDAllocator s_unique_task_source_allocator { static_cast(Task::Source::UniqueTaskSourceStart) }; +static IDAllocator s_task_id_allocator; Task::Task(Source source, DOM::Document const* document, JS::SafeFunction steps) - : m_source(source) + : m_id(s_task_id_allocator.allocate()) + , m_source(source) , m_steps(move(steps)) , m_document(JS::make_handle(document)) { } -Task::~Task() = default; +Task::~Task() +{ + s_unique_task_source_allocator.deallocate(m_id); +} void Task::execute() { diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h index ef17779800..2bfb7f4fdc 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h @@ -59,6 +59,7 @@ public: } ~Task(); + int id() const { return m_id; } Source source() const { return m_source; } void execute(); @@ -69,6 +70,7 @@ public: private: Task(Source, DOM::Document const*, JS::SafeFunction steps); + int m_id { 0 }; Source m_source { Source::Unspecified }; JS::SafeFunction m_steps; JS::Handle m_document;