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) { | |
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 PreformattedStackTraceFromJS() { | |
46 function generateWasmFromAsmJs(stdlib, foreign, heap) { | |
47 'use asm'; | |
48 var throwFunc = foreign.throwFunc; | |
49 function callThrow() { | |
50 throwFunc(); | |
51 } | |
52 function redirectFun() { | |
53 callThrow(); | |
54 } | |
55 return redirectFun; | |
56 } | |
57 | |
58 var fun = generateWasmFromAsmJs(this, {throwFunc: throwException}, undefined); | |
59 //assertWasm(fun); | |
jgruber
2016/10/11 19:07:40
Is the commented code here still needed?
Clemens Hammacher
2016/10/12 07:37:18
Fixed already.
| |
60 //assertNoWasm(throwException); | |
61 try { | |
62 fun(); | |
63 assertUnreachable('exception should have been thrown'); | |
jgruber
2016/10/11 19:07:40
This pattern may not work as intended - when asser
Clemens Hammacher
2016/10/12 07:37:19
Good catch! Fixed it for this test case.
| |
64 } catch (e) { | |
65 assertInstanceof(e, Error); | |
66 checkPreformattedStack(e, [ | |
67 '^Error: exception from JS$', | |
68 '^ *at throwException \\(' + filename + ':42:9\\)$', | |
69 '^ *at callThrow \\(' + filename + ':50:7\\)$', | |
70 '^ *at redirectFun \\(' + filename + ':53:7\\)$', | |
71 '^ *at PreformattedStackTraceFromJS \\(' + filename + ':62:5\\)$', | |
72 '^ *at ' + filename + ':75:3$' | |
73 ]); | |
74 } | |
75 })(); | |
76 | |
77 // Collect the Callsite objects instead of just a string. | |
78 Error.prepareStackTrace = function(error, frames) { | |
79 return frames; | |
80 }; | |
81 | |
82 (function CallsiteObjectsFromJS() { | |
83 function generateWasmFromAsmJs(stdlib, foreign, heap) { | |
jgruber
2016/10/11 19:07:41
Could you reuse the function from above?
Clemens Hammacher
2016/10/12 07:37:19
Fixed already.
| |
84 'use asm'; | |
85 var throwFunc = foreign.throwFunc; | |
86 function callThrow() { | |
87 throwFunc(); | |
88 } | |
89 function redirectFun() { | |
90 callThrow(); | |
91 } | |
92 return redirectFun; | |
93 } | |
94 | |
95 var fun = generateWasmFromAsmJs(this, {throwFunc: throwException}, undefined); | |
96 try { | |
97 fun(); | |
98 assertUnreachable('exception should have been thrown'); | |
99 } catch (e) { | |
100 assertInstanceof(e, Error); | |
101 checkFunctionsOnCallsites(e, [ | |
102 ['throwException', 42, 9], // -- | |
jgruber
2016/10/11 19:07:41
What are the '// --' comments?
Clemens Hammacher
2016/10/12 07:37:19
They prevent clang format from joining the lines.
| |
103 ['callThrow', 87, 7], // -- | |
104 ['redirectFun', 90, 7], // -- | |
105 ['CallsiteObjectsFromJS', 97, 5], // -- | |
106 [null, 109, 3] | |
107 ]); | |
108 } | |
109 })(); | |
OLD | NEW |