From 6932162f2475811131638755bcdb3a9483f9df85 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 12 Jan 2025 12:48:44 -0800 Subject: [PATCH] util: inspect: do not crash on Symbol function names See #56570 --- lib/internal/util/inspect.js | 2 +- test/parallel/test-util-inspect.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index cc76bbeed9bc11..6d17c7dd353cbc 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -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) { diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 94064d9491894c..9549bba2737a4f 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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)]', + ); +}