Skip to content

Commit 5bc46bb

Browse files
authored
[js-api] More subtyping removal. (WebAssembly#96)
* [js-api] Link to the fork for the core specification. * [js-api] More subtyping removal. * [js-api] Fix bugs in Table constructor. * Add an assertion to ToWebAssemblyValue.
1 parent 8dd9a90 commit 5bc46bb

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

document/js-api/index.bs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
9191
text: IterableToList; url: sec-iterabletolist
9292
type: abstract-op
9393
text: CreateMethodProperty; url: sec-createmethodproperty
94-
urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: dfn
94+
urlPrefix: https://webassembly.github.io/reference-types/core/; spec: WebAssembly; type: dfn
9595
url: valid/modules.html#valid-module
9696
text: valid
9797
text: WebAssembly module validation
@@ -110,6 +110,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
110110
text: f64.const
111111
text: ref.null
112112
text: ref.func
113+
text: ref.extern
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
@@ -145,6 +146,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
145146
text: function address; url: exec/runtime.html#syntax-funcaddr
146147
text: memory address; url: exec/runtime.html#syntax-memaddr
147148
text: global address; url: exec/runtime.html#syntax-globaladdr
149+
text: extern address; url: exec/runtime.html#syntax-externaddr
148150
url: syntax/types.html#syntax-numtype
149151
text: i32
150152
text: i64
@@ -254,7 +256,7 @@ Each [=agent=] is associated with the following [=ordered map=]s:
254256
* The <dfn>Table object cache</dfn>, mapping [=table address=]es to {{Table}} objects.
255257
* The <dfn>Exported Function cache</dfn>, mapping [=function address=]es to [=Exported Function=] objects.
256258
* The <dfn>Global object cache</dfn>, mapping [=global address=]es to {{Global}} objects.
257-
* The <dfn>Host value cache</dfn>, mapping [=host address=]es to values.
259+
* The <dfn>Extern value cache</dfn>, mapping [=extern address=]es to values.
258260

259261
<h2 id="webassembly-namespace">The WebAssembly Namespace</h2>
260262

@@ -754,15 +756,15 @@ Each {{Table}} object has the following internal slots:
754756

755757
<div algorithm>
756758
The <dfn constructor for="Table">Table(|descriptor|, |value|)</dfn> constructor, when invoked, performs the following steps:
757-
1. Let |elementType| be ToValueType(descriptor|["element"]).
759+
1. Let |elementType| be [=ToValueType=](|descriptor|["element"]).
758760
1. let |initial| be |descriptor|["initial"].
759761
1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty.
760762
1. If |maximum| is not empty and |maximum| &lt; |initial|, throw a {{RangeError}} exception.
761763
1. If |value| is missing,
762764
1. Let |ref| be [=DefaultValue=](|elementType|).
763765
1. Otherwise,
764766
1. Let |ref| be ? [=ToWebAssemblyValue=](|value|, |elementType|).
765-
1. Let |type| be the [=table type=] {[=table type|min=] |initial|, [=table type|ma𝗑=] |maximum|} [=table type|an𝗒func=].
767+
1. Let |type| be the [=table type=] {[=table type|min=] |initial|, [=table type|ma𝗑=] |maximum|} |elementType|.
766768
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
767769
1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
768770
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
@@ -1065,20 +1067,20 @@ The algorithm <dfn>ToJSValue</dfn>(|w|) coerces a [=WebAssembly value=] to a Jav
10651067
1. If |w| is of the form [=i32.const=] |i32|, return [=the Number value=] for [=signed_32=](|i32|).
10661068
1. If |w| is of the form [=f32.const=] |f32|, return [=the Number value=] for |f32|.
10671069
1. If |w| is of the form [=f64.const=] |f64|, return [=the Number value=] for |f64|.
1068-
1. If |w| is of the form [=ref.null=], return null.
1070+
1. If |w| is of the form [=ref.null=] <var ignore>t</var>, return null.
10691071
1. If |w| is of the form [=ref.func=] |funcaddr|, return the result of creating [=a new Exported Function=] from |funcaddr|.
1070-
1. If |w| is of the form [=ref.host=] |hostaddr|, return the result of [=retrieving a host value=] from |hostaddr|.
1072+
1. If |w| is of the form [=ref.extern=] |externaddr|, return the result of [=retrieving an extern value=] from |externaddr|.
10711073

10721074
<!-- If the WebAssembly value is optional, then given `None`, return JavaScript value `undefined`. -->
10731075

10741076
Note: Number values which are equal to NaN may have various observable NaN payloads; see [=NumberToRawBytes=] for details.
10751077
</div>
10761078

10771079
<div algorithm>
1078-
For <dfn>retrieving a host value</dfn> from a [=host address=] |hostaddr|, perform the following steps:
1079-
1. Let |map| be the [=surrounding agent=]'s associated [=host value cache=].
1080-
1. Assert: |map|[|hostaddr|] [=map/exists=].
1081-
1. Return |map|[|hostaddr|].
1080+
For <dfn>retrieving an extern value</dfn> from a [=extern address=] |externaddr|, perform the following steps:
1081+
1. Let |map| be the [=surrounding agent=]'s associated [=extern value cache=].
1082+
1. Assert: |map|[|externaddr|] [=map/exists=].
1083+
1. Return |map|[|externaddr|].
10821084
</div>
10831085

10841086
<div algorithm>
@@ -1095,28 +1097,24 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerces a JavaScript va
10951097
1. If |type| is [=f64=],
10961098
1. Let |f64| be ? [=ToNumber=](|v|).
10971099
1. Return [=f64.const=] |f64|.
1098-
1. Assert: |type| is a reference type.
1099-
1. If |type| is [=externref=],
1100-
1. Do nothing.
11011100
1. If |type| is [=funcref=],
1102-
1. If |v| is not an [=Exported function=] or null, throw a {{TypeError}}.
1103-
1. Return the result of [=allocating a host address=] for |v|.
1104-
1105-
</div>
1106-
1107-
<div algorithm>
1108-
For <dfn>allocating a host address</dfn> for a value |v|, perform the following steps:
11091101
1. If |v| is null,
1110-
1. Return [=ref.null=].
1102+
1. Return [=ref.null=] [=funcref=].
11111103
1. If |v| is an [=Exported Function=],
11121104
1. Let |funcaddr| be the value of |v|'s \[[FunctionAddress]] internal slot.
11131105
1. Return [=ref.func=] |funcaddr|.
1114-
1. Let |map| be the [=surrounding agent=]'s associated [=host value cache=].
1115-
1. If a [=host address=] |hostaddr| exists such that |map|[|hostaddr|] is the same as |v|,
1116-
1. Return [=ref.host=] |hostaddr|.
1117-
1. Let [=host address=] |hostaddr| be the smallest address such that |map|[|hostaddr|] [=map/exists=] is false.
1118-
1. [=map/Set=] |map|[|hostaddr|] to |v|.
1119-
1. Return [=ref.host=] |hostaddr|.
1106+
1. Throw a {{TypeError}}.
1107+
1. If |type| is [=externref=],
1108+
1. If |v| is null,
1109+
1. Return [=ref.null=] [=externref=].
1110+
1. Let |map| be the [=surrounding agent=]'s associated [=extern value cache=].
1111+
1. If a [=extern address=] |externaddr| exists such that |map|[|externaddr|] is the same as |v|,
1112+
1. Return [=ref.extern=] |externaddr|.
1113+
1. Let [=extern address=] |externaddr| be the smallest address such that |map|[|externaddr|] [=map/exists=] is false.
1114+
1. [=map/Set=] |map|[|externaddr|] to |v|.
1115+
1. Return [=ref.extern=] |externaddr|.
1116+
1. Assert: This step is not reached.
1117+
11201118
</div>
11211119

11221120

0 commit comments

Comments
 (0)