summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/globals.ts1
-rw-r--r--js/globals_test.ts26
-rw-r--r--js/lib.deno_runtime.d.ts1
3 files changed, 28 insertions, 0 deletions
diff --git a/js/globals.ts b/js/globals.ts
index b47cd80f3..ed7621165 100644
--- a/js/globals.ts
+++ b/js/globals.ts
@@ -89,6 +89,7 @@ window.onload = undefined as undefined | Function;
// standard https://www.w3.org/TR/WebCryptoAPI/#crypto-interface as it does not
// yet incorporate the SubtleCrypto interface as its "subtle" property.
window.crypto = (csprng as unknown) as Crypto;
+// window.queueMicrotask added by hand to self-maintained lib.deno_runtime.d.ts
// When creating the runtime type library, we use modifications to `window` to
// determine what is in the global namespace. When we put a class in the
diff --git a/js/globals_test.ts b/js/globals_test.ts
index 3085118de..42a055087 100644
--- a/js/globals_test.ts
+++ b/js/globals_test.ts
@@ -77,3 +77,29 @@ test(function DenoNamespaceImmutable(): void {
// @ts-ignore
assert(print === Deno.core.print);
});
+
+test(async function windowQueueMicrotask(): Promise<void> {
+ let resolve1: () => void | undefined;
+ let resolve2: () => void | undefined;
+ let microtaskDone = false;
+ const p1 = new Promise(
+ (res): void => {
+ resolve1 = (): void => {
+ microtaskDone = true;
+ res();
+ };
+ }
+ );
+ const p2 = new Promise(
+ (res): void => {
+ resolve2 = (): void => {
+ assert(microtaskDone);
+ res();
+ };
+ }
+ );
+ window.queueMicrotask(resolve1!);
+ setTimeout(resolve2!, 0);
+ await p1;
+ await p2;
+});
diff --git a/js/lib.deno_runtime.d.ts b/js/lib.deno_runtime.d.ts
index bbdc1fcb9..8ece99581 100644
--- a/js/lib.deno_runtime.d.ts
+++ b/js/lib.deno_runtime.d.ts
@@ -1264,6 +1264,7 @@ declare interface Window {
callback: (event: domTypes.Event) => void | null,
options?: boolean | domTypes.EventListenerOptions | undefined
) => void;
+ queueMicrotask: (task: () => void) => void;
Deno: typeof Deno;
}