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 dc97b50

Browse filesBrowse files
authored
util: mark proxied objects as such when inspecting them
Fixes: #60964 PR-URL: #61029 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent e5b6f89 commit dc97b50
Copy full SHA for dc97b50

4 files changed

+24-9Lines changed: 24 additions & 9 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,13 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
11801180
return ctx.stylize(`[Circular *${index}]`, 'special');
11811181
}
11821182

1183-
return formatRaw(ctx, value, recurseTimes, typedArray);
1183+
const formatted = formatRaw(ctx, value, recurseTimes, typedArray);
1184+
1185+
if (proxy !== undefined) {
1186+
return `${ctx.stylize('Proxy(', 'special')}${formatted}${ctx.stylize(')', 'special')}`;
1187+
}
1188+
1189+
return formatted;
11841190
}
11851191

11861192
function formatRaw(ctx, value, recurseTimes, typedArray) {
Collapse file

‎test/parallel/test-assert-deep.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ test('Check proxies', () => {
10681068
assert.throws(
10691069
() => assert.deepStrictEqual(arrProxy, [1, 2, 3]),
10701070
{ message: `${defaultMsgStartFull}\n\n` +
1071-
' [\n 1,\n 2,\n- 3\n ]\n' }
1071+
'+ Proxy([\n- [\n 1,\n 2,\n+ ])\n- 3\n- ]\n' }
10721072
);
10731073
util.inspect.defaultOptions = tmp;
10741074

Collapse file

‎test/parallel/test-repl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ const errorTests = [
730730
},
731731
{
732732
send: 'repl.writer.options.showProxy = false, new Proxy({x:42}, {});',
733-
expect: '{ x: 42 }'
733+
expect: 'Proxy({ x: 42 })'
734734
},
735735

736736
// Newline within template string maintains whitespace.
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect-proxy.js
+15-6Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const proxy3 = new Proxy(proxy2, proxy1);
116116
const proxy4 = new Proxy(proxy1, proxy2);
117117
const proxy5 = new Proxy(proxy3, proxy4);
118118
const proxy6 = new Proxy(proxy5, proxy5);
119-
const expected0 = '{}';
119+
const expected0 = 'Proxy({})';
120120
const expected1 = 'Proxy [ {}, {} ]';
121121
const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]';
122122
const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
@@ -154,7 +154,7 @@ assert.strictEqual(util.inspect(proxy6), expected0);
154154
const proxy7 = new Proxy([], []);
155155
const expected7 = 'Proxy [ [], [] ]';
156156
assert.strictEqual(util.inspect(proxy7, opts), expected7);
157-
assert.strictEqual(util.inspect(proxy7), '[]');
157+
assert.strictEqual(util.inspect(proxy7), 'Proxy([])');
158158

159159
// Now we're just getting silly, right?
160160
const proxy8 = new Proxy(Date, []);
@@ -163,8 +163,8 @@ const expected8 = 'Proxy [ [Function: Date], [] ]';
163163
const expected9 = 'Proxy [ [Function: Date], [Function: String] ]';
164164
assert.strictEqual(util.inspect(proxy8, opts), expected8);
165165
assert.strictEqual(util.inspect(proxy9, opts), expected9);
166-
assert.strictEqual(util.inspect(proxy8), '[Function: Date]');
167-
assert.strictEqual(util.inspect(proxy9), '[Function: Date]');
166+
assert.strictEqual(util.inspect(proxy8), 'Proxy([Function: Date])');
167+
assert.strictEqual(util.inspect(proxy9), 'Proxy([Function: Date])');
168168

169169
const proxy10 = new Proxy(() => {}, {});
170170
const proxy11 = new Proxy(() => {}, {
@@ -175,7 +175,16 @@ const proxy11 = new Proxy(() => {}, {
175175
return proxy11;
176176
}
177177
});
178-
const expected10 = '[Function (anonymous)]';
179-
const expected11 = '[Function (anonymous)]';
178+
const expected10 = 'Proxy([Function (anonymous)])';
179+
const expected11 = 'Proxy([Function (anonymous)])';
180180
assert.strictEqual(util.inspect(proxy10), expected10);
181181
assert.strictEqual(util.inspect(proxy11), expected11);
182+
183+
const proxy12 = new Proxy([1, 2, 3], proxy5);
184+
assert.strictEqual(
185+
util.inspect(proxy12, { colors: true, breakLength: 1 }),
186+
'\x1B[36mProxy(\x1B[39m' +
187+
'[\n \x1B[33m1\x1B[39m,\n \x1B[33m2\x1B[39m,\n \x1B[33m3\x1B[39m\n]\x1B[36m' +
188+
')\x1B[39m'
189+
);
190+
assert.strictEqual(util.format('%s', proxy12), 'Proxy([ 1, 2, 3 ])');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.