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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 | 30 |
31 var stack; | 31 var stack; |
32 function STACK() { | 32 function STACK() { |
33 var e = new Error(); | 33 var e = new Error(); |
34 stack = e.stack; | 34 stack = e.stack; |
35 } | 35 } |
36 | 36 |
37 var builder = new WasmModuleBuilder(); | 37 var builder = new WasmModuleBuilder(); |
38 | 38 |
39 builder.addImport("func", [kAstStmt]); | 39 builder.addImport("func", kSig_v_v); |
40 | 40 |
41 builder.addFunction("main", [kAstStmt]) | 41 builder.addFunction("main", kSig_v_v) |
42 .addBody([kExprCallImport, kArity0, 0]) | 42 .addBody([kExprCallImport, kArity0, 0]) |
43 .exportAs("main"); | 43 .exportAs("main"); |
44 | 44 |
45 builder.addFunction("exec_unreachable", [kAstStmt]) | 45 builder.addFunction("exec_unreachable", kSig_v_v) |
46 .addBody([kExprUnreachable]) | 46 .addBody([kExprUnreachable]) |
47 .exportAs("exec_unreachable"); | 47 .exportAs("exec_unreachable"); |
48 | 48 |
49 // make this function unnamed, just to test also this case | 49 // make this function unnamed, just to test also this case |
50 var mem_oob_func = builder.addFunction(undefined, [kAstStmt]) | 50 var mem_oob_func = builder.addFunction(undefined, kSig_v_v) |
51 // access the memory at offset -1 | 51 // access the memory at offset -1 |
52 .addBody([kExprI32Const, 0x7f, kExprI32LoadMem8S, 0, 0]) | 52 .addBody([kExprI32Const, 0x7f, kExprI32LoadMem8S, 0, 0]) |
53 .exportAs("mem_out_of_bounds"); | 53 .exportAs("mem_out_of_bounds"); |
54 | 54 |
55 // call the mem_out_of_bounds function, in order to have two WASM stack frames | 55 // call the mem_out_of_bounds function, in order to have two WASM stack frames |
56 builder.addFunction("call_mem_out_of_bounds", [kAstStmt]) | 56 builder.addFunction("call_mem_out_of_bounds", kSig_v_v) |
57 .addBody([kExprCallFunction, kArity0, mem_oob_func.index]) | 57 .addBody([kExprCallFunction, kArity0, mem_oob_func.index]) |
58 .exportAs("call_mem_out_of_bounds"); | 58 .exportAs("call_mem_out_of_bounds"); |
59 | 59 |
60 var module = builder.instantiate({func: STACK}); | 60 var module = builder.instantiate({func: STACK}); |
61 | 61 |
62 (function testSimpleStack() { | 62 (function testSimpleStack() { |
63 var expected_string = "Error\n" + | 63 var expected_string = "Error\n" + |
64 // The line numbers below will change as this test gains / loses lines.. | 64 // The line numbers below will change as this test gains / loses lines.. |
65 " at STACK (stack.js:33:11)\n" + // -- | 65 " at STACK (stack.js:33:11)\n" + // -- |
66 " at <WASM> (<anonymous>)\n" + // TODO(jfb): wasm stack here. | 66 " at <WASM> (<anonymous>)\n" + // TODO(jfb): wasm stack here. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 assertContains("out of bounds", e.message); | 113 assertContains("out of bounds", e.message); |
114 verifyStack(e.stack, [ | 114 verifyStack(e.stack, [ |
115 // function line file toString | 115 // function line file toString |
116 [ "<WASM>", null, null, "<WASM>"], | 116 [ "<WASM>", null, null, "<WASM>"], |
117 [ "<WASM>", null, null, "<WASM>"], | 117 [ "<WASM>", null, null, "<WASM>"], |
118 ["testWasmMemOutOfBounds", 110, "stack.js", "stack.js:110:20"], | 118 ["testWasmMemOutOfBounds", 110, "stack.js", "stack.js:110:20"], |
119 [ null, 122, "stack.js", "stack.js:122:3"] | 119 [ null, 122, "stack.js", "stack.js:122:3"] |
120 ]); | 120 ]); |
121 } | 121 } |
122 })(); | 122 })(); |
OLD | NEW |