Skip to content

Commit 034a8f1

Browse files
committed
Update explainer on stack trace support in JS API
This updates the explainer on - We add stack trace option to `Exception` class in the JS API - `Exception` can contain an optional `externref` to carry a stack trace - `Exception` is not a subclass of JS `Error` Addresses WebAssembly#183 and WebAssembly#189.
1 parent 76419ef commit 034a8f1

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

proposals/exception-handling/Exceptions.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,6 @@ within `()` after `delegate`s are the label operands in immediate values.
394394

395395
### JS API
396396

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-
404397
#### Traps
405398

406399
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
455448
check ensures that without access to a WebAssembly module's exported exception
456449
tag, the associated data fields cannot be read.
457450

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+
458466
More formally, the added interfaces look like the following:
459467

460468
```WebIDL
@@ -464,11 +472,17 @@ interface Tag {
464472
TagType type();
465473
};
466474
475+
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
476+
dictionary ExceptionOptions {
477+
optional boolean traceStack;
478+
};
479+
467480
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
468481
interface Exception {
469-
constructor(Tag tag, sequence<any> payload);
482+
constructor(Tag tag, sequence<any> payload, optional ExceptionOptions options);
470483
any getArg(Tag tag, unsigned long index);
471484
boolean is(Tag tag);
485+
readonly attribute (DOMString or undefined) stack;
472486
};
473487
```
474488

0 commit comments

Comments
 (0)