Skip to content

Commit a1f581a

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 038decf commit a1f581a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎lib/internal/util/inspect.js‎

Lines changed: 1 addition & 1 deletion
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-
returndescriptor.value.name;
584+
returnString(descriptor.value.name);
585585
}
586586

587587
obj=ObjectGetPrototypeOf(obj);

‎test/parallel/test-util-inspect.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,9 @@ if (typeof Symbol !== 'undefined'){
13961396
classSetSubclassextendsSet{}
13971397
classMapSubclassextendsMap{}
13981398
classPromiseSubclassextendsPromise{}
1399+
classSymbolNameClass{
1400+
staticname=Symbol('name');
1401+
}
13991402

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

0 commit comments

Comments
(0)