Diff
Modified: trunk/LayoutTests/ChangeLog (274403 => 274404)
--- trunk/LayoutTests/ChangeLog 2021-03-14 20:47:25 UTC (rev 274403)
+++ trunk/LayoutTests/ChangeLog 2021-03-14 21:19:25 UTC (rev 274404)
@@ -1,3 +1,18 @@
+2021-03-14 Yusuke Suzuki <[email protected]>
+
+ Prevent dynamic import in service worker
+ https://bugs.webkit.org/show_bug.cgi?id=222308
+
+ Reviewed by Youenn Fablet.
+
+ 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):
+
2021-03-13 Wenson Hsieh <[email protected]>
[iOS] Selecting the first word in an image overlay may select text in the previous line
Added: trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https-expected.txt (0 => 274404)
--- trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https-expected.txt 2021-03-14 21:19:25 UTC (rev 274404)
@@ -0,0 +1,3 @@
+
+PASS dynamic-import is prohibited in AudioWorklets
+
Added: trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https.html (0 => 274404)
--- trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https.html (rev 0)
+++ trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https.html 2021-03-14 21:19:25 UTC (rev 274404)
@@ -0,0 +1,30 @@
+<!doctype html>
+<title>Tests dynamic-import is prohibited in AudioWorklets</title>
+<script src=""
+<script src=""
+<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>
Added: trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/processors/dynamic-import-is-prohibited.js (0 => 274404)
--- trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/processors/dynamic-import-is-prohibited.js (rev 0)
+++ trunk/LayoutTests/http/wpt/webaudio/the-audio-api/the-audioworklet-interface/processors/dynamic-import-is-prohibited.js 2021-03-14 21:19:25 UTC (rev 274404)
@@ -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);
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (274403 => 274404)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-03-14 20:47:25 UTC (rev 274403)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-03-14 21:19:25 UTC (rev 274404)
@@ -1,3 +1,14 @@
+2021-03-14 Yusuke Suzuki <[email protected]>
+
+ Prevent dynamic import in service worker
+ https://bugs.webkit.org/show_bug.cgi?id=222308
+
+ Reviewed by Youenn Fablet.
+
+ Covering service-worker case.
+
+ * web-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt:
+
2021-03-13 Commit Queue <[email protected]>
Unreviewed, reverting r274379.
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt (274403 => 274404)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt 2021-03-14 20:47:25 UTC (rev 274403)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt 2021-03-14 21:19:25 UTC (rev 274404)
@@ -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
Modified: trunk/Source/WebCore/ChangeLog (274403 => 274404)
--- trunk/Source/WebCore/ChangeLog 2021-03-14 20:47:25 UTC (rev 274403)
+++ trunk/Source/WebCore/ChangeLog 2021-03-14 21:19:25 UTC (rev 274404)
@@ -1,3 +1,17 @@
+2021-03-14 Yusuke Suzuki <[email protected]>
+
+ Prevent dynamic import in service worker
+ https://bugs.webkit.org/show_bug.cgi?id=222308
+
+ Reviewed by Youenn Fablet.
+
+ dynamic-import should be always rejected if script is executed in Worklets or ServiceWorkers.
+ This is recently changed in the spec https://github.com/whatwg/html/pull/6395.
+
+ * bindings/js/ScriptModuleLoader.cpp:
+ (WebCore::isWorkletOrServiceWorker):
+ (WebCore::ScriptModuleLoader::importModule):
+
2021-03-14 Rob Buis <[email protected]>
Cancel image loader events after first dispatch
Modified: trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp (274403 => 274404)
--- trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp 2021-03-14 20:47:25 UTC (rev 274403)
+++ trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp 2021-03-14 21:19:25 UTC (rev 274404)
@@ -45,6 +45,7 @@
#include "WorkerOrWorkletScriptController.h"
#include "WorkerScriptFetcher.h"
#include "WorkerScriptLoader.h"
+#include "WorkletGlobalScope.h"
#include <_javascript_Core/Completion.h>
#include <_javascript_Core/JSInternalPromise.h>
#include <_javascript_Core/JSModuleRecord.h>
@@ -54,6 +55,10 @@
#include <_javascript_Core/JSString.h>
#include <_javascript_Core/Symbol.h>
+#if ENABLE(SERVICE_WORKER)
+#include "ServiceWorkerGlobalScope.h"
+#endif
+
namespace WebCore {
ScriptModuleLoader::ScriptModuleLoader(ScriptExecutionContext& context, OwnerType ownerType)
@@ -258,11 +263,27 @@
return jsPromise;
}
+static bool isWorkletOrServiceWorker(ScriptExecutionContext& context)
+{
+ if (is<WorkletGlobalScope>(context))
+ return true;
+#if ENABLE(SERVICE_WORKER)
+ if (is<ServiceWorkerGlobalScope>(context))
+ return true;
+#endif
+ return false;
+}
+
JSC::JSInternalPromise* ScriptModuleLoader::importModule(JSC::JSGlobalObject* jsGlobalObject, JSC::JSModuleLoader*, JSC::JSString* moduleName, JSC::JSValue parameters, const JSC::SourceOrigin& sourceOrigin)
{
JSC::VM& vm = jsGlobalObject->vm();
auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(jsGlobalObject);
+ // https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-specifier,-promisecapability)
+ // If settings object's global object implements WorkletGlobalScope or ServiceWorkerGlobalScope, then:
+ if (isWorkletOrServiceWorker(m_context))
+ return rejectPromise(globalObject, TypeError, "Dynamic-import is not available in Worklets or ServiceWorkers"_s);
+
// If SourceOrigin and/or CachedScriptFetcher is null, we import the module with the default fetcher.
// SourceOrigin can be null if the source code is not coupled with the script file.
// The examples,