@@ -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,6 +448,21 @@ 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
@@ -464,11 +472,17 @@ interface Tag {
464
472
TagType type();
465
473
};
466
474
475
+ [LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
476
+ dictionary ExceptionOptions {
477
+ optional boolean traceStack;
478
+ };
479
+
467
480
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
468
481
interface Exception {
469
- constructor(Tag tag, sequence<any> payload);
482
+ constructor(Tag tag, sequence<any> payload, optional ExceptionOptions options );
470
483
any getArg(Tag tag, unsigned long index);
471
484
boolean is(Tag tag);
485
+ readonly attribute (DOMString or undefined) stack;
472
486
};
473
487
```
474
488
0 commit comments