diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.any.js b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.any.js new file mode 100644 index 00000000000000..82cb3b215dbad2 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.any.js @@ -0,0 +1,32 @@ +// META: global=window,dedicatedworker,sharedworker +// META: script=ticker.js + +promise_test(async t => { + const getCount = ticker(1000); + + const importP = import(""); + await promise_rejects_js(t, TypeError, importP, 'import() should reject'); + + assert_less_than(getCount(), 1000); +}, "import() should not drain the microtask queue if it fails during specifier resolution"); + +promise_test(async t => { + // Use Date.now() to ensure that the module is not in the module map + const specifier = "./empty-module.js?" + Date.now(); + + await import(specifier); + + const getCount = ticker(1000); + await import(specifier); + assert_less_than(getCount(), 1000); +}, "import() should not drain the microtask queue when loading an already loaded module"); + +promise_test(async t => { + // Use Date.now() to ensure that the module is not in the module map + const specifier = "./empty-module.js?" + Date.now(); + + const getCount = ticker(1e7); + await import(specifier); + assert_equals(getCount(), 1e7); +}, "import() should drain the microtask queue when fetching a new module"); + diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/css-import-in-worker.any.js b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/css-import-in-worker.any.js new file mode 100644 index 00000000000000..bd6f5d092f3a6a --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/css-import-in-worker.any.js @@ -0,0 +1,14 @@ +// META: global=dedicatedworker,sharedworker +// META: script=ticker.js + +promise_test(async t => { + // Use Date.now() to ensure that the module is not in the module map + const specifier = "./empty-module.css?" + Date.now(); + + const getCount = ticker(1000); + + const importP = import(specifier, { assert: { type: "css" } }); + await promise_rejects_js(t, TypeError, importP, 'import() should reject'); + + assert_less_than(getCount(), 1000); +}, "import() should not drain the microtask queue if it fails because of the 'type: css' assertion in a worker"); diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.css b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.css new file mode 100644 index 00000000000000..108e7649bddfe7 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.css @@ -0,0 +1,4 @@ +/* +This file is empty, because all it matters is if the +dynamic import that loads it fails or succedes. +*/ diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.js b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.js new file mode 100644 index 00000000000000..108e7649bddfe7 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.js @@ -0,0 +1,4 @@ +/* +This file is empty, because all it matters is if the +dynamic import that loads it fails or succedes. +*/ diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/serviceworker.any.js b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/serviceworker.any.js new file mode 100644 index 00000000000000..4c75cab1b65b4b --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/serviceworker.any.js @@ -0,0 +1,14 @@ +// META: global=serviceworker +// META: script=ticker.js + +promise_test(async t => { + // Use Date.now() to ensure that the module is not in the module map + const specifier = "./empty-module.js?" + Date.now(); + + const getCount = ticker(1000); + + const importP = import(specifier); + await promise_rejects_js(t, TypeError, importP, 'import() should reject'); + + assert_less_than(getCount(), 1000); +}, "import() should not drain the microtask queue if it fails because it's used in a ServiceWorker"); diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/ticker.js b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/ticker.js new file mode 100644 index 00000000000000..42619b6e700e52 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/ticker.js @@ -0,0 +1,13 @@ +globalThis.ticker = function ticker(max) { + let i = 0; + let stop = false; + Promise.resolve().then(function loop() { + if (stop || i >= max) return; + i++; + Promise.resolve().then(loop); + }); + return () => { + stop = true; + return i; + }; +}; diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.any.js b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.any.js new file mode 100644 index 00000000000000..f67ba9a1ae4fce --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.any.js @@ -0,0 +1,15 @@ +// META: global=window,dedicatedworker,sharedworker +// META: script=ticker.js + +promise_test(async t => { + // Use Date.now() to ensure that the module is not in the module map + const specifier = "./empty-module.js?" + Date.now(); + + const getCount = ticker(1000); + + const importP = import(specifier, { assert: { type: "" } }); + await promise_rejects_js(t, TypeError, importP, 'import() should reject'); + + assert_less_than(getCount(), 1000); +}, "import() should not drain the microtask queue if it fails while validating the 'type' assertion"); + diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.https.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.https.html new file mode 100644 index 00000000000000..6c598aee3937a1 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.https.html @@ -0,0 +1,10 @@ + + + diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.https.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.https.html new file mode 100644 index 00000000000000..5cd59f86dc7708 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.https.html @@ -0,0 +1,43 @@ + + + + + + + + +
+ + + +