summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-04 09:02:00 -0400
committerLinus Groh <mail@linusgroh.de>2023-04-07 16:02:22 +0200
commit807891c0df081084abf6227c05e7ce489fe29508 (patch)
tree8d02042bc7ba3e9594b498834a53e1f33e4da8c2 /Userland/Libraries/LibWeb/HTML
parent4d9c14ca6766204ba998e3f89588b723abcd1db3 (diff)
downloadserenity-807891c0df081084abf6227c05e7ce489fe29508.zip
LibWeb: Support unique task sources
Some elements, like HTMLMediaElement, must have a unique task sources for every instance of that element that is created. Support this with a simple wrapper around IDAllocator.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r--Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp13
-rw-r--r--Userland/Libraries/LibWeb/HTML/EventLoop/Task.h13
2 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp
index 91f89765a4..60471f68d2 100644
--- a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp
+++ b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.cpp
@@ -4,11 +4,14 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/IDAllocator.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/EventLoop/Task.h>
namespace Web::HTML {
+static IDAllocator s_unique_task_source_allocator { static_cast<int>(Task::Source::UniqueTaskSourceStart) };
+
Task::Task(Source source, DOM::Document const* document, JS::SafeFunction<void()> steps)
: m_source(source)
, m_steps(move(steps))
@@ -35,4 +38,14 @@ DOM::Document const* Task::document() const
return m_document.ptr();
}
+UniqueTaskSource::UniqueTaskSource()
+ : source(static_cast<Task::Source>(s_unique_task_source_allocator.allocate()))
+{
+}
+
+UniqueTaskSource::~UniqueTaskSource()
+{
+ s_unique_task_source_allocator.deallocate(static_cast<int>(source));
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h
index a850df2152..98f8ca3b1e 100644
--- a/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h
+++ b/Userland/Libraries/LibWeb/HTML/EventLoop/Task.h
@@ -15,6 +15,8 @@
namespace Web::HTML {
+struct UniqueTaskSource;
+
class Task {
public:
// https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources
@@ -29,6 +31,10 @@ public:
Microtask,
TimerTask,
JavaScriptEngine,
+
+ // Some elements, such as the HTMLMediaElement, must have a unique task source per instance.
+ // Keep this field last, to serve as the base value of all unique task sources.
+ UniqueTaskSourceStart,
};
static NonnullOwnPtr<Task> create(Source source, DOM::Document const* document, JS::SafeFunction<void()> steps)
@@ -52,4 +58,11 @@ private:
JS::Handle<DOM::Document const> m_document;
};
+struct UniqueTaskSource {
+ UniqueTaskSource();
+ ~UniqueTaskSource();
+
+ Task::Source const source;
+};
+
}