Skip to content

Commit

Permalink
Test breaking out of a try (#270)
Browse files Browse the repository at this point in the history
Tests that breaking out of a try resets the exception handler correctly.

See WebAssembly/wabt#2203
  • Loading branch information
SoniEx2 authored May 24, 2024
1 parent f3ebba3 commit 4433e3f
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 4433e3f

Please sign in to comment.