| 1 |
/* Copyright 2021 Mozilla Foundation |
| 2 |
* |
| 3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
* you may not use this file except in compliance with the License. |
| 5 |
* You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software |
| 10 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
* See the License for the specific language governing permissions and |
| 13 |
* limitations under the License. |
| 14 |
*/ |
| 15 |
|
| 16 |
// ./test/core/throw_ref.wast |
| 17 |
|
| 18 |
// ./test/core/throw_ref.wast:3 |
| 19 |
let $0 = instantiate(`(module |
| 20 |
(tag $$e0) |
| 21 |
(tag $$e1) |
| 22 |
|
| 23 |
(func (export "catch-throw_ref-0") |
| 24 |
(block $$h (result exnref) |
| 25 |
(try_table (catch_ref $$e0 $$h) (throw $$e0)) |
| 26 |
(unreachable) |
| 27 |
) |
| 28 |
(throw_ref) |
| 29 |
) |
| 30 |
|
| 31 |
(func (export "catch-throw_ref-1") (param i32) (result i32) |
| 32 |
(block $$h (result exnref) |
| 33 |
(try_table (result i32) (catch_ref $$e0 $$h) (throw $$e0)) |
| 34 |
(return) |
| 35 |
) |
| 36 |
(if (param exnref) (i32.eqz (local.get 0)) |
| 37 |
(then (throw_ref)) |
| 38 |
(else (drop)) |
| 39 |
) |
| 40 |
(i32.const 23) |
| 41 |
) |
| 42 |
|
| 43 |
(func (export "catchall-throw_ref-0") |
| 44 |
(block $$h (result exnref) |
| 45 |
(try_table (result exnref) (catch_all_ref $$h) (throw $$e0)) |
| 46 |
) |
| 47 |
(throw_ref) |
| 48 |
) |
| 49 |
|
| 50 |
(func (export "catchall-throw_ref-1") (param i32) (result i32) |
| 51 |
(block $$h (result exnref) |
| 52 |
(try_table (result i32) (catch_all_ref $$h) (throw $$e0)) |
| 53 |
(return) |
| 54 |
) |
| 55 |
(if (param exnref) (i32.eqz (local.get 0)) |
| 56 |
(then (throw_ref)) |
| 57 |
(else (drop)) |
| 58 |
) |
| 59 |
(i32.const 23) |
| 60 |
) |
| 61 |
|
| 62 |
(func (export "throw_ref-nested") (param i32) (result i32) |
| 63 |
(local $$exn1 exnref) |
| 64 |
(local $$exn2 exnref) |
| 65 |
(block $$h1 (result exnref) |
| 66 |
(try_table (result i32) (catch_ref $$e1 $$h1) (throw $$e1)) |
| 67 |
(return) |
| 68 |
) |
| 69 |
(local.set $$exn1) |
| 70 |
(block $$h2 (result exnref) |
| 71 |
(try_table (result i32) (catch_ref $$e0 $$h2) (throw $$e0)) |
| 72 |
(return) |
| 73 |
) |
| 74 |
(local.set $$exn2) |
| 75 |
(if (i32.eq (local.get 0) (i32.const 0)) |
| 76 |
(then (throw_ref (local.get $$exn1))) |
| 77 |
) |
| 78 |
(if (i32.eq (local.get 0) (i32.const 1)) |
| 79 |
(then (throw_ref (local.get $$exn2))) |
| 80 |
) |
| 81 |
(i32.const 23) |
| 82 |
) |
| 83 |
|
| 84 |
(func (export "throw_ref-recatch") (param i32) (result i32) |
| 85 |
(local $$e exnref) |
| 86 |
(block $$h1 (result exnref) |
| 87 |
(try_table (result i32) (catch_ref $$e0 $$h1) (throw $$e0)) |
| 88 |
(return) |
| 89 |
) |
| 90 |
(local.set $$e) |
| 91 |
(block $$h2 (result exnref) |
| 92 |
(try_table (result i32) (catch_ref $$e0 $$h2) |
| 93 |
(if (i32.eqz (local.get 0)) |
| 94 |
(then (throw_ref (local.get $$e))) |
| 95 |
) |
| 96 |
(i32.const 42) |
| 97 |
) |
| 98 |
(return) |
| 99 |
) |
| 100 |
(drop) (i32.const 23) |
| 101 |
) |
| 102 |
|
| 103 |
(func (export "throw_ref-stack-polymorphism") |
| 104 |
(local $$e exnref) |
| 105 |
(block $$h (result exnref) |
| 106 |
(try_table (result f64) (catch_ref $$e0 $$h) (throw $$e0)) |
| 107 |
(unreachable) |
| 108 |
) |
| 109 |
(local.set $$e) |
| 110 |
(i32.const 1) |
| 111 |
(throw_ref (local.get $$e)) |
| 112 |
) |
| 113 |
)`); |
| 114 |
|
| 115 |
// ./test/core/throw_ref.wast:99 |
| 116 |
assert_exception(() => invoke($0, `catch-throw_ref-0`, [])); |
| 117 |
|
| 118 |
// ./test/core/throw_ref.wast:101 |
| 119 |
assert_exception(() => invoke($0, `catch-throw_ref-1`, [0])); |
| 120 |
|
| 121 |
// ./test/core/throw_ref.wast:102 |
| 122 |
assert_return(() => invoke($0, `catch-throw_ref-1`, [1]), [value("i32", 23)]); |
| 123 |
|
| 124 |
// ./test/core/throw_ref.wast:104 |
| 125 |
assert_exception(() => invoke($0, `catchall-throw_ref-0`, [])); |
| 126 |
|
| 127 |
// ./test/core/throw_ref.wast:106 |
| 128 |
assert_exception(() => invoke($0, `catchall-throw_ref-1`, [0])); |
| 129 |
|
| 130 |
// ./test/core/throw_ref.wast:107 |
| 131 |
assert_return(() => invoke($0, `catchall-throw_ref-1`, [1]), [value("i32", 23)]); |
| 132 |
|
| 133 |
// ./test/core/throw_ref.wast:108 |
| 134 |
assert_exception(() => invoke($0, `throw_ref-nested`, [0])); |
| 135 |
|
| 136 |
// ./test/core/throw_ref.wast:109 |
| 137 |
assert_exception(() => invoke($0, `throw_ref-nested`, [1])); |
| 138 |
|
| 139 |
// ./test/core/throw_ref.wast:110 |
| 140 |
assert_return(() => invoke($0, `throw_ref-nested`, [2]), [value("i32", 23)]); |
| 141 |
|
| 142 |
// ./test/core/throw_ref.wast:112 |
| 143 |
assert_return(() => invoke($0, `throw_ref-recatch`, [0]), [value("i32", 23)]); |
| 144 |
|
| 145 |
// ./test/core/throw_ref.wast:113 |
| 146 |
assert_return(() => invoke($0, `throw_ref-recatch`, [1]), [value("i32", 42)]); |
| 147 |
|
| 148 |
// ./test/core/throw_ref.wast:115 |
| 149 |
assert_exception(() => invoke($0, `throw_ref-stack-polymorphism`, [])); |
| 150 |
|
| 151 |
// ./test/core/throw_ref.wast:117 |
| 152 |
assert_invalid(() => instantiate(`(module (func (throw_ref)))`), `type mismatch`); |
| 153 |
|
| 154 |
// ./test/core/throw_ref.wast:118 |
| 155 |
assert_invalid(() => instantiate(`(module (func (block (throw_ref))))`), `type mismatch`); |