mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:07:34 +00:00
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.
This commit is contained in:
parent
4d9c14ca67
commit
807891c0df
2 changed files with 26 additions and 0 deletions
|
@ -4,11 +4,14 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/IDAllocator.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/HTML/EventLoop/Task.h>
|
#include <LibWeb/HTML/EventLoop/Task.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
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)
|
Task::Task(Source source, DOM::Document const* document, JS::SafeFunction<void()> steps)
|
||||||
: m_source(source)
|
: m_source(source)
|
||||||
, m_steps(move(steps))
|
, m_steps(move(steps))
|
||||||
|
@ -35,4 +38,14 @@ DOM::Document const* Task::document() const
|
||||||
return m_document.ptr();
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
struct UniqueTaskSource;
|
||||||
|
|
||||||
class Task {
|
class Task {
|
||||||
public:
|
public:
|
||||||
// https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources
|
// https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources
|
||||||
|
@ -29,6 +31,10 @@ public:
|
||||||
Microtask,
|
Microtask,
|
||||||
TimerTask,
|
TimerTask,
|
||||||
JavaScriptEngine,
|
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)
|
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;
|
JS::Handle<DOM::Document const> m_document;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct UniqueTaskSource {
|
||||||
|
UniqueTaskSource();
|
||||||
|
~UniqueTaskSource();
|
||||||
|
|
||||||
|
Task::Source const source;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue