@@ -64,7 +64,6 @@ const inspectDefaultOptions = Object.seal({
64
64
65
65
const numbersOnlyRE = / ^ \d + $ / ;
66
66
67
- const objectHasOwnProperty = Object . prototype . hasOwnProperty ;
68
67
const propertyIsEnumerable = Object . prototype . propertyIsEnumerable ;
69
68
const regExpToString = RegExp . prototype . toString ;
70
69
const dateToISOString = Date . prototype . toISOString ;
@@ -683,22 +682,36 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
683
682
var output = [ ] ;
684
683
let visibleLength = 0 ;
685
684
let index = 0 ;
686
- while ( index < value . length && visibleLength < ctx . maxArrayLength ) {
687
- let emptyItems = 0 ;
688
- while ( index < value . length && ! hasOwnProperty ( value , String ( index ) ) ) {
689
- emptyItems ++ ;
690
- index ++ ;
691
- }
692
- if ( emptyItems > 0 ) {
685
+ for ( const elem of keys ) {
686
+ if ( visibleLength === ctx . maxArrayLength )
687
+ break ;
688
+ // Symbols might have been added to the keys
689
+ if ( typeof elem !== 'string' )
690
+ continue ;
691
+ const i = + elem ;
692
+ if ( index !== i ) {
693
+ // Skip zero and negative numbers as well as non numbers
694
+ if ( i > 0 === false )
695
+ continue ;
696
+ const emptyItems = i - index ;
693
697
const ending = emptyItems > 1 ? 's' : '' ;
694
698
const message = `<${ emptyItems } empty item${ ending } >` ;
695
699
output . push ( ctx . stylize ( message , 'undefined' ) ) ;
696
- } else {
697
- output . push ( formatProperty ( ctx , value , recurseTimes , visibleKeys ,
698
- String ( index ) , true ) ) ;
699
- index ++ ;
700
+ index = i ;
701
+ if ( ++ visibleLength === ctx . maxArrayLength )
702
+ break ;
700
703
}
704
+ output . push ( formatProperty ( ctx , value , recurseTimes , visibleKeys ,
705
+ elem , true ) ) ;
701
706
visibleLength ++ ;
707
+ index ++ ;
708
+ }
709
+ if ( index < value . length && visibleLength !== ctx . maxArrayLength ) {
710
+ const len = value . length - index ;
711
+ const ending = len > 1 ? 's' : '' ;
712
+ const message = `<${ len } empty item${ ending } >` ;
713
+ output . push ( ctx . stylize ( message , 'undefined' ) ) ;
714
+ index = value . length ;
702
715
}
703
716
var remaining = value . length - index ;
704
717
if ( remaining > 0 ) {
@@ -814,7 +827,7 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
814
827
str = ctx . stylize ( '[Setter]' , 'special' ) ;
815
828
}
816
829
}
817
- if ( ! hasOwnProperty ( visibleKeys , key ) ) {
830
+ if ( visibleKeys [ key ] === undefined ) {
818
831
if ( typeof key === 'symbol' ) {
819
832
name = `[${ ctx . stylize ( key . toString ( ) , 'symbol' ) } ]` ;
820
833
} else {
@@ -993,11 +1006,6 @@ function _extend(target, source) {
993
1006
return target ;
994
1007
}
995
1008
996
- function hasOwnProperty ( obj , prop ) {
997
- return objectHasOwnProperty . call ( obj , prop ) ;
998
- }
999
-
1000
-
1001
1009
// Deprecated old stuff.
1002
1010
1003
1011
function print ( ...args ) {
0 commit comments