diff options
author | Heejin Ahn <aheejin@gmail.com> | 2021-01-15 18:48:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 18:48:00 +0900 |
commit | beccdf70258cd99ea25f10af13103e14dc243ffa (patch) | |
tree | 1081d7d350fbab7f901b917f2f082c8d351c3157 /test/binaryen.js/expressions.js | |
parent | f18c18e01d03d6d293fe3d701408855bbcea58bd (diff) | |
download | binaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.tar.gz binaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.tar.bz2 binaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.zip |
Basic EH instrucion support for the new spec (#3487)
This updates `try`-`catch`-`catch_all` and `rethrow` instructions to
match the new spec. `delegate` is not included. Now `Try` contains not a
single `catchBody` expression but a vector of catch
bodies and events.
This updates most existing routines, optimizations, and tests modulo the
interpreter and the CFG traversal. Because the interpreter has not been
updated yet, the EH spec test is temporarily disabled in check.py. Also,
because the CFG traversal for EH is not yet updated, several EH tests in
`rse_all-features.wast`, which uses CFG traversal, are temporarily
commented out.
Also added a few more tests in existing EH test functions in
test/passes. In the previous spec, `catch` was catching all exceptions
so it was assumed that anything `try` body throws is caught by its
`catch`, but now we can assume the same only if there is a `catch_all`.
Newly added tests test cases when there is a `catch_all` and cases there
are only `catch`es separately.
Diffstat (limited to 'test/binaryen.js/expressions.js')
-rw-r--r-- | test/binaryen.js/expressions.js | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index 61fc0a3ef..757d88b1b 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -1435,31 +1435,69 @@ console.log("# RefEq"); console.log("# Try"); (function testTry() { const module = new binaryen.Module(); + module.addEvent("event1", 0, binaryen.none, binaryen.none); + module.addEvent("event2", 0, binaryen.none, binaryen.none); + module.addEvent("event3", 0, binaryen.none, binaryen.none); var body = module.i32.const(1); - var catchBody = module.i32.const(2); - const theTry = binaryen.Try(module.try(body, catchBody)); + var catchBodies = [ + module.i32.const(2), + module.i32.const(3) + ]; + const theTry = binaryen.Try(module.try(body, ["event1"], catchBodies)); assert(theTry instanceof binaryen.Try); assert(theTry instanceof binaryen.Expression); assert(theTry.body === body); - assert(theTry.catchBody === catchBody); + assertDeepEqual(theTry.catchBodies, catchBodies); assert(theTry.type === binaryen.i32); + assert(theTry.getNumCatchEvents() == 1); + assert(theTry.getNumCatchBodies() == 2); + assert(theTry.hasCatchAll() == 1); + console.log(theTry.toText()); - theTry.body = body = module.i32.const(3); + theTry.body = body = module.i32.const(4); assert(theTry.body === body); - theTry.catchBody = catchBody = module.i32.const(4); - assert(theTry.catchBody === catchBody); + catchBodies = [ + module.i32.const(5) // set + //remove + ]; + theTry.setCatchBodies(catchBodies); + assertDeepEqual(theTry.catchBodies, catchBodies); + assertDeepEqual(theTry.getCatchBodies(), catchBodies); + console.log(theTry.toText()); + + theTry.insertCatchEventAt(1, "event2"); + theTry.insertCatchBodyAt(0, module.i32.const(6)); + assert(theTry.getNumCatchEvents() == 2); + assert(theTry.getNumCatchBodies() == 2); + assert(theTry.hasCatchAll() == 0); + console.log(theTry.toText()); + + assert(theTry.removeCatchEventAt(1) == "event2"); + theTry.removeCatchBodyAt(1); + assert(theTry.getNumCatchEvents() == 1); + assert(theTry.getNumCatchBodies() == 1); + console.log(theTry.toText()); + + theTry.appendCatchEvent("event3"); + theTry.appendCatchBody(module.drop(module.i32.const(7))); + assert(theTry.getCatchEventAt(0) == "event1"); + assert(theTry.getCatchEventAt(1) == "event3"); + theTry.setCatchEvents(["event2", "event3"]); + assertDeepEqual(theTry.getCatchEvents(), ["event2", "event3"]); + theTry.setCatchBodies([module.i32.const(8), module.i32.const(9)]); + assert(theTry.getCatchEventAt(0) == "event2"); + assert(theTry.getCatchEventAt(1) == "event3"); + theTry.setCatchEventAt(1, "event1"); + theTry.setCatchBodyAt(1, module.i32.const(10)); + assert(theTry.getCatchEventAt(1) == "event1"); + console.log(theTry.toText()); + theTry.type = binaryen.f64; theTry.finalize(); assert(theTry.type === binaryen.i32); console.log(theTry.toText()); - assert( - theTry.toText() - == - "(try (result i32)\n (do\n (i32.const 3)\n )\n (catch\n (i32.const 4)\n )\n)\n" - ); - module.dispose(); })(); @@ -1512,15 +1550,14 @@ console.log("# Rethrow"); (function testRethrow() { const module = new binaryen.Module(); - var exnref = module.local.get(1, binaryen.exnref); - const theRethrow = binaryen.Rethrow(module.rethrow(exnref)); + const theRethrow = binaryen.Rethrow(module.rethrow(0)); assert(theRethrow instanceof binaryen.Rethrow); assert(theRethrow instanceof binaryen.Expression); - assert(theRethrow.exnref === exnref); + assert(theRethrow.depth === 0); assert(theRethrow.type === binaryen.unreachable); - theRethrow.exnref = exnref = module.local.get(2, binaryen.exnref); - assert(theRethrow.exnref === exnref); + theRethrow.depth = 1 + assert(theRethrow.depth === 1); theRethrow.type = binaryen.f64; theRethrow.finalize(); assert(theRethrow.type === binaryen.unreachable); @@ -1529,7 +1566,7 @@ console.log("# Rethrow"); assert( theRethrow.toText() == - "(rethrow\n (local.get $2)\n)\n" + "(rethrow 1)\n" ); module.dispose(); |