Skip to content

Commit

Permalink
Test breaking out of a try
Browse files Browse the repository at this point in the history
  • Loading branch information
SoniEx2 committed May 22, 2024
1 parent d399b9e commit 25ce339
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/legacy/exceptions/try_catch.wast
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@
(catch $e0)
)
)

(func (export "break-try-catch")
(try (do (br 0)) (catch $e0))
)

(func (export "break-try-catch_all")
(try (do (br 0)) (catch_all))
)
)

(assert_return (invoke "empty-catch"))
Expand Down Expand Up @@ -211,6 +219,9 @@
(assert_exception (invoke "return-call-in-try-catch"))
(assert_exception (invoke "return-call-indirect-in-try-catch"))

(assert_return (invoke "break-try-catch"))
(assert_return (invoke "break-try-catch_all"))

(module
(func $imported-throw (import "test" "throw"))
(tag $e0)
Expand Down
45 changes: 45 additions & 0 deletions test/legacy/exceptions/try_delegate.wast
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,46 @@
(catch $e0)
)
)

(func (export "break-try-delegate")
(try (do (br 0)) (delegate 0))
)

(func (export "break-and-call-throw") (result i32)
(try $outer (result i32)
(do
(try (result i32)
(do
(block $a
(try (do (br $a)) (delegate $outer))
)
(call $throw-void)
(i32.const 0)
)
(catch $e0 (i32.const 1))
)
)
(catch $e0 (i32.const 2))
)
)

(func (export "break-and-throw") (result i32)
(try $outer (result i32)
(do
(try (result i32)
(do
(block $a
(try (do (br $a)) (delegate $outer))
)
(throw $e0)
(i32.const 0)
)
(catch $e0 (i32.const 1))
)
)
(catch $e0 (i32.const 2))
)
)
)

(assert_return (invoke "delegate-no-throw") (i32.const 1))
Expand Down Expand Up @@ -173,6 +213,11 @@
(assert_exception (invoke "return-call-in-try-delegate"))
(assert_exception (invoke "return-call-indirect-in-try-delegate"))

(assert_return (invoke "break-try-delegate"))

(assert_return (invoke "break-and-call-throw") (i32.const 1))
(assert_return (invoke "break-and-throw") (i32.const 1))

(assert_malformed
(module quote "(module (func (delegate 0)))")
"unexpected token"
Expand Down

0 comments on commit 25ce339

Please sign in to comment.