| 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 |
| 11 // The stack trace contains file path, only keep "stack.js". | 11 // The stack trace contains file path, only keep "stack.js". |
| 12 function stripPath(s) { | 12 function stripPath(s) { |
| 13 return s.replace(/[^ (]*stack\.js/g, "stack.js"); | 13 return s.replace(/[^ (]*stack\.js/g, "stack.js"); |
| 14 } | 14 } |
| 15 | 15 |
| 16 function verifyStack(frames, expected) { | 16 function verifyStack(frames, expected) { |
| 17 assertEquals(expected.length, frames.length, "number of frames mismatch"); | 17 assertEquals(expected.length, frames.length, "number of frames mismatch"); |
| 18 expected.forEach(function(exp, i) { | 18 expected.forEach(function(exp, i) { |
| 19 if (exp[1] != "?") { | 19 assertEquals(exp[1], frames[i].getFunctionName(), |
| 20 assertEquals(exp[1], frames[i].getFunctionName(), | 20 "["+i+"].getFunctionName()"); |
| 21 "["+i+"].getFunctionName()"); | |
| 22 } | |
| 23 assertEquals(exp[2], frames[i].getLineNumber(), "["+i+"].getLineNumber()"); | 21 assertEquals(exp[2], frames[i].getLineNumber(), "["+i+"].getLineNumber()"); |
| 24 if (exp[0]) | 22 if (exp[0]) |
| 25 assertEquals(exp[3], frames[i].getPosition(), | 23 assertEquals(exp[3], frames[i].getPosition(), |
| 26 "["+i+"].getPosition()"); | 24 "["+i+"].getPosition()"); |
| 27 assertContains(exp[4], frames[i].getFileName(), "["+i+"].getFileName()"); | 25 assertContains(exp[4], frames[i].getFileName(), "["+i+"].getFileName()"); |
| 28 var toString; | 26 var toString; |
| 29 if (exp[0]) { | 27 if (exp[0]) { |
| 30 var funName = exp[1] == "?" ? "" : exp[1]; | 28 toString = exp[1] + " (<WASM>[" + exp[2] + "]+" + exp[3] + ")"; |
| 31 toString = funName + " (<WASM>[" + exp[2] + "]+" + exp[3] + ")"; | |
| 32 } else { | 29 } else { |
| 33 toString = exp[4] + ":" + exp[2] + ":"; | 30 toString = exp[4] + ":" + exp[2] + ":"; |
| 34 } | 31 } |
| 35 assertContains(toString, frames[i].toString(), "["+i+"].toString()"); | 32 assertContains(toString, frames[i].toString(), "["+i+"].toString()"); |
| 36 }); | 33 }); |
| 37 } | 34 } |
| 38 | 35 |
| 39 | 36 |
| 40 var stack; | 37 var stack; |
| 41 function STACK() { | 38 function STACK() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 64 // Call the mem_out_of_bounds function, in order to have two WASM stack frames. | 61 // Call the mem_out_of_bounds function, in order to have two WASM stack frames. |
| 65 builder.addFunction("call_mem_out_of_bounds", kSig_v_v) | 62 builder.addFunction("call_mem_out_of_bounds", kSig_v_v) |
| 66 .addBody([kExprCallFunction, kArity0, mem_oob_func.index]) | 63 .addBody([kExprCallFunction, kArity0, mem_oob_func.index]) |
| 67 .exportAs("call_mem_out_of_bounds"); | 64 .exportAs("call_mem_out_of_bounds"); |
| 68 | 65 |
| 69 var module = builder.instantiate({func: STACK}); | 66 var module = builder.instantiate({func: STACK}); |
| 70 | 67 |
| 71 (function testSimpleStack() { | 68 (function testSimpleStack() { |
| 72 var expected_string = "Error\n" + | 69 var expected_string = "Error\n" + |
| 73 // The line numbers below will change as this test gains / loses lines.. | 70 // The line numbers below will change as this test gains / loses lines.. |
| 74 " at STACK (stack.js:42:11)\n" + // -- | 71 " at STACK (stack.js:39:11)\n" + // -- |
| 75 " at main (<WASM>[0]+1)\n" + // -- | 72 " at main (<WASM>[0]+1)\n" + // -- |
| 76 " at testSimpleStack (stack.js:79:18)\n" + // -- | 73 " at testSimpleStack (stack.js:76:18)\n" + // -- |
| 77 " at stack.js:81:3"; // -- | 74 " at stack.js:78:3"; // -- |
| 78 | 75 |
| 79 module.exports.main(); | 76 module.exports.main(); |
| 80 assertEquals(expected_string, stripPath(stack)); | 77 assertEquals(expected_string, stripPath(stack)); |
| 81 })(); | 78 })(); |
| 82 | 79 |
| 83 // For the remaining tests, collect the Callsite objects instead of just a | 80 // For the remaining tests, collect the Callsite objects instead of just a |
| 84 // string: | 81 // string: |
| 85 Error.prepareStackTrace = function(error, frames) { | 82 Error.prepareStackTrace = function(error, frames) { |
| 86 return frames; | 83 return frames; |
| 87 }; | 84 }; |
| 88 | 85 |
| 89 (function testStackFrames() { | 86 (function testStackFrames() { |
| 90 module.exports.main(); | 87 module.exports.main(); |
| 91 | 88 |
| 92 verifyStack(stack, [ | 89 verifyStack(stack, [ |
| 93 // isWasm function line pos file | 90 // isWasm function line pos file |
| 94 [ false, "STACK", 42, 0, "stack.js"], | 91 [ false, "STACK", 39, 0, "stack.js"], |
| 95 [ true, "main", 0, 1, null], | 92 [ true, "main", 0, 1, null], |
| 96 [ false, "testStackFrames", 90, 0, "stack.js"], | 93 [ false, "testStackFrames", 87, 0, "stack.js"], |
| 97 [ false, null, 99, 0, "stack.js"] | 94 [ false, null, 96, 0, "stack.js"] |
| 98 ]); | 95 ]); |
| 99 })(); | 96 })(); |
| 100 | 97 |
| 101 (function testWasmUnreachable() { | 98 (function testWasmUnreachable() { |
| 102 try { | 99 try { |
| 103 module.exports.exec_unreachable(); | 100 module.exports.exec_unreachable(); |
| 104 fail("expected wasm exception"); | 101 fail("expected wasm exception"); |
| 105 } catch (e) { | 102 } catch (e) { |
| 106 assertContains("unreachable", e.message); | 103 assertContains("unreachable", e.message); |
| 107 verifyStack(e.stack, [ | 104 verifyStack(e.stack, [ |
| 108 // isWasm function line pos file | 105 // isWasm function line pos file |
| 109 [ true, "exec_unreachable", 1, 1, null], | 106 [ true, "exec_unreachable", 1, 1, null], |
| 110 [ false, "testWasmUnreachable", 103, 0, "stack.js"], | 107 [ false, "testWasmUnreachable", 100, 0, "stack.js"], |
| 111 [ false, null, 114, 0, "stack.js"] | 108 [ false, null, 111, 0, "stack.js"] |
| 112 ]); | 109 ]); |
| 113 } | 110 } |
| 114 })(); | 111 })(); |
| 115 | 112 |
| 116 (function testWasmMemOutOfBounds() { | 113 (function testWasmMemOutOfBounds() { |
| 117 try { | 114 try { |
| 118 module.exports.call_mem_out_of_bounds(); | 115 module.exports.call_mem_out_of_bounds(); |
| 119 fail("expected wasm exception"); | 116 fail("expected wasm exception"); |
| 120 } catch (e) { | 117 } catch (e) { |
| 121 assertContains("out of bounds", e.message); | 118 assertContains("out of bounds", e.message); |
| 122 verifyStack(e.stack, [ | 119 verifyStack(e.stack, [ |
| 123 // isWasm function line pos file | 120 // isWasm function line pos file |
| 124 [ true, "?", 2, 3, null], | 121 [ true, "", 2, 3, null], |
| 125 [ true, "call_mem_out_of_bounds", 3, 1, null], | 122 [ true, "call_mem_out_of_bounds", 3, 1, null], |
| 126 [ false, "testWasmMemOutOfBounds", 118, 0, "stack.js"], | 123 [ false, "testWasmMemOutOfBounds", 115, 0, "stack.js"], |
| 127 [ false, null, 130, 0, "stack.js"] | 124 [ false, null, 127, 0, "stack.js"] |
| 128 ]); | 125 ]); |
| 129 } | 126 } |
| 130 })(); | 127 })(); |
| OLD | NEW |