Skip to content

Commit 29bc735

Browse files
TrottMylesBorins
authored andcommitted
console: fix console.table() display edge case
If the properties are not specified in `console.table()`, then we should make a best effort to determine them rather than put all values into a "Values" column. PR-URL: #20323 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent be34388 commit 29bc735

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

โ€Žlib/console.jsโ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,7 @@ Console.prototype.table = function(tabularData, properties) {
363363
tabularData = previewSetIterator(tabularData);
364364

365365
const setlike = setIter || isSet(tabularData);
366-
if (setlike ||
367-
(properties === undefined &&
368-
(isArray(tabularData) || isTypedArray(tabularData)))) {
366+
if (setlike) {
369367
const values = [];
370368
let length = 0;
371369
for (const v of tabularData) {

โ€Žtest/parallel/test-console-table.jsโ€Ž

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ test([1, 2, 3], `
4141
`);
4242

4343
test([Symbol(), 5, [10]], `
44-
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
45-
โ”‚ (index) โ”‚ Values โ”‚
46-
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
47-
โ”‚ 0 โ”‚ Symbol() โ”‚
48-
โ”‚ 1 โ”‚ 5 โ”‚
49-
โ”‚ 2 โ”‚ [ 10 ] โ”‚
50-
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
44+
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
45+
โ”‚ (index) โ”‚ 0 โ”‚ Values โ”‚
46+
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
47+
โ”‚ 0 โ”‚ โ”‚ Symbol() โ”‚
48+
โ”‚ 1 โ”‚ โ”‚ 5 โ”‚
49+
โ”‚ 2 โ”‚ 10 โ”‚ โ”‚
50+
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
5151
`);
5252

5353
test([undefined, 5], `
@@ -182,10 +182,10 @@ test({ a: undefined }, ['x'], `
182182
`);
183183

184184
test([], `
185-
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
186-
โ”‚ (index) โ”‚ Values โ”‚
187-
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
188-
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
185+
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
186+
โ”‚ (index) โ”‚
187+
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
188+
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
189189
`);
190190

191191
test(new Map(), `
@@ -194,3 +194,12 @@ test(new Map(), `
194194
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
195195
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
196196
`);
197+
198+
test([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], `
199+
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”
200+
โ”‚ (index) โ”‚ a โ”‚ b โ”‚
201+
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ค
202+
โ”‚ 0 โ”‚ 1 โ”‚ 'Y' โ”‚
203+
โ”‚ 1 โ”‚ 'Z' โ”‚ 2 โ”‚
204+
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”˜
205+
`);

0 commit comments

Comments
ย (0)