From 4433e3f6f39d8187ffab1993225b773537991354 Mon Sep 17 00:00:00 2001 From: Soni L Date: Fri, 24 May 2024 14:47:12 -0300 Subject: [PATCH] Test breaking out of a try (#270) Tests that breaking out of a try resets the exception handler correctly. See WebAssembly/wabt#2203 --- test/legacy/exceptions/try_catch.wast | 11 ++++++ test/legacy/exceptions/try_delegate.wast | 45 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/test/legacy/exceptions/try_catch.wast b/test/legacy/exceptions/try_catch.wast index 2a0e9ff6..07399f3a 100644 --- a/test/legacy/exceptions/try_catch.wast +++ b/test/legacy/exceptions/try_catch.wast @@ -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")) @@ -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) diff --git a/test/legacy/exceptions/try_delegate.wast b/test/legacy/exceptions/try_delegate.wast index aae3a301..39ee09a2 100644 --- a/test/legacy/exceptions/try_delegate.wast +++ b/test/legacy/exceptions/try_delegate.wast @@ -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)) @@ -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"