Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: test/mjsunit/wasm/stack.js

Issue 1875153002: [wasm] Also test structured stack trace (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-throw-error
Patch Set: fix assertContains helper function Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/mjsunit.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/stack.js
diff --git a/test/mjsunit/wasm/stack.js b/test/mjsunit/wasm/stack.js
index ed05517ae5070bb1361c5f23ef3c3618beed7114..d2b0be02f37e89b8e7e3583a9e844a58378dca87 100644
--- a/test/mjsunit/wasm/stack.js
+++ b/test/mjsunit/wasm/stack.js
@@ -7,34 +7,92 @@
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
-var expected = "Error\n" +
- // The line numbers below will change as this test gains / loses lines..
- " at STACK (stack.js:24:11)\n" + // --
- " at <WASM> (<anonymous>)\n" + // TODO(jfb): wasm stack here.
- " at testStack (stack.js:38:18)\n" + // --
- " at stack.js:40:3"; // --
-
// The stack trace contains file path, only keep "stack.js".
function stripPath(s) {
return s.replace(/[^ (]*stack\.js/g, "stack.js");
}
+// Check a property for the return values of a function called on each frame.
+Array.prototype.verify = function(frames, func_name, check_func) {
+ assertEquals(this.length, frames.length, "number of frames mismatch");
+ this.forEach(
+ function(element, index) {
+ var frame = frames[index];
+ check_func(element, (frame[func_name])());
+ }
+ );
+}
+
+// Check for every frame that a certain method returns the
+// expected value for every frame.
+Array.prototype.verifyEquals = function(frames, func_name) {
+ this.verify(frames, func_name, function(exp, cur) {
+ assertEquals(exp, cur, func_name + "()");
+ });
+}
+
+// Check for every frame that a certain method has a return value
+// that contains the expected pattern for every frame.
+Array.prototype.verifyContains = function(frames, func_name) {
+ this.verify(frames, func_name, function(exp, cur) {
+ assertContains(cur, exp, func_name + "()");
+ });
+}
+
+// Check for every frame that a certain method returns undefined
+// when expected.
+Array.prototype.verifyUndefined = function(frames, func_name) {
+ this.verify(frames, func_name, function(exp, cur) {
+ if ((cur == undefined) != !!exp)
+ assertEquals((exp ? '' : 'not ') + 'undefined', cur, func_name + "()");
+ });
+}
+
+
var stack;
function STACK() {
var e = new Error();
stack = e.stack;
}
-(function testStack() {
- var builder = new WasmModuleBuilder();
+var builder = new WasmModuleBuilder();
+
+builder.addImport("func", [kAstStmt]);
- builder.addImport("func", [kAstStmt]);
+builder.addFunction("main", [kAstStmt])
+ .addBody([kExprCallImport, 0])
+ .exportAs("main");
- builder.addFunction(undefined, [kAstStmt])
- .addBody([kExprCallImport, 0])
- .exportAs("main");
+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:54:11)\n" + // --
+ " at <WASM> (<anonymous>)\n" + // TODO(jfb): wasm stack here.
+ " at testSimpleStack (stack.js:76:18)\n" + // --
+ " at stack.js:78:3"; // --
- var module = builder.instantiate({func: STACK});
module.exports.main();
- assertEquals(expected, stripPath(stack));
+ assertEquals(expected_string, stripPath(stack));
+})();
+
+// For the remaining tests, collect the Callsite objects instead of just a
+// string:
+Error.prepareStackTrace = function(error, frames) {
+ return frames;
+};
+
+(function testStackFrames() {
+ module.exports.main();
+
+ ["STACK", "<WASM>", "testStackFrames", null]
+ .verifyEquals(stack, "getFunctionName");
+ [54, null, 87, 98]
+ .verifyEquals(stack, "getLineNumber");
+ ["stack.js", null, "stack.js", "stack.js"]
+ .verifyContains(stack, "getFileName");
+ ["stack.js:54:11", "<WASM>", "stack.js:87:18", "stack.js:98:3"]
+ .verifyContains(stack, "toString");
+ // TODO(clemensh): add a isWasm() method or similar, and test it
})();
JF 2016/04/11 19:35:09 I find that structure hard to read, IMO it would b
Clemens Hammacher 2016/04/12 08:57:03 Sure, that's nicer. Changed it accordingly.
« no previous file with comments | « test/mjsunit/mjsunit.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698