diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 5e5e31bece..69fe5aa1c0 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -705,18 +705,6 @@ void Window::fire_a_page_transition_event(DeprecatedFlyString const& event_name,
dispatch_event(event);
}
-// https://html.spec.whatwg.org/#dom-queuemicrotask
-void Window::queue_microtask_impl(WebIDL::CallbackType& callback)
-{
- // The queueMicrotask(callback) method must queue a microtask to invoke callback,
- HTML::queue_a_microtask(&associated_document(), [this, &callback] {
- auto result = WebIDL::invoke_callback(callback, {});
- // and if callback throws an exception, report the exception.
- if (result.is_error())
- HTML::report_exception(result, realm());
- });
-}
-
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-localstorage
JS::NonnullGCPtr Window::local_storage()
{
@@ -883,8 +871,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge(realm, realm)), 0);
// FIXME: Implement codegen for readonly properties with [PutForwards]
@@ -1564,21 +1550,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::clear_interval)
return JS::js_undefined();
}
-JS_DEFINE_NATIVE_FUNCTION(Window::queue_microtask)
-{
- auto* impl = TRY(impl_from(vm));
- if (!vm.argument_count())
- return vm.throw_completion(JS::ErrorType::BadArgCountAtLeastOne, "queueMicrotask");
- auto* callback_object = TRY(vm.argument(0).to_object(vm));
- if (!callback_object->is_function())
- return vm.throw_completion(JS::ErrorType::NotAFunctionNoParam);
-
- auto callback = vm.heap().allocate_without_realm(*callback_object, HTML::incumbent_settings_object());
-
- impl->queue_microtask_impl(*callback);
- return JS::js_undefined();
-}
-
// https://html.spec.whatwg.org/multipage/window-object.html#number-of-document-tree-child-browsing-contexts
size_t Window::document_tree_child_browsing_context_count() const
{
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index 704b998e39..2ead4a0299 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -61,6 +61,7 @@ public:
using WindowOrWorkerGlobalScopeMixin::atob;
using WindowOrWorkerGlobalScopeMixin::btoa;
using WindowOrWorkerGlobalScopeMixin::fetch;
+ using WindowOrWorkerGlobalScopeMixin::queue_microtask;
using WindowOrWorkerGlobalScopeMixin::structured_clone;
// ^DOM::EventTarget
@@ -97,8 +98,6 @@ public:
void clear_timeout_impl(i32);
void clear_interval_impl(i32);
- void queue_microtask_impl(WebIDL::CallbackType& callback);
-
void did_set_location_href(Badge, AK::URL const& new_href);
void did_call_location_reload(Badge);
void did_call_location_replace(Badge, DeprecatedString url);
@@ -255,8 +254,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(clear_interval);
JS_DECLARE_NATIVE_FUNCTION(clear_timeout);
- JS_DECLARE_NATIVE_FUNCTION(queue_microtask);
-
HTML::Location* m_location { nullptr };
// [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap
diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
index 119d3cd980..a2831e5c7d 100644
--- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
@@ -12,10 +12,14 @@
#include
#include
#include
+#include
#include
+#include
#include
+#include
#include
#include
+#include
#include
#include
@@ -86,6 +90,24 @@ WebIDL::ExceptionOr WindowOrWorkerGlobalScopeMixin::atob(String const& d
return TRY_OR_THROW_OOM(vm, decoder->to_utf8(decoded_data.value()));
}
+// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask
+void WindowOrWorkerGlobalScopeMixin::queue_microtask(WebIDL::CallbackType& callback)
+{
+ auto& vm = this_impl().vm();
+ auto& realm = *vm.current_realm();
+
+ JS::GCPtr document;
+ if (is(this_impl()))
+ document = &static_cast(this_impl()).associated_document();
+
+ // The queueMicrotask(callback) method must queue a microtask to invoke callback, and if callback throws an exception, report the exception.
+ HTML::queue_a_microtask(document, [&callback, &realm] {
+ auto result = WebIDL::invoke_callback(callback, {});
+ if (result.is_error())
+ HTML::report_exception(result, realm);
+ });
+}
+
// https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone
WebIDL::ExceptionOr WindowOrWorkerGlobalScopeMixin::structured_clone(JS::Value value, StructuredSerializeOptions const& options) const
{
diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
index c01021c4c6..598aa7b717 100644
--- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
+++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
@@ -28,6 +28,7 @@ public:
bool cross_origin_isolated() const;
WebIDL::ExceptionOr btoa(String const& data) const;
WebIDL::ExceptionOr atob(String const& data) const;
+ void queue_microtask(WebIDL::CallbackType&);
WebIDL::ExceptionOr structured_clone(JS::Value, StructuredSerializeOptions const&) const;
JS::NonnullGCPtr fetch(Fetch::RequestInfo const&, Fetch::RequestInit const&) const;
};
diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl
index 23443c8f5a..dc734395af 100644
--- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl
+++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl
@@ -2,6 +2,9 @@
#import
#import
+// FIXME: Support VoidFunction in the IDL parser
+callback VoidFunction = undefined ();
+
// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope
interface mixin WindowOrWorkerGlobalScope {
[Replaceable] readonly attribute USVString origin;
@@ -21,7 +24,7 @@ interface mixin WindowOrWorkerGlobalScope {
// FIXME: undefined clearInterval(optional long id = 0);
// microtask queuing
- // FIXME: undefined queueMicrotask(VoidFunction callback);
+ undefined queueMicrotask(VoidFunction callback);
// ImageBitmap
// FIXME: Promise createImageBitmap(ImageBitmapSource image, optional ImageBitmapOptions options = {});