From cc152816bdc14e40a3eaf8bbf0cebd178160f272 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 20 Mar 2025 18:13:02 -0700 Subject: [PATCH 1/8] ESM Phase Imports import() & new Worker() support for WA.Module --- document/js-api/index.bs | 11 ++++++++++ document/web-api/index.bs | 45 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index eeb9ab38..aaaf552a 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1447,6 +1447,17 @@ WebAssembly Module Records have the following methods: +
+ +

ModuleSourcesEqual ( |otherRecord| ) Concrete Method

+1. If |otherRecord| is not a WebAssemly Module Record, return false. +1. Let |record| be this WebAssembly Module Record. +1. Let |module| be |record|.\[[ModuleSource]]. +1. Let |otherModule| be |otherRecord|.\[[ModuleSource]]. +1. Return true if |module|.\[[Bytes]] is equal to |otherModule|.\[[Bytes]], and false otherwise. + +
+

GetModuleSourceKind ( ) Concrete Method

diff --git a/document/web-api/index.bs b/document/web-api/index.bs index c086c432..65bba43e 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -148,15 +148,54 @@ The [=serialization steps=], given |value|, |serialized|, and |forStorage|, are: 1. Set |serialized|.\[[AgentCluster]] to the [=current Realm=]'s corresponding [=agent cluster=]. + 1. Let |rooted| be false. + + 1. If |value|.\[[ModuleRecord]] is not empty and |value|.\[[ModuleRecord]].\[[HostDefined]] is not empty, + + 1. Let |moduleScript| be |value|.\[[ModuleRecord]].\[[HostDefined]]. + + 1. Set |rooted| to |moduleScript|'s [=rooted source=] boolean. + + 1. If |rooted| is true then, + + 1. Set |serialized|.\[[Rooted]] to true. + + 1. Set |serialized|.\[[BaseURL]] to |moduleScript|'s base URL. + + 1. If |rooted| is false, + + 1. Set |serialized|.\[[Rooted]] to false. + + 1. Set |serialized|.\[[BaseURL]] to null. + The [=deserialization steps=], given |serialized|, |value|, and |targetRealm| are: 1. Let |bytes| be the [=sub-deserialization=] of |serialized|.\[[Bytes]]. - 1. Set |value|.\[[Bytes]] to |bytes|. + 1. Let |rooted| be the [=sub-deserialization=] of |serialized|.\[[Rooted]]. + + 1. Let |baseURL| be the [=sub-deserialization=] of |serialized|.\[[BaseURL]]. + + 1. If |rooted| is false then, + + 1. Set |value|.\[[Bytes]] to |bytes|. + + 1. If |targetRealm|'s corresponding [=agent cluster=] is not |serialized|.\[[AgentCluster]], then throw a "DataCloneError" {{DOMException}}. + + 1. [=Compile a WebAssembly module=] from |bytes| and set |value|.\[[Module]] to the result. + + 1. Otherwise, + + 1. Let |settings| be the [=current settings object=]. + + 1. Let |fetchOptions| be the [=default script fetch options=]. + + 1. Let |moduleScript| be the result of [=creating a WebAssembly module script=] given |bytes|, |settings|, |baseURL|, |fetchOptions|, true. + + 1. [=Parse a WebAssembly module=] given |bytes|, [=current Realm=] and |moduleScript| and set |value|.\[[Module]] to the result. - 1. If |targetRealm|'s corresponding [=agent cluster=] is not |serialized|.\[[AgentCluster]], then throw a "DataCloneError" {{DOMException}}. + 1. Assert: there was no compile error as this same module was previously compiled successfully. - 1. [=Compile a WebAssembly module=] from |bytes| and set |value|.\[[Module]] to the result. Engines should attempt to share/reuse internal compiled code when performing a structured serialization, although in corner cases like CPU upgrade or browser From 6bbaae9781a59ba982015213a0c72d816fa73545 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 20 Mar 2025 18:43:34 -0700 Subject: [PATCH 2/8] add definitions --- document/web-api/index.bs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/document/web-api/index.bs b/document/web-api/index.bs index 65bba43e..24b40829 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -60,7 +60,11 @@ urlPrefix: https://webassembly.github.io/spec/js-api/; spec: WASMJS text: asynchronously compile a webassembly module; url: #asynchronously-compile-a-webassembly-module text: instantiate a promise of a module; url: #instantiate-a-promise-of-a-module text: Exported Function; url: #exported-function -url:https://html.spec.whatwg.org/#cors-same-origin;text:CORS-same-origin;type:dfn;spec:HTML +urlPrefix: https://html.spec.whatwg.org/; spec: HTML; type: dfn + text: rooted source; url: #concept-script-rooted-source + text: default script fetch options; url: #default-script-fetch-options + text: current settings object; url: #current-settings-object + text: CORS-same-origin; url: #cors-same-origin url:https://fetch.spec.whatwg.org/#concept-body-consume-body;text:consume body;type:dfn;spec:FETCH @@ -160,7 +164,7 @@ The [=serialization steps=], given |value|, |serialized|, and |forStorage|, are: 1. Set |serialized|.\[[Rooted]] to true. - 1. Set |serialized|.\[[BaseURL]] to |moduleScript|'s base URL. + 1. Set |serialized|.\[[BaseURL]] to |moduleScript|'s [=base URL=]. 1. If |rooted| is false, From b11742e9cb06c8f327663cc366a0b436c2703399 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 20 Mar 2025 19:10:39 -0700 Subject: [PATCH 3/8] rework spec orderings for consistency --- document/js-api/index.bs | 11 ++++------- document/web-api/index.bs | 26 +++++++++++--------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index aaaf552a..d46e320c 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1381,14 +1381,11 @@ Note: While this specification is not yet merged into the main Wasm specificatio WebAssembly Module Records are a subclass of [=Cyclic Module Record=] which contain WebAssembly code.
-To parse a WebAssembly module given a byte sequence |bytes|, a Realm |realm| and object |hostDefined|, perform the following steps. +To create a WebAssembly Module Record given a WebAssembly module object |moduleObject|, a Realm |realm| and object |hostDefined|, perform the following steps. -1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bytes|. -1. [=Compile a WebAssembly module|Compile the WebAssembly module=] |stableBytes| and store the result as |module|. -1. If |module| is [=error=], throw a {{CompileError}} exception. -1. [=Construct a WebAssembly module object=] from |module| and |bytes|, and let |module| be the result. +1. Assert: |moduleObject|.\[[ModuleRecord]] is not defined. 1. Let |requestedModules| be a set. -1. For each (|moduleName|, name, type) in [=module_imports=](|module|.\[[Module]]), +1. For each (|moduleName|, name, type) in [=module_imports=](|moduleObject|.\[[Module]]), 1. [=set/Append=] |moduleName| to |requestedModules|. 1. Let |moduleRecord| be { @@ -1411,7 +1408,7 @@ To parse a WebAssembly module given a byte sequence |by \[[AsyncParentModules]]: « », \[[PendingAsyncDependencies]]: ~empty~, }. -1. Set |module|.\[[ModuleRecord]] to |moduleRecord|. +1. Set |moduleObject|.\[[ModuleRecord]] to |moduleRecord|. 1. Return |moduleRecord|. Note: From HTML, it's not observable when [=parse a WebAssembly module=] begins, so any work perfomed in compilation may be performed off-thread. diff --git a/document/web-api/index.bs b/document/web-api/index.bs index 24b40829..68f3d0a1 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -65,6 +65,7 @@ urlPrefix: https://html.spec.whatwg.org/; spec: HTML; type: dfn text: default script fetch options; url: #default-script-fetch-options text: current settings object; url: #current-settings-object text: CORS-same-origin; url: #cors-same-origin + text: creating a WebAssembly Module Script; url: #creating-a-webassembly-module-script url:https://fetch.spec.whatwg.org/#concept-body-consume-body;text:consume body;type:dfn;spec:FETCH @@ -174,32 +175,27 @@ The [=serialization steps=], given |value|, |serialized|, and |forStorage|, are: The [=deserialization steps=], given |serialized|, |value|, and |targetRealm| are: - 1. Let |bytes| be the [=sub-deserialization=] of |serialized|.\[[Bytes]]. - - 1. Let |rooted| be the [=sub-deserialization=] of |serialized|.\[[Rooted]]. + 1. If |targetRealm|'s corresponding [=agent cluster=] is not |serialized|.\[[AgentCluster]], then throw a "DataCloneError" {{DOMException}}. - 1. Let |baseURL| be the [=sub-deserialization=] of |serialized|.\[[BaseURL]]. + 1. Let |bytes| be the [=sub-deserialization=] of |serialized|.\[[Bytes]]. - 1. If |rooted| is false then, + 1. Set |value|.\[[Bytes]] to |bytes|. + + 1. [=Compile a WebAssembly module=] from |bytes| and set |value|.\[[Module]] to the result. - 1. Set |value|.\[[Bytes]] to |bytes|. + 1. Assert: there was no compile error as this same module was previously compiled successfully. - 1. If |targetRealm|'s corresponding [=agent cluster=] is not |serialized|.\[[AgentCluster]], then throw a "DataCloneError" {{DOMException}}. + 1. Let |rooted| be the [=sub-deserialization=] of |serialized|.\[[Rooted]]. - 1. [=Compile a WebAssembly module=] from |bytes| and set |value|.\[[Module]] to the result. + 1. If |rooted| is true then, - 1. Otherwise, + 1. Let |baseURL| be the [=sub-deserialization=] of |serialized|.\[[BaseURL]]. 1. Let |settings| be the [=current settings object=]. 1. Let |fetchOptions| be the [=default script fetch options=]. - 1. Let |moduleScript| be the result of [=creating a WebAssembly module script=] given |bytes|, |settings|, |baseURL|, |fetchOptions|, true. - - 1. [=Parse a WebAssembly module=] given |bytes|, [=current Realm=] and |moduleScript| and set |value|.\[[Module]] to the result. - - 1. Assert: there was no compile error as this same module was previously compiled successfully. - + 1. Let moduleScript be the result of [=creating a WebAssembly module script=] given |value|, |settings|, |baseURL|, |fetchOptions|, true. Engines should attempt to share/reuse internal compiled code when performing a structured serialization, although in corner cases like CPU upgrade or browser From 7aa43edd54ae1c017bbdf349565213d0431062bd Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 20 Mar 2025 19:37:36 -0700 Subject: [PATCH 4/8] corrections --- document/js-api/index.bs | 4 ++-- document/web-api/index.bs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index d46e320c..c39a501e 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1392,7 +1392,7 @@ To create a WebAssembly Module Record given a WebAssembly modu \[[Realm]]: |realm|, \[[Environment]]: ~empty~, \[[Namespace]]: ~empty~, - \[[ModuleSource]]: |module|, + \[[ModuleSource]]: |moduleObject|, \[[HostDefined]]: |hostDefined|, \[[Status]]: "new", @@ -1411,7 +1411,7 @@ To create a WebAssembly Module Record given a WebAssembly modu 1. Set |moduleObject|.\[[ModuleRecord]] to |moduleRecord|. 1. Return |moduleRecord|. -Note: From HTML, it's not observable when [=parse a WebAssembly module=] begins, so any work perfomed in compilation may be performed off-thread. +Note: From HTML, it's not observable when [=create a WebAssembly Module Record=] begins, so any work perfomed in compilation may be performed off-thread.
diff --git a/document/web-api/index.bs b/document/web-api/index.bs index 68f3d0a1..09e2f41e 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -155,7 +155,7 @@ The [=serialization steps=], given |value|, |serialized|, and |forStorage|, are: 1. Let |rooted| be false. - 1. If |value|.\[[ModuleRecord]] is not empty and |value|.\[[ModuleRecord]].\[[HostDefined]] is not empty, + 1. If |value|.\[[ModuleRecord]] is not null and |value|.\[[ModuleRecord]].\[[HostDefined]] is not empty, 1. Let |moduleScript| be |value|.\[[ModuleRecord]].\[[HostDefined]]. @@ -195,7 +195,7 @@ The [=deserialization steps=], given |serialized|, |value|, and |targetRealm| ar 1. Let |fetchOptions| be the [=default script fetch options=]. - 1. Let moduleScript be the result of [=creating a WebAssembly module script=] given |value|, |settings|, |baseURL|, |fetchOptions|, true. + 1. Let moduleScript be the result of [=creating a WebAssembly module script=] given |value|.\[[Module]], |settings|, |baseURL|, |fetchOptions|, true. Engines should attempt to share/reuse internal compiled code when performing a structured serialization, although in corner cases like CPU upgrade or browser From a2f9600fab4a83f649cd1c9fbd1860d92b9ff9a5 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 21 Mar 2025 10:51:05 -0700 Subject: [PATCH 5/8] finish up restructure --- document/js-api/index.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index c39a501e..fd3c5ac6 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -619,6 +619,7 @@ In addition, the interface object for {{Module}} must have as its \[[Prototype]] 1. If |module| is [=error=], throw a {{CompileError}} exception. 1. Set **this**.\[[Module]] to |module|. 1. Set **this**.\[[Bytes]] to |stableBytes|. + 1. Set **this**.\[[ModuleRecord]] to null. Note: Some implementations enforce a size limitation on |bytes|. Use of this API is discouraged, in favor of asynchronous APIs.
@@ -1383,7 +1384,7 @@ Note: While this specification is not yet merged into the main Wasm specificatio
To create a WebAssembly Module Record given a WebAssembly module object |moduleObject|, a Realm |realm| and object |hostDefined|, perform the following steps. -1. Assert: |moduleObject|.\[[ModuleRecord]] is not defined. +1. Assert: |moduleObject|.\[[ModuleRecord]] is null. 1. Let |requestedModules| be a set. 1. For each (|moduleName|, name, type) in [=module_imports=](|moduleObject|.\[[Module]]), 1. [=set/Append=] |moduleName| to |requestedModules|. From d9bb39467a79e83c5e933c42f7372fdd7cb1e075 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 24 Mar 2025 11:37:18 -0700 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Anne van Kesteren --- document/web-api/index.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/document/web-api/index.bs b/document/web-api/index.bs index 09e2f41e..f66f92b1 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -155,7 +155,7 @@ The [=serialization steps=], given |value|, |serialized|, and |forStorage|, are: 1. Let |rooted| be false. - 1. If |value|.\[[ModuleRecord]] is not null and |value|.\[[ModuleRecord]].\[[HostDefined]] is not empty, + 1. If |value|.\[[ModuleRecord]] is not null and |value|.\[[ModuleRecord]].\[[HostDefined]] is not empty: 1. Let |moduleScript| be |value|.\[[ModuleRecord]].\[[HostDefined]]. @@ -167,7 +167,7 @@ The [=serialization steps=], given |value|, |serialized|, and |forStorage|, are: 1. Set |serialized|.\[[BaseURL]] to |moduleScript|'s [=base URL=]. - 1. If |rooted| is false, + 1. If |rooted| is false: 1. Set |serialized|.\[[Rooted]] to false. @@ -187,7 +187,7 @@ The [=deserialization steps=], given |serialized|, |value|, and |targetRealm| ar 1. Let |rooted| be the [=sub-deserialization=] of |serialized|.\[[Rooted]]. - 1. If |rooted| is true then, + 1. If |rooted| is true: 1. Let |baseURL| be the [=sub-deserialization=] of |serialized|.\[[BaseURL]]. From 175fe4bfd3351386c68d01ca37d516a97f8db6c6 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 24 Mar 2025 12:18:42 -0700 Subject: [PATCH 7/8] Update document/web-api/index.bs --- document/web-api/index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/web-api/index.bs b/document/web-api/index.bs index f66f92b1..4d9a1d97 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -195,7 +195,7 @@ The [=deserialization steps=], given |serialized|, |value|, and |targetRealm| ar 1. Let |fetchOptions| be the [=default script fetch options=]. - 1. Let moduleScript be the result of [=creating a WebAssembly module script=] given |value|.\[[Module]], |settings|, |baseURL|, |fetchOptions|, true. + 1. [=Create a WebAssembly module script=] given |value|.\[[Module]], |settings|, |baseURL|, |fetchOptions|, and true. Engines should attempt to share/reuse internal compiled code when performing a structured serialization, although in corner cases like CPU upgrade or browser From 5f55cd517ae11e804493b1d58a9ff0694084a561 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 24 Mar 2025 12:22:05 -0700 Subject: [PATCH 8/8] update reference --- document/web-api/index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/web-api/index.bs b/document/web-api/index.bs index 4d9a1d97..fe5f31f6 100644 --- a/document/web-api/index.bs +++ b/document/web-api/index.bs @@ -65,7 +65,7 @@ urlPrefix: https://html.spec.whatwg.org/; spec: HTML; type: dfn text: default script fetch options; url: #default-script-fetch-options text: current settings object; url: #current-settings-object text: CORS-same-origin; url: #cors-same-origin - text: creating a WebAssembly Module Script; url: #creating-a-webassembly-module-script + text: create a WebAssembly Module Script; url: #creating-a-webassembly-module-script url:https://fetch.spec.whatwg.org/#concept-body-consume-body;text:consume body;type:dfn;spec:FETCH