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. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Now that we know throwing works, we test catching the exceptions we raise. | 72 // Now that we know throwing works, we test catching the exceptions we raise. |
73 var test_catch = (function () { | 73 var test_catch = (function () { |
74 var builder = new WasmModuleBuilder(); | 74 var builder = new WasmModuleBuilder(); |
75 | 75 |
76 // Helper function for throwing from js. It is imported by the Wasm module | 76 // Helper function for throwing from js. It is imported by the Wasm module |
77 // as throw_i. | 77 // as throw_i. |
78 function throw_value(value) { | 78 function throw_value(value) { |
79 throw value; | 79 throw value; |
80 } | 80 } |
81 var sig_index = builder.addType(kSig_v_i); | 81 var sig_index = builder.addType(kSig_v_i); |
82 var kJSThrowI = builder.addImport("throw_i", sig_index); | 82 var kJSThrowI = builder.addImport("", "throw_i", sig_index); |
83 | 83 |
84 // Helper function that throws a string. Wasm should not catch it. | 84 // Helper function that throws a string. Wasm should not catch it. |
85 function throw_string() { | 85 function throw_string() { |
86 throw "use wasm;"; | 86 throw "use wasm;"; |
87 } | 87 } |
88 sig_index = builder.addType(kSig_v_v); | 88 sig_index = builder.addType(kSig_v_v); |
89 var kJSThrowString = builder.addImport("throw_string", sig_index); | 89 var kJSThrowString = builder.addImport("", "throw_string", sig_index); |
90 | 90 |
91 // Helper function that throws undefined. Wasm should not catch it. | 91 // Helper function that throws undefined. Wasm should not catch it. |
92 function throw_undefined() { | 92 function throw_undefined() { |
93 throw undefined; | 93 throw undefined; |
94 } | 94 } |
95 var kJSThrowUndefined = builder.addImport("throw_undefined", sig_index); | 95 var kJSThrowUndefined = builder.addImport("", "throw_undefined", sig_index); |
96 | 96 |
97 // Helper function that throws an fp. Wasm should not catch it. | 97 // Helper function that throws an fp. Wasm should not catch it. |
98 function throw_fp() { | 98 function throw_fp() { |
99 throw 10.5; | 99 throw 10.5; |
100 } | 100 } |
101 var kJSThrowFP = builder.addImport("throw_fp", sig_index); | 101 var kJSThrowFP = builder.addImport("", "throw_fp", sig_index); |
102 | 102 |
103 // Helper function that throws a large number. Wasm should not catch it. | 103 // Helper function that throws a large number. Wasm should not catch it. |
104 function throw_large() { | 104 function throw_large() { |
105 throw 1e+28; | 105 throw 1e+28; |
106 } | 106 } |
107 var kJSThrowLarge = builder.addImport("throw_large", sig_index); | 107 var kJSThrowLarge = builder.addImport("", "throw_large", sig_index); |
108 | 108 |
109 // Helper function for throwing from WebAssembly. | 109 // Helper function for throwing from WebAssembly. |
110 var kWasmThrowFunction = | 110 var kWasmThrowFunction = |
111 builder.addFunction("throw", kSig_v_i) | 111 builder.addFunction("throw", kSig_v_i) |
112 .addBody([ | 112 .addBody([ |
113 kExprGetLocal, 0, | 113 kExprGetLocal, 0, |
114 kExprThrow | 114 kExprThrow |
115 ]) | 115 ]) |
116 .index; | 116 .index; |
117 | 117 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 kExprCallFunction, kJSThrowLarge | 328 kExprCallFunction, kJSThrowLarge |
329 ]) | 329 ]) |
330 .exportFunc(); | 330 .exportFunc(); |
331 | 331 |
332 builder.addFunction("undefined_from_js", kSig_v_v) | 332 builder.addFunction("undefined_from_js", kSig_v_v) |
333 .addBody([ | 333 .addBody([ |
334 kExprCallFunction, kJSThrowUndefined | 334 kExprCallFunction, kJSThrowUndefined |
335 ]) | 335 ]) |
336 .exportFunc(); | 336 .exportFunc(); |
337 | 337 |
338 return builder.instantiate({ | 338 return builder.instantiate({"": { |
339 throw_i: throw_value, | 339 throw_i: throw_value, |
340 throw_string: throw_string, | 340 throw_string: throw_string, |
341 throw_fp: throw_fp, | 341 throw_fp: throw_fp, |
342 throw_large, throw_large, | 342 throw_large, throw_large, |
343 throw_undefined: throw_undefined | 343 throw_undefined: throw_undefined |
344 }); | 344 }}); |
345 })(); | 345 })(); |
346 | 346 |
347 // Check the test_catch exists. | 347 // Check the test_catch exists. |
348 assertFalse(test_catch === undefined); | 348 assertFalse(test_catch === undefined); |
349 assertFalse(test_catch === null); | 349 assertFalse(test_catch === null); |
350 assertFalse(test_catch === 0); | 350 assertFalse(test_catch === 0); |
351 assertEquals("object", typeof test_catch.exports); | 351 assertEquals("object", typeof test_catch.exports); |
352 assertEquals("function", typeof test_catch.exports.same_scope); | 352 assertEquals("function", typeof test_catch.exports.same_scope); |
353 assertEquals("function", typeof test_catch.exports.same_scope_ignore); | 353 assertEquals("function", typeof test_catch.exports.same_scope_ignore); |
354 assertEquals("function", typeof test_catch.exports.same_scope_multiple); | 354 assertEquals("function", typeof test_catch.exports.same_scope_multiple); |
(...skipping 19 matching lines...) Expand all 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 |