Skip to content

Commit fe9d847

Browse files
committed
Minor code cleanup and additional documentation
1 parent 34825ec commit fe9d847

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

stacktrace.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Luke Smith http://lucassmith.name/ (2008)
33
// Loic Dachary <loic@dachary.org> (2008)
44
// Johan Euphrosine <proppy@aminche.com> (2008)
5-
// Øyvind Sean Kinsey http://kinsey.no/blog
5+
// Øyvind Sean Kinsey http://kinsey.no/blog (2010)
66
//
77
// Information and discussions
88
// http://jspoker.pokersource.info/skin/test-printstacktrace.html
@@ -68,8 +68,7 @@ printStackTrace.implementation.prototype = {
6868
var mode = this._mode || this.mode();
6969
if (mode === 'other') {
7070
return this.other(arguments.callee);
71-
}
72-
else {
71+
} else {
7372
ex = ex ||
7473
(function() {
7574
try {
@@ -104,19 +103,19 @@ printStackTrace.implementation.prototype = {
104103
replace(/^[^\(]+?[\n$]/gm, '').
105104
replace(/^\s+at\s+/gm, '').
106105
replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@').
107-
split("\n");
106+
split('\n');
108107
},
109108

110109
firefox: function(e) {
111110
return e.stack.replace(/^.*?\n/, '').
112111
replace(/(?:\n@:0)?\s+$/m, '').
113112
replace(/^\(/gm, '{anonymous}(').
114-
split("\n");
113+
split('\n');
115114
},
116115

117116
// Opera 7.x and 8.x only!
118117
opera: function(e) {
119-
var lines = e.message.split("\n"), ANON = '{anonymous}',
118+
var lines = e.message.split('\n'), ANON = '{anonymous}',
120119
lineRE = /Line\s+(\d+).*?script\s+(http\S+)(?:.*?in\s+function\s+(\S+))?/i, i, j, len;
121120

122121
for (i = 4, j = 0, len = lines.length; i < len; i += 2) {
@@ -133,7 +132,7 @@ printStackTrace.implementation.prototype = {
133132

134133
// Safari, Opera 9+, IE, and others
135134
other: function(curr) {
136-
var ANON = "{anonymous}", fnRE = /function\s*([\w\-$]+)?\s*\(/i, stack = [], j = 0, fn, args;
135+
var ANON = '{anonymous}', fnRE = /function\s*([\w\-$]+)?\s*\(/i, stack = [], j = 0, fn, args;
137136

138137
var maxStackSize = 10;
139138
while (curr && stack.length < maxStackSize) {
@@ -143,14 +142,17 @@ printStackTrace.implementation.prototype = {
143142

144143
//Opera bug: if curr.caller does not exist, Opera returns curr (WTF)
145144
if (curr === curr.caller && window.opera) {
146-
//TODO: check for same arguments if possible
145+
//TODO: check for same arguments if possible
147146
break;
148147
}
149148
curr = curr.caller;
150149
}
151150
return stack;
152151
},
153152

153+
/**
154+
* @return given arguments array as a String, subsituting type names for non-string types.
155+
*/
154156
stringifyArguments: function(args) {
155157
for (var i = 0; i < args.length; ++i) {
156158
var argument = args[i];
@@ -167,28 +169,31 @@ printStackTrace.implementation.prototype = {
167169

168170
sourceCache: {},
169171

172+
/**
173+
* @return the text from a given URL.
174+
*/
170175
ajax: function(url) {
171176
var req = this.createXMLHTTPObject();
172177
if (!req) {
173178
return;
174179
}
175180
req.open('GET', url, false);
176-
req.setRequestHeader("User-Agent", "XMLHTTP/1.0");
181+
req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
177182
req.send('');
178183
return req.responseText;
179184
},
180185

181186
createXMLHTTPObject: function() {
182-
// Try XHR methods in order and store XHR factory
187+
// Try XHR methods in order and store XHR factory
183188
var xmlhttp, XMLHttpFactories = [
184189
function() {
185190
return new XMLHttpRequest();
186191
}, function() {
187-
return new ActiveXObject("Msxml2.XMLHTTP");
192+
return new ActiveXObject('Msxml2.XMLHTTP');
188193
}, function() {
189-
return new ActiveXObject("Msxml3.XMLHTTP");
194+
return new ActiveXObject('Msxml3.XMLHTTP');
190195
}, function() {
191-
return new ActiveXObject("Microsoft.XMLHTTP");
196+
return new ActiveXObject('Microsoft.XMLHTTP');
192197
}
193198
];
194199
for (var i = 0; i < XMLHttpFactories.length; i++) {
@@ -203,7 +208,7 @@ printStackTrace.implementation.prototype = {
203208

204209
getSource: function(url) {
205210
if (!(url in this.sourceCache)) {
206-
this.sourceCache[url] = this.ajax(url).split("\n");
211+
this.sourceCache[url] = this.ajax(url).split('\n');
207212
}
208213
return this.sourceCache[url];
209214
},
@@ -241,17 +246,16 @@ printStackTrace.implementation.prototype = {
241246
line = source[lineNo - i] + line;
242247
if (line !== undefined) {
243248
var m = reGuessFunction.exec(line);
244-
if (m) {
245-
return m[1];
246-
}
247-
else {
248-
m = reFunctionArgNames.exec(line);
249-
}
250249
if (m && m[1]) {
251250
return m[1];
251+
} else {
252+
m = reFunctionArgNames.exec(line);
253+
if (m && m[1]) {
254+
return m[1];
255+
}
252256
}
253257
}
254258
}
255-
return "(?)";
259+
return '(?)';
256260
}
257261
};

0 commit comments

Comments
 (0)