summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/spec/exception-handling/throw_ref.wast.js
blob: 50b7b49837e7e8babebb74784d5faa71a7c3a597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* Copyright 2021 Mozilla Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// ./test/core/throw_ref.wast

// ./test/core/throw_ref.wast:3
let $0 = instantiate(`(module
  (tag $$e0)
  (tag $$e1)

  (func (export "catch-throw_ref-0")
    (block $$h (result exnref)
      (try_table (catch_ref $$e0 $$h) (throw $$e0))
      (unreachable)
    )
    (throw_ref)
  )

  (func (export "catch-throw_ref-1") (param i32) (result i32)
    (block $$h (result exnref)
      (try_table (result i32) (catch_ref $$e0 $$h) (throw $$e0))
      (return)
    )
    (if (param exnref) (i32.eqz (local.get 0))
      (then (throw_ref))
      (else (drop))
    )
    (i32.const 23)
  )

  (func (export "catchall-throw_ref-0")
    (block $$h (result exnref)
      (try_table (result exnref) (catch_all_ref $$h) (throw $$e0))
    )
    (throw_ref)
  )

  (func (export "catchall-throw_ref-1") (param i32) (result i32)
    (block $$h (result exnref)
      (try_table (result i32) (catch_all_ref $$h) (throw $$e0))
      (return)
    )
    (if (param exnref) (i32.eqz (local.get 0))
      (then (throw_ref))
      (else (drop))
    )
    (i32.const 23)
  )

  (func (export "throw_ref-nested") (param i32) (result i32)
    (local $$exn1 exnref)
    (local $$exn2 exnref)
    (block $$h1 (result exnref)
      (try_table (result i32) (catch_ref $$e1 $$h1) (throw $$e1))
      (return)
    )
    (local.set $$exn1)
    (block $$h2 (result exnref)
      (try_table (result i32) (catch_ref $$e0 $$h2) (throw $$e0))
      (return)
    )
    (local.set $$exn2)
    (if (i32.eq (local.get 0) (i32.const 0))
      (then (throw_ref (local.get $$exn1)))
    )
    (if (i32.eq (local.get 0) (i32.const 1))
      (then (throw_ref (local.get $$exn2)))
    )
    (i32.const 23)
  )

  (func (export "throw_ref-recatch") (param i32) (result i32)
    (local $$e exnref)
    (block $$h1 (result exnref)
      (try_table (result i32) (catch_ref $$e0 $$h1) (throw $$e0))
      (return)
    )
    (local.set $$e)
    (block $$h2 (result exnref)
      (try_table (result i32) (catch_ref $$e0 $$h2)
        (if (i32.eqz (local.get 0))
          (then (throw_ref (local.get $$e)))
        )
        (i32.const 42)
      )
      (return)
    )
    (drop) (i32.const 23)
  )

  (func (export "throw_ref-stack-polymorphism")
    (local $$e exnref)
    (block $$h (result exnref)
      (try_table (result f64) (catch_ref $$e0 $$h) (throw $$e0))
      (unreachable)
    )
    (local.set $$e)
    (i32.const 1)
    (throw_ref (local.get $$e))
  )
)`);

// ./test/core/throw_ref.wast:99
assert_exception(() => invoke($0, `catch-throw_ref-0`, []));

// ./test/core/throw_ref.wast:101
assert_exception(() => invoke($0, `catch-throw_ref-1`, [0]));

// ./test/core/throw_ref.wast:102
assert_return(() => invoke($0, `catch-throw_ref-1`, [1]), [value("i32", 23)]);

// ./test/core/throw_ref.wast:104
assert_exception(() => invoke($0, `catchall-throw_ref-0`, []));

// ./test/core/throw_ref.wast:106
assert_exception(() => invoke($0, `catchall-throw_ref-1`, [0]));

// ./test/core/throw_ref.wast:107
assert_return(() => invoke($0, `catchall-throw_ref-1`, [1]), [value("i32", 23)]);

// ./test/core/throw_ref.wast:108
assert_exception(() => invoke($0, `throw_ref-nested`, [0]));

// ./test/core/throw_ref.wast:109
assert_exception(() => invoke($0, `throw_ref-nested`, [1]));

// ./test/core/throw_ref.wast:110
assert_return(() => invoke($0, `throw_ref-nested`, [2]), [value("i32", 23)]);

// ./test/core/throw_ref.wast:112
assert_return(() => invoke($0, `throw_ref-recatch`, [0]), [value("i32", 23)]);

// ./test/core/throw_ref.wast:113
assert_return(() => invoke($0, `throw_ref-recatch`, [1]), [value("i32", 42)]);

// ./test/core/throw_ref.wast:115
assert_exception(() => invoke($0, `throw_ref-stack-polymorphism`, []));

// ./test/core/throw_ref.wast:117
assert_invalid(() => instantiate(`(module (func (throw_ref)))`), `type mismatch`);

// ./test/core/throw_ref.wast:118
assert_invalid(() => instantiate(`(module (func (block (throw_ref))))`), `type mismatch`);