| 1 |
;; RUN: wast --assert default,no-test-folded --snapshot tests/snapshots % -f legacy-exceptions |
| 2 |
|
| 3 |
;; Test rethrow instruction. |
| 4 |
|
| 5 |
(module |
| 6 |
(tag $e0) |
| 7 |
(tag $e1) |
| 8 |
|
| 9 |
(func (export "catch-rethrow-0") |
| 10 |
try |
| 11 |
throw $e0 |
| 12 |
catch $e0 |
| 13 |
rethrow 0 |
| 14 |
end |
| 15 |
) |
| 16 |
|
| 17 |
(func (export "catch-rethrow-1") (param i32) (result i32) |
| 18 |
try (result i32) |
| 19 |
throw $e0 |
| 20 |
catch $e0 |
| 21 |
local.get 0 |
| 22 |
i32.eqz |
| 23 |
if |
| 24 |
rethrow 1 |
| 25 |
end |
| 26 |
i32.const 23 |
| 27 |
end |
| 28 |
) |
| 29 |
|
| 30 |
(func (export "catchall-rethrow-0") |
| 31 |
try |
| 32 |
throw $e0 |
| 33 |
catch_all |
| 34 |
rethrow 0 |
| 35 |
end |
| 36 |
) |
| 37 |
|
| 38 |
(func (export "catchall-rethrow-1") (param i32) (result i32) |
| 39 |
try (result i32) |
| 40 |
throw $e0 |
| 41 |
catch_all |
| 42 |
local.get 0 |
| 43 |
i32.eqz |
| 44 |
if |
| 45 |
rethrow 1 |
| 46 |
end |
| 47 |
i32.const 23 |
| 48 |
end |
| 49 |
) |
| 50 |
|
| 51 |
(func (export "rethrow-nested") (param i32) (result i32) |
| 52 |
try (result i32) |
| 53 |
throw $e1 |
| 54 |
catch $e1 |
| 55 |
try (result i32) |
| 56 |
throw $e0 |
| 57 |
catch $e0 |
| 58 |
local.get 0 |
| 59 |
i32.const 0 |
| 60 |
i32.eq |
| 61 |
if |
| 62 |
rethrow 1 |
| 63 |
end |
| 64 |
local.get 0 |
| 65 |
i32.const 1 |
| 66 |
i32.eq |
| 67 |
if |
| 68 |
rethrow 2 |
| 69 |
end |
| 70 |
i32.const 23 |
| 71 |
end |
| 72 |
end |
| 73 |
) |
| 74 |
|
| 75 |
(func (export "rethrow-recatch") (param i32) (result i32) |
| 76 |
try (result i32) |
| 77 |
throw $e0 |
| 78 |
catch $e0 |
| 79 |
try (result i32) |
| 80 |
local.get 0 |
| 81 |
i32.eqz |
| 82 |
if |
| 83 |
rethrow 2 |
| 84 |
end |
| 85 |
i32.const 42 |
| 86 |
catch $e0 |
| 87 |
i32.const 23 |
| 88 |
end |
| 89 |
end |
| 90 |
) |
| 91 |
|
| 92 |
(func (export "rethrow-stack-polymorphism") |
| 93 |
try |
| 94 |
throw $e0 |
| 95 |
catch $e0 |
| 96 |
i32.const 1 |
| 97 |
rethrow 0 |
| 98 |
end |
| 99 |
) |
| 100 |
) |
| 101 |
|
| 102 |
(assert_exception (invoke "catch-rethrow-0")) |
| 103 |
|
| 104 |
(assert_exception (invoke "catch-rethrow-1" (i32.const 0))) |
| 105 |
(assert_return (invoke "catch-rethrow-1" (i32.const 1)) (i32.const 23)) |
| 106 |
|
| 107 |
(assert_exception (invoke "catchall-rethrow-0")) |
| 108 |
|
| 109 |
(assert_exception (invoke "catchall-rethrow-1" (i32.const 0))) |
| 110 |
(assert_return (invoke "catchall-rethrow-1" (i32.const 1)) (i32.const 23)) |
| 111 |
(assert_exception (invoke "rethrow-nested" (i32.const 0))) |
| 112 |
(assert_exception (invoke "rethrow-nested" (i32.const 1))) |
| 113 |
(assert_return (invoke "rethrow-nested" (i32.const 2)) (i32.const 23)) |
| 114 |
|
| 115 |
(assert_return (invoke "rethrow-recatch" (i32.const 0)) (i32.const 23)) |
| 116 |
(assert_return (invoke "rethrow-recatch" (i32.const 1)) (i32.const 42)) |
| 117 |
|
| 118 |
(assert_exception (invoke "rethrow-stack-polymorphism")) |
| 119 |
|
| 120 |
(assert_invalid (module (func (rethrow 0))) "invalid rethrow label") |
| 121 |
(assert_invalid (module (func (block (rethrow 0)))) "invalid rethrow label") |
| 122 |
(assert_invalid (module (func |
| 123 |
try |
| 124 |
rethrow 0 |
| 125 |
delegate 0)) |
| 126 |
"invalid rethrow label") |