@@ -394,13 +394,6 @@ within `()` after `delegate`s are the label operands in immediate values.
394
394
395
395
### JS API
396
396
397
- #### Stack traces
398
-
399
- When an exception is thrown, the runtime will pop the stack across function
400
- calls until a corresponding, enclosing try block is found. Some runtimes,
401
- especially web VMs may also associate a stack trace that can be used to report
402
- uncaught exceptions. However, the details of this are left to the embedder.
403
-
404
397
#### Traps
405
398
406
399
The ` catch ` /` catch_all ` instruction catches exceptions generated by the ` throw `
@@ -455,27 +448,51 @@ access to the data fields of a `Exception` if a matching tag is given. This last
455
448
check ensures that without access to a WebAssembly module's exported exception
456
449
tag, the associated data fields cannot be read.
457
450
451
+ The ` Exception ` constructor can take an optional ` ExceptionOptions ` argument,
452
+ which can optionally contain ` traceStack ` entry. When ` traceStack ` is ` true ` ,
453
+ web VMs can attach a stack trace string to ` Exception.stack ` field, as in
454
+ JavaScript's ` Error ` class. While ` Exception ` is not a subclass of JavaScript's
455
+ ` Error ` and it can be used to represent normal control flow constructs,
456
+ ` traceStack ` field can be set when we use it to represent errors. The format of
457
+ stack trace strings conform to the [ WebAssembly stack trace
458
+ conventions] ( https://webassembly.github.io/spec/web-api/index.html#conventions ) .
459
+ When ` ExceptionOption ` is not provided or it does not contain ` traceStack `
460
+ entry, ` traceStack ` is considered ` false ` by default.
461
+
462
+ To preserve stack trace info when crossing the JS to Wasm boundary, ` Exception `
463
+ can internally contain an optional ` externref ` value containing a stack trace
464
+ string, which is propagated when caught by ` catch ` and rethrown by ` rethrow ` .
465
+
458
466
More formally, the added interfaces look like the following:
459
467
460
468
``` WebIDL
469
+ dictionary TagType {
470
+ required sequence<ValueType> parameters;
471
+ };
472
+
461
473
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
462
474
interface Tag {
463
475
constructor(TagType type);
464
476
TagType type();
465
477
};
466
478
479
+ dictionary ExceptionOptions {
480
+ boolean traceStack = false;
481
+ };
482
+
467
483
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
468
484
interface Exception {
469
- constructor(Tag tag, sequence<any> payload);
485
+ constructor(Tag tag, sequence<any> payload, optional ExceptionOptions options );
470
486
any getArg(Tag tag, unsigned long index);
471
487
boolean is(Tag tag);
488
+ readonly attribute (DOMString or undefined) stack;
472
489
};
473
490
```
474
491
475
- Where ` type TagType = {parameters: ValueType[]} ` , following the format of the
476
- type reflection proposal ( ` TagType ` corresponds to a ` FunctionType ` without a
477
- ` results ` property). ` TagType ` could be extended in the future for other
478
- proposals that require a richer type specification.
492
+ ` TagType ` corresponds to a ` FunctionType ` in [ the type reflection
493
+ proposal] ( https://github.com/WebAssembly/js-types/blob/main/proposals/js-types/Overview.md ) ,
494
+ without a ` results ` property). ` TagType ` could be extended in the future for
495
+ other proposals that require a richer type specification.
479
496
480
497
## Changes to the text format
481
498
0 commit comments