1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibWeb: Implement window.queueMicrotask(callback)

This API allows authors to schedule a serialized JS callback that will
get invoked at the next spec-allowed opportunity.
This commit is contained in:
Andreas Kling 2021-09-26 14:36:20 +02:00
parent 831fdcaabc
commit a248ec63e3
10 changed files with 144 additions and 19 deletions

View file

@ -12,6 +12,7 @@
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/DOM/Timer.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/PageTransitionEvent.h>
#include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
@ -295,4 +296,17 @@ void Window::fire_a_page_transition_event(FlyString event_name, bool persisted)
dispatch_event(move(event));
}
// https://html.spec.whatwg.org/#dom-queuemicrotask
void Window::queue_microtask(JS::FunctionObject& callback)
{
// The queueMicrotask(callback) method must queue a microtask to invoke callback,
HTML::queue_a_microtask(associated_document(), [&callback, handle = JS::make_handle(&callback)]() {
auto& vm = callback.vm();
[[maybe_unused]] auto rc = vm.call(callback, JS::js_null());
// FIXME: ...and if callback throws an exception, report the exception.
if (vm.exception())
vm.clear_exception();
});
}
}