Permalink
Browse files

util: don't throw when obj.inspect() returns a non-string value

Fixes #410.
  • Loading branch information...
1 parent 4cf0ce5 commit 4cf91eda96808f68b893e2813a41f5f32dbb5d83 @bnoordhuis committed Sep 6, 2011
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/util.js
  2. +8 −0 test/simple/test-util-inspect.js
View
@@ -144,7 +144,7 @@ function inspect(obj, showHidden, depth, colors) {
value !== exports &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
- return value.inspect(recurseTimes);
+ return '' + value.inspect(recurseTimes);
}
// Primitive types cannot have properties
@@ -33,3 +33,11 @@ var orig = util.inspect(d);
Date2.prototype.foo = 'bar';
var after = util.inspect(d);
assert.equal(orig, after);
+
+// .inspect() function that returns a non-string
+// should not trigger an exception
+// https://github.com/joyent/node/issues/410
+var o = {
+ inspect: function() {}
+};
+assert.equal(util.inspect(o), 'undefined');

1 comment on commit 4cf91ed

👍

Please sign in to comment.