summaryrefslogtreecommitdiff
path: root/test/binaryen.js/exception-handling.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/binaryen.js/exception-handling.js')
-rw-r--r--test/binaryen.js/exception-handling.js92
1 files changed, 42 insertions, 50 deletions
diff --git a/test/binaryen.js/exception-handling.js b/test/binaryen.js/exception-handling.js
index 5ee53667c..b3c9974e7 100644
--- a/test/binaryen.js/exception-handling.js
+++ b/test/binaryen.js/exception-handling.js
@@ -1,7 +1,3 @@
-function assert(x) {
- if (!x) throw 'error!';
-}
-
function cleanInfo(info) {
var ret = {};
for (var x in info) {
@@ -13,52 +9,48 @@ function cleanInfo(info) {
}
function stringify(expr) {
- return JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(expr)));
+ return JSON.stringify(cleanInfo(binaryen.getExpressionInfo(expr)));
}
-function test() {
- var module = new Binaryen.Module();
- module.setFeatures(Binaryen.Features.ReferenceTypes |
- Binaryen.Features.ExceptionHandling);
-
- var event_ = module.addEvent("e", 0, Binaryen.i32, Binaryen.none);
-
- // (try
- // (throw $e (i32.const 0))
- // (catch
- // ;; We don't support multi-value yet. Use locals instead.
- // (local.set 0 (exnref.pop))
- // (drop
- // (block $l (result i32)
- // (rethrow
- // (br_on_exn $l $e (local.get 0))
- // )
- // )
- // )
- // )
- // )
- var throw_ = module.throw("e", [module.i32.const(0)]);
- var br_on_exn = module.br_on_exn("l", "e", module.local.get(0, Binaryen.exnref));
- var rethrow = module.rethrow(br_on_exn);
- var try_ = module.try(
- throw_,
- module.block(null, [
- module.local.set(0, module.exnref.pop()),
- module.drop(
- module.block("l", [rethrow], Binaryen.i32)
- )
- ]
+var module = new binaryen.Module();
+module.setFeatures(binaryen.Features.ReferenceTypes |
+ binaryen.Features.ExceptionHandling);
+
+var event_ = module.addEvent("e", 0, binaryen.i32, binaryen.none);
+
+// (try
+// (throw $e (i32.const 0))
+// (catch
+// ;; We don't support multi-value yet. Use locals instead.
+// (local.set 0 (exnref.pop))
+// (drop
+// (block $l (result i32)
+// (rethrow
+// (br_on_exn $l $e (local.get 0))
+// )
+// )
+// )
+// )
+// )
+var throw_ = module.throw("e", [module.i32.const(0)]);
+var br_on_exn = module.br_on_exn("l", "e", module.local.get(0, binaryen.exnref));
+var rethrow = module.rethrow(br_on_exn);
+var try_ = module.try(
+ throw_,
+ module.block(null, [
+ module.local.set(0, module.exnref.pop()),
+ module.drop(
+ module.block("l", [rethrow], binaryen.i32)
)
- );
- var func = module.addFunction("test", Binaryen.none, Binaryen.none, [Binaryen.exnref], try_);
-
- console.log(module.emitText());
- assert(module.validate());
-
- console.log("getExpressionInfo(throw) = " + stringify(throw_));
- console.log("getExpressionInfo(br_on_exn) = " + stringify(br_on_exn));
- console.log("getExpressionInfo(rethrow) = " + stringify(rethrow));
- console.log("getExpressionInfo(try) = " + stringify(try_));
-}
-
-Binaryen.ready.then(test);
+ ]
+ )
+);
+var func = module.addFunction("test", binaryen.none, binaryen.none, [binaryen.exnref], try_);
+
+console.log(module.emitText());
+assert(module.validate());
+
+console.log("getExpressionInfo(throw) = " + stringify(throw_));
+console.log("getExpressionInfo(br_on_exn) = " + stringify(br_on_exn));
+console.log("getExpressionInfo(rethrow) = " + stringify(rethrow));
+console.log("getExpressionInfo(try) = " + stringify(try_));