| 1 |
;; Test throw_ref instruction. |
| 2 |
|
| 3 |
(module |
| 4 |
(tag $e0) |
| 5 |
(tag $e1) |
| 6 |
|
| 7 |
(func (export "catch-throw_ref-0") |
| 8 |
(block $h (result exnref) |
| 9 |
(try_table (catch_ref $e0 $h) (throw $e0)) |
| 10 |
(unreachable) |
| 11 |
) |
| 12 |
(throw_ref) |
| 13 |
) |
| 14 |
|
| 15 |
(func (export "catch-throw_ref-1") (param i32) (result i32) |
| 16 |
(block $h (result exnref) |
| 17 |
(try_table (result i32) (catch_ref $e0 $h) (throw $e0)) |
| 18 |
(return) |
| 19 |
) |
| 20 |
(if (param exnref) (i32.eqz (local.get 0)) |
| 21 |
(then (throw_ref)) |
| 22 |
(else (drop)) |
| 23 |
) |
| 24 |
(i32.const 23) |
| 25 |
) |
| 26 |
|
| 27 |
(func (export "catchall-throw_ref-0") |
| 28 |
(block $h (result exnref) |
| 29 |
(try_table (result exnref) (catch_all_ref $h) (throw $e0)) |
| 30 |
) |
| 31 |
(throw_ref) |
| 32 |
) |
| 33 |
|
| 34 |
(func (export "catchall-throw_ref-1") (param i32) (result i32) |
| 35 |
(block $h (result exnref) |
| 36 |
(try_table (result i32) (catch_all_ref $h) (throw $e0)) |
| 37 |
(return) |
| 38 |
) |
| 39 |
(if (param exnref) (i32.eqz (local.get 0)) |
| 40 |
(then (throw_ref)) |
| 41 |
(else (drop)) |
| 42 |
) |
| 43 |
(i32.const 23) |
| 44 |
) |
| 45 |
|
| 46 |
(func (export "throw_ref-nested") (param i32) (result i32) |
| 47 |
(local $exn1 exnref) |
| 48 |
(local $exn2 exnref) |
| 49 |
(block $h1 (result exnref) |
| 50 |
(try_table (result i32) (catch_ref $e1 $h1) (throw $e1)) |
| 51 |
(return) |
| 52 |
) |
| 53 |
(local.set $exn1) |
| 54 |
(block $h2 (result exnref) |
| 55 |
(try_table (result i32) (catch_ref $e0 $h2) (throw $e0)) |
| 56 |
(return) |
| 57 |
) |
| 58 |
(local.set $exn2) |
| 59 |
(if (i32.eq (local.get 0) (i32.const 0)) |
| 60 |
(then (throw_ref (local.get $exn1))) |
| 61 |
) |
| 62 |
(if (i32.eq (local.get 0) (i32.const 1)) |
| 63 |
(then (throw_ref (local.get $exn2))) |
| 64 |
) |
| 65 |
(i32.const 23) |
| 66 |
) |
| 67 |
|
| 68 |
(func (export "throw_ref-recatch") (param i32) (result i32) |
| 69 |
(local $e exnref) |
| 70 |
(block $h1 (result exnref) |
| 71 |
(try_table (result i32) (catch_ref $e0 $h1) (throw $e0)) |
| 72 |
(return) |
| 73 |
) |
| 74 |
(local.set $e) |
| 75 |
(block $h2 (result exnref) |
| 76 |
(try_table (result i32) (catch_ref $e0 $h2) |
| 77 |
(if (i32.eqz (local.get 0)) |
| 78 |
(then (throw_ref (local.get $e))) |
| 79 |
) |
| 80 |
(i32.const 42) |
| 81 |
) |
| 82 |
(return) |
| 83 |
) |
| 84 |
(drop) (i32.const 23) |
| 85 |
) |
| 86 |
|
| 87 |
(func (export "throw_ref-stack-polymorphism") |
| 88 |
(local $e exnref) |
| 89 |
(block $h (result exnref) |
| 90 |
(try_table (result f64) (catch_ref $e0 $h) (throw $e0)) |
| 91 |
(unreachable) |
| 92 |
) |
| 93 |
(local.set $e) |
| 94 |
(i32.const 1) |
| 95 |
(throw_ref (local.get $e)) |
| 96 |
) |
| 97 |
) |
| 98 |
|
| 99 |
(assert_exception (invoke "catch-throw_ref-0")) |
| 100 |
|
| 101 |
(assert_exception (invoke "catch-throw_ref-1" (i32.const 0))) |
| 102 |
(assert_return (invoke "catch-throw_ref-1" (i32.const 1)) (i32.const 23)) |
| 103 |
|
| 104 |
(assert_exception (invoke "catchall-throw_ref-0")) |
| 105 |
|
| 106 |
(assert_exception (invoke "catchall-throw_ref-1" (i32.const 0))) |
| 107 |
(assert_return (invoke "catchall-throw_ref-1" (i32.const 1)) (i32.const 23)) |
| 108 |
(assert_exception (invoke "throw_ref-nested" (i32.const 0))) |
| 109 |
(assert_exception (invoke "throw_ref-nested" (i32.const 1))) |
| 110 |
(assert_return (invoke "throw_ref-nested" (i32.const 2)) (i32.const 23)) |
| 111 |
|
| 112 |
(assert_return (invoke "throw_ref-recatch" (i32.const 0)) (i32.const 23)) |
| 113 |
(assert_return (invoke "throw_ref-recatch" (i32.const 1)) (i32.const 42)) |
| 114 |
|
| 115 |
(assert_exception (invoke "throw_ref-stack-polymorphism")) |
| 116 |
|
| 117 |
(assert_invalid (module (func (throw_ref))) "type mismatch") |
| 118 |
(assert_invalid (module (func (block (throw_ref)))) "type mismatch") |