Skip to content

Commit c7e3087

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

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

document/js-api/index.bs

Lines changed: 25 additions & 15 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, 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,39 @@ 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 |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 and |elementType| is {{TableKind/anyfunc}},
770+
1. Set |value| to null.
771+
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
772+
1. Let |type| be the [=table type=] {[=table type|𝗆𝗂𝗇=] |initial|, [=table type|𝗆𝖺𝗑=] |maximum|} |elementType|.
769773
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 -->
774+
1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
771775
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
772776
1. [=initialize a table object|Initialize=] **this** from |tableaddr|.
777+
1. [=list/Empty=] **this**.\[[Values]].
778+
1. [=list/Append=] |value| to **this**.\[[Values]] |initial| times.
773779
</div>
774780

775781
<div algorithm=dom-Table-grow>
776-
The <dfn method for="Table">grow(|delta|)</dfn> method, when invoked, performs the following steps:
782+
The <dfn method for="Table">grow(|delta|, |value|)</dfn> method, when invoked, performs the following steps:
777783
1. Let |tableaddr| be **this**.\[[Table]].
778784
1. Let |initialSize| be the length of **this**.\[[Values]].
779785
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
780-
1. Let |result| be [=table_grow=](|store|, |tableaddr|, |delta|, [=ref.null=]).
786+
1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|tableaddr|).
787+
1. If |value| is missing and |elementType| is {{TableKind/anyfunc}},
788+
1. Set |value| to null.
789+
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
790+
1. Let |result| be [=table_grow=](|store|, |tableaddr|, |delta|, |ref|).
781791
1. If |result| is [=error=], throw a {{RangeError}} exception.
782792

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

785795
1. Set the [=surrounding agent=]'s [=associated store=] to |result|.
786-
1. [=list/Append=] null to **this**.\[[Values]] |delta| times.
796+
1. [=list/Append=] |value| to **this**.\[[Values]] |delta| times.
787797
1. Return |initialSize|.
788798
</div>
789799

@@ -803,10 +813,10 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
803813
The <dfn method for="Table">set(|index|, |value|)</dfn> method, when invoked, performs the following steps:
804814
1. Let |tableaddr| be **this**.\[[Table]].
805815
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]].
816+
1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|tableaddr|).
817+
1. If |value| is undefined and |elementType| is {{TableKind/anyfunc}},
818+
1. Set |value| to null.
819+
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
810820
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
811821
1. Let |store| be [=table_write=](|store|, |tableaddr|, |index|, |ref|).
812822
1. If |store| is [=error=], throw a {{RangeError}} exception.

0 commit comments

Comments
 (0)