Skip to content

Commit b8695e6

Browse files
Fixes #56. Improved formatting for anonymous functions in Chrome. Tests for Chrome and Firefox reworked with use of CapturedExceptions.
1 parent b932366 commit b8695e6

2 files changed

Lines changed: 220 additions & 160 deletions

File tree

stacktrace.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Johan Euphrosine <proppy@aminche.com> (2008)
55
// Oyvind Sean Kinsey http://kinsey.no/blog (2010)
66
// Victor Homyakov <victor-homyakov@users.sourceforge.net> (2010)
7-
/*global module, exports, define*/
7+
/*global module, exports, define, ActiveXObject*/
88
(function(global, factory) {
99
if (typeof exports === 'object') {
1010
// Node
@@ -143,10 +143,13 @@
143143
* @return Array<String> of function calls, files and line numbers
144144
*/
145145
chrome: function(e) {
146-
var stack = (e.stack + '\n').replace(/^\S[^\(]+?[\n$]/gm, '').
147-
replace(/^\s+(at eval )?at\s+/gm, '').
148-
replace(/^([^\(]+?)([\n$])/gm, '{anonymous}()@$1$2').
149-
replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm, '{anonymous}()@$1').split('\n');
146+
var stack = (e.stack + '\n')
147+
.replace(/^\S[^\(]+?[\n$]/gm, '') // remove first line
148+
.replace(/^\s+(at eval )?at\s+/gm, '') // remove 'at' and indentation
149+
.replace(/^([^\(]+?)([\n$])/gm, '{anonymous}() ($1)$2')
150+
.replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm, '{anonymous}() ($1)')
151+
.replace(/^(.+) \((.+)\)$/gm, '$1@$2')
152+
.split('\n');
150153
stack.pop();
151154
return stack;
152155
},
@@ -185,7 +188,9 @@
185188
* @return Array<String> of function calls, files and line numbers
186189
*/
187190
firefox: function(e) {
188-
return e.stack.replace(/(?:\n@:0)?\s+$/m, '').replace(/^[\(@]/gm, '{anonymous}()@').split('\n');
191+
return e.stack.replace(/(?:\n@:0)?\s+$/m, '')
192+
.replace(/^(?:\((\S*)\))?@/gm, '{anonymous}($1)@')
193+
.split('\n');
189194
},
190195

191196
opera11: function(e) {

0 commit comments

Comments
 (0)