Skip to content
Permalink
Browse files

util: fix util.inspect with proxied function

PR-URL: #25244
Fixes: #25212
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
  • Loading branch information...
starkwang authored and targos committed Dec 28, 2018
1 parent fee8a11 commit 37976251b5f0ed16957de014c94324dd76fc4df1
Showing with 18 additions and 1 deletion.
  1. +4 −1 lib/internal/util/inspect.js
  2. +14 −0 test/parallel/test-util-inspect-proxy.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}]`;
@@ -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);

0 comments on commit 3797625

Please sign in to comment.
You can’t perform that action at this time.