Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit b2310ef

Browse files
committed
[js-api] Extend the WebAssembly.Table API.
Fixes #22. Fixes #67.
1 parent cca5fdf commit b2310ef

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

document/js-api/index.bs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,10 @@ dictionary TableDescriptor {
722722

723723
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
724724
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);
729729
readonly attribute unsigned long length;
730730
};
731731
</pre>
@@ -736,7 +736,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
736736
{{Table}} object has the following internal slots:
737737

738738
* \[[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=].
740740
</div>
741741

742742
<div algorithm>
@@ -761,29 +761,37 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
761761
</div>
762762

763763
<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"]).
765766
1. let |initial| be |descriptor|["initial"].
766767
1. If |descriptor|["maximum"] is [=present=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty.
767768
1. If |maximum| is not empty and |maximum| &lt; |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, set |value| to [=DefaultValue=](|elementType|).
770+
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
771+
1. Let |type| be the [=table type=] {[=table type|𝗆𝗂𝗇=] |initial|, [=table type|𝗆𝖺𝗑=] |maximum|} |elementType|.
769772
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 -->
773+
1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
771774
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
772775
1. [=initialize a table object|Initialize=] **this** from |tableaddr|.
776+
1. [=list/Empty=] **this**.\[[Values]].
777+
1. [=list/Append=] |value| to **this**.\[[Values]] |initial| times.
773778
</div>
774779

775780
<div algorithm=dom-Table-grow>
776-
The <dfn method for="Table">grow(|delta|)</dfn> method, when invoked, performs the following steps:
781+
The <dfn method for="Table">grow(|delta|, |value|)</dfn> method, when invoked, performs the following steps:
777782
1. Let |tableaddr| be **this**.\[[Table]].
778783
1. Let |initialSize| be the length of **this**.\[[Values]].
779784
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
780-
1. Let |result| be [=table_grow=](|store|, |tableaddr|, |delta|, [=ref.null=]).
785+
1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|tableaddr|).
786+
1. If |value| is missing, set |value| to [=DefaultValue=](|elementType|).
787+
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
788+
1. Let |result| be [=table_grow=](|store|, |tableaddr|, |delta|, |ref|).
781789
1. If |result| is [=error=], throw a {{RangeError}} exception.
782790

783791
Note: The above exception may happen due to either insufficient memory or an invalid size parameter.
784792

785793
1. Set the [=surrounding agent=]'s [=associated store=] to |result|.
786-
1. [=list/Append=] null to **this**.\[[Values]] |delta| times.
794+
1. [=list/Append=] |value| to **this**.\[[Values]] |delta| times.
787795
1. Return |initialSize|.
788796
</div>
789797

@@ -803,10 +811,9 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
803811
The <dfn method for="Table">set(|index|, |value|)</dfn> method, when invoked, performs the following steps:
804812
1. Let |tableaddr| be **this**.\[[Table]].
805813
1. Let |values| be **this**.\[[Values]].
806-
1. If |value| is null, let |ref| be [=ref.null=].
807-
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]].
814+
1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|tableaddr|).
815+
1. If |value| is missing, set |value| to [=DefaultValue=](|elementType|).
816+
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
810817
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
811818
1. Let |store| be [=table_write=](|store|, |tableaddr|, |index|, |ref|).
812819
1. If |store| is [=error=], throw a {{RangeError}} exception.
@@ -822,7 +829,10 @@ enum ValueType {
822829
"i32",
823830
"i64",
824831
"f32",
825-
"f64"
832+
"f64",
833+
"nullref",
834+
"anyref",
835+
"anyfunc",
826836
};
827837
</pre>
828838

@@ -886,14 +896,17 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
886896
1. If |valuetype| equals [=𝗂𝟨𝟦=], return [=𝗂𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] 0.
887897
1. If |valuetype| equals [=𝖿𝟥𝟤=], return [=𝖿𝟥𝟤.𝖼𝗈𝗇𝗌𝗍=] 0.
888898
1. If |valuetype| equals [=𝖿𝟨𝟦=], return [=𝖿𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] 0.
889-
1. Else, return [=ref.null=].
899+
1. If |valuetype| equals [=nullref=], return [=ref.null=].
900+
1. If |valuetype| equals [=anyref=], return [=ToWebAssemblyValue=](undefined, |valuetype|).
901+
1. If |valuetype| equals [=nullref=], return [=ref.null=].
902+
1. Assert: This step is not reached.
890903
</div>
891904

892905
<div algorithm>
893906
The <dfn constructor for="Global">Global(|descriptor|, |v|)</dfn> constructor, when invoked, performs the following steps:
894907
1. Let |mutable| be |descriptor|["mutable"].
895908
1. Let |valuetype| be [=ToValueType=](|descriptor|["value"]).
896-
1. If |v| is undefined,
909+
1. If |v| is missing,
897910
1. let |value| be [=DefaultValue=](|valuetype|).
898911
1. Otherwise,
899912
1. If |valuetype| is [=𝗂𝟨𝟦=], throw a {{TypeError}} exception.

0 commit comments

Comments
 (0)