Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) {
addPrototypeProperties(
ctx, tmp, firstProto || tmp, recurseTimes, protoProps);
}
return descriptor.value.name;
const name = descriptor.value.name;
return typeof name === 'symbol' ? SymbolPrototypeToString(name) : name;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const name = descriptor.value.name;
return typeof name === 'symbol' ? SymbolPrototypeToString(name) : name;
return String(descriptor.value.name);

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you. That makes sense!

}

obj = ObjectGetPrototypeOf(obj);
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,9 @@ if (typeof Symbol !== 'undefined') {
class SetSubclass extends Set {}
class MapSubclass extends Map {}
class PromiseSubclass extends Promise {}
class SymbolNameClass {
static name = Symbol('name');
}

const x = new ObjectSubclass();
x.foo = 42;
Expand All @@ -1409,6 +1412,8 @@ if (typeof Symbol !== 'undefined') {
"MapSubclass(1) [Map] { 'foo' => 42 }");
assert.strictEqual(util.inspect(new PromiseSubclass(() => {})),
'PromiseSubclass [Promise] { <pending> }');
assert.strictEqual(util.inspect(new SymbolNameClass()),
'Symbol(name) {}');
assert.strictEqual(
util.inspect({ a: { b: new ArraySubclass([1, [2], 3]) } }, { depth: 1 }),
'{ a: { b: [ArraySubclass] } }'
Expand Down