@@ -33,15 +33,22 @@ const kIoMaxLength = 2 ** 31 - 1;
33
33
// in case they are created but never used due to an exception.
34
34
35
35
const {
36
- Map,
36
+ ArrayPrototypePush,
37
+ BigIntPrototypeToString,
37
38
MathMax,
38
39
Number,
39
40
NumberIsSafeInteger,
40
41
ObjectCreate,
41
42
ObjectDefineProperties,
42
43
ObjectDefineProperty,
43
44
Promise,
45
+ ReflectApply,
46
+ RegExpPrototypeExec,
47
+ SafeMap,
44
48
String,
49
+ StringPrototypeCharCodeAt,
50
+ StringPrototypeIndexOf,
51
+ StringPrototypeSlice,
45
52
} = primordials ;
46
53
47
54
const { fs : constants } = internalBinding ( 'constants' ) ;
@@ -329,7 +336,7 @@ function readFile(path, options, callback) {
329
336
}
330
337
if ( context . isUserFd ) {
331
338
process . nextTick ( function tick ( context ) {
332
- readFileAfterOpen . call ( { context } , null , path ) ;
339
+ ReflectApply ( readFileAfterOpen , { context } , [ null , path ] ) ;
333
340
} , context ) ;
334
341
return ;
335
342
}
@@ -414,7 +421,7 @@ function readFileSync(path, options) {
414
421
buffer = Buffer . allocUnsafe ( 8192 ) ;
415
422
bytesRead = tryReadSync ( fd , isUserFd , buffer , 0 , 8192 ) ;
416
423
if ( bytesRead !== 0 ) {
417
- buffers . push ( buffer . slice ( 0 , bytesRead ) ) ;
424
+ ArrayPrototypePush ( buffers , buffer . slice ( 0 , bytesRead ) ) ;
418
425
}
419
426
pos += bytesRead ;
420
427
} while ( bytesRead !== 0 ) ;
@@ -1580,7 +1587,7 @@ function watch(filename, options, listener) {
1580
1587
}
1581
1588
1582
1589
1583
- const statWatchers = new Map ( ) ;
1590
+ const statWatchers = new SafeMap ( ) ;
1584
1591
1585
1592
function watchFile ( filename , options , listener ) {
1586
1593
filename = getValidatedPath ( filename ) ;
@@ -1652,13 +1659,13 @@ if (isWindows) {
1652
1659
// slash.
1653
1660
const splitRootRe = / ^ (?: [ a - z A - Z ] : | [ \\ / ] { 2 } [ ^ \\ / ] + [ \\ / ] [ ^ \\ / ] + ) ? [ \\ / ] * / ;
1654
1661
splitRoot = function splitRoot ( str ) {
1655
- return splitRootRe . exec ( str ) [ 0 ] ;
1662
+ return RegExpPrototypeExec ( splitRootRe , str ) [ 0 ] ;
1656
1663
} ;
1657
1664
} else {
1658
1665
splitRoot = function splitRoot ( str ) {
1659
1666
for ( let i = 0 ; i < str . length ; ++ i ) {
1660
- if ( str . charCodeAt ( i ) !== CHAR_FORWARD_SLASH )
1661
- return str . slice ( 0 , i ) ;
1667
+ if ( StringPrototypeCharCodeAt ( str , i ) !== CHAR_FORWARD_SLASH )
1668
+ return StringPrototypeSlice ( str , 0 , i ) ;
1662
1669
}
1663
1670
return str ;
1664
1671
} ;
@@ -1679,7 +1686,7 @@ let nextPart;
1679
1686
if ( isWindows ) {
1680
1687
nextPart = function nextPart ( p , i ) {
1681
1688
for ( ; i < p . length ; ++ i ) {
1682
- const ch = p . charCodeAt ( i ) ;
1689
+ const ch = StringPrototypeCharCodeAt ( p , i ) ;
1683
1690
1684
1691
// Check for a separator character
1685
1692
if ( ch === CHAR_BACKWARD_SLASH || ch === CHAR_FORWARD_SLASH )
@@ -1688,7 +1695,9 @@ if (isWindows) {
1688
1695
return - 1 ;
1689
1696
} ;
1690
1697
} else {
1691
- nextPart = function nextPart ( p , i ) { return p . indexOf ( '/' , i ) ; } ;
1698
+ nextPart = function nextPart ( p , i ) {
1699
+ return StringPrototypeIndexOf ( p , '/' , i ) ;
1700
+ } ;
1692
1701
}
1693
1702
1694
1703
const emptyObj = ObjectCreate ( null ) ;
@@ -1740,13 +1749,13 @@ function realpathSync(p, options) {
1740
1749
const result = nextPart ( p , pos ) ;
1741
1750
previous = current ;
1742
1751
if ( result === - 1 ) {
1743
- const last = p . slice ( pos ) ;
1752
+ const last = StringPrototypeSlice ( p , pos ) ;
1744
1753
current += last ;
1745
1754
base = previous + last ;
1746
1755
pos = p . length ;
1747
1756
} else {
1748
- current += p . slice ( pos , result + 1 ) ;
1749
- base = previous + p . slice ( pos , result ) ;
1757
+ current += StringPrototypeSlice ( p , pos , result + 1 ) ;
1758
+ base = previous + StringPrototypeSlice ( p , pos , result ) ;
1750
1759
pos = result + 1 ;
1751
1760
}
1752
1761
@@ -1783,8 +1792,8 @@ function realpathSync(p, options) {
1783
1792
let linkTarget = null ;
1784
1793
let id ;
1785
1794
if ( ! isWindows ) {
1786
- const dev = stats [ 0 ] . toString ( 32 ) ;
1787
- const ino = stats [ 7 ] . toString ( 32 ) ;
1795
+ const dev = BigIntPrototypeToString ( stats [ 0 ] , 32 ) ;
1796
+ const ino = BigIntPrototypeToString ( stats [ 7 ] , 32 ) ;
1788
1797
id = `${ dev } :${ ino } ` ;
1789
1798
if ( seenLinks [ id ] ) {
1790
1799
linkTarget = seenLinks [ id ] ;
@@ -1804,7 +1813,7 @@ function realpathSync(p, options) {
1804
1813
}
1805
1814
1806
1815
// Resolve the link, then start over
1807
- p = pathModule . resolve ( resolvedLink , p . slice ( pos ) ) ;
1816
+ p = pathModule . resolve ( resolvedLink , StringPrototypeSlice ( p , pos ) ) ;
1808
1817
1809
1818
// Skip over roots
1810
1819
current = base = splitRoot ( p ) ;
@@ -1883,13 +1892,13 @@ function realpath(p, options, callback) {
1883
1892
const result = nextPart ( p , pos ) ;
1884
1893
previous = current ;
1885
1894
if ( result === - 1 ) {
1886
- const last = p . slice ( pos ) ;
1895
+ const last = StringPrototypeSlice ( p , pos ) ;
1887
1896
current += last ;
1888
1897
base = previous + last ;
1889
1898
pos = p . length ;
1890
1899
} else {
1891
- current += p . slice ( pos , result + 1 ) ;
1892
- base = previous + p . slice ( pos , result ) ;
1900
+ current += StringPrototypeSlice ( p , pos , result + 1 ) ;
1901
+ base = previous + StringPrototypeSlice ( p , pos , result ) ;
1893
1902
pos = result + 1 ;
1894
1903
}
1895
1904
@@ -1919,8 +1928,8 @@ function realpath(p, options, callback) {
1919
1928
// `dev`/`ino` always return 0 on windows, so skip the check.
1920
1929
let id ;
1921
1930
if ( ! isWindows ) {
1922
- const dev = stats . dev . toString ( 32 ) ;
1923
- const ino = stats . ino . toString ( 32 ) ;
1931
+ const dev = BigIntPrototypeToString ( stats . dev , 32 ) ;
1932
+ const ino = BigIntPrototypeToString ( stats . ino , 32 ) ;
1924
1933
id = `${ dev } :${ ino } ` ;
1925
1934
if ( seenLinks [ id ] ) {
1926
1935
return gotTarget ( null , seenLinks [ id ] ) ;
@@ -1944,7 +1953,7 @@ function realpath(p, options, callback) {
1944
1953
1945
1954
function gotResolvedLink ( resolvedLink ) {
1946
1955
// Resolve the link, then start over
1947
- p = pathModule . resolve ( resolvedLink , p . slice ( pos ) ) ;
1956
+ p = pathModule . resolve ( resolvedLink , StringPrototypeSlice ( p , pos ) ) ;
1948
1957
current = base = splitRoot ( p ) ;
1949
1958
pos = current . length ;
1950
1959
0 commit comments