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 // clang-format off | 5 // clang-format off |
6 // Flags: --expose-wasm | 6 // Flags: --expose-wasm |
7 | 7 |
8 load("test/mjsunit/wasm/wasm-constants.js"); | 8 load("test/mjsunit/wasm/wasm-constants.js"); |
9 load("test/mjsunit/wasm/wasm-module-builder.js"); | 9 load("test/mjsunit/wasm/wasm-module-builder.js"); |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 | 36 |
37 var stack; | 37 var stack; |
38 function STACK() { | 38 function STACK() { |
39 var e = new Error(); | 39 var e = new Error(); |
40 stack = e.stack; | 40 stack = e.stack; |
41 } | 41 } |
42 | 42 |
43 var builder = new WasmModuleBuilder(); | 43 var builder = new WasmModuleBuilder(); |
44 | 44 |
| 45 builder.addMemory(0, 1, false); |
| 46 |
45 builder.addImport("mod", "func", kSig_v_v); | 47 builder.addImport("mod", "func", kSig_v_v); |
46 | 48 |
47 builder.addFunction("main", kSig_v_v) | 49 builder.addFunction("main", kSig_v_v) |
48 .addBody([kExprCallFunction, 0]) | 50 .addBody([kExprCallFunction, 0]) |
49 .exportAs("main"); | 51 .exportAs("main"); |
50 | 52 |
51 builder.addFunction("exec_unreachable", kSig_v_v) | 53 builder.addFunction("exec_unreachable", kSig_v_v) |
52 .addBody([kExprUnreachable]) | 54 .addBody([kExprUnreachable]) |
53 .exportAs("exec_unreachable"); | 55 .exportAs("exec_unreachable"); |
54 | 56 |
55 // Make this function unnamed, just to test also this case. | 57 // Make this function unnamed, just to test also this case. |
56 var mem_oob_func = builder.addFunction(undefined, kSig_i_v) | 58 var mem_oob_func = builder.addFunction(undefined, kSig_i_v) |
57 // Access the memory at offset -1, to provoke a trap. | 59 // Access the memory at offset -1, to provoke a trap. |
58 .addBody([kExprI32Const, 0x7f, kExprI32LoadMem8S, 0, 0]) | 60 .addBody([kExprI32Const, 0x7f, kExprI32LoadMem8S, 0, 0]) |
59 .exportAs("mem_out_of_bounds"); | 61 .exportAs("mem_out_of_bounds"); |
60 | 62 |
61 // Call the mem_out_of_bounds function, in order to have two WASM stack frames. | 63 // Call the mem_out_of_bounds function, in order to have two WASM stack frames. |
62 builder.addFunction("call_mem_out_of_bounds", kSig_i_v) | 64 builder.addFunction("call_mem_out_of_bounds", kSig_i_v) |
63 .addBody([kExprCallFunction, mem_oob_func.index]) | 65 .addBody([kExprCallFunction, mem_oob_func.index]) |
64 .exportAs("call_mem_out_of_bounds"); | 66 .exportAs("call_mem_out_of_bounds"); |
65 | 67 |
66 var module = builder.instantiate({mod: {func: STACK}}); | 68 var module = builder.instantiate({mod: {func: STACK}}); |
67 | 69 |
68 (function testSimpleStack() { | 70 (function testSimpleStack() { |
69 var expected_string = "Error\n" + | 71 var expected_string = "Error\n" + |
70 // The line numbers below will change as this test gains / loses lines.. | 72 // The line numbers below will change as this test gains / loses lines.. |
71 " at STACK (stack.js:39:11)\n" + // -- | 73 " at STACK (stack.js:39:11)\n" + // -- |
72 " at main (<WASM>[1]+1)\n" + // -- | 74 " at main (<WASM>[1]+1)\n" + // -- |
73 " at testSimpleStack (stack.js:76:18)\n" + // -- | 75 " at testSimpleStack (stack.js:78:18)\n" + // -- |
74 " at stack.js:78:3"; // -- | 76 " at stack.js:80:3"; // -- |
75 | 77 |
76 module.exports.main(); | 78 module.exports.main(); |
77 assertEquals(expected_string, stripPath(stack)); | 79 assertEquals(expected_string, stripPath(stack)); |
78 })(); | 80 })(); |
79 | 81 |
80 // For the remaining tests, collect the Callsite objects instead of just a | 82 // For the remaining tests, collect the Callsite objects instead of just a |
81 // string: | 83 // string: |
82 Error.prepareStackTrace = function(error, frames) { | 84 Error.prepareStackTrace = function(error, frames) { |
83 return frames; | 85 return frames; |
84 }; | 86 }; |
85 | 87 |
86 (function testStackFrames() { | 88 (function testStackFrames() { |
87 module.exports.main(); | 89 module.exports.main(); |
88 | 90 |
89 verifyStack(stack, [ | 91 verifyStack(stack, [ |
90 // isWasm function line pos file | 92 // isWasm function line pos file |
91 [ false, "STACK", 39, 0, "stack.js"], | 93 [ false, "STACK", 39, 0, "stack.js"], |
92 [ true, "main", 1, 1, null], | 94 [ true, "main", 1, 1, null], |
93 [ false, "testStackFrames", 87, 0, "stack.js"], | 95 [ false, "testStackFrames", 89, 0, "stack.js"], |
94 [ false, null, 96, 0, "stack.js"] | 96 [ false, null, 98, 0, "stack.js"] |
95 ]); | 97 ]); |
96 })(); | 98 })(); |
97 | 99 |
98 (function testWasmUnreachable() { | 100 (function testWasmUnreachable() { |
99 try { | 101 try { |
100 module.exports.exec_unreachable(); | 102 module.exports.exec_unreachable(); |
101 fail("expected wasm exception"); | 103 fail("expected wasm exception"); |
102 } catch (e) { | 104 } catch (e) { |
103 assertContains("unreachable", e.message); | 105 assertContains("unreachable", e.message); |
104 verifyStack(e.stack, [ | 106 verifyStack(e.stack, [ |
105 // isWasm function line pos file | 107 // isWasm function line pos file |
106 [ true, "exec_unreachable", 2, 1, null], | 108 [ true, "exec_unreachable", 2, 1, null], |
107 [ false, "testWasmUnreachable", 100, 0, "stack.js"], | 109 [ false, "testWasmUnreachable", 102, 0, "stack.js"], |
108 [ false, null, 111, 0, "stack.js"] | 110 [ false, null, 113, 0, "stack.js"] |
109 ]); | 111 ]); |
110 } | 112 } |
111 })(); | 113 })(); |
112 | 114 |
113 (function testWasmMemOutOfBounds() { | 115 (function testWasmMemOutOfBounds() { |
114 try { | 116 try { |
115 module.exports.call_mem_out_of_bounds(); | 117 module.exports.call_mem_out_of_bounds(); |
116 fail("expected wasm exception"); | 118 fail("expected wasm exception"); |
117 } catch (e) { | 119 } catch (e) { |
118 assertContains("out of bounds", e.message); | 120 assertContains("out of bounds", e.message); |
119 verifyStack(e.stack, [ | 121 verifyStack(e.stack, [ |
120 // isWasm function line pos file | 122 // isWasm function line pos file |
121 [ true, "", 3, 3, null], | 123 [ true, "", 3, 3, null], |
122 [ true, "call_mem_out_of_bounds", 4, 1, null], | 124 [ true, "call_mem_out_of_bounds", 4, 1, null], |
123 [ false, "testWasmMemOutOfBounds", 115, 0, "stack.js"], | 125 [ false, "testWasmMemOutOfBounds", 117, 0, "stack.js"], |
124 [ false, null, 127, 0, "stack.js"] | 126 [ false, null, 129, 0, "stack.js"] |
125 ]); | 127 ]); |
126 } | 128 } |
127 })(); | 129 })(); |
128 | 130 |
129 | 131 |
130 (function testStackOverflow() { | 132 (function testStackOverflow() { |
131 print("testStackOverflow"); | 133 print("testStackOverflow"); |
132 var builder = new WasmModuleBuilder(); | 134 var builder = new WasmModuleBuilder(); |
133 | 135 |
134 var sig_index = builder.addType(kSig_v_v); | 136 var sig_index = builder.addType(kSig_v_v); |
(...skipping 13 matching lines...) Expand all Loading... |
148 assertTrue(e.stack.length >= 4, "expected at least 4 stack entries"); | 150 assertTrue(e.stack.length >= 4, "expected at least 4 stack entries"); |
149 verifyStack(e.stack.splice(0, 4), [ | 151 verifyStack(e.stack.splice(0, 4), [ |
150 // isWasm function line pos file | 152 // isWasm function line pos file |
151 [ true, "recursion", 0, 0, null], | 153 [ true, "recursion", 0, 0, null], |
152 [ true, "recursion", 0, 3, null], | 154 [ true, "recursion", 0, 3, null], |
153 [ true, "recursion", 0, 3, null], | 155 [ true, "recursion", 0, 3, null], |
154 [ true, "recursion", 0, 3, null] | 156 [ true, "recursion", 0, 3, null] |
155 ]); | 157 ]); |
156 } | 158 } |
157 })(); | 159 })(); |
OLD | NEW |