diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index d78a4e97d218a6..efb0483d0b96b2 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -579,7 +579,7 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) { addPrototypeProperties( ctx, tmp, firstProto || tmp, recurseTimes, protoProps); } - return descriptor.value.name; + return String(descriptor.value.name); } obj = ObjectGetPrototypeOf(obj); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 43913c3ab4c9da..45bf8d70030bed 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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; @@ -1409,6 +1412,8 @@ if (typeof Symbol !== 'undefined') { "MapSubclass(1) [Map] { 'foo' => 42 }"); assert.strictEqual(util.inspect(new PromiseSubclass(() => {})), 'PromiseSubclass [Promise] { }'); + assert.strictEqual(util.inspect(new SymbolNameClass()), + 'Symbol(name) {}'); assert.strictEqual( util.inspect({ a: { b: new ArraySubclass([1, [2], 3]) } }, { depth: 1 }), '{ a: { b: [ArraySubclass] } }'