Browse Source

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

v0.9.1-release
Alex Kocharin 13 years ago
committed by Ben Noordhuis
parent
commit
e85927119c
  1. 2
      lib/util.js
  2. 7
      test/simple/test-util-inspect.js

2
lib/util.js

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

7
test/simple/test-util-inspect.js

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

Loading…
Cancel
Save