Skip to content

Commit 1e6bf08

Browse files
authored
Move segment and start operations to the end of instantiation in JS.md (#780)
* Move segment and start operations to the end * Add link to Assert * Fix grammar, add imported Tables link
1 parent 1bd8f34 commit 1e6bf08

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

JS.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,10 @@ function, global, memory and table imports):
199199
throw a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror).
200200
* Otherwise, append `v.[[Table]]` to `imports`.
201201

202-
Let `instance` be the result of evaluating
203-
[`Eval.init`](https://github.com/WebAssembly/spec/blob/master/ml-proto/spec/eval.ml#L319)
204-
with arguments `module` and `imports`.
205-
Note: this synchronously executes the [`start`](Modules.md#module-start-function)
206-
function, if present.
202+
Let `instance` be the result of creating a new
203+
[`Eval.instance`](https://github.com/WebAssembly/spec/blob/master/ml-proto/spec/eval.ml#L15)
204+
given `module` and `imports`. Note: this step does not mutate imported memories
205+
or tables.
207206

208207
Let `exports` be a list of (string, JS value) pairs that is mapped from
209208
`module.exports` as follows (assuming the ML spec
@@ -215,11 +214,12 @@ has been modified so that each export simply has a `name`, `type` and `index`:
215214
* If the `type` is function, then export an
216215
[Exported Function Exotic Object](#exported-function-exotic-objects),
217216
reusing an existing object if one exists for the given function definition,
218-
otherwise creating a new object.
217+
otherwise creating a new object given `instance` and `index`.
219218
* If the `type` is global:
220-
* If the global is not immutable, then throw a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror).
219+
* [Assert](https://tc39.github.io/ecma262/#assert): the global is immutable
220+
by MVP validation constraint.
221221
* Let `v` be the global variable's initialized value.
222-
* Otherwise, export [`ToJSValue`](#tojsvalue)`(v)`.
222+
* Export [`ToJSValue`](#tojsvalue)`(v)`.
223223
* If the `type` is memory, then export a `WebAssembly.Memory` object, reusing
224224
an existing object if one exists for the given memory definition, otherwise
225225
creating a new object via [`CreateMemoryObject`](#creatememoryobject).
@@ -243,8 +243,30 @@ of `exports`. Let `moduleNamespace` be the result of calling
243243
[`ModuleNamespaceCreate(moduleRecord, exportStrings)`](http://tc39.github.io/ecma262/#sec-modulenamespacecreate).
244244
Set `moduleRecord.[[Namespace]]` to `moduleNamespace`.
245245

246-
Return a new `WebAssembly.Instance` object setting `[[Instance]]` to `instance`
247-
and `exports` to `moduleNamespace`.
246+
Let `instanceObject` be a new `WebAssembly.Instance` object setting
247+
`[[Instance]]` to `instance` and `exports` to `moduleNamespace`.
248+
249+
If any of the elements of an [Elements section](Modules.md#elements-section)
250+
refers to an imported function which is not an
251+
[Exported Function Exotic Object](#exported-function-exotic-objects), throw a
252+
[`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror).
253+
254+
If, after evaluating the `offset` [initializer expression](Modules.md#initializer-expression)
255+
of every [Data](Modules.md#data-section) and [Element](Modules.md#elements-section)
256+
Segment, any of the segments do not fit in their respective Memory or Table, throw a
257+
[`RangeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-rangeerror).
258+
259+
Apply all Data and Element segments to their respective Memory or Table in the
260+
order in which they appear in the module. Segments may overlap and, if they do,
261+
the final value is the last value written in order. Note: there should be no
262+
errors possible that would cause this operation to fail partway through. After
263+
this operation completes, elements of `instance` are visible and callable
264+
through [imported Tables](Modules.md#imports), even if `start` fails.
265+
266+
If a [`start`](Modules.md#module-start-function) is present, it is evaluated
267+
given `instance`. Any errors thrown by `start` are propagated to the caller.
268+
269+
Return `instanceObject`.
248270

249271
### WebAssembly Module Record
250272

Modules.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ mismatch.
6161

6262
A *global variable import* includes the *value type* and *mutability*
6363
of the global variable. These fields have the same meaning as in the
64-
[Global section](#global-section).
64+
[Global section](#global-section). In the MVP, global variable imports must be
65+
*immutable*.
6566

6667
A *linear memory import* includes the same set of fields defined in the
6768
[Linear Memory section](#linear-memory-section): *default flag*, *initial
@@ -116,6 +117,8 @@ if another WebAssembly instance imports the definition, then both instances
116117
will share the same definition and the associated state (global variable value,
117118
linear memory bytes, table elements) is shared.
118119

120+
In the MVP, only *immutable* global variables can be exported.
121+
119122
## Integration with ES6 modules
120123

121124
While ES6 defines how to parse, link and execute a module, ES6 does not

0 commit comments

Comments
 (0)