mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +00:00
LibWeb: Implement the "queue a task" steps as a distinct AO
This will be needed by EventSource.
This commit is contained in:
parent
b6f824a313
commit
9cc186b929
Notes:
sideshowbarker
2024-07-16 20:12:13 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/9cc186b929 Pull-request: https://github.com/SerenityOS/serenity/pull/24452 Issue: https://github.com/SerenityOS/serenity/issues/23847
2 changed files with 27 additions and 4 deletions
|
@ -369,6 +369,31 @@ void EventLoop::process()
|
|||
});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task
|
||||
int queue_a_task(HTML::Task::Source source, JS::GCPtr<EventLoop> event_loop, JS::GCPtr<DOM::Document> document, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
|
||||
{
|
||||
// 1. If event loop was not given, set event loop to the implied event loop.
|
||||
if (!event_loop)
|
||||
event_loop = main_thread_event_loop();
|
||||
|
||||
// FIXME: 2. If document was not given, set document to the implied document.
|
||||
|
||||
// 3. Let task be a new task.
|
||||
// 4. Set task's steps to steps.
|
||||
// 5. Set task's source to source.
|
||||
// 6. Set task's document to the document.
|
||||
// 7. Set task's script evaluation environment settings object set to an empty set.
|
||||
auto task = HTML::Task::create(event_loop->vm(), source, document, steps);
|
||||
|
||||
// 8. Let queue be the task queue to which source is associated on event loop.
|
||||
auto& queue = event_loop->task_queue();
|
||||
|
||||
// 9. Append task to queue.
|
||||
queue.add(task);
|
||||
|
||||
return queue.last_added_task()->id();
|
||||
}
|
||||
|
||||
// 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<JS::HeapFunction<void()>> steps)
|
||||
{
|
||||
|
@ -384,10 +409,7 @@ int queue_global_task(HTML::Task::Source source, JS::Object& global_object, JS::
|
|||
}
|
||||
|
||||
// 3. Queue a task given source, event loop, document, and steps.
|
||||
auto& vm = global_object.vm();
|
||||
event_loop->task_queue().add(HTML::Task::create(vm, source, document, steps));
|
||||
|
||||
return event_loop->task_queue().last_added_task()->id();
|
||||
return queue_a_task(source, *event_loop, document, steps);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#queue-a-microtask
|
||||
|
|
|
@ -116,6 +116,7 @@ private:
|
|||
};
|
||||
|
||||
EventLoop& main_thread_event_loop();
|
||||
int queue_a_task(HTML::Task::Source, JS::GCPtr<EventLoop>, JS::GCPtr<DOM::Document>, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps);
|
||||
int queue_global_task(HTML::Task::Source, JS::Object&, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps);
|
||||
void queue_a_microtask(DOM::Document const*, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps);
|
||||
void perform_a_microtask_checkpoint();
|
||||
|
|
Loading…
Add table
Reference in a new issue