aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/globalscope.rs10
-rw-r--r--components/script/dom/webidls/WindowOrWorkerGlobalScope.webidl3
-rw-r--r--components/script/dom/window.rs7
-rw-r--r--components/script/dom/workerglobalscope.rs7
4 files changed, 26 insertions, 1 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index 04f8d948a24..e551009b59d 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -4,6 +4,7 @@
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::EventSourceBinding::EventSourceBinding::EventSourceMethods;
+use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
use crate::dom::bindings::conversions::{root_from_object, root_from_object_static};
@@ -32,7 +33,7 @@ use crate::dom::performance::Performance;
use crate::dom::window::Window;
use crate::dom::workerglobalscope::WorkerGlobalScope;
use crate::dom::workletglobalscope::WorkletGlobalScope;
-use crate::microtask::{Microtask, MicrotaskQueue};
+use crate::microtask::{Microtask, MicrotaskQueue, UserMicrotask};
use crate::script_module::ModuleTree;
use crate::script_runtime::{CommonScriptMsg, JSContext as SafeJSContext, ScriptChan, ScriptPort};
use crate::script_thread::{MainThreadScriptChan, ScriptThread};
@@ -1772,6 +1773,13 @@ impl GlobalScope {
self.timers.clear_timeout_or_interval(self, handle);
}
+ pub fn queue_function_as_microtask(&self, callback: Rc<VoidFunction>) {
+ self.enqueue_microtask(Microtask::User(UserMicrotask {
+ callback: callback,
+ pipeline: self.pipeline_id(),
+ }))
+ }
+
pub fn fire_timer(&self, handle: TimerEventId) {
self.timers.fire_timer(handle, self);
}
diff --git a/components/script/dom/webidls/WindowOrWorkerGlobalScope.webidl b/components/script/dom/webidls/WindowOrWorkerGlobalScope.webidl
index c798b56ab00..61f150f8e81 100644
--- a/components/script/dom/webidls/WindowOrWorkerGlobalScope.webidl
+++ b/components/script/dom/webidls/WindowOrWorkerGlobalScope.webidl
@@ -20,6 +20,9 @@ interface mixin WindowOrWorkerGlobalScope {
long setInterval(TimerHandler handler, optional long timeout = 0, any... arguments);
void clearInterval(optional long handle = 0);
+ // microtask queuing
+ void queueMicrotask(VoidFunction callback);
+
// ImageBitmap
// Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, optional ImageBitmapOptions options);
// Promise<ImageBitmap> createImageBitmap(
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index d48f16ea662..80fa021346c 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -11,6 +11,7 @@ use crate::dom::bindings::codegen::Bindings::HistoryBinding::HistoryBinding::His
use crate::dom::bindings::codegen::Bindings::MediaQueryListBinding::MediaQueryListBinding::MediaQueryListMethods;
use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionState;
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
+use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction;
use crate::dom::bindings::codegen::Bindings::WindowBinding::{
self, FrameRequestCallback, WindowMethods, WindowPostMessageOptions,
};
@@ -871,6 +872,12 @@ impl WindowMethods for Window {
self.ClearTimeout(handle);
}
+ // https://html.spec.whatwg.org/multipage/#dom-queuemicrotask
+ fn QueueMicrotask(&self, callback: Rc<VoidFunction>) {
+ self.upcast::<GlobalScope>()
+ .queue_function_as_microtask(callback);
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-window
fn Window(&self) -> DomRoot<WindowProxy> {
self.window_proxy()
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index f29fd70f99f..0b8d7e33478 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -5,6 +5,7 @@
use crate::compartments::InCompartment;
use crate::dom::bindings::cell::{DomRefCell, Ref};
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
+use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction;
use crate::dom::bindings::codegen::Bindings::WorkerBinding::WorkerType;
use crate::dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
use crate::dom::bindings::codegen::UnionTypes::{RequestOrUSVString, StringOrFunction};
@@ -341,6 +342,12 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
self.ClearTimeout(handle);
}
+ // https://html.spec.whatwg.org/multipage/#dom-queuemicrotask
+ fn QueueMicrotask(&self, callback: Rc<VoidFunction>) {
+ self.upcast::<GlobalScope>()
+ .queue_function_as_microtask(callback);
+ }
+
#[allow(unrooted_must_root)]
// https://fetch.spec.whatwg.org/#fetch-method
fn Fetch(