You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 3, 2021. It is now read-only.
@@ -326,7 +335,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
326
335
1. [=Append=] |externfunc| to |imports|.
327
336
1. If |externtype| is of the form [=𝗀𝗅𝗈𝖻𝖺𝗅=] |globaltype|,
328
337
1. If |globaltype| is [=𝗂𝟨𝟦=] or [=Type=](|v|) is not [=Number=], throw a {{LinkError}} exception.
329
-
1. Let |value| be [=ToWebAssemblyValue=](|v|, |globaltype|.<em>[=global type|valtype=]</em>)
338
+
1. Let |value| be [=ToWebAssemblyValue=](|v|, |globaltype|.<em>[=global type|valtype=]</em>, {{LinkError}})
330
339
1. Assert: |globaltype|.<em>[=global type|mut=]</em> is [=global type|𝖼𝗈𝗇𝗌𝗍=], as verified by WebAssembly validation.
331
340
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
332
341
1. Let (|store|, |globaladdr|) be [=alloc_global=](|store|, |globaltype|, |value|).
@@ -590,6 +599,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
590
599
591
600
<pre class="idl">
592
601
enum TableKind {
602
+
"anyref",
603
+
"anyeqref",
593
604
"anyfunc",
594
605
// Note: More values may be added in future iterations,
595
606
// e.g., typed function references, typed GC references
@@ -742,7 +753,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
742
753
1. For each type |t| of |parameters|,
743
754
1. If the length of |argValues| > |i|, let |arg| be |argValues|[i].
744
755
1. Otherwise, let |arg| be undefined.
745
-
1. [=Append=][=ToWebAssemblyValue=](|arg|, |t|) to |args|.
756
+
1. [=Append=][=ToWebAssemblyValue=](|arg|, |t|, {{TypeError}}) to |args|.
746
757
1. Set |i| to |i| + 1.
747
758
1. Let (|store|, |ret|) be the result of [=invoke_func=](|store|, |funcaddr|, |args|).
748
759
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
@@ -767,7 +778,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
767
778
1. Let |ret| be ? [=Call=](|func|, undefined, |jsArguments|). If an exception is thrown, trigger a WebAssembly trap, and propagate the exception to the enclosing JavaScript.
768
779
1. Let [|parameters|] → [|results|] be |functype|.
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
772
783
1. Let (|store|, |funcaddr|) be [=alloc_func=](|store|, |functype|, |hostfunc|).
773
784
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
@@ -781,14 +792,24 @@ Assert: |w| is not of the form [=𝗂𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] |i64|.
781
792
1. If |w| is of the form [=𝗂𝟥𝟤.𝖼𝗈𝗇𝗌𝗍=] |i32|, return [=the Number value=] for [=signed_32=](|i32|).
782
793
1. If |w| is of the form [=𝖿𝟥𝟤.𝖼𝗈𝗇𝗌𝗍=] |f32|, return [=the Number value=] for |f32|.
783
794
1. If |w| is of the form [=𝖿𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] |f64|, return [=the Number value=] for |f64|.
795
+
1. If |w| is of the form [=ref.null=], return null.
796
+
1. If |w| is of the form [=ref.func=] |funcaddr|, return the result of creating [=a new Exported Function=] from |funcaddr|.
797
+
1. If |w| is of the form [=ref.host=] |hostaddr|, return the result of [=retrieving a host value=] from |hostaddr|.
784
798
785
799
<!-- If the WebAssembly value is optional, then given `None`, return JavaScript value `undefined`. -->
786
800
787
801
Note: Implementations may optionally replace the NaN payload with any other NaN payload at this point in the f32 or f64 cases; such a change would not be observable through [=NumberToRawBytes=].
788
802
</div>
789
803
790
804
<div algorithm>
791
-
The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerce a JavaScript value to a [=WebAssembly value=] performs the following steps:
805
+
For <dfn>retrieving a host value</dfn> from a [=host address=] |hostaddr|, perform the following steps:
806
+
1. Let |map| be the [=surrounding agent=]'s associated [=host value cache=].
807
+
1. Assert: |map|[|hostaddr|][=map/exists=].
808
+
1. Return |map|[|hostaddr|].
809
+
</div>
810
+
811
+
<div algorithm>
812
+
The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|, |error|) coerces a JavaScript value to a [=WebAssembly value=] performs the following steps:
792
813
793
814
794
815
Assert: |type| is not [=𝗂𝟨𝟦=].
@@ -801,9 +822,34 @@ Assert: |type| is not [=𝗂𝟨𝟦=].
801
822
1. If |type| is [=𝖿𝟨𝟦=],
802
823
1. Let |f64| be ? [=ToNumber=](|v|).
803
824
1. Return [=𝖿𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] |f64|.
825
+
1. If |type| is [=anyref=],
826
+
1. If |v| is a primitive value but not a string, symbol, or null, throw |error|.
827
+
1. Return the result of [=allocating a host address=] for |v|.
828
+
1. If |type| is [=anyeqref=],
829
+
1. If |v| is a primitive value but not a symbol or null, throw |error|.
830
+
1. Return the result of [=allocating a host address=] for |v|.
831
+
1. If |type| is [=anyfunc=],
832
+
1. If |v| is not an [=Exported function=] or null, throw |error|.
833
+
1. Return the result of [=allocating a host address=] for |v|.
804
834
805
835
</div>
806
836
837
+
<div algorithm>
838
+
For <dfn>allocating a host address</dfn> for a value |v|, perform the following steps:
839
+
1. If |v| is null,
840
+
1. Return [=ref.null=].
841
+
1. If |v| is an [=Exported Function=],
842
+
1. Let |funcaddr| be the value of |v|'s \[[FunctionAddress]] internal slot.
843
+
1. Return [=ref.func=] |funcaddr|.
844
+
1. Let |map| be the [=surrounding agent=]'s associated [=host value cache=].
845
+
1. If a [=host address=] |hostaddr| exists such that |map|[|hostaddr|] is the same as |v|,
846
+
1. Return [=ref.host=] |hostaddr|.
847
+
1. Let [=host address=] |hostaddr| be the smallest address such that |map|[|hostaddr|][=map/exists=] is false.
848
+
1. [=map/Set=] |map|[|hostaddr|] to |v|.
849
+
1. Return [=ref.host=] |hostaddr|.
850
+
</div>
851
+
852
+
807
853
<h3 id="error-objects">Error Objects</h3>
808
854
809
855
WebAssembly defines the following Error classes: {{CompileError}}, {{LinkError}}, and {{RuntimeError}}. WebAssembly errors have the following custom bindings:
0 commit comments