@@ -6,6 +6,7 @@ const internalUtil = require('internal/util'); |
6 | 6 | const binding = process.binding('util'); |
7 | 7 |
|
8 | 8 | const isError = internalUtil.isError; |
| 9 | +const kDefaultMaxLength = 100; |
9 | 10 |
|
10 | 11 | var Debug; |
11 | 12 |
|
@@ -141,6 +142,8 @@ function inspect(obj, opts) { |
141 | 142 | if (ctx.customInspect === undefined) ctx.customInspect = true; |
142 | 143 | if (ctx.showProxy === undefined) ctx.showProxy = false; |
143 | 144 | if (ctx.colors) ctx.stylize = stylizeWithColor; |
| 145 | + if (ctx.maxArrayLength === undefined) ctx.maxArrayLength = kDefaultMaxLength; |
| 146 | + if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity; |
144 | 147 | return formatValue(ctx, obj, ctx.depth); |
145 | 148 | } |
146 | 149 | exports.inspect = inspect; |
@@ -579,14 +582,19 @@ function formatObject(ctx, value, recurseTimes, visibleKeys, keys) { |
579 | 582 |
|
580 | 583 | function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { |
581 | 584 | var output = []; |
582 | | - for (var i = 0, l = value.length; i < l; ++i) { |
| 585 | + const maxLength = Math.min(Math.max(0, ctx.maxArrayLength), value.length); |
| 586 | + const remaining = value.length - maxLength; |
| 587 | + for (var i = 0; i < maxLength; ++i) { |
583 | 588 | if (hasOwnProperty(value, String(i))) { |
584 | 589 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, |
585 | 590 | String(i), true)); |
586 | 591 | } else { |
587 | 592 | output.push(''); |
588 | 593 | } |
589 | 594 | } |
| 595 | + if (remaining > 0) { |
| 596 | + output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`); |
| 597 | + } |
590 | 598 | keys.forEach(function(key) { |
591 | 599 | if (typeof key === 'symbol' || !key.match(/^\d+$/)) { |
592 | 600 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, |
@@ -598,9 +606,14 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { |
598 | 606 |
|
599 | 607 |
|
600 | 608 | function formatTypedArray(ctx, value, recurseTimes, visibleKeys, keys) { |
601 | | - var output = new Array(value.length); |
602 | | - for (var i = 0, l = value.length; i < l; ++i) |
| 609 | + const maxLength = Math.min(Math.max(0, ctx.maxArrayLength), value.length); |
| 610 | + const remaining = value.length - maxLength; |
| 611 | + var output = new Array(maxLength); |
| 612 | + for (var i = 0; i < maxLength; ++i) |
603 | 613 | output[i] = formatNumber(ctx, value[i]); |
| 614 | + if (remaining > 0) { |
| 615 | + output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`); |
| 616 | + } |
604 | 617 | for (const key of keys) { |
605 | 618 | if (typeof key === 'symbol' || !key.match(/^\d+$/)) { |
606 | 619 | output.push( |
|