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

[js-api] Extend with reference types support. #79

Merged
merged 2 commits into from
Mar 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions document/js-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,10 @@ dictionary TableDescriptor {

[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
interface Table {
constructor(TableDescriptor descriptor);
unsigned long grow([EnforceRange] unsigned long delta);
Function? get([EnforceRange] unsigned long index);
void set([EnforceRange] unsigned long index, Function? value);
constructor(TableDescriptor descriptor, optional any value);
unsigned long grow([EnforceRange] unsigned long delta, optional any value);
any get([EnforceRange] unsigned long index);
void set([EnforceRange] unsigned long index, optional any value);
readonly attribute unsigned long length;
};
</pre>
Expand All @@ -736,7 +736,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
{{Table}} object has the following internal slots:

* \[[Table]] : a [=table address=]
* \[[Values]] : a [=list=] whose elements are either null or [=Exported Function=]s.
* \[[Values]] : a [=list=] whose elements depend on the element type of \[[Table]]'s [=table type=].
</div>

<div algorithm>
Expand All @@ -761,29 +761,41 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
</div>

<div algorithm>
The <dfn constructor for="Table">Table(|descriptor|)</dfn> constructor, when invoked, performs the following steps:
The <dfn constructor for="Table">Table(|descriptor|, |value|)</dfn> constructor, when invoked, performs the following steps:
1. Let |elementType| be ToValueType(descriptor|["element"]).
1. let |initial| be |descriptor|["initial"].
1. If |descriptor|["maximum"] is [=present=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty.
1. If |maximum| is not empty and |maximum| &lt; |initial|, throw a {{RangeError}} exception.
1. Let |type| be the [=table type=] {[=table type|𝗆𝗂𝗇=] n, [=table type|𝗆𝖺𝗑=] |maximum|} [=table type|funcref=].
1. If |value| is missing,
1. Let |ref| be [=DefaultValue=](|elementType|).
1. Otherwise,
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
1. Let |type| be the [=table type=] {[=table type|𝗆𝗂𝗇=] |initial|, [=table type|𝗆𝖺𝗑=] |maximum|} |elementType|.
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, [=ref.null=]). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1. [=initialize a table object|Initialize=] **this** from |tableaddr|.
1. [=list/Empty=] **this**.\[[Values]].
1. [=list/Append=] |value| to **this**.\[[Values]] |initial| times.
</div>

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

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

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

Expand All @@ -803,10 +815,11 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
The <dfn method for="Table">set(|index|, |value|)</dfn> method, when invoked, performs the following steps:
1. Let |tableaddr| be **this**.\[[Table]].
1. Let |values| be **this**.\[[Values]].
1. If |value| is null, let |ref| be [=ref.null=].
1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|tableaddr|).
1. If |value| is missing,
1. Let |ref| be [=DefaultValue=](|elementType|).
1. Otherwise,
1. If |value| does not have a \[[FunctionAddress]] internal slot, throw a {{TypeError}} exception.
1. Let |ref| be [=ref.func=] |value|.\[[FunctionAddress]].
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1. Let |store| be [=table_write=](|store|, |tableaddr|, |index|, |ref|).
1. If |store| is [=error=], throw a {{RangeError}} exception.
Expand All @@ -822,7 +835,10 @@ enum ValueType {
"i32",
"i64",
"f32",
"f64"
"f64",
"nullref",
"anyref",
"anyfunc",
};
</pre>

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

<div algorithm>
The <dfn constructor for="Global">Global(|descriptor|, |v|)</dfn> constructor, when invoked, performs the following steps:
1. Let |mutable| be |descriptor|["mutable"].
1. Let |valuetype| be [=ToValueType=](|descriptor|["value"]).
1. If |v| is undefined,
1. If |v| is missing,
1. let |value| be [=DefaultValue=](|valuetype|).
1. Otherwise,
1. If |valuetype| is [=𝗂𝟨𝟦=], throw a {{TypeError}} exception.
Expand Down Expand Up @@ -993,7 +1012,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
1. For each type |t| of |parameters|,
1. If the length of |argValues| &gt; |i|, let |arg| be |argValues|[|i|].
1. Otherwise, let |arg| be undefined.
1. [=list/Append=] [=ToWebAssemblyValue=](|arg|, |t|, {{TypeError}}) to |args|.
1. [=list/Append=] [=ToWebAssemblyValue=](|arg|, |t|) to |args|.
1. Set |i| to |i| + 1.
1. Let |argsSeq| be a WebAssembly [=sequence=] containing the elements of |args|.
1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |argsSeq|).
Expand Down Expand Up @@ -1060,7 +1079,7 @@ Note: Number values which are equal to NaN may have various observable NaN paylo
</div>

<div algorithm>
The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|, |error|) coerces a JavaScript value to a [=WebAssembly value=] performs the following steps:
The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerces a JavaScript value to a [=WebAssembly value=] performs the following steps:


1. Assert: |type| is not [=𝗂𝟨𝟦=].
Expand All @@ -1077,9 +1096,9 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|, |error|) coerces a Java
1. If |type| is [=anyref=],
1. Do nothing.
1. If |type| is [=funcref=],
1. If |v| is not an [=Exported function=] or null, throw |error|.
1. If |v| is not an [=Exported function=] or null, throw a {{TypeError}}.
1. If |type| is [=nullref=],
1. If |v| is not null, throw |error|.
1. If |v| is not null, throw a {{TypeError}}.
1. Return the result of [=allocating a host address=] for |v|.

</div>
Expand Down