Skip to content

Commit 48ff069

Browse files
committed
stringifyArguments handles undefined and null properly
1 parent 5cfdb6c commit 48ff069

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

stacktrace.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,24 @@ printStackTrace.implementation.prototype = {
154154
stringifyArguments: function(args) {
155155
for (var i = 0; i < args.length; ++i) {
156156
var arg = args[i];
157-
if (!arg || !arg.constructor) {
158-
return;
159-
}
160-
if (arg.constructor === Array) {
161-
if (arg.length < 3) {
162-
args[i] = '[' + this.stringifyArguments(arg) + ']';
163-
} else {
164-
args[i] = '[' + this.stringifyArguments(Array.prototype.slice.call(arg, 0, 1)) + '...' + this.stringifyArguments(Array.prototype.slice.call(arg, -1)) + ']';
157+
if (arg === undefined) {
158+
args[i] = 'undefined';
159+
} else if (arg === null) {
160+
args[i] = 'null';
161+
} else if (arg.constructor) {
162+
if (arg.constructor === Array) {
163+
if (arg.length < 3) {
164+
args[i] = '[' + this.stringifyArguments(arg) + ']';
165+
} else {
166+
args[i] = '[' + this.stringifyArguments(Array.prototype.slice.call(arg, 0, 1)) + '...' + this.stringifyArguments(Array.prototype.slice.call(arg, -1)) + ']';
167+
}
168+
} else if (arg.constructor === Object) {
169+
args[i] = '#object';
170+
} else if (arg.constructor === Function) {
171+
args[i] = '#function';
172+
} else if (arg.constructor === String) {
173+
args[i] = '"' + arg + '"';
165174
}
166-
} else if (arg.constructor === Object) {
167-
args[i] = '#object';
168-
} else if (arg.constructor === Function) {
169-
args[i] = '#function';
170-
} else if (arg.constructor === String) {
171-
args[i] = '"' + arg + '"';
172175
}
173176
}
174177
return args.join(',');

test-stacktrace.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ test("recursion other", function() {
208208

209209
test("stringify", function() {
210210
expect(5);
211-
equals(printStackTrace.implementation.prototype.stringifyArguments(["a", 1, {}, function() {}]), '"a",1,#object,#function');
212-
equals(printStackTrace.implementation.prototype.stringifyArguments([1, 2, 3]), '1,2,3');
213-
equals(printStackTrace.implementation.prototype.stringifyArguments([['a', 'b']]), '["a","b"]');
211+
equals(printStackTrace.implementation.prototype.stringifyArguments(["a", 1, {}, function() {}, undefined]), '"a",1,#object,#function,undefined');
212+
equals(printStackTrace.implementation.prototype.stringifyArguments([0, 1, 2, 3]), '0,1,2,3');
213+
equals(printStackTrace.implementation.prototype.stringifyArguments([['a', null]]), '["a",null]');
214214
equals(printStackTrace.implementation.prototype.stringifyArguments([[2, 4, 6, 8, 10, 12, 14]]), '[2...14]');
215215
equals(printStackTrace.implementation.prototype.stringifyArguments([]), '');
216216
});

0 commit comments

Comments
 (0)