Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Utils module: assert() now optionally prints stack trace.

  • Loading branch information...
commit 13b2e96d4c3a56d09350f1bfd4f8ff1da9c3fffa 1 parent 5483b9e
@bard bard authored
Showing with 11 additions and 9 deletions.
  1. +11 −9 modules/utils.jsm
View
20 modules/utils.jsm
@@ -319,19 +319,21 @@ function assert(condition, callerArgs) {
}
var lineNumber = Components.stack.caller.lineNumber;
- var fileUrl = Components.stack.caller.filename;
+ var fileUrl = Components.stack.caller.filename.replace(/^.+> /, '');
var callerName = Components.stack.caller.name || '[anon]';
- var m = fileUrl.split(/ -> /);
- if(m[1])
- fileUrl = m[1];
var assertion = extractAssertionSource(getLine(fileUrl, lineNumber));
- throw new Error('Failed assertion: "' + assertion + '"\n' +
- 'In: ' + callerName + '(' + (callerArgs ?
- Array.slice(callerArgs).toSource().replace(/(^\[|\]$)/g, '') :
- '...') + ')\n' +
- 'At: ' + fileUrl + ':' + lineNumber);
+ var errorMessage =
+ 'Failed assertion: "' + assertion + '"\n' +
+ 'In: ' + callerName + '(' + (callerArgs ?
+ Array.slice(callerArgs).toSource().replace(/(^\[|\]$)/g, '') :
+ '...') + ')\n' +
+ 'At: ' + fileUrl + ':' + lineNumber;
+ if(arguments.callee.outputStackTrace)
+ errorMessage += '\nStack:\n' + new Error().stack;
+
+ throw new Error(errorMessage);
}
// INTERNALS
Please sign in to comment.
Something went wrong with that request. Please try again.