Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: fix TypeError when console.log a static property name in class #42790

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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