summaryrefslogtreecommitdiff
path: root/test/binaryen.js
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-02-13 21:23:47 +0900
committerGitHub <noreply@github.com>2021-02-13 21:23:47 +0900
commitc12cc3f50c0ef798b218739fc3de06237ea2c5d5 (patch)
tree512a69360c953ac88f257fb7340a35bf895c4b6d /test/binaryen.js
parentac3188facecb78ebaea1eec6cd6e4723a1a161fe (diff)
downloadbinaryen-c12cc3f50c0ef798b218739fc3de06237ea2c5d5.tar.gz
binaryen-c12cc3f50c0ef798b218739fc3de06237ea2c5d5.tar.bz2
binaryen-c12cc3f50c0ef798b218739fc3de06237ea2c5d5.zip
[EH] Update C and binaryen.js API for delegate (#3565)
This updates C and binaryen.js API to match the new `Try` structure to support `delegate`, added in #3561. Now `try` can take a name (which can be null) like a block, and also has an additional `delegateTarget` field argument which should only be used for try-delegate and otherwise null. This also adds several more variant of `makeTry` methods in wasm-builder. Some are for making try-delegate and some are for try-catch(_all).
Diffstat (limited to 'test/binaryen.js')
-rw-r--r--test/binaryen.js/exception-handling.js40
-rw-r--r--test/binaryen.js/exception-handling.js.txt18
-rw-r--r--test/binaryen.js/expressions.js10
-rw-r--r--test/binaryen.js/expressions.js.txt7
-rw-r--r--test/binaryen.js/kitchen-sink.js4
5 files changed, 71 insertions, 8 deletions
diff --git a/test/binaryen.js/exception-handling.js b/test/binaryen.js/exception-handling.js
index e6cadcf88..40dc9d489 100644
--- a/test/binaryen.js/exception-handling.js
+++ b/test/binaryen.js/exception-handling.js
@@ -3,7 +3,8 @@ 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 == 'depth' || x == 'hasCatchAll' || x == 'delegateTarget' ||
+ x == 'isDelegate') {
ret[x] = info[x];
}
}
@@ -31,7 +32,8 @@ var event_ = module.addEvent("e", 0, binaryen.i32, binaryen.none);
// )
var throw_ = module.throw("e", [module.i32.const(0)]);
var rethrow = module.rethrow(0);
-var try_ = module.try(
+var try_catch = module.try(
+ '',
throw_,
["e"],
[
@@ -42,14 +44,42 @@ var try_ = module.try(
],
binaryen.none
)
- ]
+ ],
+ ''
);
-var func = module.addFunction("test", binaryen.none, binaryen.none, [], try_);
+// (try $try_outer
+// (do
+// (try
+// (do
+// (throw $a-event (i32.const 0))
+// )
+// (delegate $try_outer)
+// )
+// )
+// (catch_all)
+// )
+var try_delegate = module.try(
+ 'try_outer',
+ module.try(
+ '',
+ throw_,
+ [],
+ [],
+ 'try_outer'
+ ),
+ [],
+ [module.nop()],
+ ''
+);
+
+var body = module.block('', [try_catch, try_delegate])
+var func = module.addFunction("test", binaryen.none, binaryen.none, [], body);
console.log(module.emitText());
assert(module.validate());
console.log("getExpressionInfo(throw) = " + stringify(throw_));
console.log("getExpressionInfo(rethrow) = " + stringify(rethrow));
-console.log("getExpressionInfo(try) = " + stringify(try_));
+console.log("getExpressionInfo(try_catch) = " + stringify(try_catch));
+console.log("getExpressionInfo(try_delegate) = " + stringify(try_delegate));
diff --git a/test/binaryen.js/exception-handling.js.txt b/test/binaryen.js/exception-handling.js.txt
index 69b619564..350d543e5 100644
--- a/test/binaryen.js/exception-handling.js.txt
+++ b/test/binaryen.js/exception-handling.js.txt
@@ -16,9 +16,25 @@
(rethrow 0)
)
)
+ (try $try_outer
+ (do
+ (try
+ (do
+ (throw $e
+ (i32.const 0)
+ )
+ )
+ (delegate $try_outer)
+ )
+ )
+ (catch_all
+ (nop)
+ )
+ )
)
)
getExpressionInfo(throw) = {"id":48,"type":1,"event":"e"}
getExpressionInfo(rethrow) = {"id":49,"type":1,"depth":0}
-getExpressionInfo(try) = {"id":47,"type":1,"hasCatchAll":0}
+getExpressionInfo(try_catch) = {"id":47,"type":1,"name":"","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 4c97cdb90..688321675 100644
--- a/test/binaryen.js/expressions.js
+++ b/test/binaryen.js/expressions.js
@@ -1469,7 +1469,7 @@ console.log("# Try");
module.i32.const(2),
module.i32.const(3)
];
- const theTry = binaryen.Try(module.try(body, ["event1"], catchBodies));
+ const theTry = binaryen.Try(module.try('', body, ["event1"], catchBodies, ''));
assert(theTry instanceof binaryen.Try);
assert(theTry instanceof binaryen.Expression);
assert(theTry.body === body);
@@ -1523,6 +1523,14 @@ console.log("# Try");
assert(theTry.type === binaryen.i32);
console.log(theTry.toText());
+
+ const tryDelegate = binaryen.Try(module.try('', body, [], [], "try_blah"));
+ assert(tryDelegate.isDelegate() == 1);
+ assert(tryDelegate.getDelegateTarget() == "try_blah");
+ tryDelegate.setDelegateTarget("try_outer");
+ assert(tryDelegate.getDelegateTarget() == "try_outer");
+ console.log(tryDelegate.toText());
+
module.dispose();
})();
diff --git a/test/binaryen.js/expressions.js.txt b/test/binaryen.js/expressions.js.txt
index 80a642af8..8467c55c0 100644
--- a/test/binaryen.js/expressions.js.txt
+++ b/test/binaryen.js/expressions.js.txt
@@ -283,6 +283,13 @@
)
)
+(try (result i32)
+ (do
+ (i32.const 4)
+ )
+ (delegate $try_outer)
+)
+
# Throw
(throw $bar
(i32.const 6)
diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js
index 327cf0534..2a28cc5b2 100644
--- a/test/binaryen.js/kitchen-sink.js
+++ b/test/binaryen.js/kitchen-sink.js
@@ -545,9 +545,11 @@ function test_core() {
// Exception handling
module.try(
+ '',
module.throw("a-event", [module.i32.const(0)]),
["a-event"],
- [module.drop(module.i32.pop())]
+ [module.drop(module.i32.pop())],
+ ''
),
// Atomics