diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index e6787760fea392..79e9c8790103d1 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -541,8 +541,7 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) { const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor'); if (descriptor !== undefined && typeof descriptor.value === 'function' && - descriptor.value.name !== '' && - tmp instanceof descriptor.value) { + descriptor.value.name !== '') { if (protoProps !== undefined && (firstProto !== obj || !builtInObjects.has(descriptor.value.name))) { diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 70f2ff64328b64..8d0e87eb00901e 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -623,6 +623,18 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); ); } +// Test for property descriptors on null/empty object +{ + function prototype() {} + prototype.prototype = null; + const obj = {}; + obj.constructor = prototype; + assert.strictEqual( + util.inspect(obj, false), + 'prototype { constructor: [Function: prototype] }' + ); +} + // Exceptions should print the error message, not '{}'. { [