summaryrefslogtreecommitdiff
path: root/test/exception-handling.wast
diff options
context:
space:
mode:
Diffstat (limited to 'test/exception-handling.wast')
-rw-r--r--test/exception-handling.wast92
1 files changed, 75 insertions, 17 deletions
diff --git a/test/exception-handling.wast b/test/exception-handling.wast
index 862b82d88..72eb0be4a 100644
--- a/test/exception-handling.wast
+++ b/test/exception-handling.wast
@@ -1,6 +1,7 @@
(module
- (event $e0 (attr 0) (param i32))
- (event $e1 (attr 0) (param externref))
+ (event $e-i32 (attr 0) (param i32))
+ (event $e-i64 (attr 0) (param i64))
+ (event $e-i32-i64 (attr 0) (param i32 i64))
(func $exnref_test (param $0 exnref) (result exnref)
(local.get $0)
@@ -9,20 +10,27 @@
(func $foo)
(func $bar)
- (func $eh_test (local $exn exnref)
+ (func $eh_test (local $x (i32 i64))
+ ;; Simple try-catch
(try
(do
- (throw $e0 (i32.const 0))
+ (throw $e-i32 (i32.const 0))
)
- (catch
- ;; Multi-value is not available yet, so block can't take a value from
- ;; stack. So this uses locals for now.
- (local.set $exn (pop exnref))
+ (catch $e-i32
+ (drop (pop i32))
+ )
+ )
+
+ ;; try-catch with multivalue event
+ (try
+ (do
+ (throw $e-i32-i64 (i32.const 0) (i64.const 0))
+ )
+ (catch $e-i32-i64
+ (local.set $x (pop i32 i64))
(drop
- (block $l0 (result i32)
- (rethrow
- (br_on_exn $l0 $e0 (local.get $exn))
- )
+ (tuple.extract 0
+ (local.get $x)
)
)
)
@@ -33,7 +41,8 @@
(do
(br $l1)
)
- (catch
+ (catch $e-i32
+ (drop (pop i32))
(br $l1)
)
)
@@ -41,8 +50,8 @@
;; Empty try body
(try
(do)
- (catch
- (drop (pop exnref))
+ (catch $e-i32
+ (drop (pop i32))
)
)
@@ -52,11 +61,60 @@
(call $foo)
(call $bar)
)
- (catch
- (drop (pop exnref))
+ (catch $e-i32
+ (drop (pop i32))
+ (call $foo)
+ (call $bar)
+ )
+ )
+
+ ;; Multiple catch clauses
+ (try
+ (do
+ (throw $e-i32 (i32.const 0))
+ )
+ (catch $e-i32
+ (drop (pop i32))
+ )
+ (catch $e-i64
+ (drop (pop i64))
+ )
+ )
+
+ ;; Single catch-all clause
+ (try
+ (do
+ (throw $e-i32 (i32.const 0))
+ )
+ (catch_all)
+ )
+
+ ;; catch and catch-all clauses together
+ (try
+ (do
+ (throw $e-i32 (i32.const 0))
+ )
+ (catch $e-i32
+ (drop (pop i32))
+ )
+ (catch $e-i64
+ (drop (pop i64))
+ )
+ (catch_all
(call $foo)
(call $bar)
)
)
+
+ ;; rethrow
+ (try
+ (do
+ (throw $e-i32 (i32.const 0))
+ )
+ (catch $e-i32
+ (drop (pop i32))
+ (rethrow 0)
+ )
+ )
)
)