Skip to content

Commit 64847e3

Browse files
starkwangBethGriggs
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 c04c487 commit 64847e3

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
@@ -592,7 +592,10 @@ function formatRaw(ctx, value, recurseTimes) {
592592
}
593593
} else if (typeof value === 'function') {
594594
const type = constructor || tag || 'Function';
595-
const name = `${type}${value.name ? `: ${value.name}` : ''}`;
595+
let name = `${type}`;
596+
if (value.name && typeof value.name === 'string') {
597+
name += `: ${value.name}`;
598+
}
596599
if (keys.length === 0)
597600
return ctx.stylize(`[${name}]`, 'special');
598601
base = `[${name}]`;

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

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

0 commit comments

Comments
 (0)