OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --validate-asm --allow-natives-syntax | |
6 | |
7 var filename = '(?:[^ ]+/)?test/mjsunit/wasm/asm-wasm-stack.js'; | |
8 filename = filename.replace(/\//g, '[/\\\\]'); | |
9 | |
10 function checkPreformattedStack(e, expected_lines) { | |
11 print('preformatted stack: ' + e.stack); | |
12 var lines = e.stack.split('\n'); | |
13 assertEquals(expected_lines.length, lines.length); | |
14 for (var i = 0; i < lines.length; ++i) { | |
15 assertMatches(expected_lines[i], lines[i], 'line ' + i); | |
16 } | |
17 } | |
18 | |
19 function checkFunctionsOnCallsites(e, locations) { | |
20 var stack = e.stack; | |
21 print('callsite objects (size ' + stack.length + '):'); | |
22 for (var i = 0; i < stack.length; ++i) { | |
titzer
2016/10/12 08:03:05
I think we can improve the checking here by making
Clemens Hammacher
2016/10/12 08:17:46
This is exactly what happens here. I first print t
| |
23 var s = stack[i]; | |
24 print( | |
25 ' [' + i + '] ' + s.getFunctionName() + ' (' + s.getFileName() + ':' + | |
26 s.getLineNumber() + ':' + s.getColumnNumber() + ')'); | |
27 } | |
28 for (var i = 0; i < locations.length; ++i) { | |
29 var cs = stack[i]; | |
30 assertMatches('^' + filename + '$', cs.getFileName(), 'file name at ' + i); | |
31 assertEquals( | |
32 locations[i][0], cs.getFunctionName(), 'function name at ' + i); | |
33 assertEquals(locations[i][1], cs.getLineNumber(), 'line number at ' + i); | |
34 assertEquals( | |
35 locations[i][2], cs.getColumnNumber(), 'column number at ' + i); | |
36 assertNotNull(cs.getThis(), 'receiver should be global'); | |
37 assertEquals(stack[0].getThis(), cs.getThis(), 'receiver should be global'); | |
38 } | |
39 } | |
40 | |
41 function throwException() { | |
42 throw new Error('exception from JS'); | |
43 } | |
44 | |
45 function generateWasmFromAsmJs(stdlib, foreign, heap) { | |
46 'use asm'; | |
47 var throwFunc = foreign.throwFunc; | |
48 function callThrow() { | |
49 throwFunc(); | |
50 } | |
51 function redirectFun() { | |
52 callThrow(); | |
53 } | |
54 return redirectFun; | |
55 } | |
56 | |
57 (function PreformattedStackTraceFromJS() { | |
58 var fun = generateWasmFromAsmJs(this, {throwFunc: throwException}, undefined); | |
59 var e = null; | |
60 try { | |
61 fun(); | |
62 } catch (ex) { | |
63 e = ex; | |
64 } | |
65 assertInstanceof(e, Error, 'exception should have been thrown'); | |
66 checkPreformattedStack(e, [ | |
67 '^Error: exception from JS$', | |
68 '^ *at throwException \\(' + filename + ':42:9\\)$', | |
69 '^ *at callThrow \\(' + filename + ':49:5\\)$', | |
70 '^ *at redirectFun \\(' + filename + ':52:5\\)$', | |
71 '^ *at PreformattedStackTraceFromJS \\(' + filename + ':61:5\\)$', | |
72 '^ *at ' + filename + ':74:3$' | |
73 ]); | |
74 })(); | |
75 | |
76 // Now collect the Callsite objects instead of just a string. | |
77 Error.prepareStackTrace = function(error, frames) { | |
78 return frames; | |
79 }; | |
80 | |
81 (function CallsiteObjectsFromJS() { | |
82 var fun = generateWasmFromAsmJs(this, {throwFunc: throwException}, undefined); | |
83 var e = null; | |
84 try { | |
85 fun(); | |
86 } catch (ex) { | |
87 e = ex; | |
88 } | |
89 assertInstanceof(e, Error, 'exception should have been thrown'); | |
90 checkFunctionsOnCallsites(e, [ | |
91 ['throwException', 42, 9], // -- | |
92 ['callThrow', 49, 5], // -- | |
93 ['redirectFun', 52, 5], // -- | |
94 ['CallsiteObjectsFromJS', 85, 5], // -- | |
95 [null, 97, 3] | |
96 ]); | |
97 })(); | |
OLD | NEW |