diff options
Diffstat (limited to 'test/spec/exception-handling.wast')
-rw-r--r-- | test/spec/exception-handling.wast | 223 |
1 files changed, 118 insertions, 105 deletions
diff --git a/test/spec/exception-handling.wast b/test/spec/exception-handling.wast index 05ecb97a9..d951441e0 100644 --- a/test/spec/exception-handling.wast +++ b/test/spec/exception-handling.wast @@ -1,6 +1,7 @@ (module (event $e-v (attr 0)) (event $e-i32 (attr 0) (param i32)) + (event $e-f32 (attr 0) (param f32)) (event $e-i32-f32 (attr 0) (param i32 f32)) (func $throw_single_value (export "throw_single_value") @@ -11,17 +12,13 @@ (throw $e-i32-f32 (i32.const 3) (f32.const 3.5)) ) - (func (export "rethrow_null") - (rethrow (ref.null exn)) - ) - (func (export "try_nothrow") (result i32) (try (result i32) (do (i32.const 3) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (i32.const 0) ) ) @@ -32,178 +29,201 @@ (do (throw $e-i32 (i32.const 5)) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (i32.const 3) ) ) ) - (func (export "try_call_catch") (result i32) + (func (export "try_throw_nocatch") (result i32) (try (result i32) (do - (call $throw_single_value) - (unreachable) + (throw $e-i32 (i32.const 5)) ) - (catch - (drop (pop exnref)) + (catch $e-f32 + (drop (pop f32)) (i32.const 3) ) ) ) - (func (export "try_throw_rethrow") - (try + (func (export "try_throw_catchall") (result i32) + (try (result i32) (do (throw $e-i32 (i32.const 5)) ) - (catch - (rethrow (pop exnref)) + (catch $e-f32 + (drop (pop f32)) + (i32.const 4) + ) + (catch_all + (i32.const 3) ) ) ) - (func $try_call_rethrow (export "try_call_rethrow") - (try + (func (export "try_call_catch") (result i32) + (try (result i32) (do (call $throw_single_value) + (unreachable) ) - (catch - (rethrow (pop exnref)) + (catch $e-i32 + (pop i32) ) ) ) - (func (export "br_on_exn_null") (result i32) - (block $l0 (result i32) - (drop - (br_on_exn $l0 $e-i32 (ref.null exn)) - ) - (i32.const 0) - ) - ) - - (func (export "br_on_exn_match_no_value") (local $exn exnref) - (try + (func (export "try_throw_multivalue_catch") (result i32) (local $x (i32 f32)) + (try (result i32) (do - (throw $e-v) + (throw $e-i32-f32 (i32.const 5) (f32.const 1.5)) ) - (catch - (local.set $exn (pop exnref)) - (block $l0 - (rethrow - (br_on_exn $l0 $e-v (local.get $exn)) - ) + (catch $e-i32-f32 + (local.set $x + (pop i32 f32) + ) + (tuple.extract 0 + (local.get $x) ) ) ) ) - (func (export "br_on_exn_match_single_value") (result i32) (local $exn exnref) - (try (result i32) + (func (export "try_throw_rethrow") + (try (do (throw $e-i32 (i32.const 5)) ) - (catch - (local.set $exn (pop exnref)) - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e-i32 (local.get $exn)) - ) - ) + (catch $e-i32 + (drop (pop i32)) + (rethrow 0) ) ) ) - (func (export "br_on_exn_match_multiple_values") (result i32 f32) - (local $exn exnref) - (try (result i32 f32) + (func (export "try_call_rethrow") + (try (do - (throw $e-i32-f32 (i32.const 3) (f32.const 3.5)) + (call $throw_single_value) ) - (catch - (local.set $exn (pop exnref)) - (block $l0 (result i32 f32) - (rethrow - (br_on_exn $l0 $e-i32-f32 (local.get $exn)) - ) - ) + (catch_all + (rethrow 0) ) ) ) - (func (export "br_on_exn_dont_match") (local $exn exnref) - (try + (func (export "rethrow_depth_test1") (result i32) + (try (result i32) (do - (throw $e-i32 (i32.const 5)) - ) - (catch - (local.set $exn (pop exnref)) - (block $l0 - (rethrow - (br_on_exn $l0 $e-v (local.get $exn)) + (try + (do + (throw $e-i32 (i32.const 1)) + ) + (catch_all + (try + (do + (throw $e-i32 (i32.const 2)) + ) + (catch $e-i32 + (drop (pop i32)) + (rethrow 0) ;; rethrow (i32.const 2) + ) + ) ) ) ) + (catch $e-i32 + (pop i32) ;; result is (i32.const 2) + ) ) ) - (func (export "call_br_on_exn") (result i32) (local $exn exnref) + ;; Can we handle rethrows with the depth > 0? + (func (export "rethrow_depth_test2") (result i32) (try (result i32) (do - (call $throw_single_value) - (unreachable) - ) - (catch - (local.set $exn (pop exnref)) - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e-i32 (local.get $exn)) + (try + (do + (throw $e-i32 (i32.const 1)) + ) + (catch_all + (try + (do + (throw $e-i32 (i32.const 2)) + ) + (catch $e-i32 + (drop (pop i32)) + (rethrow 1) ;; rethrow (i32.const 1) + ) + ) ) ) ) + (catch $e-i32 + (pop i32) ;; result is (i32.const 1) + ) ) ) - (func (export "call_rethrow_br_on_exn") (result i32) (local $exn exnref) + ;; Tests whether the exception stack is managed correctly after rethrows + (func (export "rethrow_depth_test3") (result i32) (try (result i32) (do - (call $try_call_rethrow) - (unreachable) - ) - (catch - (local.set $exn (pop exnref)) - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e-i32 (local.get $exn)) + (try + (do + (try + (do + (throw $e-i32 (i32.const 1)) + ) + (catch_all + (try + (do + (throw $e-i32 (i32.const 2)) + ) + (catch $e-i32 + (drop (pop i32)) + (rethrow 1) ;; rethrow (i32.const 1) + ) + ) + ) + ) + ) + (catch $e-i32 + (rethrow 0) ;; rethrow (i32.const 1) again ) ) ) + (catch $e-i32 + (pop i32) ;; result is (i32.const 1) + ) ) ) ) (assert_trap (invoke "throw_single_value")) (assert_trap (invoke "throw_multiple_values")) -(assert_trap (invoke "rethrow_null")) (assert_return (invoke "try_nothrow") (i32.const 3)) (assert_return (invoke "try_throw_catch") (i32.const 3)) -(assert_return (invoke "try_call_catch") (i32.const 3)) +(assert_trap (invoke "try_throw_nocatch")) +(assert_return (invoke "try_throw_catchall") (i32.const 3)) +(assert_return (invoke "try_call_catch") (i32.const 5)) +(assert_return (invoke "try_throw_multivalue_catch") (i32.const 5)) (assert_trap (invoke "try_throw_rethrow")) (assert_trap (invoke "try_call_rethrow")) -(assert_trap (invoke "br_on_exn_null")) -(assert_return (invoke "br_on_exn_match_no_value")) -(assert_return (invoke "br_on_exn_match_single_value") (i32.const 5)) -(assert_return (invoke "br_on_exn_match_multiple_values") (tuple.make (i32.const 3) (f32.const 3.5))) -(assert_trap (invoke "br_on_exn_dont_match")) -(assert_return (invoke "call_rethrow_br_on_exn") (i32.const 5)) +(assert_return (invoke "rethrow_depth_test1") (i32.const 2)) +(assert_return (invoke "rethrow_depth_test2") (i32.const 1)) +(assert_return (invoke "rethrow_depth_test3") (i32.const 1)) (assert_invalid (module (func $f0 (try (do (nop)) - (catch (i32.const 0)) + (catch $e-i32 + (pop i32) + ) ) ) ) @@ -215,7 +235,9 @@ (func $f0 (try (do (i32.const 0)) - (catch (i32.const 0)) + (catch $e-i32 + (pop i32) + ) ) ) ) @@ -244,15 +266,6 @@ (assert_invalid (module - (func $f0 - (rethrow (i32.const 0)) - ) - ) - "rethrow's argument must be exnref type" -) - -(assert_invalid - (module (event $e-i32 (attr 0) (param i32)) (func $f0 (result i32) (block $l0 (result i32) |