Skip to content

Commit

Permalink
util: fix TypeError of symbol in template literals
Browse files Browse the repository at this point in the history
PR-URL: #42790
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
cola119 authored and panva committed Jun 17, 2022
1 parent 8c4cf96 commit 027c288
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,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);
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

0 comments on commit 027c288

Please sign in to comment.