Support Module Source Worker Instantiation #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is draft HTML PR spec text to verify the cross-specification interactions of the ESM Source Phase proposal, specifying:
new Worker(moduleSource)
for both JS and Wasm module sources, based on the newHostGetModuleSourceModuleRecord
host hook andGetModuleSourceModuleRecord
concrete method.import(moduleSource)
based on the updatedHostLoadImportedModule
API, with full registry key coalescing based on module source equivalence via the newModuleSourcesEqual
concrete method.ModuleSourcesEqual
check, only registry rooted sources are treated as equivalent in this check, which have arooted source
value. These correspond to "evalish" modules. See the security section below for more info.postMessage(moduleSource)
based on supported structured serialize and deserialize for JS source objects with a[[SourceTextModuleRecord]]
slot (Wasm's support already being defined in https://www.w3.org/TR/wasm-web-api-2/ as always being unrooted transfer, yet to be updated to support rooted transfer in turn).This is based to the latest version of ESM Phase Imports (https://tc39.es/proposal-esm-phase-imports/).
The WebAssembly ESM Integration side of this has now been landed including support in
HostGetModuleRecordFromSource
being able to synthesize a module record when needed forimport()
ornew Worker()
.In order to extend WebAssembly's structured clone of
WebAssembly.Module
to also support serialization of the URL an rooted source properties of the WebAssembly module script, the associated PR to the Wasm Web API is needed - WebAssembly/esm-integration#106. This PR also definesModuleSourcesEqual
for WA.Module needed for registry identity with structured clone semantics.There is some discussion to be had around the security model here, to outline the approach:
rooted source
to distinguish between sources known by the host to have been provided from the module registry to their base URL directly to the origin and evalish / compiled sources (egnew WebAssembly.Module(bytes)
today and in futureeval('module {...}')
ornew ModuleSource('export var foo')
).responseURL
does not match theirbaseURL
for consistency with the rooted source semantics.rooted source
, and otherwise set the worker URL to null.postMessage
a module created dynamically eg vianew WebAssembly.Module(bytes)
, we transfer the rooted source status and then transfer baseURL from the parent to the child along with the module only when it is a rooted source. This way, for rooted sources, relative paths that worked in the parent can still work in the child.Shared workers and worklets are not currently supported but could be nice additions.