Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup commit 1
  • Loading branch information
BridgeAR committed Jul 28, 2017
commit a2574f0bc5571997134532723bc2ee43bf349c0f
5 changes: 4 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,12 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
var output = [];
let visibleLength = 0;
let index = 0;
for (const elem in value) {
for (const elem of keys) {
if (visibleLength === ctx.maxArrayLength)
break;
// Symbols might have been added to the keys
if (typeof elem !== 'string')
continue;
const i = +elem;
if (index !== i) {
// Skip zero and negative numbers as well as non numbers
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ assert.strictEqual(
'[ 1, 2, 3, growingLength: [Getter], \'-1\': -1 ]');
}

// Array with inherited number properties
{
class CustomArray extends Array {};
CustomArray.prototype[5] = 'foo';
const arr = new CustomArray(50);
assert.strictEqual(util.inspect(arr), 'CustomArray [ <50 empty items> ]');
}

// Function with properties
{
const value = () => {};
Expand Down