@@ -117,6 +117,9 @@ const setSizeGetter = uncurryThis(
117
117
ObjectGetOwnPropertyDescriptor ( SetPrototype , 'size' ) . get ) ;
118
118
const mapSizeGetter = uncurryThis (
119
119
ObjectGetOwnPropertyDescriptor ( MapPrototype , 'size' ) . get ) ;
120
+ const typedArraySizeGetter = uncurryThis (
121
+ ObjectGetOwnPropertyDescriptor (
122
+ ObjectGetPrototypeOf ( Uint8Array . prototype ) , 'length' ) . get ) ;
120
123
121
124
let hexSlice ;
122
125
@@ -562,18 +565,18 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, isProto, output) {
562
565
} while ( ++ depth !== 3 ) ;
563
566
}
564
567
565
- function getPrefix ( constructor , tag , fallback ) {
568
+ function getPrefix ( constructor , tag , fallback , size = '' ) {
566
569
if ( constructor === null ) {
567
570
if ( tag !== '' ) {
568
- return `[${ fallback } : null prototype] [${ tag } ] ` ;
571
+ return `[${ fallback } ${ size } : null prototype] [${ tag } ] ` ;
569
572
}
570
- return `[${ fallback } : null prototype] ` ;
573
+ return `[${ fallback } ${ size } : null prototype] ` ;
571
574
}
572
575
573
576
if ( tag !== '' && constructor !== tag ) {
574
- return `${ constructor } [${ tag } ] ` ;
577
+ return `${ constructor } ${ size } [${ tag } ] ` ;
575
578
}
576
- return `${ constructor } ` ;
579
+ return `${ constructor } ${ size } ` ;
577
580
}
578
581
579
582
// Look up the keys of the object.
@@ -758,58 +761,48 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
758
761
if ( value [ SymbolIterator ] || constructor === null ) {
759
762
noIterator = false ;
760
763
if ( ArrayIsArray ( value ) ) {
761
- keys = getOwnNonIndexProperties ( value , filter ) ;
762
764
// Only set the constructor for non ordinary ("Array [...]") arrays.
763
- const prefix = getPrefix ( constructor , tag , 'Array' ) ;
764
- braces = [ `${ prefix === 'Array ' ? '' : prefix } [` , ']' ] ;
765
+ const prefix = ( constructor !== 'Array' || tag !== '' ) ?
766
+ getPrefix ( constructor , tag , 'Array' , `(${ value . length } )` ) :
767
+ '' ;
768
+ keys = getOwnNonIndexProperties ( value , filter ) ;
769
+ braces = [ `${ prefix } [` , ']' ] ;
765
770
if ( value . length === 0 && keys . length === 0 && protoProps === undefined )
766
771
return `${ braces [ 0 ] } ]` ;
767
772
extrasType = kArrayExtrasType ;
768
773
formatter = formatArray ;
769
774
} else if ( isSet ( value ) ) {
770
775
const size = setSizeGetter ( value ) ;
776
+ const prefix = getPrefix ( constructor , tag , 'Set' , `(${ size } )` ) ;
771
777
keys = getKeys ( value , ctx . showHidden ) ;
772
- let prefix = '' ;
773
- if ( constructor !== null ) {
774
- if ( constructor === tag )
775
- tag = '' ;
776
- prefix = getPrefix ( `${ constructor } (${ size } )` , tag , '' ) ;
777
- formatter = formatSet . bind ( null , value , size ) ;
778
- } else {
779
- prefix = getPrefix ( constructor , tag , `Set(${ size } )` ) ;
780
- formatter = formatSet . bind ( null , SetPrototypeValues ( value ) , size ) ;
781
- }
778
+ formatter = constructor !== null ?
779
+ formatSet . bind ( null , value ) :
780
+ formatSet . bind ( null , SetPrototypeValues ( value ) ) ;
782
781
if ( size === 0 && keys . length === 0 && protoProps === undefined )
783
782
return `${ prefix } {}` ;
784
783
braces = [ `${ prefix } {` , '}' ] ;
785
784
} else if ( isMap ( value ) ) {
786
785
const size = mapSizeGetter ( value ) ;
786
+ const prefix = getPrefix ( constructor , tag , 'Map' , `(${ size } )` ) ;
787
787
keys = getKeys ( value , ctx . showHidden ) ;
788
- let prefix = '' ;
789
- if ( constructor !== null ) {
790
- if ( constructor === tag )
791
- tag = '' ;
792
- prefix = getPrefix ( `${ constructor } (${ size } )` , tag , '' ) ;
793
- formatter = formatMap . bind ( null , value , size ) ;
794
- } else {
795
- prefix = getPrefix ( constructor , tag , `Map(${ size } )` ) ;
796
- formatter = formatMap . bind ( null , MapPrototypeEntries ( value ) , size ) ;
797
- }
788
+ formatter = constructor !== null ?
789
+ formatMap . bind ( null , value ) :
790
+ formatMap . bind ( null , MapPrototypeEntries ( value ) ) ;
798
791
if ( size === 0 && keys . length === 0 && protoProps === undefined )
799
792
return `${ prefix } {}` ;
800
793
braces = [ `${ prefix } {` , '}' ] ;
801
794
} else if ( isTypedArray ( value ) ) {
802
795
keys = getOwnNonIndexProperties ( value , filter ) ;
803
796
let bound = value ;
804
- let prefix = '' ;
797
+ let fallback = '' ;
805
798
if ( constructor === null ) {
806
799
const constr = findTypedConstructor ( value ) ;
807
- prefix = getPrefix ( constructor , tag , constr . name ) ;
800
+ fallback = constr . name ;
808
801
// Reconstruct the array information.
809
802
bound = new constr ( value ) ;
810
- } else {
811
- prefix = getPrefix ( constructor , tag ) ;
812
803
}
804
+ const size = typedArraySizeGetter ( value ) ;
805
+ const prefix = getPrefix ( constructor , tag , fallback , `(${ size } )` ) ;
813
806
braces = [ `${ prefix } [` , ']' ] ;
814
807
if ( value . length === 0 && keys . length === 0 && ! ctx . showHidden )
815
808
return `${ braces [ 0 ] } ]` ;
@@ -1425,7 +1418,7 @@ function formatTypedArray(value, ctx, ignored, recurseTimes) {
1425
1418
return output ;
1426
1419
}
1427
1420
1428
- function formatSet ( value , size , ctx , ignored , recurseTimes ) {
1421
+ function formatSet ( value , ctx , ignored , recurseTimes ) {
1429
1422
const output = [ ] ;
1430
1423
ctx . indentationLvl += 2 ;
1431
1424
for ( const v of value ) {
@@ -1435,7 +1428,7 @@ function formatSet(value, size, ctx, ignored, recurseTimes) {
1435
1428
return output ;
1436
1429
}
1437
1430
1438
- function formatMap ( value , size , ctx , ignored , recurseTimes ) {
1431
+ function formatMap ( value , ctx , ignored , recurseTimes ) {
1439
1432
const output = [ ] ;
1440
1433
ctx . indentationLvl += 2 ;
1441
1434
for ( const [ k , v ] of value ) {
0 commit comments