util: handle non-string return value in .inspect()

pull/24503/head
Alex Kocharin 2012-05-06 13:32:49 +04:00 committed by Ben Noordhuis
parent 7d2e68fdbd
commit e85927119c
2 changed files with 8 additions and 1 deletions

View File

@ -158,7 +158,7 @@ function formatValue(ctx, value, recurseTimes) {
value.inspect !== exports.inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
return value.inspect(recurseTimes);
return String(value.inspect(recurseTimes));
}
// Primitive types cannot have properties

View File

@ -97,6 +97,13 @@ assert.doesNotThrow(function() {
util.inspect(r);
});
// bug with user-supplied inspect function returns non-string
assert.doesNotThrow(function() {
util.inspect([{
inspect: function() { return 123; }
}]);
});
// GH-2225
var x = { inspect: util.inspect };
assert.ok(util.inspect(x).indexOf('inspect') != -1);