Changeset 274404 in webkit


Ignore:
Timestamp:
Mar 14, 2021 2:19:25 PM (16 months ago)
Author:
ysuzuki@apple.com
Message:

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 https://github.com/whatwg/html/pull/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):

Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r274396 r274404  
     12021-03-14  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        Prevent dynamic import in service worker
     4        https://bugs.webkit.org/show_bug.cgi?id=222308
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Covering worklet case.
     9
     10        * http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https-expected.txt: Added.
     11        * http/wpt/webaudio/the-audio-api/the-audioworklet-interface/dynamic-import-is-prohibited.https.html: Added.
     12        * http/wpt/webaudio/the-audio-api/the-audioworklet-interface/processors/dynamic-import-is-prohibited.js: Added.
     13        (DynamicImportIsProhibitedProcessor.prototype.process):
     14        (DynamicImportIsProhibitedProcessor):
     15
    1162021-03-13  Wenson Hsieh  <wenson_hsieh@apple.com>
    217
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r274393 r274404  
     12021-03-14  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        Prevent dynamic import in service worker
     4        https://bugs.webkit.org/show_bug.cgi?id=222308
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Covering service-worker case.
     9
     10        * web-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt:
     11
    1122021-03-13  Commit Queue  <commit-queue@webkit.org>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt

    r273224 r274404  
    22PASS Static import.
    33PASS Nested static import.
    4 PASS Static import and then dynamic import.
    5 PASS Dynamic import.
    6 PASS Nested dynamic import.
    7 PASS Dynamic import and then static import.
    8 PASS eval(import()).
     4FAIL 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
     5FAIL Dynamic import. assert_array_equals: value is "Failed to do dynamic import: TypeError: Dynamic-import is not available in Worklets or ServiceWorkers", expected array
     6FAIL 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
     7FAIL 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
     8FAIL eval(import()). assert_array_equals: value is "Failed to do dynamic import: TypeError: Dynamic-import is not available in Worklets or ServiceWorkers", expected array
    99
  • trunk/Source/WebCore/ChangeLog

    r274403 r274404  
     12021-03-14  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        Prevent dynamic import in service worker
     4        https://bugs.webkit.org/show_bug.cgi?id=222308
     5
     6        Reviewed by Youenn Fablet.
     7
     8        dynamic-import should be always rejected if script is executed in Worklets or ServiceWorkers.
     9        This is recently changed in the spec https://github.com/whatwg/html/pull/6395.
     10
     11        * bindings/js/ScriptModuleLoader.cpp:
     12        (WebCore::isWorkletOrServiceWorker):
     13        (WebCore::ScriptModuleLoader::importModule):
     14
    1152021-03-14  Rob Buis  <rbuis@igalia.com>
    216
  • trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp

    r273299 r274404  
    4646#include "WorkerScriptFetcher.h"
    4747#include "WorkerScriptLoader.h"
     48#include "WorkletGlobalScope.h"
    4849#include <JavaScriptCore/Completion.h>
    4950#include <JavaScriptCore/JSInternalPromise.h>
     
    5455#include <JavaScriptCore/JSString.h>
    5556#include <JavaScriptCore/Symbol.h>
     57
     58#if ENABLE(SERVICE_WORKER)
     59#include "ServiceWorkerGlobalScope.h"
     60#endif
    5661
    5762namespace WebCore {
     
    259264}
    260265
     266static bool isWorkletOrServiceWorker(ScriptExecutionContext& context)
     267{
     268    if (is<WorkletGlobalScope>(context))
     269        return true;
     270#if ENABLE(SERVICE_WORKER)
     271    if (is<ServiceWorkerGlobalScope>(context))
     272        return true;
     273#endif
     274    return false;
     275}
     276
    261277JSC::JSInternalPromise* ScriptModuleLoader::importModule(JSC::JSGlobalObject* jsGlobalObject, JSC::JSModuleLoader*, JSC::JSString* moduleName, JSC::JSValue parameters, const JSC::SourceOrigin& sourceOrigin)
    262278{
    263279    JSC::VM& vm = jsGlobalObject->vm();
    264280    auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(jsGlobalObject);
     281
     282    // https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-specifier,-promisecapability)
     283    // If settings object's global object implements WorkletGlobalScope or ServiceWorkerGlobalScope, then:
     284    if (isWorkletOrServiceWorker(m_context))
     285        return rejectPromise(globalObject, TypeError, "Dynamic-import is not available in Worklets or ServiceWorkers"_s);
    265286
    266287    // If SourceOrigin and/or CachedScriptFetcher is null, we import the module with the default fetcher.
Note: See TracChangeset for help on using the changeset viewer.