From 4cf91eda96808f68b893e2813a41f5f32dbb5d83 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 6 Sep 2011 22:55:56 +0200 Subject: [PATCH] util: don't throw when obj.inspect() returns a non-string value Fixes #410. --- lib/util.js | 2 +- test/simple/test-util-inspect.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index f47e39fddda..3161f7e3be2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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 diff --git a/test/simple/test-util-inspect.js b/test/simple/test-util-inspect.js index 717182f88de..b929caec5f2 100644 --- a/test/simple/test-util-inspect.js +++ b/test/simple/test-util-inspect.js @@ -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'); \ No newline at end of file