Skip to content

Commit 26e706f

Browse files
cola119targos
authored andcommitted
util: fix TypeError of symbol in template literals
PR-URL: #42790 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 6062c92 commit 26e706f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/internal/util/inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) {
581581
addPrototypeProperties(
582582
ctx, tmp, firstProto || tmp, recurseTimes, protoProps);
583583
}
584-
return descriptor.value.name;
584+
return String(descriptor.value.name);
585585
}
586586

587587
obj = ObjectGetPrototypeOf(obj);

test/parallel/test-util-inspect.js

+5
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,9 @@ if (typeof Symbol !== 'undefined') {
13961396
class SetSubclass extends Set {}
13971397
class MapSubclass extends Map {}
13981398
class PromiseSubclass extends Promise {}
1399+
class SymbolNameClass {
1400+
static name = Symbol('name');
1401+
}
13991402

14001403
const x = new ObjectSubclass();
14011404
x.foo = 42;
@@ -1409,6 +1412,8 @@ if (typeof Symbol !== 'undefined') {
14091412
"MapSubclass(1) [Map] { 'foo' => 42 }");
14101413
assert.strictEqual(util.inspect(new PromiseSubclass(() => {})),
14111414
'PromiseSubclass [Promise] { <pending> }');
1415+
assert.strictEqual(util.inspect(new SymbolNameClass()),
1416+
'Symbol(name) {}');
14121417
assert.strictEqual(
14131418
util.inspect({ a: { b: new ArraySubclass([1, [2], 3]) } }, { depth: 1 }),
14141419
'{ a: { b: [ArraySubclass] } }'

0 commit comments

Comments
 (0)