diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 19eb165b780fe3..b23ae9438ff877 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -628,7 +628,10 @@ function formatRaw(ctx, value, recurseTimes) { } } else if (typeof value === 'function') { const type = constructor || tag || 'Function'; - const name = `${type}${value.name ? `: ${value.name}` : ''}`; + let name = `${type}`; + if (value.name && typeof value.name === 'string') { + name += `: ${value.name}`; + } if (keys.length === 0) return ctx.stylize(`[${name}]`, 'special'); base = `[${name}]`; diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index b3438a625240a2..adc0810722d553 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -87,3 +87,17 @@ assert.strictEqual(util.inspect(proxy8, opts), expected8); assert.strictEqual(util.inspect(proxy9, opts), expected9); assert.strictEqual(util.inspect(proxy8), '[Function: Date]'); assert.strictEqual(util.inspect(proxy9), '[Function: Date]'); + +const proxy10 = new Proxy(() => {}, {}); +const proxy11 = new Proxy(() => {}, { + get() { + return proxy11; + }, + apply() { + return proxy11; + } +}); +const expected10 = '[Function]'; +const expected11 = '[Function]'; +assert.strictEqual(util.inspect(proxy10), expected10); +assert.strictEqual(util.inspect(proxy11), expected11);