OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm --wasm-eh-prototype | 5 // Flags: --expose-wasm --wasm-eh-prototype |
6 | 6 |
7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
9 | 9 |
10 // The following methods do not attempt to catch the exception they raise. | 10 // The following methods do not attempt to catch the exception they raise. |
11 var test_throw = (function () { | 11 var test_throw = (function () { |
12 var builder = new WasmModuleBuilder(); | 12 var builder = new WasmModuleBuilder(); |
13 | 13 |
14 builder.addFunction("throw_param_if_not_zero", kSig_i_i) | 14 builder.addFunction("throw_param_if_not_zero", kSig_i_i) |
15 .addBody([ | 15 .addBody([ |
16 kExprGetLocal, 0, | 16 kExprGetLocal, 0, |
17 kExprI32Const, 0, | 17 kExprI32Const, 0, |
18 kExprI32Ne, | 18 kExprI32Ne, |
19 kExprIf, kAstStmt, | 19 kExprIf, kWasmStmt, |
20 kExprGetLocal, 0, | 20 kExprGetLocal, 0, |
21 kExprThrow, | 21 kExprThrow, |
22 kExprEnd, | 22 kExprEnd, |
23 kExprI32Const, 1 | 23 kExprI32Const, 1 |
24 ]) | 24 ]) |
25 .exportFunc() | 25 .exportFunc() |
26 | 26 |
27 builder.addFunction("throw_20", kSig_v_v) | 27 builder.addFunction("throw_20", kSig_v_v) |
28 .addBody([ | 28 .addBody([ |
29 kExprI32Const, 20, | 29 kExprI32Const, 20, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 .addBody([ | 112 .addBody([ |
113 kExprGetLocal, 0, | 113 kExprGetLocal, 0, |
114 kExprThrow | 114 kExprThrow |
115 ]) | 115 ]) |
116 .index; | 116 .index; |
117 | 117 |
118 // Scenario 1: Throw and catch appear on the same function. This should | 118 // Scenario 1: Throw and catch appear on the same function. This should |
119 // happen in case of inlining, for example. | 119 // happen in case of inlining, for example. |
120 builder.addFunction("same_scope", kSig_i_i) | 120 builder.addFunction("same_scope", kSig_i_i) |
121 .addBody([ | 121 .addBody([ |
122 kExprTry, kAstI32, | 122 kExprTry, kWasmI32, |
123 kExprGetLocal, 0, | 123 kExprGetLocal, 0, |
124 kExprI32Const, 0, | 124 kExprI32Const, 0, |
125 kExprI32Ne, | 125 kExprI32Ne, |
126 kExprIf, kAstStmt, | 126 kExprIf, kWasmStmt, |
127 kExprGetLocal, 0, | 127 kExprGetLocal, 0, |
128 kExprThrow, | 128 kExprThrow, |
129 kExprUnreachable, | 129 kExprUnreachable, |
130 kExprEnd, | 130 kExprEnd, |
131 kExprI32Const, 63, | 131 kExprI32Const, 63, |
132 kExprCatch, 1, | 132 kExprCatch, 1, |
133 kExprGetLocal, 1, | 133 kExprGetLocal, 1, |
134 kExprEnd | 134 kExprEnd |
135 ]) | 135 ]) |
136 .addLocals({i32_count: 1}) | 136 .addLocals({i32_count: 1}) |
137 .exportFunc() | 137 .exportFunc() |
138 .index; | 138 .index; |
139 | 139 |
140 builder.addFunction("same_scope_ignore", kSig_i_i) | 140 builder.addFunction("same_scope_ignore", kSig_i_i) |
141 .addBody([ | 141 .addBody([ |
142 kExprTry, kAstI32, | 142 kExprTry, kWasmI32, |
143 kExprGetLocal, 0, | 143 kExprGetLocal, 0, |
144 kExprThrow, | 144 kExprThrow, |
145 kExprUnreachable, | 145 kExprUnreachable, |
146 kExprCatch, 1, | 146 kExprCatch, 1, |
147 kExprGetLocal, 0, | 147 kExprGetLocal, 0, |
148 kExprEnd, | 148 kExprEnd, |
149 ]) | 149 ]) |
150 .addLocals({i32_count: 1}) | 150 .addLocals({i32_count: 1}) |
151 .exportFunc(); | 151 .exportFunc(); |
152 | 152 |
(...skipping 24 matching lines...) Expand all Loading... |
177 // path |= v | 256; | 177 // path |= v | 256; |
178 // } | 178 // } |
179 // | 179 // |
180 // return path; | 180 // return path; |
181 // | 181 // |
182 // p == 1 -> path == 293 | 182 // p == 1 -> path == 293 |
183 // p == 2 -> path == 298 | 183 // p == 2 -> path == 298 |
184 // p == 3 -> path == 338 | 184 // p == 3 -> path == 338 |
185 // else -> path == 146 | 185 // else -> path == 146 |
186 .addBody([ | 186 .addBody([ |
187 kExprTry, kAstI32, | 187 kExprTry, kWasmI32, |
188 kExprTry, kAstI32, | 188 kExprTry, kWasmI32, |
189 kExprTry, kAstI32, | 189 kExprTry, kWasmI32, |
190 kExprGetLocal, 0, | 190 kExprGetLocal, 0, |
191 kExprI32Const, 1, | 191 kExprI32Const, 1, |
192 kExprI32Eq, | 192 kExprI32Eq, |
193 kExprIf, kAstStmt, | 193 kExprIf, kWasmStmt, |
194 kExprI32Const, 1, | 194 kExprI32Const, 1, |
195 kExprThrow, | 195 kExprThrow, |
196 kExprUnreachable, | 196 kExprUnreachable, |
197 kExprEnd, | 197 kExprEnd, |
198 kExprI32Const, 2, | 198 kExprI32Const, 2, |
199 kExprCatch, 1, | 199 kExprCatch, 1, |
200 kExprGetLocal, 1, | 200 kExprGetLocal, 1, |
201 kExprI32Const, 4, | 201 kExprI32Const, 4, |
202 kExprI32Ior, | 202 kExprI32Ior, |
203 kExprThrow, | 203 kExprThrow, |
204 kExprUnreachable, | 204 kExprUnreachable, |
205 kExprEnd, | 205 kExprEnd, |
206 kExprTeeLocal, 2, | 206 kExprTeeLocal, 2, |
207 kExprGetLocal, 0, | 207 kExprGetLocal, 0, |
208 kExprI32Const, 2, | 208 kExprI32Const, 2, |
209 kExprI32Eq, | 209 kExprI32Eq, |
210 kExprIf, kAstStmt, | 210 kExprIf, kWasmStmt, |
211 kExprGetLocal, 2, | 211 kExprGetLocal, 2, |
212 kExprI32Const, 8, | 212 kExprI32Const, 8, |
213 kExprI32Ior, | 213 kExprI32Ior, |
214 kExprThrow, | 214 kExprThrow, |
215 kExprUnreachable, | 215 kExprUnreachable, |
216 kExprEnd, | 216 kExprEnd, |
217 kExprI32Const, 16, | 217 kExprI32Const, 16, |
218 kExprI32Ior, | 218 kExprI32Ior, |
219 kExprCatch, 1, | 219 kExprCatch, 1, |
220 kExprGetLocal, 1, | 220 kExprGetLocal, 1, |
221 kExprI32Const, 32, | 221 kExprI32Const, 32, |
222 kExprI32Ior, | 222 kExprI32Ior, |
223 kExprThrow, | 223 kExprThrow, |
224 kExprUnreachable, | 224 kExprUnreachable, |
225 kExprEnd, | 225 kExprEnd, |
226 kExprTeeLocal, 2, | 226 kExprTeeLocal, 2, |
227 kExprGetLocal, 0, | 227 kExprGetLocal, 0, |
228 kExprI32Const, 3, | 228 kExprI32Const, 3, |
229 kExprI32Eq, | 229 kExprI32Eq, |
230 kExprIf, kAstStmt, | 230 kExprIf, kWasmStmt, |
231 kExprGetLocal, 2, | 231 kExprGetLocal, 2, |
232 kExprI32Const, /*64=*/ 192, 0, | 232 kExprI32Const, /*64=*/ 192, 0, |
233 kExprI32Ior, | 233 kExprI32Ior, |
234 kExprThrow, | 234 kExprThrow, |
235 kExprUnreachable, | 235 kExprUnreachable, |
236 kExprEnd, | 236 kExprEnd, |
237 kExprI32Const, /*128=*/ 128, 1, | 237 kExprI32Const, /*128=*/ 128, 1, |
238 kExprI32Ior, | 238 kExprI32Ior, |
239 kExprCatch, 1, | 239 kExprCatch, 1, |
240 kExprGetLocal, 1, | 240 kExprGetLocal, 1, |
241 kExprI32Const, /*256=*/ 128, 2, | 241 kExprI32Const, /*256=*/ 128, 2, |
242 kExprI32Ior, | 242 kExprI32Ior, |
243 kExprEnd, | 243 kExprEnd, |
244 ]) | 244 ]) |
245 .addLocals({i32_count: 2}) | 245 .addLocals({i32_count: 2}) |
246 .exportFunc(); | 246 .exportFunc(); |
247 | 247 |
248 // Scenario 2: Catches an exception raised from the direct callee. | 248 // Scenario 2: Catches an exception raised from the direct callee. |
249 var kFromDirectCallee = | 249 var kFromDirectCallee = |
250 builder.addFunction("from_direct_callee", kSig_i_i) | 250 builder.addFunction("from_direct_callee", kSig_i_i) |
251 .addBody([ | 251 .addBody([ |
252 kExprTry, kAstI32, | 252 kExprTry, kWasmI32, |
253 kExprGetLocal, 0, | 253 kExprGetLocal, 0, |
254 kExprCallFunction, kWasmThrowFunction, | 254 kExprCallFunction, kWasmThrowFunction, |
255 kExprI32Const, /*-1=*/ 127, | 255 kExprI32Const, /*-1=*/ 127, |
256 kExprCatch, 1, | 256 kExprCatch, 1, |
257 kExprGetLocal, 1, | 257 kExprGetLocal, 1, |
258 kExprEnd | 258 kExprEnd |
259 ]) | 259 ]) |
260 .addLocals({i32_count: 1}) | 260 .addLocals({i32_count: 1}) |
261 .exportFunc() | 261 .exportFunc() |
262 .index; | 262 .index; |
263 | 263 |
264 // Scenario 3: Catches an exception raised from an indirect callee. | 264 // Scenario 3: Catches an exception raised from an indirect callee. |
265 var kFromIndirectCalleeHelper = kFromDirectCallee + 1; | 265 var kFromIndirectCalleeHelper = kFromDirectCallee + 1; |
266 builder.addFunction("from_indirect_callee_helper", kSig_v_ii) | 266 builder.addFunction("from_indirect_callee_helper", kSig_v_ii) |
267 .addBody([ | 267 .addBody([ |
268 kExprGetLocal, 0, | 268 kExprGetLocal, 0, |
269 kExprI32Const, 0, | 269 kExprI32Const, 0, |
270 kExprI32GtS, | 270 kExprI32GtS, |
271 kExprIf, kAstStmt, | 271 kExprIf, kWasmStmt, |
272 kExprGetLocal, 0, | 272 kExprGetLocal, 0, |
273 kExprI32Const, 1, | 273 kExprI32Const, 1, |
274 kExprI32Sub, | 274 kExprI32Sub, |
275 kExprGetLocal, 1, | 275 kExprGetLocal, 1, |
276 kExprI32Const, 1, | 276 kExprI32Const, 1, |
277 kExprI32Sub, | 277 kExprI32Sub, |
278 kExprCallFunction, kFromIndirectCalleeHelper, | 278 kExprCallFunction, kFromIndirectCalleeHelper, |
279 kExprEnd, | 279 kExprEnd, |
280 kExprGetLocal, 1, | 280 kExprGetLocal, 1, |
281 kExprCallFunction, kWasmThrowFunction, | 281 kExprCallFunction, kWasmThrowFunction, |
282 ]); | 282 ]); |
283 | 283 |
284 builder.addFunction("from_indirect_callee", kSig_i_i) | 284 builder.addFunction("from_indirect_callee", kSig_i_i) |
285 .addBody([ | 285 .addBody([ |
286 kExprTry, kAstI32, | 286 kExprTry, kWasmI32, |
287 kExprGetLocal, 0, | 287 kExprGetLocal, 0, |
288 kExprI32Const, 0, | 288 kExprI32Const, 0, |
289 kExprCallFunction, kFromIndirectCalleeHelper, | 289 kExprCallFunction, kFromIndirectCalleeHelper, |
290 kExprI32Const, /*-1=*/ 127, | 290 kExprI32Const, /*-1=*/ 127, |
291 kExprCatch, 1, | 291 kExprCatch, 1, |
292 kExprGetLocal, 1, | 292 kExprGetLocal, 1, |
293 kExprEnd | 293 kExprEnd |
294 ]) | 294 ]) |
295 .addLocals({i32_count: 1}) | 295 .addLocals({i32_count: 1}) |
296 .exportFunc(); | 296 .exportFunc(); |
297 | 297 |
298 // Scenario 4: Catches an exception raised in JS. | 298 // Scenario 4: Catches an exception raised in JS. |
299 builder.addFunction("from_js", kSig_i_i) | 299 builder.addFunction("from_js", kSig_i_i) |
300 .addBody([ | 300 .addBody([ |
301 kExprTry, kAstI32, | 301 kExprTry, kWasmI32, |
302 kExprGetLocal, 0, | 302 kExprGetLocal, 0, |
303 kExprCallFunction, kJSThrowI, | 303 kExprCallFunction, kJSThrowI, |
304 kExprI32Const, /*-1=*/ 127, | 304 kExprI32Const, /*-1=*/ 127, |
305 kExprCatch, 1, | 305 kExprCatch, 1, |
306 kExprGetLocal, 1, | 306 kExprGetLocal, 1, |
307 kExprEnd, | 307 kExprEnd, |
308 ]) | 308 ]) |
309 .addLocals({i32_count: 1}) | 309 .addLocals({i32_count: 1}) |
310 .exportFunc(); | 310 .exportFunc(); |
311 | 311 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 assertEquals(-1, test_catch.exports.from_direct_callee(0xFFFFFFFF)); | 374 assertEquals(-1, test_catch.exports.from_direct_callee(0xFFFFFFFF)); |
375 assertEquals(0x7FFFFFFF, test_catch.exports.from_direct_callee(0x7FFFFFFF)); | 375 assertEquals(0x7FFFFFFF, test_catch.exports.from_direct_callee(0x7FFFFFFF)); |
376 assertEquals(-10, test_catch.exports.from_indirect_callee(10)); | 376 assertEquals(-10, test_catch.exports.from_indirect_callee(10)); |
377 assertEquals(-77, test_catch.exports.from_indirect_callee(77)); | 377 assertEquals(-77, test_catch.exports.from_indirect_callee(77)); |
378 assertEquals(10, test_catch.exports.from_js(10)); | 378 assertEquals(10, test_catch.exports.from_js(10)); |
379 assertEquals(-10, test_catch.exports.from_js(-10)); | 379 assertEquals(-10, test_catch.exports.from_js(-10)); |
380 | 380 |
381 assertThrowsEquals(test_catch.exports.string_from_js, "use wasm;"); | 381 assertThrowsEquals(test_catch.exports.string_from_js, "use wasm;"); |
382 assertThrowsEquals(test_catch.exports.large_from_js, 1e+28); | 382 assertThrowsEquals(test_catch.exports.large_from_js, 1e+28); |
383 assertThrowsEquals(test_catch.exports.undefined_from_js, undefined); | 383 assertThrowsEquals(test_catch.exports.undefined_from_js, undefined); |
OLD | NEW |