Skip to content

Commit 6932162

Browse files
committed
util: inspect: do not crash on Symbol function names
See #56570
1 parent 4c27393 commit 6932162

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/internal/util/inspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ function getFunctionBase(value, constructor, tag) {
12501250
if (value.name === '') {
12511251
base += ' (anonymous)';
12521252
} else {
1253-
base += `: ${value.name}`;
1253+
base += `: ${typeof value.name === 'symbol' ? inspect(value.name) : value.name}`;
12541254
}
12551255
base += ']';
12561256
if (constructor !== type && constructor !== null) {

test/parallel/test-util-inspect.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,3 +3426,13 @@ assert.strictEqual(
34263426
Object.defineProperty(BuiltinPrototype, 'constructor', desc);
34273427
}
34283428
}
3429+
3430+
{
3431+
function f() {}
3432+
Object.defineProperty(f, 'name', { value: Symbol('f') });
3433+
3434+
assert.strictEqual(
3435+
util.inspect(f),
3436+
'[Function: Symbol(f)]',
3437+
);
3438+
}

0 commit comments

Comments
 (0)