Skip to content

Commit

Permalink
util: inspect: do not crash on Symbol function names
Browse files Browse the repository at this point in the history
See #56570
  • Loading branch information
ljharb committed Jan 12, 2025
1 parent 4c27393 commit 6932162
Show file tree
Hide file tree
Showing 2 changed files with 11 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 @@ -1250,7 +1250,7 @@ function getFunctionBase(value, constructor, tag) {
if (value.name === '') {
base += ' (anonymous)';
} else {
base += `: ${value.name}`;
base += `: ${typeof value.name === 'symbol' ? inspect(value.name) : value.name}`;
}
base += ']';
if (constructor !== type && constructor !== null) {
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3426,3 +3426,13 @@ assert.strictEqual(
Object.defineProperty(BuiltinPrototype, 'constructor', desc);
}
}

{
function f() {}
Object.defineProperty(f, 'name', { value: Symbol('f') });

assert.strictEqual(
util.inspect(f),
'[Function: Symbol(f)]',
);
}

0 comments on commit 6932162

Please sign in to comment.