OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 | 5 // Flags: --expose-wasm |
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 // Collect the Callsite objects instead of just a string: | 10 // Collect the Callsite objects instead of just a string: |
(...skipping 12 matching lines...) Expand all Loading... |
23 // unreachable; | 23 // unreachable; |
24 // } else { | 24 // } else { |
25 // return call_indirect(idx); | 25 // return call_indirect(idx); |
26 // } | 26 // } |
27 // There are four different traps which are triggered by different input values: | 27 // There are four different traps which are triggered by different input values: |
28 // (0) division by zero; (1) mem oob; (2) unreachable; (3) invalid call target | 28 // (0) division by zero; (1) mem oob; (2) unreachable; (3) invalid call target |
29 // Each of them also has a different location where it traps. | 29 // Each of them also has a different location where it traps. |
30 builder.addFunction("main", kSig_i_i) | 30 builder.addFunction("main", kSig_i_i) |
31 .addBody([ | 31 .addBody([ |
32 // offset 1 | 32 // offset 1 |
33 kExprBlock, kAstI32, | 33 kExprBlock, kWasmI32, |
34 kExprGetLocal, 0, | 34 kExprGetLocal, 0, |
35 kExprI32Const, 2, | 35 kExprI32Const, 2, |
36 kExprI32LtU, | 36 kExprI32LtU, |
37 kExprIf, kAstStmt, | 37 kExprIf, kWasmStmt, |
38 // offset 9 | 38 // offset 9 |
39 kExprI32Const, 0x7e /* -2 */, | 39 kExprI32Const, 0x7e /* -2 */, |
40 kExprGetLocal, 0, | 40 kExprGetLocal, 0, |
41 kExprI32DivU, | 41 kExprI32DivU, |
42 // offset 15 | 42 // offset 15 |
43 kExprI32LoadMem, 0, 0, | 43 kExprI32LoadMem, 0, 0, |
44 kExprBr, 1, | 44 kExprBr, 1, |
45 kExprEnd, | 45 kExprEnd, |
46 // offset 21 | 46 // offset 21 |
47 kExprGetLocal, 0, | 47 kExprGetLocal, 0, |
48 kExprI32Const, 2, | 48 kExprI32Const, 2, |
49 kExprI32Eq, | 49 kExprI32Eq, |
50 kExprIf, kAstStmt, | 50 kExprIf, kWasmStmt, |
51 kExprUnreachable, | 51 kExprUnreachable, |
52 kExprEnd, | 52 kExprEnd, |
53 // offset 30 | 53 // offset 30 |
54 kExprGetLocal, 0, | 54 kExprGetLocal, 0, |
55 kExprCallIndirect, sig_index, kTableZero, | 55 kExprCallIndirect, sig_index, kTableZero, |
56 kExprEnd, | 56 kExprEnd, |
57 ]) | 57 ]) |
58 .exportAs("main"); | 58 .exportAs("main"); |
59 builder.appendToTable([0]); | 59 builder.appendToTable([0]); |
60 | 60 |
61 var module = builder.instantiate(); | 61 var module = builder.instantiate(); |
62 | 62 |
63 function testWasmTrap(value, reason, position) { | 63 function testWasmTrap(value, reason, position) { |
64 try { | 64 try { |
65 module.exports.main(value); | 65 module.exports.main(value); |
66 fail("expected wasm exception"); | 66 fail("expected wasm exception"); |
67 } catch (e) { | 67 } catch (e) { |
68 assertEquals(kTrapMsgs[reason], e.message, "trap reason"); | 68 assertEquals(kTrapMsgs[reason], e.message, "trap reason"); |
69 assertEquals(3, e.stack.length, "number of frames"); | 69 assertEquals(3, e.stack.length, "number of frames"); |
70 assertEquals(0, e.stack[0].getLineNumber(), "wasmFunctionIndex"); | 70 assertEquals(0, e.stack[0].getLineNumber(), "wasmFunctionIndex"); |
71 assertEquals(position, e.stack[0].getPosition(), "position"); | 71 assertEquals(position, e.stack[0].getPosition(), "position"); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 // The actual tests: | 75 // The actual tests: |
76 testWasmTrap(0, kTrapDivByZero, 14); | 76 testWasmTrap(0, kTrapDivByZero, 14); |
77 testWasmTrap(1, kTrapMemOutOfBounds, 15); | 77 testWasmTrap(1, kTrapMemOutOfBounds, 15); |
78 testWasmTrap(2, kTrapUnreachable, 28); | 78 testWasmTrap(2, kTrapUnreachable, 28); |
79 testWasmTrap(3, kTrapFuncInvalid, 32); | 79 testWasmTrap(3, kTrapFuncInvalid, 32); |
OLD | NEW |