Index: test/mjsunit/wasm/stack.js |
diff --git a/test/mjsunit/wasm/stack.js b/test/mjsunit/wasm/stack.js |
index 5235ce950fb4f7b55eeb1823d53dc6c0d0ae28ba..e0d39b35a6bf8b4a07f005d5ded322d5b202dee6 100644 |
--- a/test/mjsunit/wasm/stack.js |
+++ b/test/mjsunit/wasm/stack.js |
@@ -16,8 +16,10 @@ function stripPath(s) { |
function verifyStack(frames, expected) { |
assertEquals(expected.length, frames.length, "number of frames mismatch"); |
expected.forEach(function(exp, i) { |
- assertEquals(exp[0], frames[i].getFunctionName(), |
- "["+i+"].getFunctionName()"); |
+ if (exp[0] != "?") { |
+ assertEquals(exp[0], frames[i].getFunctionName(), |
+ "["+i+"].getFunctionName()"); |
+ } |
assertEquals(exp[1], frames[i].getLineNumber(), |
"["+i+"].getLineNumber()"); |
assertContains(exp[2], frames[i].getFileName(), |
@@ -27,6 +29,21 @@ function verifyStack(frames, expected) { |
}); |
} |
+function verifyWasmStack(frames, expected) { |
+ assertEquals(expected.length, frames.length, "number of frames mismatch"); |
+ expected.forEach(function(exp, i) { |
+ assertEquals(exp[0], frames[i].isWasm(), |
+ "["+i+"].isWasm()"); |
+ assertEquals(exp[0], frames[i].getWasmObject() != null, |
+ "["+i+"].getWasmObject() != null"); |
+ assertEquals(exp[1], frames[i].getWasmFunctionIndex(), |
+ "["+i+"].getWasmFunctionIndex()"); |
+ if (exp[0]) |
+ assertEquals(exp[2], frames[i].getPosition(), |
+ "["+i+"].getPosition()"); |
+ }); |
+} |
+ |
var stack; |
function STACK() { |
@@ -38,22 +55,23 @@ var builder = new WasmModuleBuilder(); |
builder.addImport("func", [kAstStmt]); |
-builder.addFunction("main", [kAstStmt]) |
+var main_func = builder.addFunction("main", [kAstStmt]) |
.addBody([kExprCallImport, 0]) |
.exportAs("main"); |
-builder.addFunction("exec_unreachable", [kAstStmt]) |
+var unreach_func = builder.addFunction("exec_unreachable", [kAstStmt]) |
.addBody([kExprUnreachable]) |
.exportAs("exec_unreachable"); |
-// make this function unnamed, just to test also this case |
+// Make this function unnamed, just to test also this case. |
var mem_oob_func = builder.addFunction(undefined, [kAstStmt]) |
- // access the memory at offset -1 |
+ // Access the memory at offset -1, to provoke a trap. |
.addBody([kExprI32LoadMem8S, 0, 0, kExprI32Const, 0x7f]) |
.exportAs("mem_out_of_bounds"); |
-// call the mem_out_of_bounds function, in order to have two WASM stack frames |
-builder.addFunction("call_mem_out_of_bounds", [kAstStmt]) |
+// Call the mem_out_of_bounds function, in order to have two WASM stack frames. |
+var call_mem_oob_func = builder.addFunction("call_mem_out_of_bounds", |
+ [kAstStmt]) |
.addBody([kExprCallFunction, mem_oob_func.index]) |
.exportAs("call_mem_out_of_bounds"); |
@@ -62,10 +80,10 @@ var module = builder.instantiate({func: STACK}); |
(function testSimpleStack() { |
var expected_string = "Error\n" + |
// The line numbers below will change as this test gains / loses lines.. |
- " at STACK (stack.js:33:11)\n" + // -- |
- " at <WASM> (<anonymous>)\n" + // TODO(jfb): wasm stack here. |
- " at testSimpleStack (stack.js:70:18)\n" + // -- |
- " at stack.js:72:3"; // -- |
+ " at STACK (stack.js:50:11)\n" + // -- |
+ " at main (<WASM>:1)\n" + // -- |
+ " at testSimpleStack (stack.js:88:18)\n" + // -- |
+ " at stack.js:90:3"; // -- |
module.exports.main(); |
assertEquals(expected_string, stripPath(stack)); |
@@ -80,13 +98,19 @@ Error.prepareStackTrace = function(error, frames) { |
(function testStackFrames() { |
module.exports.main(); |
- // TODO(clemensh): add a isWasm() method or similar, and test it |
verifyStack(stack, [ |
- // function line file toString |
- [ "STACK", 33, "stack.js", "stack.js:33:11"], |
- [ "<WASM>", null, null, "<WASM>"], |
- ["testStackFrames", 81, "stack.js", "stack.js:81:18"], |
- [ null, 91, "stack.js", "stack.js:91:3"] |
+ // function line file toString |
+ [ "STACK", 50, "stack.js", "stack.js:50:11"], |
+ [ "main", null, null, "main (<WASM>:1)"], |
+ ["testStackFrames", 99, "stack.js", "stack.js:99:18"], |
+ [ null, 115, "stack.js", "stack.js:115:3"] |
+ ]); |
+ verifyWasmStack(stack, [ |
+ // isWasm funcIndex byteOffset |
+ [ false, undefined, null], |
+ [ true, main_func.index, 1], |
+ [ false, undefined, null], |
+ [ false, undefined, null], |
]); |
})(); |
@@ -97,10 +121,16 @@ Error.prepareStackTrace = function(error, frames) { |
} catch (e) { |
assertContains("unreachable", e.message); |
verifyStack(e.stack, [ |
- // function line file toString |
- [ "<WASM>", null, null, "<WASM>"], |
- ["testWasmUnreachable", 95, "stack.js", "stack.js:95:20"], |
- [ null, 106, "stack.js", "stack.js:106:3"] |
+ // function line file toString |
+ [ "exec_unreachable", null, null, "exec_unreachable (<WASM>:-1)"], // TODO(clemensh): position should be 1 |
+ ["testWasmUnreachable", 119, "stack.js", "stack.js:119:20"], |
+ [ null, 136, "stack.js", "stack.js:136:3"] |
+ ]); |
+ verifyWasmStack(e.stack, [ |
+ // isWasm funcIndex byteOffset |
+ [ true, unreach_func.index, -1], // TODO(clemensh): position should be 1 |
+ [ false, undefined, null], |
+ [ false, undefined, null], |
]); |
} |
})(); |
@@ -112,11 +142,19 @@ Error.prepareStackTrace = function(error, frames) { |
} catch (e) { |
assertContains("out of bounds", e.message); |
verifyStack(e.stack, [ |
- // function line file toString |
- [ "<WASM>", null, null, "<WASM>"], |
- [ "<WASM>", null, null, "<WASM>"], |
- ["testWasmMemOutOfBounds", 110, "stack.js", "stack.js:110:20"], |
- [ null, 122, "stack.js", "stack.js:122:3"] |
+ // function line file toString |
+ [ "?", null, null, " (<WASM>:-1)"], // TODO(clemensh): position should be 1 |
+ ["call_mem_out_of_bounds", null, null, "bounds (<WASM>:1)"], |
+ ["testWasmMemOutOfBounds", 140, "stack.js", "stack.js:140:20"], |
+ [ null, 160, "stack.js", "stack.js:160:3"] |
+ ]); |
+ assertTrue(call_mem_oob_func.index != mem_oob_func.index); |
+ verifyWasmStack(e.stack, [ |
+ // isWasm funcIndex byteOffset |
+ [ true, mem_oob_func.index, -1], // TODO(clemensh): position should be 1 |
+ [ true, call_mem_oob_func.index, 1], |
+ [ false, undefined, 1], |
+ [ false, undefined, 1], |
]); |
} |
})(); |