Commit f0caab3
committed
JS Modules in Workers
https://bugs.webkit.org/show_bug.cgi?id=164860
Reviewed by Saam Barati.
LayoutTests/imported/w3c:
Some of worklet failures in WPT is because,
1. Previously, worklet does not support module. These tests are passing incorrectly when modules are not supported.
Now, modules are supported, and some edge features are missing, so start failing
2. WPT is using www1.localhost in some tests (CSP tests), and this is not supported in WebKit's WPT testing. So failing incorrectly.
* web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/non-object.tentative.any.worker-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-workerglobalscope-onerror-module-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/alpha/base-url-worker-importScripts-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/alpha/base-url-worker.sub-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/evaluation-order-1-nothrow-worker-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/evaluation-order-1-worker-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/evaluation-order-2-import-worker-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/evaluation-order-3-dynamic-worker-expected.txt:
* web-platform-tests/service-workers/service-worker/import-module-scripts.https-expected.txt:
* web-platform-tests/workers/baseurl/alpha/import-in-moduleworker-expected.txt:
* web-platform-tests/workers/baseurl/alpha/importScripts-in-worker-expected.txt:
* web-platform-tests/workers/baseurl/alpha/xhr-in-moduleworker-expected.txt:
* web-platform-tests/workers/baseurl/alpha/xhr-in-worker-expected.txt:
* web-platform-tests/workers/constructors/Worker/same-origin-expected.txt:
* web-platform-tests/workers/interfaces/WorkerGlobalScope/location/redirect-expected.txt:
* web-platform-tests/workers/interfaces/WorkerGlobalScope/location/redirect-module-expected.txt:
* web-platform-tests/workers/modules/dedicated-worker-import-blob-url.any-expected.txt:
* web-platform-tests/workers/modules/dedicated-worker-import-csp-expected.txt:
* web-platform-tests/workers/modules/dedicated-worker-import-failure-expected.txt:
* web-platform-tests/workers/modules/dedicated-worker-import-meta-expected.txt:
* web-platform-tests/workers/modules/dedicated-worker-import-meta.html:
* web-platform-tests/workers/modules/dedicated-worker-import-referrer-expected.txt:
* web-platform-tests/workers/modules/dedicated-worker-import.any-expected.txt:
* web-platform-tests/workers/modules/dedicated-worker-options-type-expected.txt:
* web-platform-tests/workers/modules/dedicated-worker-parse-error-failure-expected.txt:
* web-platform-tests/workers/name-property-expected.txt:
* web-platform-tests/worklets/audio-worklet-credentials.https-expected.txt:
* web-platform-tests/worklets/audio-worklet-csp.https-expected.txt:
* web-platform-tests/worklets/audio-worklet-import.https-expected.txt:
* web-platform-tests/worklets/audio-worklet-referrer.https-expected.txt:
* web-platform-tests/xhr/open-url-redirected-worker-origin-expected.txt:
Source/JavaScriptCore:
Add error information to extract this in WebCore's module loader.
Currently, we are using Promise pipeline, and this makes it a bit difficult to extract error information.
This error information attached in this patch allows us to extract SyntaxError in WebCore, and throwing
JS SyntaxError instead of AbortError.
We are planning to update our module pipieline not using Promises in the future. The current design derived
from the original module loader pipeline where using Promises is critical. But now, that proposal was abandoned,
so we can just simplify the module loader.
* runtime/AggregateError.cpp:
(JSC::AggregateError::AggregateError):
* runtime/Error.cpp:
(JSC::createError):
(JSC::createEvalError):
(JSC::createRangeError):
(JSC::createReferenceError):
(JSC::createSyntaxError):
(JSC::createTypeError):
(JSC::createURIError):
(JSC::createGetterTypeError):
(JSC::throwSyntaxError):
* runtime/Error.h:
* runtime/ErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/ErrorInstance.cpp:
(JSC::ErrorInstance::ErrorInstance):
(JSC::ErrorInstance::create):
(JSC::ErrorInstance::sanitizedMessageString):
(JSC::ErrorInstance::sanitizedNameString):
(JSC::ErrorInstance::sanitizedToString):
* runtime/ErrorInstance.h:
(JSC::ErrorInstance::create):
(JSC::ErrorInstance::errorType const):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/NativeErrorConstructor.cpp:
(JSC::NativeErrorConstructor<errorType>::constructImpl):
(JSC::NativeErrorConstructor<errorType>::callImpl):
* runtime/NullSetterFunction.cpp:
(JSC::NullSetterFunctionInternal::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/JSWebAssemblyCompileError.cpp:
(JSC::JSWebAssemblyCompileError::JSWebAssemblyCompileError):
* wasm/js/JSWebAssemblyLinkError.cpp:
(JSC::JSWebAssemblyLinkError::JSWebAssemblyLinkError):
* wasm/js/JSWebAssemblyRuntimeError.cpp:
(JSC::JSWebAssemblyRuntimeError::JSWebAssemblyRuntimeError):
* wasm/js/WebAssemblyCompileErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyLinkErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
Source/WebCore:
This patch implements JS modules in Workers and Worklets. We are not supporting modules in ServiceWorkers' initialization yet.
But service-worker can import modules via JS `import()`.
The worker can be executed as a module if we pass, `type: "module"` to worker options. Worklet is executed as modules by default.
1. In Worker, we first fetch the initial code. And then, analyze the dependencies and load subsequent modules.
We iterate run-loop to load all the dependent modules in the module loader. At that time, we annotate run-loop tasks with
special taskMode to iterate tasks with this taskMode. This prevents us from discarding different tasks in this run-loop driving
phase. (e.g. postMessage can be called from the main thread while loading module graph, in that case, we should not discard this
task.)
2. In Worklet, we just request module loading to ScriptModuleLoader, and run it after loading module graph. This is OK since worklet
thread is already running. So we can just request modules and worklet thread automatically drives module loading via run-loop.
* Headers.cmake:
* Modules/webaudio/AudioWorkletGlobalScope.h:
(WebCore::AudioWorkletGlobalScope::currentFrame const): Deleted.
(WebCore::AudioWorkletGlobalScope::sampleRate const): Deleted.
(WebCore::AudioWorkletGlobalScope::currentTime const): Deleted.
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/CachedModuleScriptLoader.cpp:
(WebCore::CachedModuleScriptLoader::create):
(WebCore::CachedModuleScriptLoader::CachedModuleScriptLoader):
(WebCore::CachedModuleScriptLoader::load):
(WebCore::CachedModuleScriptLoader::notifyFinished):
* bindings/js/CachedModuleScriptLoader.h:
* bindings/js/CachedScriptFetcher.cpp:
* bindings/js/JSDOMExceptionHandling.cpp:
(WebCore::retrieveErrorMessageWithoutName):
(WebCore::createDOMException):
* bindings/js/JSDOMExceptionHandling.h:
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::scriptModuleLoader):
(WebCore::JSDOMGlobalObject::moduleLoaderResolve):
(WebCore::JSDOMGlobalObject::moduleLoaderFetch):
(WebCore::JSDOMGlobalObject::moduleLoaderEvaluate):
(WebCore::JSDOMGlobalObject::moduleLoaderImportModule):
(WebCore::JSDOMGlobalObject::moduleLoaderCreateImportMetaProperties):
* bindings/js/JSDOMGlobalObject.h:
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::moduleLoaderResolve): Deleted.
(WebCore::JSDOMWindowBase::moduleLoaderFetch): Deleted.
(WebCore::JSDOMWindowBase::moduleLoaderEvaluate): Deleted.
(WebCore::JSDOMWindowBase::moduleLoaderImportModule): Deleted.
(WebCore::JSDOMWindowBase::moduleLoaderCreateImportMetaProperties): Deleted.
* bindings/js/JSDOMWindowBase.h:
* bindings/js/JSWorkerGlobalScopeBase.cpp:
* bindings/js/JSWorkletGlobalScopeBase.cpp:
* bindings/js/ModuleScriptLoader.h: Copied from Source/WebCore/dom/ModuleFetchParameters.h.
(WebCore::ModuleScriptLoader::clearClient):
(WebCore::ModuleScriptLoader::scriptFetcher):
(WebCore::ModuleScriptLoader::parameters):
(WebCore::ModuleScriptLoader::ModuleScriptLoader):
* bindings/js/ModuleScriptLoaderClient.h: Renamed from Source/WebCore/bindings/js/CachedModuleScriptLoaderClient.h.
* bindings/js/ScriptModuleLoader.cpp:
(WebCore::ScriptModuleLoader::ScriptModuleLoader):
(WebCore::resolveModuleSpecifier):
(WebCore::ScriptModuleLoader::resolve):
(WebCore::ScriptModuleLoader::fetch):
(WebCore::ScriptModuleLoader::moduleURL):
(WebCore::ScriptModuleLoader::responseURLFromRequestURL):
(WebCore::ScriptModuleLoader::evaluate):
(WebCore::ScriptModuleLoader::importModule):
(WebCore::ScriptModuleLoader::notifyFinished):
* bindings/js/ScriptModuleLoader.h:
* bindings/js/ScriptSourceCode.h:
(WebCore::ScriptSourceCode::ScriptSourceCode):
* bindings/js/WorkerModuleScriptLoader.cpp: Added.
(WebCore::WorkerModuleScriptLoader::create):
(WebCore::WorkerModuleScriptLoader::WorkerModuleScriptLoader):
(WebCore::WorkerModuleScriptLoader::~WorkerModuleScriptLoader):
(WebCore::WorkerModuleScriptLoader::load):
(WebCore::WorkerModuleScriptLoader::referrerPolicy):
(WebCore::WorkerModuleScriptLoader::notifyFinished):
(WebCore::WorkerModuleScriptLoader::taskMode):
* bindings/js/WorkerModuleScriptLoader.h: Copied from Source/WebCore/dom/ModuleFetchParameters.h.
* bindings/js/WorkerScriptFetcher.h: Added.
* dom/Document.cpp:
* dom/ExceptionCode.h:
* dom/LoadableModuleScript.cpp:
(WebCore::LoadableModuleScript::LoadableModuleScript):
(WebCore::LoadableModuleScript::load): Deleted.
* dom/LoadableModuleScript.h:
* dom/ModuleFetchParameters.h:
(WebCore::ModuleFetchParameters::create):
(WebCore::ModuleFetchParameters::isTopLevelModule const):
(WebCore::ModuleFetchParameters::ModuleFetchParameters):
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::requestModuleScript):
* loader/ThreadableLoader.cpp:
(WebCore::ThreadableLoader::create):
* loader/ThreadableLoader.h:
(WebCore::ThreadableLoader::create):
* workers/DedicatedWorkerGlobalScope.h:
* workers/Worker.cpp:
(WebCore::Worker::Worker):
(WebCore::Worker::create):
(WebCore::Worker::notifyFinished):
* workers/Worker.h:
* workers/Worker.idl:
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::WorkerGlobalScope):
(WebCore::WorkerGlobalScope::importScripts):
* workers/WorkerGlobalScope.h:
(WebCore::WorkerGlobalScope::credentials const):
* workers/WorkerGlobalScopeProxy.h:
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
* workers/WorkerMessagingProxy.h:
* workers/WorkerOrWorkletGlobalScope.cpp:
(WebCore::WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope):
* workers/WorkerOrWorkletGlobalScope.h:
(WebCore::WorkerOrWorkletGlobalScope::moduleLoader):
* workers/WorkerOrWorkletScriptController.cpp:
(WebCore::jsValueToModuleKey):
(WebCore::WorkerOrWorkletScriptController::evaluateModule):
(WebCore::WorkerOrWorkletScriptController::loadModuleSynchronously):
(WebCore::WorkerOrWorkletScriptController::linkAndEvaluateModule):
(WebCore::WorkerOrWorkletScriptController::loadAndEvaluateModule):
* workers/WorkerOrWorkletScriptController.h:
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadAsynchronously):
(WebCore::WorkerScriptLoader::didReceiveResponse):
* workers/WorkerScriptLoader.h:
(WebCore::WorkerScriptLoader::responseSource const):
(WebCore::WorkerScriptLoader::isRedirected const):
* workers/WorkerThread.cpp:
(WebCore::WorkerParameters::isolatedCopy const):
(WebCore::WorkerThread::evaluateScriptIfNecessary):
* workers/WorkerThread.h:
* workers/WorkerType.h:
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerGlobalScope.h:
* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::fetchScriptWithContext):
* workers/service/ServiceWorkerRegistrationOptions.h:
* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::ServiceWorkerThread):
* workers/service/server/SWServerWorker.h:
* worklets/PaintWorkletGlobalScope.h:
(WebCore::PaintWorkletGlobalScope::paintDefinitionMap): Deleted.
(WebCore::PaintWorkletGlobalScope::paintDefinitionLock): Deleted.
(WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): Deleted.
* worklets/WorkletGlobalScope.cpp:
(WebCore::WorkletGlobalScope::fetchAndInvokeScript):
(WebCore::WorkletGlobalScope::processNextScriptFetchJobIfNeeded): Deleted.
(WebCore::WorkletGlobalScope::didReceiveResponse): Deleted.
(WebCore::WorkletGlobalScope::notifyFinished): Deleted.
(WebCore::WorkletGlobalScope::didCompleteScriptFetchJob): Deleted.
* worklets/WorkletGlobalScope.h:
LayoutTests:
* TestExpectations:
* http/tests/security/contentSecurityPolicy/1.1/module-scriptnonce-redirect-expected.txt:
* http/tests/subresource-integrity/sri-module-expected.txt:
* webaudio/audioworklet-addModule-failure-expected.txt:
* webaudio/worklet-crash-expected.txt:
Canonical link: https://commits.webkit.org/234389@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273203 268f45cc-cd09-0410-ab3c-d52691b4dbfc1 parent ec29cf1 commit f0caab3
113 files changed
Lines changed: 1575 additions & 525 deletions
File tree
- LayoutTests
- http/tests
- security/contentSecurityPolicy/1.1
- subresource-integrity
- imported/w3c
- web-platform-tests
- html/semantics/scripting-1/the-script-element
- json-module
- microtasks
- module
- dynamic-import/alpha
- service-workers/service-worker
- workers
- baseurl/alpha
- constructors/Worker
- interfaces/WorkerGlobalScope/location
- modules
- worklets
- xhr
- webaudio
- Source
- JavaScriptCore
- runtime
- wasm/js
- WebCore
- Modules/webaudio
- WebCore.xcodeproj
- bindings/js
- dom
- loader
- workers
- service
- context
- server
- worklets
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
1 | 14 | | |
2 | 15 | | |
3 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
643 | | - | |
644 | 643 | | |
645 | 644 | | |
646 | 645 | | |
| |||
663 | 662 | | |
664 | 663 | | |
665 | 664 | | |
666 | | - | |
667 | 665 | | |
668 | 666 | | |
669 | 667 | | |
| |||
LayoutTests/http/tests/security/contentSecurityPolicy/1.1/module-scriptnonce-redirect-expected.txt
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
1 | 46 | | |
2 | 47 | | |
3 | 48 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
4 | 3 | | |
0 commit comments