GeezerVison is showing github.com — util: improve empty typed array inspection · nodejs/node@3dc3a31
File tree
Expand 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/util.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -625,6 +625,8 @@ function formatValue(ctx, value, recurseTimes) { |
625 | 625 | formatter = formatMap; |
626 | 626 | } else if (isTypedArray(value)) { |
627 | 627 | braces = [`${getPrefix(constructor, tag)}[`, ']']; |
| 628 | + if (value.length === 0 && keyLength === 0 && !ctx.showHidden) |
| 629 | + return `${braces[0]}]`; |
628 | 630 | formatter = formatTypedArray; |
629 | 631 | } else if (isMapIterator(value)) { |
630 | 632 | braces = [`[${tag}] {`, '}']; |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,7 +79,8 @@ assert.strictEqual(util.inspect({ 'a': { 'b': { 'c': 2 } } }, false, 1), |
79 | 79 | '{ a: { b: [Object] } }'); |
80 | 80 | assert.strictEqual(util.inspect({ 'a': { 'b': ['c'] } }, false, 1), |
81 | 81 | '{ a: { b: [Array] } }'); |
82 | | -assert.strictEqual(util.inspect(new Uint8Array(0)), 'Uint8Array [ ]'); |
| 82 | +assert.strictEqual(util.inspect(new Uint8Array(0)), 'Uint8Array []'); |
| 83 | +assert(inspect(new Uint8Array(0), { showHidden: true }).includes('[buffer]')); |
83 | 84 | assert.strictEqual( |
84 | 85 | util.inspect( |
85 | 86 | Object.create( |
|