Skip to content

Commit 4a57bed

Browse files
authored
Update WebAssembly.Global definition (WebAssembly#22)
1 parent 2aca06a commit 4a57bed

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

proposals/threads/Overview.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ Return `ret` as a Number value.
394394

395395
A `WebAssembly.Global` object contains a single `global` value which can be
396396
simultaneously referenced by multiple `Instance` objects. Each `Global` object
397-
has two internal slots:
397+
has one internal slot:
398398

399-
* \[\[Global\]\]: a [`value`][]
399+
* \[\[Global\]\]: a [`global instance`][]
400400

401401
#### `WebAssembly.Global` Constructor
402402

@@ -411,7 +411,7 @@ this constructor cannot be called as a function without `new`).
411411

412412
If `Type(globalDescriptor)` is not Object, a [`TypeError`][] is thrown.
413413

414-
Let `typeName` be [`ToString`][]([`Get`][](`globalDescriptor`, `"type"`).
414+
Let `typeName` be [`ToString`][]([`Get`][](`globalDescriptor`, `"type"`)).
415415

416416
If `typeName` is not one of `"i32"`, `"f32"`, or `"f64"`, throw a [`TypeError`][].
417417

@@ -421,10 +421,22 @@ Let `type` be a [`value type`][]:
421421
* If `typeName` is `"f32"`, let `type` be `f32`.
422422
* If `typeName` is `"f64"`, let `type` be `f64`.
423423

424+
Let `mutable` be [`ToBoolean`][]([`Get`][](`globalDescriptor`, `"mutable"`)).
425+
426+
Let `mut` be `var` if `mutable` is true, or `const` if `mutable` is false.
427+
424428
Let `value` be [`ToWebAssemblyValue`][]([`Get`][](`globalDescriptor`,
425-
`"value"`) coerced to `type`.
429+
`"value"`)) coerced to `type`.
430+
431+
Return the result of `CreateGlobalObject`(`value`, `mut`).
432+
433+
#### CreateGlobalObject
434+
435+
Given an initial value `v`, and mutability `m`, to create a `WebAssembly.Global`:
436+
437+
Let `g` be a new [`global instance`][] with `value` `v` and `mut` `m`.
426438

427-
Return a new `WebAssembly.Global` instance with \[\[Global\]\] set to `value`.
439+
Return a new `WebAssembly.Global` with \[\[Global\]\] set to `g`.
428440

429441
#### `WebAssembly.Global.prototype [ @@toStringTag ]` Property
430442

@@ -451,7 +463,9 @@ For each [`import`][] `i` in `module.imports`:
451463
1. ...
452464
1. If `i` is a global import:
453465
1. If the `global_type` of `i` is `i64`, throw a `WebAssembly.LinkError`. TODO: don't throw?
454-
1. If `Type(v)` is a Number, append [`ToWebAssemblyValue`][]`(v)` to `imports`.
466+
1. If `Type(v)` is a Number:
467+
1. Let `globalinst` be a new [`global instance`][] with value [`ToWebAssemblyValue`][](`v`) and mut `i.mut`.
468+
1. Append `globalinst` to `imports`.
455469
1. If `Type(v)` is `WebAssembly.Global`, append `v.[[Global]]` to `imports`.
456470
1. Otherwise: throw a `WebAssembly.LinkError`.
457471

@@ -461,9 +475,10 @@ Let `exports` be a list of (string, JS value) pairs that is mapped from each
461475
[`external`][] value `e` in `instance.exports` as follows:
462476

463477
1. ...
464-
1. If `e` is a [global][] `v`:
465-
1. If `v` is an `i64`, throw a `WebAssembly.LinkError`. TODO: don't throw?
466-
1. Return a new `WebAssembly.Global` with [[Global]] set to `v`.
478+
1. If `e` is a [`global instance`][] `v`:
479+
1. Let `type` be the `value_type` of `v.value`.
480+
1. If `type` is `i64`, throw a `WebAssembly.LinkError`. TODO: don't throw?
481+
1. Return a new `WebAssembly.Global` with \[\[Global\]\] set to `v`.
467482

468483
## [Spec Changes][spec]
469484

@@ -892,7 +907,7 @@ used if we were to add an additional RMW operator.
892907
[`ToWebAssemblyValue`]: https://github.com/WebAssembly/design/blob/master/JS.md#towebassemblyvalue
893908
[`IsSharedArrayBuffer`]: https://tc39.github.io/ecma262/#sec-issharedarraybuffer
894909
[`value type`]: https://github.com/WebAssembly/spec/blob/master/interpreter/spec/types.ml#L3
895-
[`value`]: https://github.com/WebAssembly/spec/blob/master/interpreter/spec/values.ml#L9
910+
[`global instance`]: http://webassembly.github.io/spec/execution/runtime.html#global-instances
896911
[`external`]: https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L24
897912
[global]: https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L15
898913
[`import`]: https://github.com/WebAssembly/spec/blob/master/interpreter/spec/ast.ml#L168

0 commit comments

Comments
 (0)