@@ -33,13 +33,13 @@ const {
33
33
BigIntPrototypeToString,
34
34
MathMax,
35
35
Number,
36
- ObjectCreate,
37
36
ObjectDefineProperties,
38
37
ObjectDefineProperty,
39
38
Promise,
40
39
ReflectApply,
41
40
RegExpPrototypeExec,
42
41
SafeMap,
42
+ SafeSet,
43
43
String,
44
44
StringPrototypeCharCodeAt,
45
45
StringPrototypeIndexOf,
@@ -2472,8 +2472,8 @@ function realpathSync(p, options) {
2472
2472
return maybeCachedResult ;
2473
2473
}
2474
2474
2475
- const seenLinks = ObjectCreate ( null ) ;
2476
- const knownHard = ObjectCreate ( null ) ;
2475
+ const seenLinks = new SafeMap ( ) ;
2476
+ const knownHard = new SafeSet ( ) ;
2477
2477
const original = p ;
2478
2478
2479
2479
// Current character position in p
@@ -2494,7 +2494,7 @@ function realpathSync(p, options) {
2494
2494
const ctx = { path : base } ;
2495
2495
binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2496
2496
handleErrorFromBinding ( ctx ) ;
2497
- knownHard [ base ] = true ;
2497
+ knownHard . add ( base ) ;
2498
2498
}
2499
2499
2500
2500
// Walk down the path, swapping out linked path parts for their real
@@ -2516,7 +2516,7 @@ function realpathSync(p, options) {
2516
2516
}
2517
2517
2518
2518
// Continue if not a symlink, break if a pipe/socket
2519
- if ( knownHard [ base ] || cache ?. get ( base ) === base ) {
2519
+ if ( knownHard . has ( base ) || cache ?. get ( base ) === base ) {
2520
2520
if ( isFileType ( binding . statValues , S_IFIFO ) ||
2521
2521
isFileType ( binding . statValues , S_IFSOCK ) ) {
2522
2522
break ;
@@ -2538,7 +2538,7 @@ function realpathSync(p, options) {
2538
2538
handleErrorFromBinding ( ctx ) ;
2539
2539
2540
2540
if ( ! isFileType ( stats , S_IFLNK ) ) {
2541
- knownHard [ base ] = true ;
2541
+ knownHard . add ( base ) ;
2542
2542
cache ?. set ( base , base ) ;
2543
2543
continue ;
2544
2544
}
@@ -2551,8 +2551,8 @@ function realpathSync(p, options) {
2551
2551
const dev = BigIntPrototypeToString ( stats [ 0 ] , 32 ) ;
2552
2552
const ino = BigIntPrototypeToString ( stats [ 7 ] , 32 ) ;
2553
2553
id = `${ dev } :${ ino } ` ;
2554
- if ( seenLinks [ id ] ) {
2555
- linkTarget = seenLinks [ id ] ;
2554
+ if ( seenLinks . has ( id ) ) {
2555
+ linkTarget = seenLinks . get ( id ) ;
2556
2556
}
2557
2557
}
2558
2558
if ( linkTarget === null ) {
@@ -2565,7 +2565,7 @@ function realpathSync(p, options) {
2565
2565
resolvedLink = pathModule . resolve ( previous , linkTarget ) ;
2566
2566
2567
2567
cache ?. set ( base , resolvedLink ) ;
2568
- if ( ! isWindows ) seenLinks [ id ] = linkTarget ;
2568
+ if ( ! isWindows ) seenLinks . set ( id , linkTarget ) ;
2569
2569
}
2570
2570
2571
2571
// Resolve the link, then start over
@@ -2576,11 +2576,11 @@ function realpathSync(p, options) {
2576
2576
pos = current . length ;
2577
2577
2578
2578
// On windows, check that the root exists. On unix there is no need.
2579
- if ( isWindows && ! knownHard [ base ] ) {
2579
+ if ( isWindows && ! knownHard . has ( base ) ) {
2580
2580
const ctx = { path : base } ;
2581
2581
binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2582
2582
handleErrorFromBinding ( ctx ) ;
2583
- knownHard [ base ] = true ;
2583
+ knownHard . add ( base ) ;
2584
2584
}
2585
2585
}
2586
2586
@@ -2625,8 +2625,8 @@ function realpath(p, options, callback) {
2625
2625
validatePath ( p ) ;
2626
2626
p = pathModule . resolve ( p ) ;
2627
2627
2628
- const seenLinks = ObjectCreate ( null ) ;
2629
- const knownHard = ObjectCreate ( null ) ;
2628
+ const seenLinks = new SafeMap ( ) ;
2629
+ const knownHard = new SafeSet ( ) ;
2630
2630
2631
2631
// Current character position in p
2632
2632
let pos ;
@@ -2641,10 +2641,10 @@ function realpath(p, options, callback) {
2641
2641
pos = current . length ;
2642
2642
2643
2643
// On windows, check that the root exists. On unix there is no need.
2644
- if ( isWindows && ! knownHard [ base ] ) {
2644
+ if ( isWindows && ! knownHard . has ( base ) ) {
2645
2645
fs . lstat ( base , ( err , stats ) => {
2646
2646
if ( err ) return callback ( err ) ;
2647
- knownHard [ base ] = true ;
2647
+ knownHard . add ( base ) ;
2648
2648
LOOP ( ) ;
2649
2649
} ) ;
2650
2650
} else {
@@ -2674,7 +2674,7 @@ function realpath(p, options, callback) {
2674
2674
}
2675
2675
2676
2676
// Continue if not a symlink, break if a pipe/socket
2677
- if ( knownHard [ base ] ) {
2677
+ if ( knownHard . has ( base ) ) {
2678
2678
if ( isFileType ( binding . statValues , S_IFIFO ) ||
2679
2679
isFileType ( binding . statValues , S_IFSOCK ) ) {
2680
2680
return callback ( null , encodeRealpathResult ( p , options ) ) ;
@@ -2690,7 +2690,7 @@ function realpath(p, options, callback) {
2690
2690
2691
2691
// If not a symlink, skip to the next path part
2692
2692
if ( ! stats . isSymbolicLink ( ) ) {
2693
- knownHard [ base ] = true ;
2693
+ knownHard . add ( base ) ;
2694
2694
return process . nextTick ( LOOP ) ;
2695
2695
}
2696
2696
@@ -2702,15 +2702,15 @@ function realpath(p, options, callback) {
2702
2702
const dev = BigIntPrototypeToString ( stats . dev , 32 ) ;
2703
2703
const ino = BigIntPrototypeToString ( stats . ino , 32 ) ;
2704
2704
id = `${ dev } :${ ino } ` ;
2705
- if ( seenLinks [ id ] ) {
2706
- return gotTarget ( null , seenLinks [ id ] ) ;
2705
+ if ( seenLinks . has ( id ) ) {
2706
+ return gotTarget ( null , seenLinks . get ( id ) ) ;
2707
2707
}
2708
2708
}
2709
2709
fs . stat ( base , ( err ) => {
2710
2710
if ( err ) return callback ( err ) ;
2711
2711
2712
2712
fs . readlink ( base , ( err , target ) => {
2713
- if ( ! isWindows ) seenLinks [ id ] = target ;
2713
+ if ( ! isWindows ) seenLinks . set ( id , target ) ;
2714
2714
gotTarget ( err , target ) ;
2715
2715
} ) ;
2716
2716
} ) ;
@@ -2729,10 +2729,10 @@ function realpath(p, options, callback) {
2729
2729
pos = current . length ;
2730
2730
2731
2731
// On windows, check that the root exists. On unix there is no need.
2732
- if ( isWindows && ! knownHard [ base ] ) {
2732
+ if ( isWindows && ! knownHard . has ( base ) ) {
2733
2733
fs . lstat ( base , ( err ) => {
2734
2734
if ( err ) return callback ( err ) ;
2735
- knownHard [ base ] = true ;
2735
+ knownHard . add ( base ) ;
2736
2736
LOOP ( ) ;
2737
2737
} ) ;
2738
2738
} else {
0 commit comments