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 +407,12 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
391
407
1. Let |tableaddr| be |v|.\[[Table]].
392
408
1. Let |externtable| be the [=external value=][=external value|table=] |tableaddr|.
393
409
1. [=list/Append=] |externtable| to |imports|.
410
+
1. If |externtype| is of the form [=externtype/event=] |attribute| <var ignore>functype</var>,
411
+
1. Assert: |attribute| is [=eventtype/attribute/exception=].
412
+
1. If |v| does not [=implement=]{{Exception}}, throw a {{LinkError}} exception.
413
+
1. Let |tag| be |v|.\[[Address]].
414
+
1. Let |extern| be the [=external value=][=external value/event=] |tag|.
415
+
1. [=list/Append=] |extern| to |imports|.
394
416
1. Return |imports|.
395
417
396
418
Note: This algorithm only verifies the right kind of JavaScript values are passed.
@@ -424,6 +446,12 @@ The verification of WebAssembly type requirements is deferred to the
424
446
1. Let [=external value|table=] |tableaddr| be |externval|.
425
447
1. Let |table| be [=create a Table object|a new Table object=] created from |tableaddr|.
426
448
1. Let |value| be |table|.
449
+
1. If |externtype| is of the form [=externtype/event=] |attribute| <var ignore>functype</var>,
450
+
1. Assert: |attribute| is [=eventtype/attribute/exception=].
451
+
1. Assert: |externval| is of the form [=external value/event=] |eventaddr|.
452
+
1. Let [=external value/event=] |eventaddr| be |externval|.
453
+
1. Let |exception| be [=create an Exception object|a new Exception object=] created from |eventaddr|.
454
+
1. Let |value| be |exception|.
427
455
1. Let |status| be ! [=CreateDataProperty=](|exportsObject|, |name|, |value|).
428
456
1. Assert: |status| is true.
429
457
@@ -515,7 +543,8 @@ enum ImportExportKind {
515
543
"function",
516
544
"table",
517
545
"memory",
518
-
"global"
546
+
"global",
547
+
"event"
519
548
};
520
549
521
550
dictionary ModuleExportDescriptor {
@@ -545,6 +574,7 @@ interface Module {
545
574
* "table" if |type| is of the form [=table=]<var ignore>tabletype</var>
546
575
* "memory" if |type| is of the form [=mem=]<var ignore>memtype</var>
547
576
* "global" if |type| is of the form [=global=]<var ignore>globaltype</var>
577
+
* "event" if |type| is of the form [=externtype/event=]<var ignore>event</var>
548
578
</div>
549
579
550
580
<div algorithm>
@@ -1007,6 +1037,12 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
1007
1037
1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|).
1008
1038
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
1009
1039
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>.
1040
+
1. If |ret| is exception |exntag| |payload|, then
1041
+
1. If |exntag| is the [=JavaScript exception tag=], then
1042
+
1. Let « [=ref.extern=] |externaddr| » be |payload|.
1043
+
1. Throw the result of [=retrieving an extern value=] from |externaddr|.
1044
+
1. Let |exception| be [=create a RuntimeException object|a new RuntimeException=] for |exntag| and |payload|.
1045
+
1. Throw |exception|.
1010
1046
1. Let |outArity| be the [=list/size=] of |ret|.
1011
1047
1. If |outArity| is 0, return undefined.
1012
1048
1. Otherwise, if |outArity| is 1, return [=ToJSValue=](|ret|[0]).
@@ -1057,7 +1093,14 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1057
1093
1. [=Clean up after running a callback=] with |stored settings|.
1058
1094
1. [=Clean up after running script=] with |relevant settings|.
1059
1095
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.
1096
+
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then:
1097
+
1. If |v| [=implements=]{{RuntimeException}},
1098
+
1. Let |type| be |v|.\[[Type]].
1099
+
1. Let |payload| be |v|.\[[Payload]].
1100
+
1. Otherwise,
1101
+
1. Let |type| be the [=JavaScript exception tag=].
1102
+
1. Let |payload| be [=ToWebAssemblyValue=](|v|, [=externref=]).
1103
+
1. [=WebAssembly/Throw=] with |type| and |payload|.
1061
1104
1. Otherwise, return |result|.\[[Value]].
1062
1105
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1063
1106
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).
@@ -1126,6 +1169,146 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerces a JavaScript va
1126
1169
1127
1170
</div>
1128
1171
1172
+
1173
+
<h3 id="exceptions">Exceptions</h3>
1174
+
1175
+
The <dfn>exception_parameters</dfn> algorithm returns the [=list=] of types for a given
1. Let |types| be |exceptionType|'s [=Exception/payload types=].
1261
+
1. If |types|'s [=list/size=] is not |payload|'s [=list/size=],
1262
+
1. Throw a {{TypeError}}.
1263
+
1. Let |wasmPayload| be « ».
1264
+
1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly,
1265
+
1. [=list/Append=] ? [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|.
1266
+
1. Set **this**.\[[Type]] to |exceptionType|.\[[Address]].
1267
+
1. Set **this**.\[[Payload]] to |wasmPayload|.
1268
+
1269
+
</div>
1270
+
1271
+
<div algorithm>
1272
+
1273
+
The <dfn method for="RuntimeException">getArg(|exceptionType|, |index|)</dfn> method steps are:
1274
+
1275
+
1. If **this**.\[[Type]] is not equal to |exceptionType|.\[[Address]],
1276
+
1. Throw a {{TypeError}}.
1277
+
1. Let |payload| be **this**.\[[Payload]].
1278
+
1. If |index| ≥ |payload|'s [=list/size=],
1279
+
1. Throw a {{TypeError}}.
1280
+
1. Return [=ToJSValue=](|payload|[|index|]).
1281
+
1282
+
</div>
1283
+
1284
+
<div algorithm>
1285
+
1286
+
The <dfn method for="RuntimeException">is(|exceptionType|)</dfn> method steps are:
1287
+
1288
+
1. If **this**.\[[Type]] is not equal to |exceptionType|.\[[Address]],
1289
+
1. Return false.
1290
+
1. Return true.
1291
+
1292
+
</div>
1293
+
1294
+
<h4 id="js-exceptions">JavaScript exceptions</h4>
1295
+
1296
+
The <dfn>JavaScript exception tag</dfn> is an [=event address=] reserved by this
1297
+
specification to distinguish exceptions originating from JavaScript.
1298
+
1299
+
Issue: Should it be possible for `br_on_exn` to extract the payload from an exception with this tag?
1300
+
1301
+
<div algorithm>
1302
+
1303
+
To <dfn for=WebAssembly>throw</dfn> with an [=event address=] |type| and matching [=list=] of WebAssembly values |payload|, perform the following steps:
1304
+
1305
+
1. Unwind the stack until reaching the *catching try block* given |type|.
1306
+
1. Invoke the catch block with |payload|.
1307
+
1308
+
Note: This algorithm is expected to be moved into the core specification.
1309
+
1310
+
</div>
1311
+
1129
1312
<h3 id="error-objects">Error Objects</h3>
1130
1313
1131
1314
WebAssembly defines the following Error classes: <dfn exception>CompileError</dfn>, <dfn exception>LinkError</dfn>, and <dfn exception>RuntimeError</dfn>.
0 commit comments