3
3
const {
4
4
Array,
5
5
ArrayIsArray,
6
+ ArrayPrototypeFilter,
7
+ ArrayPrototypePush,
8
+ ArrayPrototypeSort,
9
+ ArrayPrototypeUnshift,
6
10
BigIntPrototypeValueOf,
7
11
BooleanPrototypeValueOf,
8
12
DatePrototypeGetTime,
@@ -12,7 +16,6 @@ const {
12
16
FunctionPrototypeCall,
13
17
FunctionPrototypeToString,
14
18
JSONStringify,
15
- Map,
16
19
MapPrototypeGetSize,
17
20
MapPrototypeEntries,
18
21
MathFloor,
@@ -39,14 +42,27 @@ const {
39
42
ObjectPrototypePropertyIsEnumerable,
40
43
ObjectSeal,
41
44
ObjectSetPrototypeOf,
42
- ReflectApply,
43
45
RegExp,
46
+ RegExpPrototypeTest,
44
47
RegExpPrototypeToString,
45
48
SafeStringIterator,
46
- Set,
49
+ SafeMap,
50
+ SafeSet,
47
51
SetPrototypeGetSize,
48
52
SetPrototypeValues,
49
53
String,
54
+ StringPrototypeCharCodeAt,
55
+ StringPrototypeCodePointAt,
56
+ StringPrototypeIncludes,
57
+ StringPrototypeNormalize,
58
+ StringPrototypePadEnd,
59
+ StringPrototypePadStart,
60
+ StringPrototypeRepeat,
61
+ StringPrototypeReplace,
62
+ StringPrototypeSlice,
63
+ StringPrototypeSplit,
64
+ StringPrototypeToLowerCase,
65
+ StringPrototypeTrim,
50
66
StringPrototypeValueOf,
51
67
SymbolPrototypeToString,
52
68
SymbolPrototypeValueOf,
@@ -120,8 +136,11 @@ const { NativeModule } = require('internal/bootstrap/loaders');
120
136
121
137
let hexSlice ;
122
138
123
- const builtInObjects = new Set (
124
- ObjectGetOwnPropertyNames ( global ) . filter ( ( e ) => / ^ [ A - Z ] [ a - z A - Z 0 - 9 ] + $ / . test ( e ) )
139
+ const builtInObjects = new SafeSet (
140
+ ArrayPrototypeFilter (
141
+ ObjectGetOwnPropertyNames ( global ) ,
142
+ ( e ) => RegExpPrototypeTest ( / ^ [ A - Z ] [ a - z A - Z 0 - 9 ] + $ / , e )
143
+ )
125
144
) ;
126
145
127
146
// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
@@ -430,7 +449,7 @@ function addQuotes(str, quotes) {
430
449
return `'${ str } '` ;
431
450
}
432
451
433
- const escapeFn = ( str ) => meta [ str . charCodeAt ( 0 ) ] ;
452
+ const escapeFn = ( str ) => meta [ StringPrototypeCharCodeAt ( str ) ] ;
434
453
435
454
// Escape control characters, single quotes and the backslash.
436
455
// This is similar to JSON stringify escaping.
@@ -458,10 +477,10 @@ function strEscape(str) {
458
477
}
459
478
460
479
// Some magic numbers that worked out fine while benchmarking with v8 6.0
461
- if ( str . length < 5000 && ! escapeTest . test ( str ) )
480
+ if ( str . length < 5000 && ! RegExpPrototypeTest ( escapeTest , str ) )
462
481
return addQuotes ( str , singleQuote ) ;
463
482
if ( str . length > 100 ) {
464
- str = str . replace ( escapeReplace , escapeFn ) ;
483
+ str = StringPrototypeReplace ( str , escapeReplace , escapeFn ) ;
465
484
return addQuotes ( str , singleQuote ) ;
466
485
}
467
486
@@ -477,14 +496,14 @@ function strEscape(str) {
477
496
if ( last === i ) {
478
497
result += meta [ point ] ;
479
498
} else {
480
- result += `${ str . slice ( last , i ) } ${ meta [ point ] } ` ;
499
+ result += `${ StringPrototypeSlice ( str , last , i ) } ${ meta [ point ] } ` ;
481
500
}
482
501
last = i + 1 ;
483
502
}
484
503
}
485
504
486
505
if ( last !== lastIndex ) {
487
- result += str . slice ( last ) ;
506
+ result += StringPrototypeSlice ( str , last ) ;
488
507
}
489
508
return addQuotes ( result , singleQuote ) ;
490
509
}
@@ -588,7 +607,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
588
607
}
589
608
590
609
if ( depth === 0 ) {
591
- keySet = new Set ( ) ;
610
+ keySet = new SafeSet ( ) ;
592
611
} else {
593
612
keys . forEach ( ( key ) => keySet . add ( key ) ) ;
594
613
}
@@ -661,7 +680,7 @@ function getKeys(value, showHidden) {
661
680
}
662
681
if ( symbols . length !== 0 ) {
663
682
const filter = ( key ) => ObjectPrototypePropertyIsEnumerable ( value , key ) ;
664
- keys . push ( ... symbols . filter ( filter ) ) ;
683
+ ArrayPrototypePush ( keys , ... ArrayPrototypeFilter ( symbols , filter ) ) ;
665
684
}
666
685
}
667
686
return keys ;
@@ -751,7 +770,8 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
751
770
if ( ctx . seen . includes ( value ) ) {
752
771
let index = 1 ;
753
772
if ( ctx . circular === undefined ) {
754
- ctx . circular = new Map ( [ [ value , index ] ] ) ;
773
+ ctx . circular = new SafeMap ( ) ;
774
+ ctx . circular . set ( value , index ) ;
755
775
} else {
756
776
index = ctx . circular . get ( value ) ;
757
777
if ( index === undefined ) {
@@ -924,11 +944,11 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
924
944
`{ byteLength: ${ formatNumber ( ctx . stylize , value . byteLength ) } }` ;
925
945
}
926
946
braces [ 0 ] = `${ prefix } {` ;
927
- keys . unshift ( 'byteLength' ) ;
947
+ ArrayPrototypeUnshift ( keys , 'byteLength' ) ;
928
948
} else if ( isDataView ( value ) ) {
929
949
braces [ 0 ] = `${ getPrefix ( constructor , tag , 'DataView' ) } {` ;
930
950
// .buffer goes last, it's not a primitive like the others.
931
- keys . unshift ( 'byteLength' , 'byteOffset' , 'buffer' ) ;
951
+ ArrayPrototypeUnshift ( keys , 'byteLength' , 'byteOffset' , 'buffer' ) ;
932
952
} else if ( isPromise ( value ) ) {
933
953
braces [ 0 ] = `${ getPrefix ( constructor , tag , 'Promise' ) } {` ;
934
954
formatter = formatPromise ;
@@ -1072,7 +1092,7 @@ function getBoxedBase(value, ctx, keys, constructor, tag) {
1072
1092
}
1073
1093
if ( keys . length !== 0 || ctx . stylize === stylizeNoColor )
1074
1094
return base ;
1075
- return ctx . stylize ( base , type . toLowerCase ( ) ) ;
1095
+ return ctx . stylize ( base , StringPrototypeToLowerCase ( type ) ) ;
1076
1096
}
1077
1097
1078
1098
function getClassBase ( value , constructor , tag ) {
@@ -1287,11 +1307,11 @@ function groupArrayElements(ctx, output, value) {
1287
1307
lineMaxLength += separatorSpace ;
1288
1308
maxLineLength [ i ] = lineMaxLength ;
1289
1309
}
1290
- let order = 'padStart' ;
1310
+ let order = StringPrototypePadStart ;
1291
1311
if ( value !== undefined ) {
1292
1312
for ( let i = 0 ; i < output . length ; i ++ ) {
1293
1313
if ( typeof value [ i ] !== 'number' && typeof value [ i ] !== 'bigint' ) {
1294
- order = 'padEnd' ;
1314
+ order = StringPrototypePadEnd ;
1295
1315
break ;
1296
1316
}
1297
1317
}
@@ -1307,21 +1327,21 @@ function groupArrayElements(ctx, output, value) {
1307
1327
// done line by line as some lines might contain more colors than
1308
1328
// others.
1309
1329
const padding = maxLineLength [ j - i ] + output [ j ] . length - dataLen [ j ] ;
1310
- str += `${ output [ j ] } , ` [ order ] ( padding , ' ' ) ;
1330
+ str += order ( `${ output [ j ] } , ` , padding , ' ' ) ;
1311
1331
}
1312
- if ( order === 'padStart' ) {
1332
+ if ( order === StringPrototypePadStart ) {
1313
1333
const padding = maxLineLength [ j - i ] +
1314
1334
output [ j ] . length -
1315
1335
dataLen [ j ] -
1316
1336
separatorSpace ;
1317
- str += output [ j ] . padStart ( padding , ' ' ) ;
1337
+ str += StringPrototypePadStart ( output [ j ] , padding , ' ' ) ;
1318
1338
} else {
1319
1339
str += output [ j ] ;
1320
1340
}
1321
- tmp . push ( str ) ;
1341
+ ArrayPrototypePush ( tmp , str ) ;
1322
1342
}
1323
1343
if ( ctx . maxArrayLength < output . length ) {
1324
- tmp . push ( output [ outputLength ] ) ;
1344
+ ArrayPrototypePush ( tmp , output [ outputLength ] ) ;
1325
1345
}
1326
1346
output = tmp ;
1327
1347
}
@@ -1458,8 +1478,9 @@ function formatArrayBuffer(ctx, value) {
1458
1478
}
1459
1479
if ( hexSlice === undefined )
1460
1480
hexSlice = uncurryThis ( require ( 'buffer' ) . Buffer . prototype . hexSlice ) ;
1461
- let str = hexSlice ( buffer , 0 , MathMin ( ctx . maxArrayLength , buffer . length ) )
1462
- . replace ( / ( .{ 2 } ) / g, '$1 ' ) . trim ( ) ;
1481
+ let str = StringPrototypeTrim ( StringPrototypeReplace (
1482
+ hexSlice ( buffer , 0 , MathMin ( ctx . maxArrayLength , buffer . length ) ) ,
1483
+ / ( .{ 2 } ) / g, '$1 ' ) ) ;
1463
1484
const remaining = buffer . length - ctx . maxArrayLength ;
1464
1485
if ( remaining > 0 )
1465
1486
str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
@@ -1508,7 +1529,7 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
1508
1529
'buffer'
1509
1530
] ) {
1510
1531
const str = formatValue ( ctx , value [ key ] , recurseTimes , true ) ;
1511
- output . push ( `[${ key } ]: ${ str } ` ) ;
1532
+ ArrayPrototypePush ( output , `[${ key } ]: ${ str } ` ) ;
1512
1533
}
1513
1534
ctx . indentationLvl -= 2 ;
1514
1535
}
@@ -1519,7 +1540,7 @@ function formatSet(value, ctx, ignored, recurseTimes) {
1519
1540
const output = [ ] ;
1520
1541
ctx . indentationLvl += 2 ;
1521
1542
for ( const v of value ) {
1522
- output . push ( formatValue ( ctx , v , recurseTimes ) ) ;
1543
+ ArrayPrototypePush ( output , formatValue ( ctx , v , recurseTimes ) ) ;
1523
1544
}
1524
1545
ctx . indentationLvl -= 2 ;
1525
1546
return output ;
@@ -1539,7 +1560,7 @@ function formatMap(value, ctx, ignored, recurseTimes) {
1539
1560
function formatSetIterInner ( ctx , recurseTimes , entries , state ) {
1540
1561
const maxArrayLength = MathMax ( ctx . maxArrayLength , 0 ) ;
1541
1562
const maxLength = MathMin ( maxArrayLength , entries . length ) ;
1542
- let output = new Array ( maxLength ) ;
1563
+ const output = new Array ( maxLength ) ;
1543
1564
ctx . indentationLvl += 2 ;
1544
1565
for ( let i = 0 ; i < maxLength ; i ++ ) {
1545
1566
output [ i ] = formatValue ( ctx , entries [ i ] , recurseTimes ) ;
@@ -1549,11 +1570,12 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
1549
1570
// Sort all entries to have a halfway reliable output (if more entries than
1550
1571
// retrieved ones exist, we can not reliably return the same output) if the
1551
1572
// output is not sorted anyway.
1552
- output = output . sort ( ) ;
1573
+ ArrayPrototypeSort ( output ) ;
1553
1574
}
1554
1575
const remaining = entries . length - maxLength ;
1555
1576
if ( remaining > 0 ) {
1556
- output . push ( `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ) ;
1577
+ ArrayPrototypePush ( output ,
1578
+ `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ) ;
1557
1579
}
1558
1580
return output ;
1559
1581
}
@@ -1661,7 +1683,7 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
1661
1683
( ctx . getters === 'get' && desc . set === undefined ) ||
1662
1684
( ctx . getters === 'set' && desc . set !== undefined ) ) ) {
1663
1685
try {
1664
- const tmp = ReflectApply ( desc . get , original , [ ] ) ;
1686
+ const tmp = FunctionPrototypeCall ( desc . get , original ) ;
1665
1687
ctx . indentationLvl += 2 ;
1666
1688
if ( tmp === null ) {
1667
1689
str = `${ s ( `[${ label } :` , sp ) } ${ s ( 'null' , 'null' ) } ${ s ( ']' , sp ) } ` ;
@@ -1688,11 +1710,16 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
1688
1710
return str ;
1689
1711
}
1690
1712
if ( typeof key === 'symbol' ) {
1691
- const tmp = key . toString ( ) . replace ( strEscapeSequencesReplacer , escapeFn ) ;
1713
+ const tmp = StringPrototypeReplace (
1714
+ SymbolPrototypeToString ( key ) ,
1715
+ strEscapeSequencesReplacer , escapeFn
1716
+ ) ;
1692
1717
name = `[${ ctx . stylize ( tmp , 'symbol' ) } ]` ;
1693
1718
} else if ( desc . enumerable === false ) {
1694
- name = `[${ key . replace ( strEscapeSequencesReplacer , escapeFn ) } ]` ;
1695
- } else if ( keyStrRegExp . test ( key ) ) {
1719
+ const tmp = StringPrototypeReplace ( key ,
1720
+ strEscapeSequencesReplacer , escapeFn ) ;
1721
+ name = `[${ tmp } ]` ;
1722
+ } else if ( RegExpPrototypeTest ( keyStrRegExp , key ) ) {
1696
1723
name = ctx . stylize ( key , 'name' ) ;
1697
1724
} else {
1698
1725
name = ctx . stylize ( strEscape ( key ) , 'string' ) ;
@@ -1721,7 +1748,7 @@ function isBelowBreakLength(ctx, output, start, base) {
1721
1748
}
1722
1749
}
1723
1750
// Do not line up properties on the same line if `base` contains line breaks.
1724
- return base === '' || ! base . includes ( '\n' ) ;
1751
+ return base === '' || ! StringPrototypeIncludes ( base , '\n' ) ;
1725
1752
}
1726
1753
1727
1754
function reduceToSingleString (
@@ -1764,7 +1791,7 @@ function reduceToSingleString(
1764
1791
}
1765
1792
}
1766
1793
// Line up each entry on an individual line.
1767
- const indentation = `\n${ ' ' . repeat ( ctx . indentationLvl ) } ` ;
1794
+ const indentation = `\n${ StringPrototypeRepeat ( ' ' , ctx . indentationLvl ) } ` ;
1768
1795
return `${ base ? `${ base } ` : '' } ${ braces [ 0 ] } ${ indentation } ` +
1769
1796
`${ join ( output , `,${ indentation } ` ) } ${ indentation } ${ braces [ 1 ] } ` ;
1770
1797
}
@@ -1774,7 +1801,7 @@ function reduceToSingleString(
1774
1801
return `${ braces [ 0 ] } ${ base ? ` ${ base } ` : '' } ${ join ( output , ', ' ) } ` +
1775
1802
braces [ 1 ] ;
1776
1803
}
1777
- const indentation = ' ' . repeat ( ctx . indentationLvl ) ;
1804
+ const indentation = StringPrototypeRepeat ( ' ' , ctx . indentationLvl ) ;
1778
1805
// If the opening "brace" is too large, like in the case of "Set {",
1779
1806
// we need to force the first item to be on the next line or the
1780
1807
// items will not line up correctly.
@@ -1816,7 +1843,8 @@ function hasBuiltInToString(value) {
1816
1843
builtInObjects . has ( descriptor . value . name ) ;
1817
1844
}
1818
1845
1819
- const firstErrorLine = ( error ) => error . message . split ( '\n' ) [ 0 ] ;
1846
+ const firstErrorLine = ( error ) =>
1847
+ StringPrototypeSplit ( error . message , '\n' , 1 ) [ 0 ] ;
1820
1848
let CIRCULAR_ERROR_MESSAGE ;
1821
1849
function tryStringify ( arg ) {
1822
1850
try {
@@ -1864,8 +1892,8 @@ function formatWithOptionsInternal(inspectOptions, ...args) {
1864
1892
let lastPos = 0 ;
1865
1893
1866
1894
for ( let i = 0 ; i < first . length - 1 ; i ++ ) {
1867
- if ( first . charCodeAt ( i ) === 37 ) { // '%'
1868
- const nextChar = first . charCodeAt ( ++ i ) ;
1895
+ if ( StringPrototypeCharCodeAt ( first , i ) === 37 ) { // '%'
1896
+ const nextChar = StringPrototypeCharCodeAt ( first , ++ i ) ;
1869
1897
if ( a + 1 !== args . length ) {
1870
1898
switch ( nextChar ) {
1871
1899
case 115 : // 's'
@@ -1936,19 +1964,19 @@ function formatWithOptionsInternal(inspectOptions, ...args) {
1936
1964
tempStr = '' ;
1937
1965
break ;
1938
1966
case 37 : // '%'
1939
- str += first . slice ( lastPos , i ) ;
1967
+ str += StringPrototypeSlice ( first , lastPos , i ) ;
1940
1968
lastPos = i + 1 ;
1941
1969
continue ;
1942
1970
default : // Any other character is not a correct placeholder
1943
1971
continue ;
1944
1972
}
1945
1973
if ( lastPos !== i - 1 ) {
1946
- str += first . slice ( lastPos , i - 1 ) ;
1974
+ str += StringPrototypeSlice ( first , lastPos , i - 1 ) ;
1947
1975
}
1948
1976
str += tempStr ;
1949
1977
lastPos = i + 1 ;
1950
1978
} else if ( nextChar === 37 ) {
1951
- str += first . slice ( lastPos , i ) ;
1979
+ str += StringPrototypeSlice ( first , lastPos , i ) ;
1952
1980
lastPos = i + 1 ;
1953
1981
}
1954
1982
}
@@ -1957,7 +1985,7 @@ function formatWithOptionsInternal(inspectOptions, ...args) {
1957
1985
a ++ ;
1958
1986
join = ' ' ;
1959
1987
if ( lastPos < first . length ) {
1960
- str += first . slice ( lastPos ) ;
1988
+ str += StringPrototypeSlice ( first , lastPos ) ;
1961
1989
}
1962
1990
}
1963
1991
}
@@ -2005,9 +2033,9 @@ if (internalBinding('config').hasIntl) {
2005
2033
2006
2034
if ( removeControlChars )
2007
2035
str = stripVTControlCharacters ( str ) ;
2008
- str = str . normalize ( 'NFC' ) ;
2036
+ str = StringPrototypeNormalize ( str , 'NFC' ) ;
2009
2037
for ( const char of new SafeStringIterator ( str ) ) {
2010
- const code = char . codePointAt ( 0 ) ;
2038
+ const code = StringPrototypeCodePointAt ( char , 0 ) ;
2011
2039
if ( isFullWidthCodePoint ( code ) ) {
2012
2040
width += 2 ;
2013
2041
} else if ( ! isZeroWidthCodePoint ( code ) ) {
0 commit comments