mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
Everywhere: Hoist the Libraries folder to the top-level
This commit is contained in:
parent
950e819ee7
commit
93712b24bf
Notes:
github-actions[bot]
2024-11-10 11:51:52 +00:00
Author: https://github.com/trflynn89
Commit: 93712b24bf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2256
Reviewed-by: https://github.com/sideshowbarker
4547 changed files with 104 additions and 113 deletions
72
Libraries/LibWeb/HTML/EventLoop/Task.cpp
Normal file
72
Libraries/LibWeb/HTML/EventLoop/Task.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2024, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/IDAllocator.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/EventLoop/Task.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(Task);
|
||||
|
||||
static IDAllocator s_unique_task_source_allocator { static_cast<int>(Task::Source::UniqueTaskSourceStart) };
|
||||
|
||||
[[nodiscard]] static TaskID allocate_task_id()
|
||||
{
|
||||
static u64 next_task_id = 1;
|
||||
return next_task_id++;
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<Task> Task::create(JS::VM& vm, Source source, JS::GCPtr<DOM::Document const> document, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
|
||||
{
|
||||
return vm.heap().allocate_without_realm<Task>(source, document, move(steps));
|
||||
}
|
||||
|
||||
Task::Task(Source source, JS::GCPtr<DOM::Document const> document, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
|
||||
: m_id(allocate_task_id())
|
||||
, m_source(source)
|
||||
, m_steps(steps)
|
||||
, m_document(document)
|
||||
{
|
||||
}
|
||||
|
||||
Task::~Task() = default;
|
||||
|
||||
void Task::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_steps);
|
||||
visitor.visit(m_document);
|
||||
}
|
||||
|
||||
void Task::execute()
|
||||
{
|
||||
m_steps->function()();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#concept-task-runnable
|
||||
bool Task::is_runnable() const
|
||||
{
|
||||
// A task is runnable if its document is either null or fully active.
|
||||
return !m_document.ptr() || m_document->is_fully_active();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue