@@ -722,10 +722,10 @@ dictionary TableDescriptor {
722
722
723
723
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
724
724
interface Table {
725
- constructor(TableDescriptor descriptor);
726
- unsigned long grow([EnforceRange] unsigned long delta);
727
- Function? get([EnforceRange] unsigned long index);
728
- void set([EnforceRange] unsigned long index, Function? value);
725
+ constructor(TableDescriptor descriptor, optional any value );
726
+ unsigned long grow([EnforceRange] unsigned long delta, optional any value );
727
+ any get([EnforceRange] unsigned long index);
728
+ void set([EnforceRange] unsigned long index, optional any value);
729
729
readonly attribute unsigned long length;
730
730
};
731
731
</pre>
@@ -736,7 +736,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
736
736
{{Table}} object has the following internal slots:
737
737
738
738
* \[[Table]] : a [=table address=]
739
- * \[[Values]] : a [=list=] whose elements are either null or [=Exported Function=] s .
739
+ * \[[Values]] : a [=list=] whose elements depend on the element type of \ [[Table]] 's [=table type=] .
740
740
</div>
741
741
742
742
<div algorithm>
@@ -761,29 +761,41 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
761
761
</div>
762
762
763
763
<div algorithm>
764
- The <dfn constructor for="Table">Table(|descriptor|)</dfn> constructor, when invoked, performs the following steps:
764
+ The <dfn constructor for="Table">Table(|descriptor|, |value|)</dfn> constructor, when invoked, performs the following steps:
765
+ 1. Let |elementType| be ToValueType(descriptor|["element"] ).
765
766
1. let |initial| be |descriptor|["initial"] .
766
767
1. If |descriptor|["maximum"] is [=present=] , let |maximum| be |descriptor|["maximum"] ; otherwise, let |maximum| be empty.
767
768
1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception.
768
- 1. Let |type| be the [=table type=] {[=table type|𝗆𝗂𝗇=] n, [=table type|𝗆𝖺𝗑=] |maximum|} [=table type|funcref=] .
769
+ 1. If |value| is missing,
770
+ 1. Let |ref| be [=DefaultValue=] (|elementType|).
771
+ 1. Otherwise,
772
+ 1. Let |ref| be ? [=ToWebAssemblyValue=] (|value|, |elementType|).
773
+ 1. Let |type| be the [=table type=] {[=table type|𝗆𝗂𝗇=] |initial|, [=table type|𝗆𝖺𝗑=] |maximum|} |elementType|.
769
774
1. Let |store| be the [=surrounding agent=] 's [=associated store=] .
770
- 1. Let (|store|, |tableaddr|) be [=table_alloc=] (|store|, |type|, [= ref.null=] ). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
775
+ 1. Let (|store|, |tableaddr|) be [=table_alloc=] (|store|, |type|, | ref| ). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
771
776
1. Set the [=surrounding agent=] 's [=associated store=] to |store|.
772
777
1. [=initialize a table object|Initialize=] **this** from |tableaddr|.
778
+ 1. [=list/Empty=] **this**.\[[Values]] .
779
+ 1. [=list/Append=] |value| to **this**.\[[Values]] |initial| times.
773
780
</div>
774
781
775
782
<div algorithm=dom-Table-grow>
776
- The <dfn method for="Table">grow(|delta|)</dfn> method, when invoked, performs the following steps:
783
+ The <dfn method for="Table">grow(|delta|, |value| )</dfn> method, when invoked, performs the following steps:
777
784
1. Let |tableaddr| be **this**.\[[Table]] .
778
785
1. Let |initialSize| be the length of **this**.\[[Values]] .
779
786
1. Let |store| be the [=surrounding agent=] 's [=associated store=] .
780
- 1. Let |result| be [=table_grow=] (|store|, |tableaddr|, |delta|, [=ref.null=] ).
787
+ 1. Let (<var ignore> limits</var> , |elementType|) be [=table_type=] (|tableaddr|).
788
+ 1. If |value| is missing,
789
+ 1. Let |ref| be [=DefaultValue=] (|elementType|).
790
+ 1. Otherwise,
791
+ 1. Let |ref| be ? [=ToWebAssemblyValue=] (|value|, |elementType|).
792
+ 1. Let |result| be [=table_grow=] (|store|, |tableaddr|, |delta|, |ref|).
781
793
1. If |result| is [=error=] , throw a {{RangeError}} exception.
782
794
783
795
Note: The above exception may happen due to either insufficient memory or an invalid size parameter.
784
796
785
797
1. Set the [=surrounding agent=] 's [=associated store=] to |result|.
786
- 1. [=list/Append=] null to **this**.\[[Values]] |delta| times.
798
+ 1. [=list/Append=] |value| to **this**.\[[Values]] |delta| times.
787
799
1. Return |initialSize|.
788
800
</div>
789
801
@@ -803,10 +815,11 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
803
815
The <dfn method for="Table">set(|index|, |value|)</dfn> method, when invoked, performs the following steps:
804
816
1. Let |tableaddr| be **this**.\[[Table]] .
805
817
1. Let |values| be **this**.\[[Values]] .
806
- 1. If |value| is null, let |ref| be [=ref.null=] .
818
+ 1. Let (<var ignore> limits</var> , |elementType|) be [=table_type=] (|tableaddr|).
819
+ 1. If |value| is missing,
820
+ 1. Let |ref| be [=DefaultValue=] (|elementType|).
807
821
1. Otherwise,
808
- 1. If |value| does not have a \[[FunctionAddress]] internal slot, throw a {{TypeError}} exception.
809
- 1. Let |ref| be [=ref.func=] |value|.\[[FunctionAddress]] .
822
+ 1. Let |ref| be ? [=ToWebAssemblyValue=] (|value|, |elementType|).
810
823
1. Let |store| be the [=surrounding agent=] 's [=associated store=] .
811
824
1. Let |store| be [=table_write=] (|store|, |tableaddr|, |index|, |ref|).
812
825
1. If |store| is [=error=] , throw a {{RangeError}} exception.
@@ -822,7 +835,10 @@ enum ValueType {
822
835
"i32",
823
836
"i64",
824
837
"f32",
825
- "f64"
838
+ "f64",
839
+ "nullref",
840
+ "anyref",
841
+ "anyfunc",
826
842
};
827
843
</pre>
828
844
@@ -886,14 +902,17 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
886
902
1. If |valuetype| equals [=𝗂𝟨𝟦=] , return [=𝗂𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] 0.
887
903
1. If |valuetype| equals [=𝖿𝟥𝟤=] , return [=𝖿𝟥𝟤.𝖼𝗈𝗇𝗌𝗍=] 0.
888
904
1. If |valuetype| equals [=𝖿𝟨𝟦=] , return [=𝖿𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] 0.
889
- 1. Else, return [=ref.null=] .
905
+ 1. If |valuetype| equals [=nullref=] , return [=ref.null=] .
906
+ 1. If |valuetype| equals [=anyref=] , return [=ToWebAssemblyValue=] (undefined, |valuetype|).
907
+ 1. If |valuetype| equals [=nullref=] , return [=ref.null=] .
908
+ 1. Assert: This step is not reached.
890
909
</div>
891
910
892
911
<div algorithm>
893
912
The <dfn constructor for="Global">Global(|descriptor|, |v|)</dfn> constructor, when invoked, performs the following steps:
894
913
1. Let |mutable| be |descriptor|["mutable"] .
895
914
1. Let |valuetype| be [=ToValueType=] (|descriptor|["value"] ).
896
- 1. If |v| is undefined ,
915
+ 1. If |v| is missing ,
897
916
1. let |value| be [=DefaultValue=] (|valuetype|).
898
917
1. Otherwise,
899
918
1. If |valuetype| is [=𝗂𝟨𝟦=] , throw a {{TypeError}} exception.
@@ -993,7 +1012,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
993
1012
1. For each type |t| of |parameters|,
994
1013
1. If the length of |argValues| > |i|, let |arg| be |argValues|[|i|] .
995
1014
1. Otherwise, let |arg| be undefined.
996
- 1. [=list/Append=] [=ToWebAssemblyValue=] (|arg|, |t|, {{TypeError}} ) to |args|.
1015
+ 1. [=list/Append=] [=ToWebAssemblyValue=] (|arg|, |t|) to |args|.
997
1016
1. Set |i| to |i| + 1.
998
1017
1. Let |argsSeq| be a WebAssembly [=sequence=] containing the elements of |args|.
999
1018
1. Let (|store|, |ret|) be the result of [=func_invoke=] (|store|, |funcaddr|, |argsSeq|).
@@ -1060,7 +1079,7 @@ Note: Number values which are equal to NaN may have various observable NaN paylo
1060
1079
</div>
1061
1080
1062
1081
<div algorithm>
1063
- The algorithm <dfn>ToWebAssemblyValue</dfn> (|v|, |type|, |error| ) coerces a JavaScript value to a [=WebAssembly value=] performs the following steps:
1082
+ The algorithm <dfn>ToWebAssemblyValue</dfn> (|v|, |type|) coerces a JavaScript value to a [=WebAssembly value=] performs the following steps:
1064
1083
1065
1084
1066
1085
1. Assert: |type| is not [=𝗂𝟨𝟦=] .
@@ -1077,9 +1096,9 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|, |error|) coerces a Java
1077
1096
1. If |type| is [=anyref=] ,
1078
1097
1. Do nothing.
1079
1098
1. If |type| is [=funcref=] ,
1080
- 1. If |v| is not an [=Exported function=] or null, throw |error| .
1099
+ 1. If |v| is not an [=Exported function=] or null, throw a {{TypeError}} .
1081
1100
1. If |type| is [=nullref=] ,
1082
- 1. If |v| is not null, throw |error| .
1101
+ 1. If |v| is not null, throw a {{TypeError}} .
1083
1102
1. Return the result of [=allocating a host address=] for |v|.
1084
1103
1085
1104
</div>
0 commit comments