summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/spec/exception-handling/try_delegate.wast.js
blob: 83400f02f5cc5c579e6799d172d0133e0ab41cb1 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* 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/try_delegate.wast

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

  (func (export "delegate-no-throw") (result i32)
    (try $$t (result i32)
      (do (try (result i32) (do (i32.const 1)) (delegate $$t)))
      (catch $$e0 (i32.const 2))
    )
  )

  (func $$throw-if (param i32)
    (local.get 0)
    (if (then (throw $$e0)) (else))
  )

  (func (export "delegate-throw") (param i32) (result i32)
    (try $$t (result i32)
      (do
        (try (result i32)
          (do (local.get 0) (call $$throw-if) (i32.const 1))
          (delegate $$t)
        )
      )
      (catch $$e0 (i32.const 2))
    )
  )

  (func (export "delegate-skip") (result i32)
    (try $$t (result i32)
      (do
        (try (result i32)
          (do
            (try (result i32)
              (do (throw $$e0) (i32.const 1))
              (delegate $$t)
            )
          )
          (catch $$e0 (i32.const 2))
        )
      )
      (catch $$e0 (i32.const 3))
    )
  )

  (func (export "delegate-to-block") (result i32)
    (try (result i32)
      (do (block (try (do (throw $$e0)) (delegate 0)))
          (i32.const 0))
      (catch_all (i32.const 1)))
  )

  (func (export "delegate-to-catch") (result i32)
    (try (result i32)
      (do (try
            (do (throw $$e0))
            (catch $$e0
              (try (do (rethrow 1)) (delegate 0))))
          (i32.const 0))
      (catch_all (i32.const 1)))
  )

  (func (export "delegate-to-caller")
    (try (do (try (do (throw $$e0)) (delegate 1))) (catch_all))
  )

  (func $$select-tag (param i32)
    (block (block (block (local.get 0) (br_table 0 1 2)) (return)) (throw $$e0))
    (throw $$e1)
  )

  (func (export "delegate-merge") (param i32 i32) (result i32)
    (try $$t (result i32)
      (do
        (local.get 0)
        (call $$select-tag)
        (try
          (result i32)
          (do (local.get 1) (call $$select-tag) (i32.const 1))
          (delegate $$t)
        )
      )
      (catch $$e0 (i32.const 2))
    )
  )

  (func (export "delegate-throw-no-catch") (result i32)
    (try (result i32)
      (do (try (result i32) (do (throw $$e0) (i32.const 1)) (delegate 0)))
      (catch $$e1 (i32.const 2))
    )
  )
)`);

// ./test/core/try_delegate.wast:97
assert_return(() => invoke($0, `delegate-no-throw`, []), [value("i32", 1)]);

// ./test/core/try_delegate.wast:99
assert_return(() => invoke($0, `delegate-throw`, [0]), [value("i32", 1)]);

// ./test/core/try_delegate.wast:100
assert_return(() => invoke($0, `delegate-throw`, [1]), [value("i32", 2)]);

// ./test/core/try_delegate.wast:102
assert_exception(() => invoke($0, `delegate-throw-no-catch`, []));

// ./test/core/try_delegate.wast:104
assert_return(() => invoke($0, `delegate-merge`, [1, 0]), [value("i32", 2)]);

// ./test/core/try_delegate.wast:105
assert_exception(() => invoke($0, `delegate-merge`, [2, 0]));

// ./test/core/try_delegate.wast:106
assert_return(() => invoke($0, `delegate-merge`, [0, 1]), [value("i32", 2)]);

// ./test/core/try_delegate.wast:107
assert_exception(() => invoke($0, `delegate-merge`, [0, 2]));

// ./test/core/try_delegate.wast:108
assert_return(() => invoke($0, `delegate-merge`, [0, 0]), [value("i32", 1)]);

// ./test/core/try_delegate.wast:110
assert_return(() => invoke($0, `delegate-skip`, []), [value("i32", 3)]);

// ./test/core/try_delegate.wast:112
assert_return(() => invoke($0, `delegate-to-block`, []), [value("i32", 1)]);

// ./test/core/try_delegate.wast:113
assert_return(() => invoke($0, `delegate-to-catch`, []), [value("i32", 1)]);

// ./test/core/try_delegate.wast:115
assert_exception(() => invoke($0, `delegate-to-caller`, []));

// ./test/core/try_delegate.wast:117
assert_malformed(() => instantiate(`(module (func (delegate 0))) `), `unexpected token`);

// ./test/core/try_delegate.wast:122
assert_malformed(
  () => instantiate(`(module (tag $$e) (func (try (do) (catch $$e) (delegate 0)))) `),
  `unexpected token`,
);

// ./test/core/try_delegate.wast:127
assert_malformed(
  () => instantiate(`(module (func (try (do) (catch_all) (delegate 0)))) `),
  `unexpected token`,
);

// ./test/core/try_delegate.wast:132
assert_malformed(
  () => instantiate(`(module (func (try (do) (delegate) (delegate 0)))) `),
  `unexpected token`,
);

// ./test/core/try_delegate.wast:137
assert_invalid(
  () => instantiate(`(module (func (try (do) (delegate 1))))`),
  `unknown label`,
);