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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « test/mjsunit/mjsunit.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Flags: --expose-wasm 5 // Flags: --expose-wasm
6 6
7 load("test/mjsunit/wasm/wasm-constants.js"); 7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js"); 8 load("test/mjsunit/wasm/wasm-module-builder.js");
9 9
10 var expected = "Error\n" +
11 // The line numbers below will change as this test gains / loses lines..
12 " at STACK (stack.js:24:11)\n" + // --
13 " at <WASM> (<anonymous>)\n" + // TODO(jfb): wasm stack here.
14 " at testStack (stack.js:38:18)\n" + // --
15 " at stack.js:40:3"; // --
16
17 // The stack trace contains file path, only keep "stack.js". 10 // The stack trace contains file path, only keep "stack.js".
18 function stripPath(s) { 11 function stripPath(s) {
19 return s.replace(/[^ (]*stack\.js/g, "stack.js"); 12 return s.replace(/[^ (]*stack\.js/g, "stack.js");
20 } 13 }
21 14
15 // Check a property for the return values of a function called on each frame.
16 Array.prototype.verify = function(frames, func_name, check_func) {
17 assertEquals(this.length, frames.length, "number of frames mismatch");
18 this.forEach(
19 function(element, index) {
20 var frame = frames[index];
21 check_func(element, (frame[func_name])());
22 }
23 );
24 }
25
26 // Check for every frame that a certain method returns the
27 // expected value for every frame.
28 Array.prototype.verifyEquals = function(frames, func_name) {
29 this.verify(frames, func_name, function(exp, cur) {
30 assertEquals(exp, cur, func_name + "()");
31 });
32 }
33
34 // Check for every frame that a certain method has a return value
35 // that contains the expected pattern for every frame.
36 Array.prototype.verifyContains = function(frames, func_name) {
37 this.verify(frames, func_name, function(exp, cur) {
38 assertContains(cur, exp, func_name + "()");
39 });
40 }
41
42 // Check for every frame that a certain method returns undefined
43 // when expected.
44 Array.prototype.verifyUndefined = function(frames, func_name) {
45 this.verify(frames, func_name, function(exp, cur) {
46 if ((cur == undefined) != !!exp)
47 assertEquals((exp ? '' : 'not ') + 'undefined', cur, func_name + "()");
48 });
49 }
50
51
22 var stack; 52 var stack;
23 function STACK() { 53 function STACK() {
24 var e = new Error(); 54 var e = new Error();
25 stack = e.stack; 55 stack = e.stack;
26 } 56 }
27 57
28 (function testStack() { 58 var builder = new WasmModuleBuilder();
29 var builder = new WasmModuleBuilder();
30 59
31 builder.addImport("func", [kAstStmt]); 60 builder.addImport("func", [kAstStmt]);
32 61
33 builder.addFunction(undefined, [kAstStmt]) 62 builder.addFunction("main", [kAstStmt])
34 .addBody([kExprCallImport, 0]) 63 .addBody([kExprCallImport, 0])
35 .exportAs("main"); 64 .exportAs("main");
36 65
37 var module = builder.instantiate({func: STACK}); 66 var module = builder.instantiate({func: STACK});
67
68 (function testSimpleStack() {
69 var expected_string = "Error\n" +
70 // The line numbers below will change as this test gains / loses lines..
71 " at STACK (stack.js:54:11)\n" + // --
72 " at <WASM> (<anonymous>)\n" + // TODO(jfb): wasm stack here.
73 " at testSimpleStack (stack.js:76:18)\n" + // --
74 " at stack.js:78:3"; // --
75
38 module.exports.main(); 76 module.exports.main();
39 assertEquals(expected, stripPath(stack)); 77 assertEquals(expected_string, stripPath(stack));
40 })(); 78 })();
79
80 // For the remaining tests, collect the Callsite objects instead of just a
81 // string:
82 Error.prepareStackTrace = function(error, frames) {
83 return frames;
84 };
85
86 (function testStackFrames() {
87 module.exports.main();
88
89 ["STACK", "<WASM>", "testStackFrames", null]
90 .verifyEquals(stack, "getFunctionName");
91 [54, null, 87, 98]
92 .verifyEquals(stack, "getLineNumber");
93 ["stack.js", null, "stack.js", "stack.js"]
94 .verifyContains(stack, "getFileName");
95 ["stack.js:54:11", "<WASM>", "stack.js:87:18", "stack.js:98:3"]
96 .verifyContains(stack, "toString");
97 // TODO(clemensh): add a isWasm() method or similar, and test it
98 })();
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.
OLDNEW
« 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