@@ -30,18 +30,12 @@ const {
30
30
const { TextDecoder, TextEncoder } = require ( 'internal/encoding' ) ;
31
31
const { isBuffer } = require ( 'buffer' ) . Buffer ;
32
32
33
- const {
34
- previewMapIterator,
35
- previewSetIterator,
36
- previewWeakMap,
37
- previewWeakSet
38
- } = require ( 'internal/v8' ) ;
39
-
40
33
const {
41
34
getPromiseDetails,
42
35
getProxyDetails,
43
36
kPending,
44
37
kRejected,
38
+ previewEntries
45
39
} = process . binding ( 'util' ) ;
46
40
47
41
const { internalBinding } = require ( 'internal/bootstrap/loaders' ) ;
@@ -912,7 +906,7 @@ function formatMap(ctx, value, recurseTimes, keys) {
912
906
913
907
function formatWeakSet ( ctx , value , recurseTimes , keys ) {
914
908
const maxArrayLength = Math . max ( ctx . maxArrayLength , 0 ) ;
915
- const entries = previewWeakSet ( value , maxArrayLength + 1 ) ;
909
+ const entries = previewEntries ( value ) . slice ( 0 , maxArrayLength + 1 ) ;
916
910
const maxLength = Math . min ( maxArrayLength , entries . length ) ;
917
911
let output = new Array ( maxLength ) ;
918
912
for ( var i = 0 ; i < maxLength ; ++ i )
@@ -929,16 +923,14 @@ function formatWeakSet(ctx, value, recurseTimes, keys) {
929
923
930
924
function formatWeakMap ( ctx , value , recurseTimes , keys ) {
931
925
const maxArrayLength = Math . max ( ctx . maxArrayLength , 0 ) ;
932
- const entries = previewWeakMap ( value , maxArrayLength + 1 ) ;
933
- // Entries exist as [key1, val1, key2, val2, ...]
934
- const remainder = entries . length / 2 > maxArrayLength ;
935
- const len = entries . length / 2 - ( remainder ? 1 : 0 ) ;
926
+ const entries = previewEntries ( value ) . slice ( 0 , maxArrayLength + 1 ) ;
927
+ const remainder = entries . length > maxArrayLength ;
928
+ const len = entries . length - ( remainder ? 1 : 0 ) ;
936
929
const maxLength = Math . min ( maxArrayLength , len ) ;
937
930
let output = new Array ( maxLength ) ;
938
931
for ( var i = 0 ; i < len ; i ++ ) {
939
- const pos = i * 2 ;
940
- output [ i ] = `${ formatValue ( ctx , entries [ pos ] , recurseTimes ) } => ` +
941
- formatValue ( ctx , entries [ pos + 1 ] , recurseTimes ) ;
932
+ output [ i ] = `${ formatValue ( ctx , entries [ i ] [ 0 ] , recurseTimes ) } => ` +
933
+ formatValue ( ctx , entries [ i ] [ 1 ] , recurseTimes ) ;
942
934
}
943
935
// Sort all entries to have a halfway reliable output (if more entries than
944
936
// retrieved ones exist, we can not reliably return the same output).
@@ -950,9 +942,9 @@ function formatWeakMap(ctx, value, recurseTimes, keys) {
950
942
return output ;
951
943
}
952
944
953
- function formatCollectionIterator ( preview , ctx , value , recurseTimes , keys ) {
945
+ function formatCollectionIterator ( ctx , value , recurseTimes , keys ) {
954
946
const output = [ ] ;
955
- for ( const entry of preview ( value ) ) {
947
+ for ( const entry of previewEntries ( value ) ) {
956
948
if ( ctx . maxArrayLength === output . length ) {
957
949
output . push ( '... more items' ) ;
958
950
break ;
@@ -966,13 +958,11 @@ function formatCollectionIterator(preview, ctx, value, recurseTimes, keys) {
966
958
}
967
959
968
960
function formatMapIterator ( ctx , value , recurseTimes , keys ) {
969
- return formatCollectionIterator ( previewMapIterator , ctx , value , recurseTimes ,
970
- keys ) ;
961
+ return formatCollectionIterator ( ctx , value , recurseTimes , keys ) ;
971
962
}
972
963
973
964
function formatSetIterator ( ctx , value , recurseTimes , keys ) {
974
- return formatCollectionIterator ( previewSetIterator , ctx , value , recurseTimes ,
975
- keys ) ;
965
+ return formatCollectionIterator ( ctx , value , recurseTimes , keys ) ;
976
966
}
977
967
978
968
function formatPromise ( ctx , value , recurseTimes , keys ) {
0 commit comments