Skip to content

Commit

Permalink
util: fix util.inspect with proxied function
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
starkwang authored and MylesBorins committed May 16, 2019
1 parent d44a93a commit 4e2ceba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}]`;
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 4e2ceba

Please sign in to comment.