Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3797625

Browse filesBrowse files
starkwangtargos
authored andcommitted
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>
1 parent fee8a11 commit 3797625
Copy full SHA for 3797625

File tree

Expand file treeCollapse file tree

2 files changed

+18
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+4-1Lines changed: 4 additions & 1 deletion
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}]`;
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect-proxy.js
+14Lines changed: 14 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.