Skip to content

Commit

Permalink
util: don't throw when obj.inspect() returns a non-string value
Browse files Browse the repository at this point in the history
Fixes nodejs#410.
  • Loading branch information
bnoordhuis committed Sep 6, 2011
1 parent 4cf0ce5 commit 4cf91ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util.js
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/simple/test-util-inspect.js
Expand Up @@ -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

@TooTallNate
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.