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
This change updates exception object allocation, initialization, and construction for exnref;
as well as dealing with exception propagation from invoking exported functions; throwing
exceptions from host functions into wasm; and wrapping and unwrapping JS exceptions as they
propagate into and out of wasm.
@@ -760,7 +770,7 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address
760
770
The <dfn constructor for="Table">Table(|descriptor|, |value|)</dfn> constructor, when invoked, performs the following steps:
761
771
1. Let |elementType| be [=ToValueType=](|descriptor|["element"]).
762
772
1. If |elementType| is not a [=reftype=],
763
-
1. [=Throw=] a {{TypeError}} exception.
773
+
1. Throw a {{TypeError}} exception.
764
774
1. Let |initial| be |descriptor|["initial"].
765
775
1. If |descriptor|["maximum"][=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty.
766
776
1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception.
@@ -807,7 +817,7 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address
807
817
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
808
818
1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|store|, |tableaddr|).
809
819
1. If |elementType| is [=exnref=],
810
-
1. [=Throw=] a {{TypeError}} exception.
820
+
1. Throw a {{TypeError}} exception.
811
821
1. Let |result| be [=table_read=](|store|, |tableaddr|, |index|).
812
822
1. If |result| is [=error=], throw a {{RangeError}} exception.
813
823
1. Return [=ToJSValue=](|result|).
@@ -819,7 +829,7 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address
819
829
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
820
830
1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|store|, |tableaddr|).
821
831
1. If |elementType| is [=exnref=],
822
-
1. [=Throw=] a {{TypeError}} exception.
832
+
1. Throw a {{TypeError}} exception.
823
833
1. If |value| is missing,
824
834
1. Let |ref| be [=DefaultValue=](|elementType|).
825
835
1. Otherwise,
@@ -1011,15 +1021,16 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
1011
1021
1. [=list/Append=][=ToWebAssemblyValue=](|arg|, |t|) to |args|.
1012
1022
1. Set |i| to |i| + 1.
1013
1023
1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|).
1014
-
1. Note: The expectation is that [=func_invoke=] will be updated to return (|store|, <var ignore>val</var>* | [=error=] | (exception |exntag| |payload| |opaqueData|)).
1015
1024
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1016
1025
1. If |ret| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by <a href="#errors">the WebAssembly error mapping</a>.
1017
-
1. If |ret| is exception |exntag| |payload| |opaqueData|, then
1018
-
1. If |opaqueData| is not [=ref.null=][=externref=],
1019
-
1. Let « [=ref.extern=] |externaddr| » be |opaqueData|.
1020
-
1. Throw the result of [=retrieving an extern value=] from |externaddr|.
1021
-
1. Let |exception| be [=create an Exception object|a new Exception=] for |exntag| and |payload|.
1022
-
1. Throw |exception|.
1026
+
1. If |ret| is [=THROW=][=ref.exn=] |exnaddr|, then
1027
+
1. Let (|tagaddr|, |payload|) be [=exn_read=](|store|, |exnaddr|).
1028
+
1. Let |jsTagAddr| be the result of [=get the JavaScript exception tag |getting the JavaScript exception tag=].
1029
+
1. If |tagaddr| is equal to |jsTagAddr|,
1030
+
1. Throw the result of [=retrieving an extern value=] from |payload|[0].
1031
+
1. Otherwise,
1032
+
1. Let |exception| be [=create an Exception object|a new Exception=] created from |exnaddr|.
1033
+
1. Throw |exception|.
1023
1034
1. Let |outArity| be the [=list/size=] of |ret|.
1024
1035
1. If |outArity| is 0, return undefined.
1025
1036
1. Otherwise, if |outArity| is 1, return [=ToJSValue=](|ret|[0]).
@@ -1048,7 +1059,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1048
1059
1. Otherwise, if |resultsSize| is 1, return « [=?=][=ToWebAssemblyValue=](|ret|, |results|[0]) ».
1049
1060
1. Otherwise,
1050
1061
1. Let |method| be [=?=][$GetMethod$](|ret|, {{@@iterator}}).
1051
-
1. If |method| is undefined, [=throw=] a {{TypeError}}.
1062
+
1. If |method| is undefined, throw a {{TypeError}}.
1052
1063
1. Let |values| be [=?=][$IterableToList$](|ret|, |method|).
1053
1064
1. Let |wasmValues| be a new, empty [=list=].
1054
1065
1. If |values|'s [=list/size=] is not |resultsSize|, throw a {{TypeError}} exception.
@@ -1071,18 +1082,18 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1071
1082
1. [=Clean up after running a callback=] with |stored settings|.
1072
1083
1. [=Clean up after running script=] with |relevant settings|.
1073
1084
1. Assert: |result|.\[[Type]] is <emu-const>throw</emu-const> or <emu-const>normal</emu-const>.
1085
+
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1074
1086
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then:
1075
1087
1. Let |v| be |result|.\[[Value]].
1076
1088
1. If |v| [=implements=]{{Exception}},
1077
-
1. Let |type| be |v|.\[[Type]].
1078
-
1. Let |payload| be |v|.\[[Payload]].
1089
+
1. Let |address| be |v|.\[[Address]].
1079
1090
1. Otherwise,
1080
-
1. Let |type| be the [=JavaScript exception tag=].
1081
-
1. Let |payload| be « ».
1082
-
1. Let |opaqueData| be [=ToWebAssemblyValue=](|v|, [=externref=])
1083
-
1. [=WebAssembly/Throw=] with |type|, |payload| and |opaqueData|.
1091
+
1. Let |type| be the result of [=get the JavaScript exception tag |getting the JavaScript exception tag=].
1092
+
1. Let |payload| be [=!=][=ToWebAssemblyValue=](|v|, [=externref=]).
1093
+
1. Let (|store|, |address|) be [=exn_alloc=](|store|, |type|, « |payload| »).
1094
+
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1095
+
1. Execute the WebAssembly instructions ([=ref.exn=] |address|) ([=throw_ref=]).
1084
1096
1. Otherwise, return |result|.\[[Value]].
1085
-
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1086
1097
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).
1087
1098
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1088
1099
1. Return |funcaddr|.
@@ -1171,10 +1182,6 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerces a JavaScript va
1171
1182
1172
1183
<h3 id="tags">Tags</h3>
1173
1184
1174
-
The <dfn>tag_alloc</dfn>(|store|, |parameters|) algorithm creates a new [=tag address=] for |parameters| in |store| and returns the updated store and the [=tag address=].
1175
-
1176
-
The <dfn>tag_parameters</dfn>(|store|, |tagAddress|) algorithm returns the [=list=] of types for |tagAddress| in |store|.
The <dfn>JavaScript exception tag</dfn> is a [=tag address=] reserved by this
1340
-
specification to distinguish exceptions originating from JavaScript.
1358
+
The <dfn>JavaScript exception tag</dfn> is a [=tag address=] associated with
1359
+
the surrounding agent. It is allocated in the agent's [=associated store=] on
1360
+
first use and cached. It always has the [=tag type=] « [=externref=] » → « ».
1341
1361
1342
-
For any [=associated store=] |store|, the result of
1343
-
[=tag_parameters=](|store|, [=JavaScript exception tag=]) must be « ».
1344
1362
1345
1363
<div algorithm>
1346
1364
1347
-
To <dfn for=WebAssembly>throw</dfn> with a [=tag address=] |type|, a matching [=list=] of WebAssembly values |payload|, and an [=externref=] |opaqueData|, perform the following steps:
1348
-
1349
-
1. Unwind the stack until reaching the *catching try block* given |type|.
1350
-
1. Invoke the catch block with |payload| and |opaqueData|.
1365
+
To <dfn>get the JavaScript exception tag</dfn>, perform the following steps:
1351
1366
1352
-
Note: This algorithm is expected to be moved into the core specification.
1367
+
1. If the [=surrounding agent=]'s associated [=JavaScript exception tag=] has been initialized,
1368
+
1. return the [=surrounding agent=]'s associated [=JavaScript exception tag=]
1369
+
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1370
+
1. Let (|store|, |tagAddress|) be [=tag_alloc=](|store|, « [=externref=] » → « »).
1371
+
1. Set the current agent's [=associated store=] to |store|.
1372
+
1. Set the current agent's associated [=JavaScript exception tag=] to |tagAddress|.
0 commit comments