Skip to content

Commit

Permalink
Merge pull request #98 from WebAssembly/get-module-source-module-record
Browse files Browse the repository at this point in the history
Use updated HostGetModuleSourceModuleRecord host function
  • Loading branch information
guybedford authored Feb 11, 2025
2 parents cad8154 + ba0f161 commit 8f8a354
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions document/js-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,15 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje

* \[[Module]] : a WebAssembly [=/module=]
* \[[Bytes]] : the source bytes of \[[Module]].
* \[[ModuleRecord]] : the <a>WebAssembly Module Record</a> if this WebAssembly module is associated with one.

<div algorithm>
To <dfn>construct a WebAssembly module object</dfn> from a module |module| and source bytes |bytes|, perform the following steps:

1. Let |moduleObject| be a new {{Module}} object.
1. Set |moduleObject|.\[[Module]] to |module|.
1. Set |moduleObject|.\[[Bytes]] to |bytes|.
1. Set |moduleObject|.\[[ModuleRecord]] to null.
1. Return |moduleObject|.
</div>

Expand Down Expand Up @@ -1388,7 +1390,7 @@ To <dfn export>parse a WebAssembly module</dfn> given a <a>byte sequence</a> |by
1. Let |requestedModules| be a set.
1. For each (|moduleName|, <var ignore>name</var>, <var ignore>type</var>) in [=module_imports=](|module|.\[[Module]]),
1. [=set/Append=] |moduleName| to |requestedModules|.
1. Return {
1. Let |moduleRecord| be {
<!-- Abstract Module Records -->
\[[Realm]]: |realm|,
\[[Environment]]: ~empty~,
Expand All @@ -1409,6 +1411,8 @@ To <dfn export>parse a WebAssembly module</dfn> given a <a>byte sequence</a> |by
\[[AsyncParentModules]]: &laquo; &raquo;,
\[[PendingAsyncDependencies]]: ~empty~,
}.
1. Set |module|.\[[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.
</div>
Expand Down Expand Up @@ -1443,6 +1447,13 @@ WebAssembly Module Records have the following methods:

</div>

<div algorithm=GetModuleSourceKind>

<h3 id="get-module-source-kind">GetModuleSourceKind ( ) Concrete Method</h3>
1. Return "WebAssembly.Module".

</div>

<div algorithm=InitializeEnvironment>

<h3 id="module-declaration-environment-setup">InitializeEnvironment ( ) Concrete Method</h3>
Expand Down Expand Up @@ -1481,9 +1492,38 @@ WebAssembly Module Records have the following methods:

</div>

<h3 id="hostgetmodulesourcename">HostGetModuleSourceName</h3>

Hosts should implement [$HostGetModuleSourceName$] such that whenever a WebAssembly {{Module}} object is provided with a \[[Module]] internal slot, the string "<code data-x="">WebAssembly.Module</code>" is always returned.
<h3 id="hostgetmodulesourcemodulerecord">HostGetModuleSourceModuleRecord ( |specifier| )</h3>
1. If |specifier| is a WebAssembly {{Module}} object with a \[[Module]] internal slot,
1. If |specifier|.\[[Module]].\[[ModuleRecord]] is null,
1. Let |realm| be the current agent's realm record.
1. Let |requestedModules| be a set.
1. For each (|moduleName|, <var ignore>name</var>, <var ignore>type</var>) in [=module_imports=](|specifier|.\[[Module]]),
1. [=set/Append=] |moduleName| to |requestedModules|.
1. Let |moduleRecord| be {
<!-- Abstract Module Records -->
\[[Realm]]: |realm|,
\[[Environment]]: ~empty~,
\[[Namespace]]: ~empty~,
\[[ModuleSource]]: |module|,
\[[HostDefined]]: ~empty~,
<!-- Cyclic Module Records -->
\[[Status]]: "new",
\[[EvaluationError]]: undefined,
\[[DFSIndex]]: undefined,
\[[DFSAncestorIndex]]: undefined,
\[[RequestedModules]]: |requestedModules|,
\[[LoadedModules]]: &laquo; &raquo;,
\[[CycleRoot]]: ~empty~,
\[[HasTLA]]: false,
\[[AsyncEvaluation]]: false,
\[[TopLevelCapability]]: ~empty~
\[[AsyncParentModules]]: &laquo; &raquo;,
\[[PendingAsyncDependencies]]: ~empty~,
}.
1. Set |module|.\[[ModuleRecord]] to |moduleRecord|.
1. Return |moduleRecord|.
1. Return |specifier|.\[[Module]].\[[ModuleRecord]].
1. Return ~not-a-source~.

Note: See corresponding modifications to HTML in <a href="https://github.com/whatwg/html/pull/10380">PR #10380</a>.

Expand Down

0 comments on commit 8f8a354

Please sign in to comment.