Skip to content

Commit b77d318

Browse files
Guy Bedfordlittledan
authored andcommitted
complete source phase imports integration
1 parent c2f9326 commit b77d318

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

document/js-api/index.bs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,15 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
328328

329329
* \[[Module]] : a WebAssembly [=/module=]
330330
* \[[Bytes]] : the source bytes of \[[Module]].
331+
* \[[SourceClassName]] : the string "WebAssembly.Module"
331332

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

335336
1. Let |moduleObject| be a new {{Module}} object.
336337
1. Set |moduleObject|.\[[Module]] to |module|.
337338
1. Set |moduleObject|.\[[Bytes]] to |bytes|.
339+
1. Set |moduleObject|.\[[SourceClassName]] to "WebAssembly.Module".
338340
1. Return |moduleObject|.
339341
</div>
340342

@@ -548,6 +550,9 @@ interface Module {
548550
};
549551
</pre>
550552

553+
Per ECMA-262 requirements for source phase import integration, the interface object for {{Module}} must have as its [[Prototype]] be %AbstractModuleSource%, created as if by ObjectCreate(%AbstractModuleSource%), instead of %ObjectPrototype%.
554+
In addition, the interface prototype object for {{Module}} must have as its [[Prototype]] %AbstractModuleSource.prototype%, created as if by ObjectCreate(%AbstractModuleSource%), instead of %ObjectPrototype%.
555+
551556
<div algorithm>
552557
The <dfn>string value of the extern type</dfn> |type| is
553558
* "function" if |type| is of the form [=func=] <var ignore>functype</var>

proposals/esm-integration/README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# WebAssembly/ES Module Integration
22

3-
This page describes WebAssembly as an ES module. With this proposal, WebAssembly could be loaded from a JavaScript `import` statement, or a `<script type=module>` tag.
3+
This page describes WebAssembly as an ES module. With this proposal, WebAssembly may be loaded with a JavaScript `import` statement, or a `<script type=module>` tag.
44

55
This proposal is at Stage 2 in [WebAssembly's process](https://github.com/WebAssembly/meetings/blob/master/process/phases.md).
66

@@ -71,9 +71,9 @@ These goals can be addressed by enabling WebAssembly modules to be loaded using
7171

7272
This system has three phases:
7373

74-
1. Fetch and parse — A module record is constructed from Module resources.
74+
1. Source — A module record is constructed from Module resources.
7575
1. Link — Exports and imports are wired up to memory locations.
76-
1. Evaluate — Top-level module code is run, assigning the value to exports.
76+
1. Evaluation — Top-level module code is run, assigning the value to exports.
7777

7878
The work completed in these phases is defined in two different specifications:
7979

@@ -82,7 +82,7 @@ The work completed in these phases is defined in two different specifications:
8282

8383
WebAssembly fits into these steps as follows:
8484

85-
### Fetch and Parse
85+
### Source Phase
8686

8787
Fetching and parsing modules is a recursive process, which can be thought of as the following steps, defined in the host specification:
8888
1. Figure out what the module specifier is pointing to, and fetch the module.
@@ -97,23 +97,34 @@ In both cases, module parsing identifies the new, named exports that this module
9797

9898
In the proposed HTML integration of WebAssembly modules, the [module name](https://webassembly.github.io/spec/core/syntax/modules.html#syntax-import) in an import is interpreted the same as a JavaScript module specifier: basically, as a URL. The [import maps](https://github.com/wicg/import-maps/) proposal adds more expressiveness to module specifiers.
9999

100-
### Link
100+
#### Source Phase Imports
101101

102-
Module records include names of imports and exports. The "link" phase checks whether the named imports correspond to things that are exported, and if so, hooking up the imports of one module to the exports of another module.
102+
[Source phase imports](https://github.com/tc39/proposal-source-phase-imports) expose the source phase of the module
103+
loading process, corresponding to a `WebAssembly.Module` source.
103104

104-
The ECMAScript specification holds the module's export in a lexical scope, as potentially mutable variables. The importing module will have the ability to read, but not write, the variables in this lexical scope.
105+
For WebAssembly, the benefit of this import phase is being able to support multiple instantiation and custom
106+
instantiation or imports, while still utilizing the ESM integration for portable module resolution and fetching.
105107

106-
At the end of the link phase, the variables in the module's lexical scope are generally uninitialized. From JavaScript, accessing an uninitialized import causes a ReferenceError. JavaScript function declarations are initialized during the Link phase, as part of function hoisting, but WebAssembly function exports are not initialized until the Evaluation phase.
108+
Source phase objects exposed by the module system must contain `AbstractModuleSource` in their prototype chain,
109+
therefore to support these imports for WebAssembly, the prototype of `WebAssembly.Module` is updated accordingly.
110+
111+
#### Import Attributes
112+
113+
[Import attributes](https://github.com/tc39/proposal-import-attributes) parameterize module imports in the module system. Currently HTML specifies a `"type"` attribute which is a requirement for CSS or JSON module imports due to their having different security privileges over full execution.
107114

108-
#### Import Assertions
115+
When importing WebAssembly from JavaScript, no `"type"` should be required since they share the same security privilege level in the ESM integration and in order to ensure transparent interoperability of the formats.
109116

110-
[Import assertions](https://github.com/tc39/proposal-import-assertions) specify linking invariants that should be verified before evaluation can proceed. Currently HTML specifies a `"type"` assertion which is a requirement for CSS or JSON module imports due to their having different security privileges over full execution.
117+
Future Wasm extensions may include supporting attributes for imports from WebAssembly modules.
111118

112-
When importing WebAssembly from JavaScript, no assertion should be required since they share the same security privilege level in the ESM integration and in order to ensure transparent interoperability of the formats.
119+
### Link Phase
113120

114-
Future Wasm extensions may include supporting these assertions for imports from WebAssembly modules.
121+
Module records include names of imports and exports. The "link" phase checks whether the named imports correspond to things that are exported, and if so, hooking up the imports of one module to the exports of another module.
122+
123+
The ECMAScript specification holds the module's export in a lexical scope, as potentially mutable variables. The importing module will have the ability to read, but not write, the variables in this lexical scope.
124+
125+
At the end of the link phase, the variables in the module's lexical scope are generally uninitialized. From JavaScript, accessing an uninitialized import causes a ReferenceError. JavaScript function declarations are initialized during the Link phase, as part of function hoisting, but WebAssembly function exports are not initialized until the Evaluation phase.
115126

116-
### Evaluate
127+
### Evaluation Phase
117128

118129
During evaluation, the code is evaluated to assign values to the exported bindings. In JS, this means running the top-level module code.
119130

0 commit comments

Comments
 (0)