Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 0297b94

Browse files
authored
Add overview on traps and JS API (#93)
This adds overview on traps not being caught by the `catch` instruction and its relationship with the JS API. Closes #1 and closes #89.
1 parent 451063d commit 0297b94

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

proposals/Exceptions.md

+24
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,30 @@ calls until a corresponding, enclosing try block is found. It may also associate
282282
a stack trace that can be used to report uncaught exceptions. However, the
283283
details of this is left to the embedder.
284284

285+
### Traps and JS API
286+
287+
The `catch` instruction catches exceptions generated by the `throw` instruction,
288+
but does not catch traps. The rationale for this is that in general traps are
289+
not locally recoverable and are not needed to be handled in local scopes like
290+
try-catch.
291+
292+
The `catch` instruction catches foreign exceptions generated from calls to
293+
function imports as well, including JavaScript exceptions, with a few
294+
exceptions:
295+
1. In order to be consistent before and after a trap reaches a JavaScript frame,
296+
the `catch` instruction does not catch exceptions generated from traps.
297+
1. The `catch` instruction does not catch JavaScript exceptions generated from
298+
stack overflow and out of memory.
299+
300+
Filtering these exceptions should be based on a predicate that is not observable
301+
by JavaScript. Traps currently generate instances of
302+
[`WebAssembly.RuntimeError`](https://webassembly.github.io/reference-types/js-api/#exceptiondef-runtimeerror),
303+
but this detail is not used to decide type. Implementations are supposed to
304+
specially mark non-catchable exceptions.
305+
([`instanceof`](https://tc39.es/ecma262/#sec-instanceofoperator) predicate can
306+
be intercepted in JS, and types of exceptions generated from stack overflow and
307+
out of memory are implementation-defined.)
308+
285309
## Changes to the text format
286310

287311
This section describes change in the [instruction syntax

0 commit comments

Comments
 (0)