Skip to content

Commit

Permalink
Check for a couple of edge cases on the inspect hook.
Browse files Browse the repository at this point in the history
Don't treat sys.inspect special, same with prototype objects.
  • Loading branch information
creationix authored and ry committed May 28, 2010
1 parent 7f5320b commit b480184
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ exports.inspect = function (obj, showHidden, depth) {
var seen = [];
function format(value, recurseTimes) {
// Provide a hook for user-specified inspect functions.
if (value && typeof value.inspect === 'function') {
// Check that value is an object with an inspect function on it
if (value && typeof value.inspect === 'function' &&
// Filter out the sys module, it's inspect function is special
value !== exports &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
return value.inspect(recurseTimes);
}

Expand Down

0 comments on commit b480184

Please sign in to comment.