Skip to content

Commit 6c7c77e

Browse files
starkwangaddaleax
authored andcommitted
util: fix util.inspect with proxied function
PR-URL: #25244 Fixes: #25212 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]>
1 parent ad10cc5 commit 6c7c77e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/internal/util/inspect.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,10 @@ function formatRaw(ctx, value, recurseTimes) {
628628
}
629629
} else if (typeof value === 'function') {
630630
const type = constructor || tag || 'Function';
631-
const name = `${type}${value.name ? `: ${value.name}` : ''}`;
631+
let name = `${type}`;
632+
if (value.name && typeof value.name === 'string') {
633+
name += `: ${value.name}`;
634+
}
632635
if (keys.length === 0)
633636
return ctx.stylize(`[${name}]`, 'special');
634637
base = `[${name}]`;

test/parallel/test-util-inspect-proxy.js

+14
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,17 @@ assert.strictEqual(util.inspect(proxy8, opts), expected8);
8787
assert.strictEqual(util.inspect(proxy9, opts), expected9);
8888
assert.strictEqual(util.inspect(proxy8), '[Function: Date]');
8989
assert.strictEqual(util.inspect(proxy9), '[Function: Date]');
90+
91+
const proxy10 = new Proxy(() => {}, {});
92+
const proxy11 = new Proxy(() => {}, {
93+
get() {
94+
return proxy11;
95+
},
96+
apply() {
97+
return proxy11;
98+
}
99+
});
100+
const expected10 = '[Function]';
101+
const expected11 = '[Function]';
102+
assert.strictEqual(util.inspect(proxy10), expected10);
103+
assert.strictEqual(util.inspect(proxy11), expected11);

0 commit comments

Comments
 (0)