mirror of https://github.com/nodejs/node.git
util: handle non-string return value in .inspect()
parent
7d2e68fdbd
commit
e85927119c
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue