LibWeb: Let queue_fetch_task() take a JS::HeapFunction

Changes the signature of queue_fetch_task() from AK:Function to
JS::HeapFunction to be more clear to the user of the function that this
is what it uses internally.
This commit is contained in:
Kenneth Myhra 2024-04-19 10:23:40 +02:00 committed by Andreas Kling
commit 291d0e5de8
Notes: sideshowbarker 2024-07-17 09:37:30 +09:00
4 changed files with 21 additions and 21 deletions

View file

@ -11,25 +11,25 @@
namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#queue-a-fetch-task
int queue_fetch_task(JS::Object& task_destination, Function<void()> algorithm)
int queue_fetch_task(JS::Object& task_destination, JS::NonnullGCPtr<JS::HeapFunction<void()>> algorithm)
{
// FIXME: 1. If taskDestination is a parallel queue, then enqueue algorithm to taskDestination.
// 2. Otherwise, queue a global task on the networking task source with taskDestination and algorithm.
auto& vm = task_destination.vm();
return HTML::queue_global_task(HTML::Task::Source::Networking, task_destination, JS::create_heap_function(vm.heap(), move(algorithm)));
return HTML::queue_global_task(HTML::Task::Source::Networking, task_destination, algorithm);
}
// AD-HOC: This overload allows tracking the queued task within the fetch controller so that we may cancel queued tasks
// when the spec indicates that we must stop an ongoing fetch.
int queue_fetch_task(JS::NonnullGCPtr<FetchController> fetch_controller, JS::Object& task_destination, Function<void()> algorithm)
int queue_fetch_task(JS::NonnullGCPtr<FetchController> fetch_controller, JS::Object& task_destination, JS::NonnullGCPtr<JS::HeapFunction<void()>> algorithm)
{
auto fetch_task_id = fetch_controller->next_fetch_task_id();
int event_id = queue_fetch_task(task_destination, [fetch_controller, fetch_task_id, algorithm = move(algorithm)]() {
auto& heap = task_destination.heap();
int event_id = queue_fetch_task(task_destination, JS::create_heap_function(heap, [fetch_controller, fetch_task_id, algorithm]() {
fetch_controller->fetch_task_complete(fetch_task_id);
algorithm();
});
algorithm->function()();
}));
fetch_controller->fetch_task_queued(fetch_task_id, event_id);
return event_id;