You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: document/js-api/index.bs
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -328,13 +328,15 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
328
328
329
329
* \[[Module]] : a WebAssembly [=/module=]
330
330
* \[[Bytes]] : the source bytes of \[[Module]].
331
+
* \[[SourceClassName]] : the string "WebAssembly.Module"
331
332
332
333
<div algorithm>
333
334
To <dfn>construct a WebAssembly module object</dfn> from a module |module| and source bytes |bytes|, perform the following steps:
334
335
335
336
1. Let |moduleObject| be a new {{Module}} object.
336
337
1. Set |moduleObject|.\[[Module]] to |module|.
337
338
1. Set |moduleObject|.\[[Bytes]] to |bytes|.
339
+
1. Set |moduleObject|.\[[SourceClassName]] to "WebAssembly.Module".
338
340
1. Return |moduleObject|.
339
341
</div>
340
342
@@ -548,6 +550,9 @@ interface Module {
548
550
};
549
551
</pre>
550
552
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
+
551
556
<div algorithm>
552
557
The <dfn>string value of the extern type</dfn> |type| is
553
558
* "function" if |type| is of the form [=func=]<var ignore>functype</var>
Copy file name to clipboardExpand all lines: proposals/esm-integration/README.md
+24-13Lines changed: 24 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# WebAssembly/ES Module Integration
2
2
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.
4
4
5
5
This proposal is at Stage 2 in [WebAssembly's process](https://github.com/WebAssembly/meetings/blob/master/process/phases.md).
6
6
@@ -71,9 +71,9 @@ These goals can be addressed by enabling WebAssembly modules to be loaded using
71
71
72
72
This system has three phases:
73
73
74
-
1.Fetch and parse — A module record is constructed from Module resources.
74
+
1.Source — A module record is constructed from Module resources.
75
75
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.
77
77
78
78
The work completed in these phases is defined in two different specifications:
79
79
@@ -82,7 +82,7 @@ The work completed in these phases is defined in two different specifications:
82
82
83
83
WebAssembly fits into these steps as follows:
84
84
85
-
### Fetch and Parse
85
+
### Source Phase
86
86
87
87
Fetching and parsing modules is a recursive process, which can be thought of as the following steps, defined in the host specification:
88
88
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
97
97
98
98
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.
99
99
100
-
###Link
100
+
#### Source Phase Imports
101
101
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.
103
104
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.
105
107
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.
107
114
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.
109
116
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.
111
118
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
113
120
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.
115
126
116
-
### Evaluate
127
+
### Evaluation Phase
117
128
118
129
During evaluation, the code is evaluated to assign values to the exported bindings. In JS, this means running the top-level module code.
0 commit comments