diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 7f9bb0c2beb02e..ab396116e8d59e 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -592,7 +592,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 d7fb28ddc77282..9fe748dec3167f 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -85,3 +85,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);