Skip to content
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

Test that dynamic import() is disallowed in paint worklets #26175

Merged
merged 2 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions css/css-paint-api/dynamic-import-ref.html
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>
37 changes: 37 additions & 0 deletions css/css-paint-api/dynamic-import.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html class="reftest-wait">
<link rel="help" href="https://html.spec.whatwg.org/#hostimportmoduledynamically(referencingscriptormodule,-specifier,-promisecapability)">
<link rel="match" href="dynamic-import-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';
try {
await import('./resources/imported-module.mjs');
} catch (e) {
if (e.constructor === TypeError) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check .name as testharness.js seems to do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, the only way .name would be different would be if someone mucked with TypeError.prototype.name, which seems unlikely?

ctx.fillStyle = 'green';
}
}
ctx.fillRect(0, 0, geom.width, geom.height);
}
});
</script>

<script>
"use strict";
importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent);
</script>
2 changes: 2 additions & 0 deletions css/css-paint-api/resources/imported-module.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This doesn't need to contain anything. If it's dynamically import()ed
// successfully, the test fails.
3 changes: 2 additions & 1 deletion html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This directory contains tests for [HTML](https://html.spec.whatwg.org/multipage/).

Sub-directory names should be based on the URL of the corresponding part of the
multipage-version specification. For example, The URL of
multipage-version specification. For example, the URL of
"8.3 Base64 utility methods" is [https://html.spec.whatwg.org/multipage/webappapis.html#atob](https://html.spec.whatwg.org/multipage/webappapis.html#atob). So the directory in WPT is [webappapis/atob/](/html/webappapis/atob).

For historical reasons, parts of HTML have their own directories:
Expand All @@ -17,4 +17,5 @@ For historical reasons, parts of HTML have their own directories:
* [/websockets](/websockets)
* [/webstorage](/webstorage)
* [/workers](/workers)
* [/worklets](/worklets)
* [/x-frame-options](/x-frame-options)
3 changes: 2 additions & 1 deletion worklets/META.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
spec: https://drafts.css-houdini.org/worklets/
spec: https://html.spec.whatwg.org/multipage/worklets.html
suggested_reviewers:
- bfgeek
- domenic
2 changes: 1 addition & 1 deletion worklets/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
These are the tests for the [Worklets Level 1 spec](https://drafts.css-houdini.org/worklets/).
These are the tests for the [Worklets](https://html.spec.whatwg.org/multipage/worklets.html) section of the HTML Standard.