@@ -33,15 +33,22 @@ const kIoMaxLength = 2 ** 31 - 1;
3333// in case they are created but never used due to an exception.
3434
3535const {
36- Map,
36+ ArrayPrototypePush,
37+ BigIntPrototypeToString,
3738 MathMax,
3839 Number,
3940 NumberIsSafeInteger,
4041 ObjectCreate,
4142 ObjectDefineProperties,
4243 ObjectDefineProperty,
4344 Promise,
45+ ReflectApply,
46+ RegExpPrototypeExec,
47+ SafeMap,
4448 String,
49+ StringPrototypeCharCodeAt,
50+ StringPrototypeIndexOf,
51+ StringPrototypeSlice,
4552} = primordials ;
4653
4754const { fs : constants } = internalBinding ( 'constants' ) ;
@@ -329,7 +336,7 @@ function readFile(path, options, callback) {
329336 }
330337 if ( context . isUserFd ) {
331338 process . nextTick ( function tick ( context ) {
332- readFileAfterOpen . call ( { context } , null , path ) ;
339+ ReflectApply ( readFileAfterOpen , { context } , [ null , path ] ) ;
333340 } , context ) ;
334341 return ;
335342 }
@@ -414,7 +421,7 @@ function readFileSync(path, options) {
414421 buffer = Buffer . allocUnsafe ( 8192 ) ;
415422 bytesRead = tryReadSync ( fd , isUserFd , buffer , 0 , 8192 ) ;
416423 if ( bytesRead !== 0 ) {
417- buffers . push ( buffer . slice ( 0 , bytesRead ) ) ;
424+ ArrayPrototypePush ( buffers , buffer . slice ( 0 , bytesRead ) ) ;
418425 }
419426 pos += bytesRead ;
420427 } while ( bytesRead !== 0 ) ;
@@ -1580,7 +1587,7 @@ function watch(filename, options, listener) {
15801587}
15811588
15821589
1583- const statWatchers = new Map ( ) ;
1590+ const statWatchers = new SafeMap ( ) ;
15841591
15851592function watchFile ( filename , options , listener ) {
15861593 filename = getValidatedPath ( filename ) ;
@@ -1652,13 +1659,13 @@ if (isWindows) {
16521659 // slash.
16531660 const splitRootRe = / ^ (?: [ a - z A - Z ] : | [ \\ / ] { 2 } [ ^ \\ / ] + [ \\ / ] [ ^ \\ / ] + ) ? [ \\ / ] * / ;
16541661 splitRoot = function splitRoot ( str ) {
1655- return splitRootRe . exec ( str ) [ 0 ] ;
1662+ return RegExpPrototypeExec ( splitRootRe , str ) [ 0 ] ;
16561663 } ;
16571664} else {
16581665 splitRoot = function splitRoot ( str ) {
16591666 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 ) ;
16621669 }
16631670 return str ;
16641671 } ;
@@ -1679,7 +1686,7 @@ let nextPart;
16791686if ( isWindows ) {
16801687 nextPart = function nextPart ( p , i ) {
16811688 for ( ; i < p . length ; ++ i ) {
1682- const ch = p . charCodeAt ( i ) ;
1689+ const ch = StringPrototypeCharCodeAt ( p , i ) ;
16831690
16841691 // Check for a separator character
16851692 if ( ch === CHAR_BACKWARD_SLASH || ch === CHAR_FORWARD_SLASH )
@@ -1688,7 +1695,9 @@ if (isWindows) {
16881695 return - 1 ;
16891696 } ;
16901697} else {
1691- nextPart = function nextPart ( p , i ) { return p . indexOf ( '/' , i ) ; } ;
1698+ nextPart = function nextPart ( p , i ) {
1699+ return StringPrototypeIndexOf ( p , '/' , i ) ;
1700+ } ;
16921701}
16931702
16941703const emptyObj = ObjectCreate ( null ) ;
@@ -1740,13 +1749,13 @@ function realpathSync(p, options) {
17401749 const result = nextPart ( p , pos ) ;
17411750 previous = current ;
17421751 if ( result === - 1 ) {
1743- const last = p . slice ( pos ) ;
1752+ const last = StringPrototypeSlice ( p , pos ) ;
17441753 current += last ;
17451754 base = previous + last ;
17461755 pos = p . length ;
17471756 } 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 ) ;
17501759 pos = result + 1 ;
17511760 }
17521761
@@ -1783,8 +1792,8 @@ function realpathSync(p, options) {
17831792 let linkTarget = null ;
17841793 let id ;
17851794 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 ) ;
17881797 id = `${ dev } :${ ino } ` ;
17891798 if ( seenLinks [ id ] ) {
17901799 linkTarget = seenLinks [ id ] ;
@@ -1804,7 +1813,7 @@ function realpathSync(p, options) {
18041813 }
18051814
18061815 // Resolve the link, then start over
1807- p = pathModule . resolve ( resolvedLink , p . slice ( pos ) ) ;
1816+ p = pathModule . resolve ( resolvedLink , StringPrototypeSlice ( p , pos ) ) ;
18081817
18091818 // Skip over roots
18101819 current = base = splitRoot ( p ) ;
@@ -1883,13 +1892,13 @@ function realpath(p, options, callback) {
18831892 const result = nextPart ( p , pos ) ;
18841893 previous = current ;
18851894 if ( result === - 1 ) {
1886- const last = p . slice ( pos ) ;
1895+ const last = StringPrototypeSlice ( p , pos ) ;
18871896 current += last ;
18881897 base = previous + last ;
18891898 pos = p . length ;
18901899 } 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 ) ;
18931902 pos = result + 1 ;
18941903 }
18951904
@@ -1919,8 +1928,8 @@ function realpath(p, options, callback) {
19191928 // `dev`/`ino` always return 0 on windows, so skip the check.
19201929 let id ;
19211930 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 ) ;
19241933 id = `${ dev } :${ ino } ` ;
19251934 if ( seenLinks [ id ] ) {
19261935 return gotTarget ( null , seenLinks [ id ] ) ;
@@ -1944,7 +1953,7 @@ function realpath(p, options, callback) {
19441953
19451954 function gotResolvedLink ( resolvedLink ) {
19461955 // Resolve the link, then start over
1947- p = pathModule . resolve ( resolvedLink , p . slice ( pos ) ) ;
1956+ p = pathModule . resolve ( resolvedLink , StringPrototypeSlice ( p , pos ) ) ;
19481957 current = base = splitRoot ( p ) ;
19491958 pos = current . length ;
19501959
0 commit comments