Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: remove instance check on empty object #35754

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 !== '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change broke tests inspecting the prototype object, which is not an instance of its constructor.

if (protoProps !== undefined &&
(firstProto !== obj ||
!builtInObjects.has(descriptor.value.name))) {
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{}'.
{
[
Expand Down