From cca5fdf6aa408f13fd135c8a59fc4fe5a1a27a37 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 11 Feb 2020 18:27:10 +0100 Subject: [PATCH 1/2] [js-api] Remove spurious argument to ToWebAssemblyValue(). Fixes #51. --- document/js-api/index.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index f39746da..80aa8411 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -993,7 +993,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| > |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|). @@ -1060,7 +1060,7 @@ Note: Number values which are equal to NaN may have various observable NaN paylo
-The algorithm ToWebAssemblyValue(|v|, |type|, |error|) coerces a JavaScript value to a [=WebAssembly value=] performs the following steps: +The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript value to a [=WebAssembly value=] performs the following steps: 1. Assert: |type| is not [=π—‚πŸ¨πŸ¦=]. @@ -1077,9 +1077,9 @@ The algorithm ToWebAssemblyValue(|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|.
From 7adf9d48bd587e1ee07578f6bcf385be45d26234 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 11 Feb 2020 18:28:14 +0100 Subject: [PATCH 2/2] [js-api] Extend the WebAssembly.Table API. Fixes #22. Fixes #67. --- document/js-api/index.bs | 53 +++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 80aa8411..83675064 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -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; }; @@ -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=].
@@ -761,29 +761,41 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
- The Table(|descriptor|) constructor, when invoked, performs the following steps: + The Table(|descriptor|, |value|) 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| < |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=]). + 1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). 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.
- The grow(|delta|) method, when invoked, performs the following steps: + The grow(|delta|, |value|) 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 (limits, |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|.
@@ -803,10 +815,11 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each The set(|index|, |value|) 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 (limits, |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. @@ -822,7 +835,10 @@ enum ValueType { "i32", "i64", "f32", - "f64" + "f64", + "nullref", + "anyref", + "anyfunc", }; @@ -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.
The Global(|descriptor|, |v|) 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.