Skip to content

Commit

Permalink
Fixes #56. Improved formatting for anonymous functions in Chrome. Tes…
Browse files Browse the repository at this point in the history
…ts for Chrome and Firefox reworked with use of `CapturedExceptions`.
  • Loading branch information
victor-homyakov committed Jul 31, 2013
1 parent b932366 commit b8695e6
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 160 deletions.
17 changes: 11 additions & 6 deletions stacktrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Johan Euphrosine <proppy@aminche.com> (2008)
// Oyvind Sean Kinsey http://kinsey.no/blog (2010)
// Victor Homyakov <victor-homyakov@users.sourceforge.net> (2010)
/*global module, exports, define*/
/*global module, exports, define, ActiveXObject*/
(function(global, factory) {
if (typeof exports === 'object') {
// Node
Expand Down Expand Up @@ -143,10 +143,13 @@
* @return Array<String> of function calls, files and line numbers
*/
chrome: function(e) {
var stack = (e.stack + '\n').replace(/^\S[^\(]+?[\n$]/gm, '').
replace(/^\s+(at eval )?at\s+/gm, '').
replace(/^([^\(]+?)([\n$])/gm, '{anonymous}()@$1$2').
replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm, '{anonymous}()@$1').split('\n');
var stack = (e.stack + '\n')
.replace(/^\S[^\(]+?[\n$]/gm, '') // remove first line
.replace(/^\s+(at eval )?at\s+/gm, '') // remove 'at' and indentation
.replace(/^([^\(]+?)([\n$])/gm, '{anonymous}() ($1)$2')
.replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm, '{anonymous}() ($1)')
.replace(/^(.+) \((.+)\)$/gm, '$1@$2')
.split('\n');
stack.pop();
return stack;
},
Expand Down Expand Up @@ -185,7 +188,9 @@
* @return Array<String> of function calls, files and line numbers
*/
firefox: function(e) {
return e.stack.replace(/(?:\n@:0)?\s+$/m, '').replace(/^[\(@]/gm, '{anonymous}()@').split('\n');
return e.stack.replace(/(?:\n@:0)?\s+$/m, '')
.replace(/^(?:\((\S*)\))?@/gm, '{anonymous}($1)@')
.split('\n');
},

opera11: function(e) {
Expand Down
Loading

0 comments on commit b8695e6

Please sign in to comment.