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

Commit f5c5dcc

Browse files
authored
Add v128 to JS API (#360)
Following the description given in https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#javascript-api-and-simd-values and also what I64 did before bigint integration.
1 parent dae9f6c commit f5c5dcc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

document/js-api/index.bs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
110110
text: i32.const
111111
text: f32.const
112112
text: f64.const
113+
text: v128.const
113114
text: function index; url: syntax/modules.html#syntax-funcidx
114115
text: function instance; url: exec/runtime.html#function-instances
115116
text: store_init; url: appendix/embedding.html#embed-store-init
@@ -150,6 +151,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
150151
text: i64
151152
text: f32
152153
text: f64
154+
text: v128
153155
text: function element; url: exec/runtime.html#syntax-funcelem
154156
text: import component; url: syntax/modules.html#imports
155157
text: external value; url: exec/runtime.html#syntax-externval
@@ -363,6 +365,8 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
363365
1. Throw a {{LinkError}} exception.
364366
1. If |valtype| is not [=i64=] and [=Type=](|v|) is BigInt,
365367
1. Throw a {{LinkError}} exception.
368+
1. If |valtype| is [=v128=],
369+
1. Throw a {{LinkError}} exception.
366370
1. Let |value| be [=ToWebAssemblyValue=](|v|, |valtype|).
367371
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
368372
1. Let (|store|, |globaladdr|) be [=global_alloc=](|store|, [=const=] |valtype|, |value|).
@@ -816,7 +820,8 @@ enum ValueType {
816820
"i32",
817821
"i64",
818822
"f32",
819-
"f64"
823+
"f64",
824+
"v128"
820825
};
821826
</pre>
822827

@@ -866,6 +871,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
866871
1. If |s| equals "i64", return [=i64=].
867872
1. If |s| equals "f32", return [=f32=].
868873
1. If |s| equals "f64", return [=f64=].
874+
1. If |s| equals "v128", return [=v128=].
869875
</div>
870876

871877
<div algorithm>
@@ -881,6 +887,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
881887
The <dfn constructor for="Global">Global(|descriptor|, |v|)</dfn> constructor, when invoked, performs the following steps:
882888
1. Let |mutable| be |descriptor|["mutable"].
883889
1. Let |valuetype| be [=ToValueType=](|descriptor|["value"]).
890+
1. If |valuetype| is [=v128=],
891+
1. Throw a {{LinkError}} exception.
884892
1. If |v| is undefined,
885893
1. Let |value| be [=DefaultValue=](|valuetype|).
886894
1. Otherwise,
@@ -896,6 +904,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
896904
The algorithm <dfn>GetGlobalValue</dfn>({{Global}} |global|) performs the following steps:
897905
1. Let |store| be the current agent's [=associated store=].
898906
1. Let |globaladdr| be |global|.\[[Global]].
907+
1. Let |globaltype| be [=global_type=](|store|, |globaladdr|).
908+
1. If |globaltype| is of the form <var ignore>mut</var> [=v128=], throw a {{TypeError}}.
899909
1. Let |value| be [=global_read=](|store|, |globaladdr|).
900910
1. Return [=ToJSValue=](|value|).
901911
</div>
@@ -908,6 +918,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
908918
1. Let |store| be the current agent's [=associated store=].
909919
1. Let |globaladdr| be **this**.\[[Global]].
910920
1. Let |mut| |valuetype| be [=global_type=](|store|, |globaladdr|).
921+
1. If |valuetype| is [=v128=], throw a {{TypeError}}.
911922
1. If |mut| is [=const=], throw a {{TypeError}}.
912923
1. Let |value| be [=ToWebAssemblyValue=](**the given value**, |valuetype|).
913924
1. Let |store| be [=global_write=](|store|, |globaladdr|, |value|).
@@ -968,6 +979,9 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
968979
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
969980
1. Let |functype| be [=func_type=](|store|, |funcaddr|).
970981
1. Let [|parameters|][<var ignore>results</var>] be |functype|.
982+
1. If |parameters| or |results| contain [=v128=], throw a {{TypeError}}.
983+
984+
Note: the above error is thrown each time the \[[Call]] method is invoked.
971985
1. Let |args| be « ».
972986
1. Let |i| be 0.
973987
1. [=list/iterate|For each=] |t| of |parameters|,
@@ -996,6 +1010,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
9961010
To <dfn>run a host function</dfn> from the JavaScript object |func|, type |functype|, and [=list=] of [=WebAssembly values=] |arguments|, perform the following steps:
9971011

9981012
1. Let [<var ignore>parameters</var>][|results|] be |functype|.
1013+
1. If |parameters| or |results| contain [=v128=], throw a {{TypeError}}.
9991014
1. Let |jsArguments| be « ».
10001015
1. [=list/iterate|For each=] |arg| of |arguments|,
10011016
1. [=list/Append=] ! [=ToJSValue=](|arg|) to |jsArguments|.
@@ -1039,6 +1054,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
10391054
<div algorithm>
10401055
The algorithm <dfn>ToJSValue</dfn>(|w|) coerces a [=WebAssembly value=] to a JavaScript value by performing the following steps:
10411056

1057+
1. Assert: |w| is not of the form [=v128.const=] <var ignore>v128</var>.
10421058
1. If |w| is of the form [=i64.const=] |i64|,
10431059
1. Let |v| be [=signed_64=](|i64|).
10441060
1. Return a [=BigInt=] representing the mathematical value |v|.
@@ -1053,6 +1069,7 @@ Note: Number values which are equal to NaN may have various observable NaN paylo
10531069

10541070
The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerces a JavaScript value to a [=WebAssembly value=] by performing the following steps:
10551071

1072+
1. Assert: |type| is not [=v128=].
10561073
1. If |type| is [=i64=],
10571074
1. Let |i64| be ? [=ToBigInt64=](|v|).
10581075
1. Return [=i64.const=] |i64|.

0 commit comments

Comments
 (0)