From 97b631ac4fb4410b78a069b46bc0eedd9eb25b61 Mon Sep 17 00:00:00 2001 From: cola119 Date: Wed, 20 Apr 2022 10:48:52 +0900 Subject: [PATCH 1/2] util: fix TypeError of symbol in template literals --- lib/internal/util/inspect.js | 3 ++- test/parallel/test-util-inspect.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index d78a4e97d218a6..d477bf37b6c98e 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -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; } 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] } }' From a562ec3fb03f40e7135eca87568ca4595955c356 Mon Sep 17 00:00:00 2001 From: cola119 Date: Sat, 23 Apr 2022 10:10:25 +0900 Subject: [PATCH 2/2] fixup! util: fix TypeError of symbol in template literals --- lib/internal/util/inspect.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index d477bf37b6c98e..efb0483d0b96b2 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -579,8 +579,7 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) { addPrototypeProperties( ctx, tmp, firstProto || tmp, recurseTimes, protoProps); } - const name = descriptor.value.name; - return typeof name === 'symbol' ? SymbolPrototypeToString(name) : name; + return String(descriptor.value.name); } obj = ObjectGetPrototypeOf(obj);