From 485ce9638a954e8e1215b8b1840501210bed4163 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 30 Dec 2019 01:59:33 -0800 Subject: [PATCH 1/8] Add overview on traps and JS API This adds overview on traps not being caught by the `catch` instruction and its relationship with the JS API. Closes #1 and closes #89. --- proposals/Exceptions.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/proposals/Exceptions.md b/proposals/Exceptions.md index 7915940b..2b41d241 100644 --- a/proposals/Exceptions.md +++ b/proposals/Exceptions.md @@ -280,6 +280,30 @@ calls until a corresponding, enclosing try block is found. It may also associate a stack trace that can be used to report uncaught exceptions. However, the details of this is left to the embedder. +### Traps and JS API + +The `catch` instruction catches exceptions generated by the `throw` instruction, +but is not supposed to catch traps. The rationale for this is traps, which +corresponds to hardware failures in real machines, are not generally needed to +be handled in locals scopes like try-catch. + +The `catch` instruction catches foreign exceptions generated from calls to +function imports as well, including JavaScript exceptions, with a few +exceptions: +1. When an exported function called from a JavaScript frame traps, the + JavaScript frame throws an exception of + [`WebAssembly.RuntimeError`](https://webassembly.github.io/reference-types/js-api/#exceptiondef-runtimeerror) + type. To be consistent before and after a trap reaches a JavaScript frame, + `catch` instruction does not catch `WebAssembly.RuntimeError` exceptions. +2. The `catch` instruction does not catch JavaScript exceptions generated from + stack overflow and out of memory. + +Filtering these exceptions should be based on a predicate that is not observable +by JavaScript, because +[`instanceof`](https://tc39.es/ecma262/#sec-instanceofoperator) predicate can be +intercepted in JS, and types of exceptions generated from stack overflow and out +of memory are implementation-defined. + ## Changes to the text format This section describes change in the [instruction syntax From 323589a4ea93c8687948b0d165b8cc89790bb9a0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 6 Jan 2020 13:34:41 -0800 Subject: [PATCH 2/8] Update proposals/Exceptions.md Co-Authored-By: Derek Schuff --- proposals/Exceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/Exceptions.md b/proposals/Exceptions.md index 2b41d241..4c3f18a0 100644 --- a/proposals/Exceptions.md +++ b/proposals/Exceptions.md @@ -283,7 +283,7 @@ details of this is left to the embedder. ### Traps and JS API The `catch` instruction catches exceptions generated by the `throw` instruction, -but is not supposed to catch traps. The rationale for this is traps, which +but does not catch traps. The rationale for this is that traps, which corresponds to hardware failures in real machines, are not generally needed to be handled in locals scopes like try-catch. From e7eef0d8db33371e4c07366f5d15e4c213ee4a66 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 6 Jan 2020 13:49:30 -0800 Subject: [PATCH 3/8] Address a comment --- proposals/Exceptions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/Exceptions.md b/proposals/Exceptions.md index 4c3f18a0..defe9dfc 100644 --- a/proposals/Exceptions.md +++ b/proposals/Exceptions.md @@ -283,9 +283,9 @@ details of this is left to the embedder. ### Traps and JS API The `catch` instruction catches exceptions generated by the `throw` instruction, -but does not catch traps. The rationale for this is that traps, which -corresponds to hardware failures in real machines, are not generally needed to -be handled in locals scopes like try-catch. +but does not catch traps. The rationale for this is that in general traps are +not locally recoverable and are not needed to be handled in locals scopes like +try-catch. The `catch` instruction catches foreign exceptions generated from calls to function imports as well, including JavaScript exceptions, with a few From d85118dd09ee8048ca101e58bfeabd7fd5e84b30 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 6 Jan 2020 18:07:40 -0800 Subject: [PATCH 4/8] Reword JS API changes --- proposals/Exceptions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proposals/Exceptions.md b/proposals/Exceptions.md index defe9dfc..a33aa80d 100644 --- a/proposals/Exceptions.md +++ b/proposals/Exceptions.md @@ -290,11 +290,11 @@ try-catch. The `catch` instruction catches foreign exceptions generated from calls to function imports as well, including JavaScript exceptions, with a few exceptions: -1. When an exported function called from a JavaScript frame traps, the - JavaScript frame throws an exception of +1. In order to be consistent before and after a trap reaches a JavaScript frame, + the `catch` instruction does not catch exception generated from traps. This + is currently [`WebAssembly.RuntimeError`](https://webassembly.github.io/reference-types/js-api/#exceptiondef-runtimeerror) - type. To be consistent before and after a trap reaches a JavaScript frame, - `catch` instruction does not catch `WebAssembly.RuntimeError` exceptions. + type. 2. The `catch` instruction does not catch JavaScript exceptions generated from stack overflow and out of memory. From 69e27825b76523f418bf5cdc47573f1e4ca06798 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 6 Jan 2020 18:11:22 -0800 Subject: [PATCH 5/8] plural --- proposals/Exceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/Exceptions.md b/proposals/Exceptions.md index a33aa80d..233090cc 100644 --- a/proposals/Exceptions.md +++ b/proposals/Exceptions.md @@ -291,7 +291,7 @@ The `catch` instruction catches foreign exceptions generated from calls to function imports as well, including JavaScript exceptions, with a few exceptions: 1. In order to be consistent before and after a trap reaches a JavaScript frame, - the `catch` instruction does not catch exception generated from traps. This + the `catch` instruction does not catch exceptions generated from traps. This is currently [`WebAssembly.RuntimeError`](https://webassembly.github.io/reference-types/js-api/#exceptiondef-runtimeerror) type. From 93ff37076c6ce322408ca735727123fdad96e50e Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 8 Jan 2020 00:34:50 -0800 Subject: [PATCH 6/8] Update proposals/Exceptions.md Co-Authored-By: Clemens (Hammacher) Backes --- proposals/Exceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/Exceptions.md b/proposals/Exceptions.md index 233090cc..9829f400 100644 --- a/proposals/Exceptions.md +++ b/proposals/Exceptions.md @@ -284,7 +284,7 @@ details of this is left to the embedder. The `catch` instruction catches exceptions generated by the `throw` instruction, but does not catch traps. The rationale for this is that in general traps are -not locally recoverable and are not needed to be handled in locals scopes like +not locally recoverable and are not needed to be handled in local scopes like try-catch. The `catch` instruction catches foreign exceptions generated from calls to From 607cd882de1aef42985f6b866998b4ce00c3fb48 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 8 Jan 2020 00:35:05 -0800 Subject: [PATCH 7/8] Update proposals/Exceptions.md Co-Authored-By: Clemens (Hammacher) Backes --- proposals/Exceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/Exceptions.md b/proposals/Exceptions.md index 9829f400..49fb7f2f 100644 --- a/proposals/Exceptions.md +++ b/proposals/Exceptions.md @@ -295,7 +295,7 @@ exceptions: is currently [`WebAssembly.RuntimeError`](https://webassembly.github.io/reference-types/js-api/#exceptiondef-runtimeerror) type. -2. The `catch` instruction does not catch JavaScript exceptions generated from +1. The `catch` instruction does not catch JavaScript exceptions generated from stack overflow and out of memory. Filtering these exceptions should be based on a predicate that is not observable From 8207b088b1815f46a1a9be614058b20ab677251b Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 8 Jan 2020 01:14:13 -0800 Subject: [PATCH 8/8] Be explicit about type not being used --- proposals/Exceptions.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/proposals/Exceptions.md b/proposals/Exceptions.md index 49fb7f2f..d1a81995 100644 --- a/proposals/Exceptions.md +++ b/proposals/Exceptions.md @@ -291,18 +291,18 @@ The `catch` instruction catches foreign exceptions generated from calls to function imports as well, including JavaScript exceptions, with a few exceptions: 1. In order to be consistent before and after a trap reaches a JavaScript frame, - the `catch` instruction does not catch exceptions generated from traps. This - is currently - [`WebAssembly.RuntimeError`](https://webassembly.github.io/reference-types/js-api/#exceptiondef-runtimeerror) - type. + the `catch` instruction does not catch exceptions generated from traps. 1. The `catch` instruction does not catch JavaScript exceptions generated from stack overflow and out of memory. Filtering these exceptions should be based on a predicate that is not observable -by JavaScript, because -[`instanceof`](https://tc39.es/ecma262/#sec-instanceofoperator) predicate can be -intercepted in JS, and types of exceptions generated from stack overflow and out -of memory are implementation-defined. +by JavaScript. Traps currently generate instances of +[`WebAssembly.RuntimeError`](https://webassembly.github.io/reference-types/js-api/#exceptiondef-runtimeerror), +but this detail is not used to decide type. Implementations are supposed to +specially mark non-catchable exceptions. +([`instanceof`](https://tc39.es/ecma262/#sec-instanceofoperator) predicate can +be intercepted in JS, and types of exceptions generated from stack overflow and +out of memory are implementation-defined.) ## Changes to the text format