summaryrefslogtreecommitdiff
path: root/test/binaryen.js
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-02-18 04:36:56 +0900
committerGitHub <noreply@github.com>2021-02-18 04:36:56 +0900
commit1254b564b2d36cbf96ef8b8fe0c17fa2fa668ae3 (patch)
tree3cac90d2bffe8eed22ee8a857c9b1123b1235566 /test/binaryen.js
parent1d3f578d5dc26fc8ea83ea851ac0f1100a3cbad6 (diff)
downloadbinaryen-1254b564b2d36cbf96ef8b8fe0c17fa2fa668ae3.tar.gz
binaryen-1254b564b2d36cbf96ef8b8fe0c17fa2fa668ae3.tar.bz2
binaryen-1254b564b2d36cbf96ef8b8fe0c17fa2fa668ae3.zip
[EH] Make rethrow's target a try label (#3568)
I was previously mistaken about `rethrow`'s argument rule and thought it only counted `catch`'s depth. But it turns out it follows the same rule `delegate`'s label: the immediate argument follows the same rule as when computing branch labels, but it only can target `try` labels (semantically it targets that `try`'s corresponding `catch`); otherwise it will be a validation failure. Unlike `delegate`, `rethrow`'s label denotes not where to rethrow, but which exception to rethrow. For example, ```wasm try $l0 catch ($l0) try $l1 catch ($l1) rethrow $l0 ;; rethrow the exception caught by 'catch ($l0)' end end ``` Refer to this comment for the more detailed informal semantics: https://github.com/WebAssembly/exception-handling/issues/146#issuecomment-777714491 --- This also reverts some of `delegateTarget` -> `exceptionTarget` changes done in #3562 in the validator. Label validation rules apply differently for `delegate` and `rethrow` for try-catch. For example, this is valid: ```wasm try $l0 try delegate $l0 catch ($l0) end ``` But this is NOT valid: ```wasm try $l0 catch ($l0) try delegate $l0 end ``` So `try`'s label should be used within try-catch range (not catch-end range) for `delegate`s. But for the `rethrow` the rule is different. For example, this is valid: ```wasm try $l0 catch ($l0) rethrow $l0 end ``` But this is NOT valid: ```wasm try $l0 rethrow $l0 catch ($l0) end ``` So the `try`'s label should be used within catch-end range instead.
Diffstat (limited to 'test/binaryen.js')
-rw-r--r--test/binaryen.js/exception-handling.js10
-rw-r--r--test/binaryen.js/exception-handling.js.txt8
-rw-r--r--test/binaryen.js/expressions.js10
-rw-r--r--test/binaryen.js/expressions.js.txt2
4 files changed, 15 insertions, 15 deletions
diff --git a/test/binaryen.js/exception-handling.js b/test/binaryen.js/exception-handling.js
index 40dc9d489..a8d3dd3a4 100644
--- a/test/binaryen.js/exception-handling.js
+++ b/test/binaryen.js/exception-handling.js
@@ -3,7 +3,7 @@ function cleanInfo(info) {
for (var x in info) {
// Filter out address pointers and only print meaningful info
if (x == 'id' || x == 'type' || x == 'name' || x == 'event' ||
- x == 'depth' || x == 'hasCatchAll' || x == 'delegateTarget' ||
+ x == 'target' || x == 'hasCatchAll' || x == 'delegateTarget' ||
x == 'isDelegate') {
ret[x] = info[x];
}
@@ -21,19 +21,19 @@ module.setFeatures(binaryen.Features.ReferenceTypes |
var event_ = module.addEvent("e", 0, binaryen.i32, binaryen.none);
-// (try
+// (try $l0
// (do
// (throw $e (i32.const 0))
// )
// (catch
// (drop (pop i32))
-// (rethrow 0)
+// (rethrow $l0)
// )
// )
var throw_ = module.throw("e", [module.i32.const(0)]);
-var rethrow = module.rethrow(0);
+var rethrow = module.rethrow("l0");
var try_catch = module.try(
- '',
+ "l0",
throw_,
["e"],
[
diff --git a/test/binaryen.js/exception-handling.js.txt b/test/binaryen.js/exception-handling.js.txt
index 350d543e5..434546126 100644
--- a/test/binaryen.js/exception-handling.js.txt
+++ b/test/binaryen.js/exception-handling.js.txt
@@ -3,7 +3,7 @@
(type $i32_=>_none (func (param i32)))
(event $e (attr 0) (param i32))
(func $test
- (try
+ (try $l0
(do
(throw $e
(i32.const 0)
@@ -13,7 +13,7 @@
(drop
(pop i32)
)
- (rethrow 0)
+ (rethrow $l0)
)
)
(try $try_outer
@@ -35,6 +35,6 @@
)
getExpressionInfo(throw) = {"id":48,"type":1,"event":"e"}
-getExpressionInfo(rethrow) = {"id":49,"type":1,"depth":0}
-getExpressionInfo(try_catch) = {"id":47,"type":1,"name":"","hasCatchAll":0,"delegateTarget":"","isDelegate":0}
+getExpressionInfo(rethrow) = {"id":49,"type":1,"target":"l0"}
+getExpressionInfo(try_catch) = {"id":47,"type":1,"name":"l0","hasCatchAll":0,"delegateTarget":"","isDelegate":0}
getExpressionInfo(try_delegate) = {"id":47,"type":0,"name":"try_outer","hasCatchAll":1,"delegateTarget":"","isDelegate":0}
diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js
index 688321675..1ffd45362 100644
--- a/test/binaryen.js/expressions.js
+++ b/test/binaryen.js/expressions.js
@@ -1585,14 +1585,14 @@ console.log("# Rethrow");
(function testRethrow() {
const module = new binaryen.Module();
- const theRethrow = binaryen.Rethrow(module.rethrow(0));
+ const theRethrow = binaryen.Rethrow(module.rethrow("l0"));
assert(theRethrow instanceof binaryen.Rethrow);
assert(theRethrow instanceof binaryen.Expression);
- assert(theRethrow.depth === 0);
+ assert(theRethrow.target === "l0");
assert(theRethrow.type === binaryen.unreachable);
- theRethrow.depth = 1
- assert(theRethrow.depth === 1);
+ theRethrow.target = "l1";
+ assert(theRethrow.target === "l1");
theRethrow.type = binaryen.f64;
theRethrow.finalize();
assert(theRethrow.type === binaryen.unreachable);
@@ -1601,7 +1601,7 @@ console.log("# Rethrow");
assert(
theRethrow.toText()
==
- "(rethrow 1)\n"
+ "(rethrow $l1)\n"
);
module.dispose();
diff --git a/test/binaryen.js/expressions.js.txt b/test/binaryen.js/expressions.js.txt
index 8467c55c0..1efbd9e13 100644
--- a/test/binaryen.js/expressions.js.txt
+++ b/test/binaryen.js/expressions.js.txt
@@ -297,7 +297,7 @@
)
# Rethrow
-(rethrow 1)
+(rethrow $l1)
# TupleMake
(tuple.make