-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add tests for interaction between import() and microtask queue #35949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Ms2ger
merged 5 commits into
web-platform-tests:master
from
nicolo-ribaudo:add-test-for-microtask-queue-dranining-dynamic-import
Oct 24, 2022
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4975e33
Add tests for interaction between import() and microtask queue
nicolo-ribaudo f7748df
Add test for invalid import assertion
nicolo-ribaudo 19e9d13
Test various contexts
nicolo-ribaudo 0f33ff7
Worklet tests need to be https
domenic aaff7d4
Update html/semantics/scripting-1/the-script-element/module/dynamic-i…
nicolo-ribaudo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/basic.any.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// META: global=window,dedicatedworker,sharedworker | ||
// META: script=ticker.js | ||
|
||
promise_test(async t => { | ||
const getCount = ticker(1000); | ||
|
||
const importP = import("<invalid>"); | ||
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"); | ||
|
14 changes: 14 additions & 0 deletions
14
...ripting-1/the-script-element/module/dynamic-import/microtasks/css-import-in-worker.any.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
4 changes: 4 additions & 0 deletions
4
...emantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
This file is empty, because all it matters is if the | ||
dynamic import that loads it fails or succedes. | ||
*/ |
4 changes: 4 additions & 0 deletions
4
...semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/empty-module.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
This file is empty, because all it matters is if the | ||
dynamic import that loads it fails or succedes. | ||
*/ |
14 changes: 14 additions & 0 deletions
14
...tics/scripting-1/the-script-element/module/dynamic-import/microtasks/serviceworker.any.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
13 changes: 13 additions & 0 deletions
13
html/semantics/scripting-1/the-script-element/module/dynamic-import/microtasks/ticker.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
}; |
15 changes: 15 additions & 0 deletions
15
...pting-1/the-script-element/module/dynamic-import/microtasks/with-import-assertions.any.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "<invalid>" } }); | ||
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"); | ||
|
10 changes: 10 additions & 0 deletions
10
...cs/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet-ref.https.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<canvas id ="output" width="100" height="100" style="background: blue;"></canvas> | ||
<script> | ||
"use strict"; | ||
const canvas = document.getElementById('output'); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
ctx.fillStyle = 'green'; | ||
ctx.fillRect(0, 0, 100, 100); | ||
</script> |
43 changes: 43 additions & 0 deletions
43
...antics/scripting-1/the-script-element/module/dynamic-import/microtasks/worklet.https.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html class="reftest-wait"> | ||
<link rel="help" href="https://html.spec.whatwg.org/#hostimportmoduledynamically(referencingscriptormodule,-specifier,-promisecapability)"> | ||
<link rel="match" href="worklet-ref.html"> | ||
<style> | ||
#output { | ||
width: 100px; | ||
height: 100px; | ||
background-image: paint(rects); | ||
background-color: blue; | ||
} | ||
</style> | ||
<script src="/common/reftest-wait.js"></script> | ||
<script src="/common/worklet-reftest.js"></script> | ||
<body> | ||
<div id="output"></div> | ||
|
||
<script id="code" type="text/worklet"> | ||
registerPaint('rects', class { | ||
async paint(ctx, geom) { | ||
ctx.fillStyle = 'red'; | ||
|
||
const getCount = ticker(1000); | ||
|
||
try { | ||
// Use Date.now() to ensure that the module is not in the module map | ||
await import("./empty-module.js?" + Date.now()); | ||
} catch (e) { | ||
if (getCount() < 1000) { | ||
ctx.fillStyle = 'green'; | ||
} | ||
} | ||
ctx.fillRect(0, 0, geom.width, geom.height); | ||
} | ||
}); | ||
</script> | ||
|
||
<script> | ||
"use strict"; | ||
CSS.paintWorklet.addModule("./ticker.js").then(() => | ||
importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent) | ||
); | ||
</script> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.