Skip to content

Commit 7dc2808

Browse files
author
homyakov
committed
Tests reformatted; methods renamed
1 parent 18251fc commit 7dc2808

2 files changed

Lines changed: 622 additions & 519 deletions

File tree

‎stacktrace.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function printStackTrace(options) {
5555
options = options || {guess: true};
5656
var ex = options.e || null, guess = !!options.guess;
5757
var p = new printStackTrace.implementation(), result = p.run(ex);
58-
return (guess) ? p.guessFunctions(result) : result;
58+
return (guess) ? p.guessAnonymousFunctions(result) : result;
5959
}
6060

6161
printStackTrace.implementation = function() {
@@ -91,7 +91,7 @@ printStackTrace.implementation.prototype = {
9191
mode: function(e) {
9292
if (e['arguments'] && e.stack) {
9393
return (this._mode = 'chrome');
94-
} else if (typeof window !== 'undefined' && window.opera) {
94+
} else if (e.message && typeof window !== 'undefined' && window.opera) {
9595
return (this._mode = e.stacktrace ? 'opera10' : 'opera');
9696
} else if (e.stack) {
9797
return (this._mode = 'firefox');
@@ -213,6 +213,7 @@ printStackTrace.implementation.prototype = {
213213
* @return {Array} of Strings with stringified arguments
214214
*/
215215
stringifyArguments: function(args) {
216+
var slice = Array.prototype.slice;
216217
for (var i = 0; i < args.length; ++i) {
217218
var arg = args[i];
218219
if (arg === undefined) {
@@ -224,7 +225,7 @@ printStackTrace.implementation.prototype = {
224225
if (arg.length < 3) {
225226
args[i] = '[' + this.stringifyArguments(arg) + ']';
226227
} else {
227-
args[i] = '[' + this.stringifyArguments(Array.prototype.slice.call(arg, 0, 1)) + '...' + this.stringifyArguments(Array.prototype.slice.call(arg, -1)) + ']';
228+
args[i] = '[' + this.stringifyArguments(slice.call(arg, 0, 1)) + '...' + this.stringifyArguments(slice.call(arg, -1)) + ']';
228229
}
229230
} else if (arg.constructor === Object) {
230231
args[i] = '#object';
@@ -306,32 +307,33 @@ printStackTrace.implementation.prototype = {
306307
return this.sourceCache[url];
307308
},
308309

309-
guessFunctions: function(stack) {
310+
guessAnonymousFunctions: function(stack) {
310311
for (var i = 0; i < stack.length; ++i) {
311312
var reStack = /\{anonymous\}\(.*\)@(\w+:\/\/([\-\w\.]+)+(:\d+)?[^:]+):(\d+):?(\d+)?/;
312313
var frame = stack[i], m = reStack.exec(frame);
313314
if (m) {
314315
var file = m[1], lineno = m[4], charno = m[7] || 0; //m[7] is character position in Chrome
315316
if (file && this.isSameDomain(file) && lineno) {
316-
var functionName = this.guessFunctionName(file, lineno, charno);
317+
var functionName = this.guessAnonymousFunction(file, lineno, charno);
317318
stack[i] = frame.replace('{anonymous}', functionName);
318319
}
319320
}
320321
}
321322
return stack;
322323
},
323324

324-
guessFunctionName: function(url, lineNo, charNo) {
325+
guessAnonymousFunction: function(url, lineNo, charNo) {
325326
var ret;
326327
try {
327-
ret = this.guessFunctionNameFromLines(this.getSource(url), lineNo);
328+
ret = this.findFunctionName(this.getSource(url), lineNo);
328329
} catch (e) {
329330
ret = 'getSource failed with url: ' + url + ', exception: ' + e.toString();
330331
}
331332
return ret;
332333
},
333334

334-
guessFunctionNameFromLines: function(source, lineNo) {
335+
findFunctionName: function(source, lineNo) {
336+
// TODO use stringifyArguments
335337
var reFunctionArgNames = /function ([^(]*)\(([^)]*)\)/;
336338
var reGuessFunction = /['"]?([0-9A-Za-z_]+)['"]?\s*[:=]\s*(function|eval|new Function)/;
337339
// Walk backwards in the source lines until we find

0 commit comments

Comments
 (0)