forked from WebKit/WebKit-http
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent dynamic import in service worker
https://bugs.webkit.org/show_bug.cgi?id=222308 Reviewed by Youenn Fablet. LayoutTests/imported/w3c: Covering service-worker case. * web-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt: Source/WebCore: dynamic-import should be always rejected if script is executed in Worklets or ServiceWorkers. This is recently changed in the spec whatwg/html#6395. * bindings/js/ScriptModuleLoader.cpp: (WebCore::isWorkletOrServiceWorker): (WebCore::ScriptModuleLoader::importModule): LayoutTests: Covering worklet case. * http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https-expected.txt: Added. * http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https.html: Added. * http/wpt/webaudio/the-audio-api/the-audioworklet-interface/processors/dynamic-import-is-prohibited.js: Added. (DynamicImportIsProhibitedProcessor.prototype.process): (DynamicImportIsProhibitedProcessor): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@274404 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
ysuzuki@apple.com
committed
Mar 14, 2021
1 parent
97b25c2
commit 731e989
Showing
8 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
3 changes: 3 additions & 0 deletions
3
.../the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https-expected.txt
This file contains 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,3 @@ | ||
|
||
PASS dynamic-import is prohibited in AudioWorklets | ||
|
30 changes: 30 additions & 0 deletions
30
...webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https.html
This file contains 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,30 @@ | ||
<!doctype html> | ||
<title>Tests dynamic-import is prohibited in AudioWorklets</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script> | ||
var context; | ||
promise_setup(async (t) => { | ||
context = new AudioContext(); | ||
const filePath = 'processors/dynamic-import-is-prohibited.js'; | ||
await context.audioWorklet.addModule(filePath); | ||
}); | ||
|
||
const get_error = async (node) => { | ||
const event = await new Promise((resolve) => { | ||
node.port.onmessage = resolve; | ||
}); | ||
return event.data.error; | ||
}; | ||
|
||
promise_test(async (t) => { | ||
const options = { | ||
numberOfInputs: 0, | ||
numberOfOutputs: 1 | ||
}; | ||
|
||
const node = new AudioWorkletNode(context, 'dynamic-import-is-prohibited', options); | ||
const error = await get_error(node); | ||
assert_equals(error, `TypeError: Dynamic-import is not available in Worklets or ServiceWorkers`); | ||
}, 'dynamic-import is prohibited in AudioWorklets'); | ||
</script> |
16 changes: 16 additions & 0 deletions
16
...audio/the-audio-api/the-audioworklet-interface/processors/dynamic-import-is-prohibited.js
This file contains 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,16 @@ | ||
class DynamicImportIsProhibitedProcessor extends AudioWorkletProcessor { | ||
process(inputs, outputs) { | ||
import("./dynamic-import-is-prohibited.js").then(() => { | ||
this.port.postMessage({ | ||
error: null | ||
}); | ||
}, (error) => { | ||
this.port.postMessage({ | ||
error: String(error) | ||
}); | ||
}); | ||
return false; | ||
} | ||
} | ||
|
||
registerProcessor('dynamic-import-is-prohibited', DynamicImportIsProhibitedProcessor); |
This file contains 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
10 changes: 5 additions & 5 deletions
10
...eb-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt
This file contains 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
|
||
PASS Static import. | ||
PASS Nested static import. | ||
PASS Static import and then dynamic import. | ||
PASS Dynamic import. | ||
PASS Nested dynamic import. | ||
PASS Dynamic import and then static import. | ||
PASS eval(import()). | ||
FAIL Static import and then dynamic import. assert_array_equals: value is "Failed to do dynamic import: TypeError: Dynamic-import is not available in Worklets or ServiceWorkers", expected array | ||
FAIL Dynamic import. assert_array_equals: value is "Failed to do dynamic import: TypeError: Dynamic-import is not available in Worklets or ServiceWorkers", expected array | ||
FAIL Nested dynamic import. assert_array_equals: value is "Failed to do dynamic import: TypeError: Dynamic-import is not available in Worklets or ServiceWorkers", expected array | ||
FAIL Dynamic import and then static import. assert_array_equals: value is "Failed to do dynamic import: TypeError: Dynamic-import is not available in Worklets or ServiceWorkers", expected array | ||
FAIL eval(import()). assert_array_equals: value is "Failed to do dynamic import: TypeError: Dynamic-import is not available in Worklets or ServiceWorkers", expected array | ||
|
This file contains 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
This file contains 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