@@ -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,
@@ -2486,8 +2486,8 @@ function realpathSync(p, options) {
2486
2486
return maybeCachedResult ;
2487
2487
}
2488
2488
2489
- const seenLinks = ObjectCreate ( null ) ;
2490
- const knownHard = ObjectCreate ( null ) ;
2489
+ const seenLinks = new SafeMap ( ) ;
2490
+ const knownHard = new SafeSet ( ) ;
2491
2491
const original = p ;
2492
2492
2493
2493
// Current character position in p
@@ -2508,7 +2508,7 @@ function realpathSync(p, options) {
2508
2508
const ctx = { path : base } ;
2509
2509
binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2510
2510
handleErrorFromBinding ( ctx ) ;
2511
- knownHard [ base ] = true ;
2511
+ knownHard . add ( base ) ;
2512
2512
}
2513
2513
2514
2514
// Walk down the path, swapping out linked path parts for their real
@@ -2530,7 +2530,7 @@ function realpathSync(p, options) {
2530
2530
}
2531
2531
2532
2532
// Continue if not a symlink, break if a pipe/socket
2533
- if ( knownHard [ base ] || cache ?. get ( base ) === base ) {
2533
+ if ( knownHard . has ( base ) || cache ?. get ( base ) === base ) {
2534
2534
if ( isFileType ( binding . statValues , S_IFIFO ) ||
2535
2535
isFileType ( binding . statValues , S_IFSOCK ) ) {
2536
2536
break ;
@@ -2552,7 +2552,7 @@ function realpathSync(p, options) {
2552
2552
handleErrorFromBinding ( ctx ) ;
2553
2553
2554
2554
if ( ! isFileType ( stats , S_IFLNK ) ) {
2555
- knownHard [ base ] = true ;
2555
+ knownHard . add ( base ) ;
2556
2556
cache ?. set ( base , base ) ;
2557
2557
continue ;
2558
2558
}
@@ -2565,8 +2565,8 @@ function realpathSync(p, options) {
2565
2565
const dev = BigIntPrototypeToString ( stats [ 0 ] , 32 ) ;
2566
2566
const ino = BigIntPrototypeToString ( stats [ 7 ] , 32 ) ;
2567
2567
id = `${ dev } :${ ino } ` ;
2568
- if ( seenLinks [ id ] ) {
2569
- linkTarget = seenLinks [ id ] ;
2568
+ if ( seenLinks . has ( id ) ) {
2569
+ linkTarget = seenLinks . get ( id ) ;
2570
2570
}
2571
2571
}
2572
2572
if ( linkTarget === null ) {
@@ -2579,7 +2579,7 @@ function realpathSync(p, options) {
2579
2579
resolvedLink = pathModule . resolve ( previous , linkTarget ) ;
2580
2580
2581
2581
cache ?. set ( base , resolvedLink ) ;
2582
- if ( ! isWindows ) seenLinks [ id ] = linkTarget ;
2582
+ if ( ! isWindows ) seenLinks . set ( id , linkTarget ) ;
2583
2583
}
2584
2584
2585
2585
// Resolve the link, then start over
@@ -2590,11 +2590,11 @@ function realpathSync(p, options) {
2590
2590
pos = current . length ;
2591
2591
2592
2592
// On windows, check that the root exists. On unix there is no need.
2593
- if ( isWindows && ! knownHard [ base ] ) {
2593
+ if ( isWindows && ! knownHard . has ( base ) ) {
2594
2594
const ctx = { path : base } ;
2595
2595
binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2596
2596
handleErrorFromBinding ( ctx ) ;
2597
- knownHard [ base ] = true ;
2597
+ knownHard . add ( base ) ;
2598
2598
}
2599
2599
}
2600
2600
@@ -2639,8 +2639,8 @@ function realpath(p, options, callback) {
2639
2639
validatePath ( p ) ;
2640
2640
p = pathModule . resolve ( p ) ;
2641
2641
2642
- const seenLinks = ObjectCreate ( null ) ;
2643
- const knownHard = ObjectCreate ( null ) ;
2642
+ const seenLinks = new SafeMap ( ) ;
2643
+ const knownHard = new SafeSet ( ) ;
2644
2644
2645
2645
// Current character position in p
2646
2646
let pos ;
@@ -2655,10 +2655,10 @@ function realpath(p, options, callback) {
2655
2655
pos = current . length ;
2656
2656
2657
2657
// On windows, check that the root exists. On unix there is no need.
2658
- if ( isWindows && ! knownHard [ base ] ) {
2658
+ if ( isWindows && ! knownHard . has ( base ) ) {
2659
2659
fs . lstat ( base , ( err , stats ) => {
2660
2660
if ( err ) return callback ( err ) ;
2661
- knownHard [ base ] = true ;
2661
+ knownHard . add ( base ) ;
2662
2662
LOOP ( ) ;
2663
2663
} ) ;
2664
2664
} else {
@@ -2688,7 +2688,7 @@ function realpath(p, options, callback) {
2688
2688
}
2689
2689
2690
2690
// Continue if not a symlink, break if a pipe/socket
2691
- if ( knownHard [ base ] ) {
2691
+ if ( knownHard . has ( base ) ) {
2692
2692
if ( isFileType ( binding . statValues , S_IFIFO ) ||
2693
2693
isFileType ( binding . statValues , S_IFSOCK ) ) {
2694
2694
return callback ( null , encodeRealpathResult ( p , options ) ) ;
@@ -2704,7 +2704,7 @@ function realpath(p, options, callback) {
2704
2704
2705
2705
// If not a symlink, skip to the next path part
2706
2706
if ( ! stats . isSymbolicLink ( ) ) {
2707
- knownHard [ base ] = true ;
2707
+ knownHard . add ( base ) ;
2708
2708
return process . nextTick ( LOOP ) ;
2709
2709
}
2710
2710
@@ -2716,15 +2716,15 @@ function realpath(p, options, callback) {
2716
2716
const dev = BigIntPrototypeToString ( stats . dev , 32 ) ;
2717
2717
const ino = BigIntPrototypeToString ( stats . ino , 32 ) ;
2718
2718
id = `${ dev } :${ ino } ` ;
2719
- if ( seenLinks [ id ] ) {
2720
- return gotTarget ( null , seenLinks [ id ] ) ;
2719
+ if ( seenLinks . has ( id ) ) {
2720
+ return gotTarget ( null , seenLinks . get ( id ) ) ;
2721
2721
}
2722
2722
}
2723
2723
fs . stat ( base , ( err ) => {
2724
2724
if ( err ) return callback ( err ) ;
2725
2725
2726
2726
fs . readlink ( base , ( err , target ) => {
2727
- if ( ! isWindows ) seenLinks [ id ] = target ;
2727
+ if ( ! isWindows ) seenLinks . set ( id , target ) ;
2728
2728
gotTarget ( err , target ) ;
2729
2729
} ) ;
2730
2730
} ) ;
@@ -2743,10 +2743,10 @@ function realpath(p, options, callback) {
2743
2743
pos = current . length ;
2744
2744
2745
2745
// On windows, check that the root exists. On unix there is no need.
2746
- if ( isWindows && ! knownHard [ base ] ) {
2746
+ if ( isWindows && ! knownHard . has ( base ) ) {
2747
2747
fs . lstat ( base , ( err ) => {
2748
2748
if ( err ) return callback ( err ) ;
2749
- knownHard [ base ] = true ;
2749
+ knownHard . add ( base ) ;
2750
2750
LOOP ( ) ;
2751
2751
} ) ;
2752
2752
} else {
0 commit comments