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 assertEquals(locations.length, stack.length, 'stack size'); |
| 29 for (var i = 0; i < locations.length; ++i) { |
| 30 var cs = stack[i]; |
| 31 assertMatches('^' + filename + '$', cs.getFileName(), 'file name at ' + i); |
| 32 assertEquals( |
| 33 locations[i][0], cs.getFunctionName(), 'function name at ' + i); |
| 34 assertEquals(locations[i][1], cs.getLineNumber(), 'line number at ' + i); |
| 35 assertEquals( |
| 36 locations[i][2], cs.getColumnNumber(), 'column number at ' + i); |
| 37 assertNotNull(cs.getThis(), 'receiver should be global'); |
| 38 assertEquals(stack[0].getThis(), cs.getThis(), 'receiver should be global'); |
| 39 } |
| 40 } |
| 41 |
| 42 function throwException() { |
| 43 throw new Error('exception from JS'); |
| 44 } |
| 45 |
| 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 (function PreformattedStackTraceFromJS() { |
| 59 var fun = generateWasmFromAsmJs(this, {throwFunc: throwException}, undefined); |
| 60 var e = null; |
| 61 try { |
| 62 fun(); |
| 63 } catch (ex) { |
| 64 e = ex; |
| 65 } |
| 66 assertInstanceof(e, Error, 'exception should have been thrown'); |
| 67 checkPreformattedStack(e, [ |
| 68 '^Error: exception from JS$', |
| 69 '^ *at throwException \\(' + filename + ':43:9\\)$', |
| 70 '^ *at callThrow \\(' + filename + ':50:5\\)$', |
| 71 '^ *at redirectFun \\(' + filename + ':53:5\\)$', |
| 72 '^ *at PreformattedStackTraceFromJS \\(' + filename + ':62:5\\)$', |
| 73 '^ *at ' + filename + ':75:3$' |
| 74 ]); |
| 75 })(); |
| 76 |
| 77 // Now collect the Callsite objects instead of just a string. |
| 78 Error.prepareStackTrace = function(error, frames) { |
| 79 return frames; |
| 80 }; |
| 81 |
| 82 (function CallsiteObjectsFromJS() { |
| 83 var fun = generateWasmFromAsmJs(this, {throwFunc: throwException}, undefined); |
| 84 var e = null; |
| 85 try { |
| 86 fun(); |
| 87 } catch (ex) { |
| 88 e = ex; |
| 89 } |
| 90 assertInstanceof(e, Error, 'exception should have been thrown'); |
| 91 checkFunctionsOnCallsites(e, [ |
| 92 ['throwException', 43, 9], // -- |
| 93 ['callThrow', 50, 5], // -- |
| 94 ['redirectFun', 53, 5], // -- |
| 95 ['CallsiteObjectsFromJS', 86, 5], // -- |
| 96 [null, 98, 3] |
| 97 ]); |
| 98 })(); |
OLD | NEW |