Comparing version 1.5.1 to 1.5.2
@@ -17,3 +17,3 @@ // Copyright 2006-2008 the V8 project authors. All rights reserved. | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
@@ -29,39 +29,21 @@ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
function FormatStackTrace(error, frames) { | ||
var lines = []; | ||
try { | ||
lines.push(error.toString()); | ||
} catch (e) { | ||
try { | ||
lines.push("<error: " + e + ">"); | ||
} catch (ee) { | ||
lines.push("<error>"); | ||
var stack = stringify(error, String) | ||
for (var i = 0, l = frames.length; i < l; i++) { | ||
var frame = frames[i] | ||
, line = stringify(frame, FormatSourcePosition) | ||
if (line) { | ||
stack += '\n at ' + line | ||
} | ||
} | ||
for (var i = 0; i < frames.length; i++) { | ||
var frame = frames[i]; | ||
var line; | ||
try { | ||
line = FormatSourcePosition(frame); | ||
} catch (e) { | ||
try { | ||
line = "<error: " + e + ">"; | ||
} catch (ee) { | ||
// Any code that reaches this point is seriously nasty! | ||
line = "<error>"; | ||
} | ||
} | ||
if (line !== undefined) { | ||
line = " at " + line; | ||
lines.push(line); | ||
} | ||
} | ||
return lines.join("\n"); | ||
return stack | ||
} | ||
function FormatSourcePosition(frame) { | ||
var fileLocation = ""; | ||
var fileLocation = ''; | ||
if (frame.isNative()) { | ||
fileLocation = "native"; | ||
fileLocation = 'native'; | ||
} else if (frame.isEval()) { | ||
fileLocation = "eval at " + frame.getEvalOrigin(); | ||
fileLocation = 'eval at ' + frame.getEvalOrigin(); | ||
} else { | ||
@@ -73,6 +55,6 @@ var fileName = frame.getFileName(); | ||
if (lineNumber != null) { | ||
fileLocation += ":" + lineNumber; | ||
fileLocation += ':' + lineNumber; | ||
var columnNumber = frame.getColumnNumber(); | ||
if (columnNumber) { | ||
fileLocation += ":" + columnNumber; | ||
fileLocation += ':' + columnNumber; | ||
} | ||
@@ -83,5 +65,5 @@ } | ||
if (!fileLocation) { | ||
fileLocation = "unknown source"; | ||
fileLocation = 'unknown source'; | ||
} | ||
var line = ""; | ||
var line = ''; | ||
var fn = frame.getFunction(); | ||
@@ -94,13 +76,13 @@ var functionName = fn && fn.name; | ||
var methodName = frame.getMethodName(); | ||
line += frame.getTypeName() + "."; | ||
line += frame.getTypeName() + '.'; | ||
if (functionName) { | ||
line += functionName; | ||
if (methodName && (methodName != functionName)) { | ||
line += " [as " + methodName + "]"; | ||
line += ' [as ' + methodName + ']'; | ||
} | ||
} else { | ||
line += methodName || "<anonymous>"; | ||
line += methodName || '<anonymous>'; | ||
} | ||
} else if (isConstructor) { | ||
line += "new " + (functionName || "<anonymous>"); | ||
line += 'new ' + (functionName || '<anonymous>'); | ||
} else if (functionName) { | ||
@@ -113,3 +95,3 @@ line += functionName; | ||
if (addPrefix) { | ||
line += " (" + fileLocation + ")"; | ||
line += ' (' + fileLocation + ')'; | ||
} | ||
@@ -119,2 +101,17 @@ return line; | ||
module.exports = FormatStackTrace | ||
// To avoid V8 deopt | ||
function stringify(error, fn) { | ||
try { | ||
try { | ||
return fn(error) | ||
} catch(e) { | ||
return '<error: ' + e + '>' | ||
} | ||
} catch(ee) { | ||
// Any code that reaches this point is seriously nasty! | ||
return '<error>' | ||
} | ||
} | ||
module.exports = FormatStackTrace | ||
{ | ||
"name": "trycatch", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "An asynchronous domain-based exception handler with long stack traces for node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/CrabDude/trycatch", |
54689
943