GeezerVison is showing github.com — util: mark proxied objects as such when inspecting them · nodejs/node@dc97b50
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1180,7 +1180,13 @@ function formatValue(ctx, value, recurseTimes, typedArray) { | 1180 | 1180 | return ctx.stylize(`[Circular *${index}]`, 'special'); | 1181 | 1181 | } | 1182 | 1182 |
| 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; | 1184 | 1190 | } | 1185 | 1191 |
| 1186 | 1192 | function formatRaw(ctx, value, recurseTimes, typedArray) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1068,7 +1068,7 @@ test('Check proxies', () => { | 1068 | 1068 | assert.throws( | 1069 | 1069 | () => assert.deepStrictEqual(arrProxy, [1, 2, 3]), | 1070 | 1070 | { 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' } | 1072 | 1072 | ); | 1073 | 1073 | util.inspect.defaultOptions = tmp; | 1074 | 1074 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-repl.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -730,7 +730,7 @@ const errorTests = [ | 730 | 730 | }, | 731 | 731 | { | 732 | 732 | send: 'repl.writer.options.showProxy = false, new Proxy({x:42}, {});', | 733 | | - expect: '{ x: 42 }' | | 733 | + expect: 'Proxy({ x: 42 })' | 734 | 734 | }, | 735 | 735 |
| 736 | 736 | // Newline within template string maintains whitespace. | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect-proxy.js +15-6Lines changed: 15 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,7 +116,7 @@ const proxy3 = new Proxy(proxy2, proxy1); | 116 | 116 | const proxy4 = new Proxy(proxy1, proxy2); | 117 | 117 | const proxy5 = new Proxy(proxy3, proxy4); | 118 | 118 | const proxy6 = new Proxy(proxy5, proxy5); | 119 | | -const expected0 = '{}'; | | 119 | +const expected0 = 'Proxy({})'; | 120 | 120 | const expected1 = 'Proxy [ {}, {} ]'; | 121 | 121 | const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]'; | 122 | 122 | const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]'; | @@ -154,7 +154,7 @@ assert.strictEqual(util.inspect(proxy6), expected0); | 154 | 154 | const proxy7 = new Proxy([], []); | 155 | 155 | const expected7 = 'Proxy [ [], [] ]'; | 156 | 156 | assert.strictEqual(util.inspect(proxy7, opts), expected7); | 157 | | -assert.strictEqual(util.inspect(proxy7), '[]'); | | 157 | +assert.strictEqual(util.inspect(proxy7), 'Proxy([])'); | 158 | 158 |
| 159 | 159 | // Now we're just getting silly, right? | 160 | 160 | const proxy8 = new Proxy(Date, []); | @@ -163,8 +163,8 @@ const expected8 = 'Proxy [ [Function: Date], [] ]'; | 163 | 163 | const expected9 = 'Proxy [ [Function: Date], [Function: String] ]'; | 164 | 164 | assert.strictEqual(util.inspect(proxy8, opts), expected8); | 165 | 165 | 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])'); | 168 | 168 |
| 169 | 169 | const proxy10 = new Proxy(() => {}, {}); | 170 | 170 | const proxy11 = new Proxy(() => {}, { | @@ -175,7 +175,16 @@ const proxy11 = new Proxy(() => {}, { | 175 | 175 | return proxy11; | 176 | 176 | } | 177 | 177 | }); | 178 | | -const expected10 = '[Function (anonymous)]'; | 179 | | -const expected11 = '[Function (anonymous)]'; | | 178 | +const expected10 = 'Proxy([Function (anonymous)])'; | | 179 | +const expected11 = 'Proxy([Function (anonymous)])'; | 180 | 180 | assert.strictEqual(util.inspect(proxy10), expected10); | 181 | 181 | 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 ])'); |
|