From 4975e33dd2644cec8c08bed0274d3a2dab2de1e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 19 Sep 2022 16:52:40 +0200 Subject: [PATCH 1/5] Add tests for interaction between import() and microtask queue --- .../module/dynamic-import/microtasks.html | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks.html diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks.html new file mode 100644 index 00000000000000..ee1241f14cdbb6 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks.html @@ -0,0 +1,45 @@ + +Dynamic import interaction with microtask queue + + + From f7748dff52b74513275ee6c1e21ad1c58b5a63a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 30 Sep 2022 12:28:03 +0200 Subject: [PATCH 2/5] Add test for invalid import assertion --- .../basic.html} | 21 ++++--------------- .../dynamic-import/microtasks/ticker.js | 13 ++++++++++++ .../microtasks/with-import-assertions.html | 18 ++++++++++++++++ 3 files changed, 35 insertions(+), 17 deletions(-) rename html/semantics/scripting-1/the-script-element/module/dynamic-import/{microtasks.html => microtasks/basic.html} (66%) create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/ticker.js create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.html diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.html similarity index 66% rename from html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks.html rename to html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.html index ee1241f14cdbb6..f36bb693da6428 100644 --- a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks.html +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.html @@ -3,20 +3,7 @@ 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..2d655b4dafd548 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/ticker.js @@ -0,0 +1,13 @@ +export 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.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.html new file mode 100644 index 00000000000000..2d63ca7fb9a923 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.html @@ -0,0 +1,18 @@ + +Dynamic import interaction with microtask queue + + + From 19e9d133c1ff3ffd0f331fba36636b0528b8ef11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 23 Oct 2022 15:49:28 +0200 Subject: [PATCH 3/5] Test various contexts --- .../dynamic-import/microtasks/basic.any.js | 32 ++++++++++++++ .../dynamic-import/microtasks/basic.html | 32 -------------- .../microtasks/css-import-in-worker.any.js | 14 ++++++ .../microtasks/empty-module.css | 4 ++ .../dynamic-import/microtasks/empty-module.js | 4 ++ .../microtasks/serviceworker.any.js | 14 ++++++ .../dynamic-import/microtasks/ticker.js | 2 +- .../microtasks/with-import-assertions.any.js | 15 +++++++ .../microtasks/with-import-assertions.html | 18 -------- .../microtasks/worklet-ref.html | 10 +++++ .../dynamic-import/microtasks/worklet.html | 43 +++++++++++++++++++ 11 files changed, 137 insertions(+), 51 deletions(-) create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.any.js delete mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.html create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/css-import-in-worker.any.js create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.css create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.js create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/serviceworker.any.js create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.any.js delete mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.html create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.html create mode 100644 html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.html 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/basic.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.html deleted file mode 100644 index f36bb693da6428..00000000000000 --- a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.html +++ /dev/null @@ -1,32 +0,0 @@ - -Dynamic import interaction with microtask queue - - - 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 index 2d655b4dafd548..42619b6e700e52 100644 --- 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 @@ -1,4 +1,4 @@ -export function ticker(max) { +globalThis.ticker = function ticker(max) { let i = 0; let stop = false; Promise.resolve().then(function loop() { 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/with-import-assertions.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.html deleted file mode 100644 index 2d63ca7fb9a923..00000000000000 --- a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.html +++ /dev/null @@ -1,18 +0,0 @@ - -Dynamic import interaction with microtask queue - - - diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.html new file mode 100644 index 00000000000000..6c598aee3937a1 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.html @@ -0,0 +1,10 @@ + + + diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.html new file mode 100644 index 00000000000000..8ca8e8db4d230c --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.html @@ -0,0 +1,43 @@ + + + + + + + + +
+ + + + From 0f33ff7e4b37ad8be244012fcace3fa8e406abfa Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 24 Oct 2022 14:57:24 +0900 Subject: [PATCH 4/5] Worklet tests need to be https --- .../microtasks/{worklet-ref.html => worklet-ref.https.html} | 0 .../microtasks/{worklet.html => worklet.https.html} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/{worklet-ref.html => worklet-ref.https.html} (100%) rename html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/{worklet.html => worklet.https.html} (100%) diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.https.html similarity index 100% rename from html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.html rename to html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.https.html diff --git a/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.html b/html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.https.html similarity index 100% rename from html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.html rename to html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.https.html From aaff7d4d994024e5412f5b3ef26fae4bf47ac8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 24 Oct 2022 09:56:46 +0200 Subject: [PATCH 5/5] Update html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.https.html --- .../module/dynamic-import/microtasks/worklet.https.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 8ca8e8db4d230c..5cd59f86dc7708 100644 --- 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 @@ -1,7 +1,7 @@ - +