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 Apr 25, 2025. It is now read-only.
@@ -391,6 +400,12 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
391
400
1. Let |tableaddr| be |v|.\[[Table]].
392
401
1. Let |externtable| be the [=external value=][=external value|table=] |tableaddr|.
393
402
1. [=list/Append=] |externtable| to |imports|.
403
+
1. If |externtype| is of the form [=externtype/event=] |attribute| <var ignore>functype</var>,
404
+
1. Assert: |attribute| is [=eventtype/attribute/exception=].
405
+
1. If |v| does not [=implement=]{{Exception}}, throw a {{LinkError}} exception.
406
+
1. Let |tag| be |v|.\[[Address]].
407
+
1. Let |extern| be the [=external value=][=external value/event=] |tag|.
408
+
1. [=list/Append=] |extern| to |imports|.
394
409
1. Return |imports|.
395
410
396
411
Note: This algorithm only verifies the right kind of JavaScript values are passed.
@@ -424,6 +439,12 @@ The verification of WebAssembly type requirements is deferred to the
424
439
1. Let [=external value|table=] |tableaddr| be |externval|.
425
440
1. Let |table| be [=create a Table object|a new Table object=] created from |tableaddr|.
426
441
1. Let |value| be |table|.
442
+
1. If |externtype| is of the form [=externtype/event=] |attribute| <var ignore>functype</var>,
443
+
1. Assert: |attribute| is [=eventtype/attribute/exception=].
444
+
1. Assert: |externval| is of the form [=external value/event=] |eventaddr|.
445
+
1. Let [=external value/event=] |eventaddr| be |externval|.
446
+
1. Let |exception| be [=create an Exception object|a new Exception object=] created from |eventaddr|.
447
+
1. Let |value| be |exception|.
427
448
1. Let |status| be ! [=CreateDataProperty=](|exportsObject|, |name|, |value|).
428
449
1. Assert: |status| is true.
429
450
@@ -515,7 +536,8 @@ enum ImportExportKind {
515
536
"function",
516
537
"table",
517
538
"memory",
518
-
"global"
539
+
"global",
540
+
"event"
519
541
};
520
542
521
543
dictionary ModuleExportDescriptor {
@@ -545,6 +567,7 @@ interface Module {
545
567
* "table" if |type| is of the form [=table=]<var ignore>tabletype</var>
546
568
* "memory" if |type| is of the form [=mem=]<var ignore>memtype</var>
547
569
* "global" if |type| is of the form [=global=]<var ignore>globaltype</var>
570
+
* "event" if |type| is of the form [=externtype/event=]<var ignore>event</var>
548
571
</div>
549
572
550
573
<div algorithm>
@@ -1005,8 +1028,15 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
1005
1028
1. [=list/Append=][=ToWebAssemblyValue=](|arg|, |t|) to |args|.
1006
1029
1. Set |i| to |i| + 1.
1007
1030
1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|).
1031
+
1. Note: The expectation is that [=func_invoke=] will be updated to return (|store|, <var ignore>val</var>* | [=error=] | (exception |exntag| |payload|)).
1008
1032
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1009
1033
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>.
1034
+
1. If |ret| is exception |exntag| |payload|, then
1035
+
1. If |exntag| is the [=JavaScript exception tag=], then
1036
+
1. Let « [=ref.extern=] |externaddr| » be |payload|.
1037
+
1. Throw the result of [=retrieving an extern value=] from |externaddr|.
1038
+
1. Let |exception| be [=create a RuntimeException object|a new RuntimeException=] for |exntag| and |payload|.
1039
+
1. Throw |exception|.
1010
1040
1. Let |outArity| be the [=list/size=] of |ret|.
1011
1041
1. If |outArity| is 0, return undefined.
1012
1042
1. Otherwise, if |outArity| is 1, return [=ToJSValue=](|ret|[0]).
@@ -1057,7 +1087,14 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1057
1087
1. [=Clean up after running a callback=] with |stored settings|.
1058
1088
1. [=Clean up after running script=] with |relevant settings|.
1059
1089
1. Assert: |result|.\[[Type]] is <emu-const>throw</emu-const> or <emu-const>normal</emu-const>.
1060
-
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then trigger a WebAssembly trap, and propagate |result|.\[[Value]] to the enclosing JavaScript.
1090
+
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then:
1091
+
1. If |v| [=implements=]{{RuntimeException}},
1092
+
1. Let |type| be |v|.\[[Type]].
1093
+
1. Let |payload| be |v|.\[[Payload]].
1094
+
1. Otherwise,
1095
+
1. Let |type| be the [=JavaScript exception tag=].
1096
+
1. Let |payload| be [=ToWebAssemblyValue=](|v|, [=externref=]).
1097
+
1. [=WebAssembly/Throw=] with |type| and |payload|.
1061
1098
1. Otherwise, return |result|.\[[Value]].
1062
1099
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1063
1100
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).
@@ -1126,6 +1163,144 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerces a JavaScript va
1126
1163
1127
1164
</div>
1128
1165
1166
+
<h3 id="exceptions">Exceptions</h3>
1167
+
1168
+
The <dfn>exception_parameters</dfn> algorithm returns the [=list=] of types for a given
1169
+
[=event address=] in the given [=associated store=].
1. Let |types| be [=exception_parameters=](|exceptionType|.\[[Address]]).
1250
+
1. If |types|'s [=list/size=] is not |payload|'s [=list/size=],
1251
+
1. Throw a {{TypeError}}.
1252
+
1. Let |wasmPayload| be « ».
1253
+
1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly,
1254
+
1. [=list/Append=] ? [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|.
1255
+
1. Set **this**.\[[Type]] to |exceptionType|.\[[Address]].
1256
+
1. Set **this**.\[[Payload]] to |wasmPayload|.
1257
+
1258
+
</div>
1259
+
1260
+
<div algorithm>
1261
+
1262
+
The <dfn method for="RuntimeException">getArg(|exceptionType|, |index|)</dfn> method steps are:
1263
+
1264
+
1. If **this**.\[[Type]] is not equal to |exceptionType|.\[[Address]],
1265
+
1. Throw a {{TypeError}}.
1266
+
1. Let |payload| be **this**.\[[Payload]].
1267
+
1. If |index| ≥ |payload|'s [=list/size=],
1268
+
1. Throw a {{TypeError}}.
1269
+
1. Return [=ToJSValue=](|payload|[|index|]).
1270
+
1271
+
</div>
1272
+
1273
+
<div algorithm>
1274
+
1275
+
The <dfn method for="RuntimeException">is(|exceptionType|)</dfn> method steps are:
1276
+
1277
+
1. If **this**.\[[Type]] is not equal to |exceptionType|.\[[Address]],
1278
+
1. Return false.
1279
+
1. Return true.
1280
+
1281
+
</div>
1282
+
1283
+
<h4 id="js-exceptions">JavaScript exceptions</h4>
1284
+
1285
+
The <dfn>JavaScript exception tag</dfn> is an [=event address=] reserved by this
1286
+
specification to distinguish exceptions originating from JavaScript.
1287
+
1288
+
For any [=associated store=] |store|, the result of
1289
+
[=exception_parameters=](|store|, [=JavaScript exception tag=]) must be « [=externref=] ».
1290
+
1291
+
Issue: Should it be possible for `br_on_exn` to extract the payload from an exception with this tag?
1292
+
1293
+
<div algorithm>
1294
+
1295
+
To <dfn for=WebAssembly>throw</dfn> with an [=event address=] |type| and matching [=list=] of WebAssembly values |payload|, perform the following steps:
1296
+
1297
+
1. Unwind the stack until reaching the *catching try block* given |type|.
1298
+
1. Invoke the catch block with |payload|.
1299
+
1300
+
Note: This algorithm is expected to be moved into the core specification.
1301
+
1302
+
</div>
1303
+
1129
1304
<h3 id="error-objects">Error Objects</h3>
1130
1305
1131
1306
WebAssembly defines the following Error classes: <dfn exception>CompileError</dfn>, <dfn exception>LinkError</dfn>, and <dfn exception>RuntimeError</dfn>.
0 commit comments