@@ -394,9 +394,9 @@ Return `ret` as a Number value.
394
394
395
395
A ` WebAssembly.Global ` object contains a single ` global ` value which can be
396
396
simultaneously referenced by multiple ` Instance ` objects. Each ` Global ` object
397
- has two internal slots :
397
+ has one internal slot :
398
398
399
- * \[\[ Global\]\] : a [ ` value ` ] [ ]
399
+ * \[\[ Global\]\] : a [ ` global instance ` ] [ ]
400
400
401
401
#### ` WebAssembly.Global ` Constructor
402
402
@@ -411,7 +411,7 @@ this constructor cannot be called as a function without `new`).
411
411
412
412
If ` Type(globalDescriptor) ` is not Object, a [ ` TypeError ` ] [ ] is thrown.
413
413
414
- Let ` typeName ` be [ ` ToString ` ] [ ] ([ ` Get ` ] [ ] (` globalDescriptor ` , ` "type" ` ).
414
+ Let ` typeName ` be [ ` ToString ` ] [ ] ([ ` Get ` ] [ ] (` globalDescriptor ` , ` "type" ` )) .
415
415
416
416
If ` typeName ` is not one of ` "i32" ` , ` "f32" ` , or ` "f64" ` , throw a [ ` TypeError ` ] [ ] .
417
417
@@ -421,10 +421,22 @@ Let `type` be a [`value type`][]:
421
421
* If ` typeName ` is ` "f32" ` , let ` type ` be ` f32 ` .
422
422
* If ` typeName ` is ` "f64" ` , let ` type ` be ` f64 ` .
423
423
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
+
424
428
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 ` .
426
438
427
- Return a new ` WebAssembly.Global ` instance with \[\[ Global\]\] set to ` value ` .
439
+ Return a new ` WebAssembly.Global ` with \[\[ Global\]\] set to ` g ` .
428
440
429
441
#### ` WebAssembly.Global.prototype [ @@toStringTag ] ` Property
430
442
@@ -451,7 +463,9 @@ For each [`import`][] `i` in `module.imports`:
451
463
1 . ...
452
464
1 . If ` i ` is a global import:
453
465
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 ` .
455
469
1 . If ` Type(v) ` is ` WebAssembly.Global ` , append ` v.[[Global]] ` to ` imports ` .
456
470
1 . Otherwise: throw a ` WebAssembly.LinkError ` .
457
471
@@ -461,9 +475,10 @@ Let `exports` be a list of (string, JS value) pairs that is mapped from each
461
475
[ ` external ` ] [ ] value ` e ` in ` instance.exports ` as follows:
462
476
463
477
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 ` .
467
482
468
483
## [ Spec Changes] [ spec ]
469
484
@@ -892,7 +907,7 @@ used if we were to add an additional RMW operator.
892
907
[ `ToWebAssemblyValue` ] : https://github.com/WebAssembly/design/blob/master/JS.md#towebassemblyvalue
893
908
[ `IsSharedArrayBuffer` ] : https://tc39.github.io/ecma262/#sec-issharedarraybuffer
894
909
[ `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
896
911
[ `external` ] : https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L24
897
912
[ global ] : https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L15
898
913
[ `import` ] : https://github.com/WebAssembly/spec/blob/master/interpreter/spec/ast.ml#L168
0 commit comments