@@ -83,7 +83,13 @@ const {
83
83
84
84
const { FSReqCallback } = binding ;
85
85
const { toPathIfFileURL } = require ( 'internal/url' ) ;
86
- const internalUtil = require ( 'internal/util' ) ;
86
+ const {
87
+ customPromisifyArgs : kCustomPromisifyArgsSymbol ,
88
+ kEmptyObject,
89
+ promisify : {
90
+ custom : kCustomPromisifiedSymbol ,
91
+ } ,
92
+ } = require ( 'internal/util' ) ;
87
93
const {
88
94
constants : {
89
95
kIoMaxLength,
@@ -272,7 +278,7 @@ function exists(path, callback) {
272
278
}
273
279
}
274
280
275
- ObjectDefineProperty ( exists , internalUtil . promisify . custom , {
281
+ ObjectDefineProperty ( exists , kCustomPromisifiedSymbol , {
276
282
__proto__ : null ,
277
283
value : function exists ( path ) { // eslint-disable-line func-name-matching
278
284
return new Promise ( ( resolve ) => fs . exists ( path , resolve ) ) ;
@@ -619,7 +625,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
619
625
if ( ! isArrayBufferView ( buffer ) ) {
620
626
// This is fs.read(fd, params, callback)
621
627
params = buffer ;
622
- ( { buffer = Buffer . alloc ( 16384 ) } = params ?? ObjectCreate ( null ) ) ;
628
+ ( { buffer = Buffer . alloc ( 16384 ) } = params ?? kEmptyObject ) ;
623
629
}
624
630
callback = offsetOrOptions ;
625
631
} else {
@@ -632,7 +638,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
632
638
offset = 0 ,
633
639
length = buffer . byteLength - offset ,
634
640
position = null ,
635
- } = params ?? ObjectCreate ( null ) ) ;
641
+ } = params ?? kEmptyObject ) ;
636
642
}
637
643
638
644
validateBuffer ( buffer ) ;
@@ -675,7 +681,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
675
681
binding . read ( fd , buffer , offset , length , position , req ) ;
676
682
}
677
683
678
- ObjectDefineProperty ( read , internalUtil . customPromisifyArgs ,
684
+ ObjectDefineProperty ( read , kCustomPromisifyArgsSymbol ,
679
685
{ __proto__ : null , value : [ 'bytesRead' , 'buffer' ] , enumerable : false } ) ;
680
686
681
687
/**
@@ -697,7 +703,7 @@ function readSync(fd, buffer, offset, length, position) {
697
703
698
704
if ( arguments . length <= 3 ) {
699
705
// Assume fs.readSync(fd, buffer, options)
700
- const options = offset || ObjectCreate ( null ) ;
706
+ const options = offset || kEmptyObject ;
701
707
702
708
( {
703
709
offset = 0 ,
@@ -768,7 +774,7 @@ function readv(fd, buffers, position, callback) {
768
774
return binding . readBuffers ( fd , buffers , position , req ) ;
769
775
}
770
776
771
- ObjectDefineProperty ( readv , internalUtil . customPromisifyArgs ,
777
+ ObjectDefineProperty ( readv , kCustomPromisifyArgsSymbol ,
772
778
{ __proto__ : null , value : [ 'bytesRead' , 'buffers' ] , enumerable : false } ) ;
773
779
774
780
/**
@@ -825,7 +831,7 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) {
825
831
offset = 0 ,
826
832
length = buffer . byteLength - offset ,
827
833
position = null ,
828
- } = offsetOrOptions ?? ObjectCreate ( null ) ) ;
834
+ } = offsetOrOptions ?? kEmptyObject ) ;
829
835
}
830
836
831
837
if ( offset == null || typeof offset === 'function' ) {
@@ -865,7 +871,7 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) {
865
871
return binding . writeString ( fd , str , offset , length , req ) ;
866
872
}
867
873
868
- ObjectDefineProperty ( write , internalUtil . customPromisifyArgs ,
874
+ ObjectDefineProperty ( write , kCustomPromisifyArgsSymbol ,
869
875
{ __proto__ : null , value : [ 'bytesWritten' , 'buffer' ] , enumerable : false } ) ;
870
876
871
877
/**
@@ -892,7 +898,7 @@ function writeSync(fd, buffer, offsetOrOptions, length, position) {
892
898
offset = 0 ,
893
899
length = buffer . byteLength - offset ,
894
900
position = null ,
895
- } = offsetOrOptions ?? ObjectCreate ( null ) ) ;
901
+ } = offsetOrOptions ?? kEmptyObject ) ;
896
902
}
897
903
if ( position === undefined )
898
904
position = null ;
@@ -955,7 +961,7 @@ function writev(fd, buffers, position, callback) {
955
961
return binding . writeBuffers ( fd , buffers , position , req ) ;
956
962
}
957
963
958
- ObjectDefineProperty ( writev , internalUtil . customPromisifyArgs , {
964
+ ObjectDefineProperty ( writev , kCustomPromisifyArgsSymbol , {
959
965
__proto__ : null ,
960
966
value : [ 'bytesWritten' , 'buffer' ] ,
961
967
enumerable : false
@@ -1398,7 +1404,7 @@ function mkdirSync(path, options) {
1398
1404
*/
1399
1405
function readdir ( path , options , callback ) {
1400
1406
callback = makeCallback ( typeof options === 'function' ? options : callback ) ;
1401
- options = getOptions ( options , { } ) ;
1407
+ options = getOptions ( options ) ;
1402
1408
path = getValidatedPath ( path ) ;
1403
1409
1404
1410
const req = new FSReqCallback ( ) ;
@@ -1427,7 +1433,7 @@ function readdir(path, options, callback) {
1427
1433
* @returns {string | Buffer[] | Dirent[] }
1428
1434
*/
1429
1435
function readdirSync ( path , options ) {
1430
- options = getOptions ( options , { } ) ;
1436
+ options = getOptions ( options ) ;
1431
1437
path = getValidatedPath ( path ) ;
1432
1438
const ctx = { path } ;
1433
1439
const result = binding . readdir ( pathModule . toNamespacedPath ( path ) ,
@@ -1451,7 +1457,7 @@ function readdirSync(path, options) {
1451
1457
function fstat ( fd , options = { bigint : false } , callback ) {
1452
1458
if ( typeof options === 'function' ) {
1453
1459
callback = options ;
1454
- options = { } ;
1460
+ options = kEmptyObject ;
1455
1461
}
1456
1462
fd = getValidatedFd ( fd ) ;
1457
1463
callback = makeStatsCallback ( callback ) ;
@@ -1475,7 +1481,7 @@ function fstat(fd, options = { bigint: false }, callback) {
1475
1481
function lstat ( path , options = { bigint : false } , callback ) {
1476
1482
if ( typeof options === 'function' ) {
1477
1483
callback = options ;
1478
- options = { } ;
1484
+ options = kEmptyObject ;
1479
1485
}
1480
1486
callback = makeStatsCallback ( callback ) ;
1481
1487
path = getValidatedPath ( path ) ;
@@ -1498,7 +1504,7 @@ function lstat(path, options = { bigint: false }, callback) {
1498
1504
function stat ( path , options = { bigint : false } , callback ) {
1499
1505
if ( typeof options === 'function' ) {
1500
1506
callback = options ;
1501
- options = { } ;
1507
+ options = kEmptyObject ;
1502
1508
}
1503
1509
callback = makeStatsCallback ( callback ) ;
1504
1510
path = getValidatedPath ( path ) ;
@@ -1596,7 +1602,7 @@ function statSync(path, options = { bigint: false, throwIfNoEntry: true }) {
1596
1602
*/
1597
1603
function readlink ( path , options , callback ) {
1598
1604
callback = makeCallback ( typeof options === 'function' ? options : callback ) ;
1599
- options = getOptions ( options , { } ) ;
1605
+ options = getOptions ( options ) ;
1600
1606
path = getValidatedPath ( path , 'oldPath' ) ;
1601
1607
const req = new FSReqCallback ( ) ;
1602
1608
req . oncomplete = callback ;
@@ -1611,7 +1617,7 @@ function readlink(path, options, callback) {
1611
1617
* @returns {string | Buffer }
1612
1618
*/
1613
1619
function readlinkSync ( path , options ) {
1614
- options = getOptions ( options , { } ) ;
1620
+ options = getOptions ( options ) ;
1615
1621
path = getValidatedPath ( path , 'oldPath' ) ;
1616
1622
const ctx = { path } ;
1617
1623
const result = binding . readlink ( pathModule . toNamespacedPath ( path ) ,
@@ -2282,7 +2288,7 @@ function watch(filename, options, listener) {
2282
2288
if ( typeof options === 'function' ) {
2283
2289
listener = options ;
2284
2290
}
2285
- options = getOptions ( options , { } ) ;
2291
+ options = getOptions ( options ) ;
2286
2292
2287
2293
// Don't make changes directly on options object
2288
2294
options = copyObject ( options ) ;
@@ -2445,16 +2451,14 @@ if (isWindows) {
2445
2451
} ;
2446
2452
}
2447
2453
2448
- const emptyObj = ObjectCreate ( null ) ;
2449
-
2450
2454
/**
2451
2455
* Returns the resolved pathname.
2452
2456
* @param {string | Buffer | URL } p
2453
2457
* @param {string | { encoding?: string | null; } } [options]
2454
2458
* @returns {string | Buffer }
2455
2459
*/
2456
2460
function realpathSync ( p , options ) {
2457
- options = getOptions ( options , emptyObj ) ;
2461
+ options = getOptions ( options ) ;
2458
2462
p = toPathIfFileURL ( p ) ;
2459
2463
if ( typeof p !== 'string' ) {
2460
2464
p += '' ;
@@ -2591,7 +2595,7 @@ function realpathSync(p, options) {
2591
2595
* @returns {string | Buffer }
2592
2596
*/
2593
2597
realpathSync . native = ( path , options ) => {
2594
- options = getOptions ( options , { } ) ;
2598
+ options = getOptions ( options ) ;
2595
2599
path = getValidatedPath ( path ) ;
2596
2600
const ctx = { path } ;
2597
2601
const result = binding . realpath ( path , options . encoding , undefined , ctx ) ;
@@ -2612,7 +2616,7 @@ realpathSync.native = (path, options) => {
2612
2616
*/
2613
2617
function realpath ( p , options , callback ) {
2614
2618
callback = typeof options === 'function' ? options : maybeCallback ( callback ) ;
2615
- options = getOptions ( options , { } ) ;
2619
+ options = getOptions ( options ) ;
2616
2620
p = toPathIfFileURL ( p ) ;
2617
2621
2618
2622
if ( typeof p !== 'string' ) {
@@ -2750,7 +2754,7 @@ function realpath(p, options, callback) {
2750
2754
*/
2751
2755
realpath . native = ( path , options , callback ) => {
2752
2756
callback = makeCallback ( callback || options ) ;
2753
- options = getOptions ( options , { } ) ;
2757
+ options = getOptions ( options ) ;
2754
2758
path = getValidatedPath ( path ) ;
2755
2759
const req = new FSReqCallback ( ) ;
2756
2760
req . oncomplete = callback ;
@@ -2769,7 +2773,7 @@ realpath.native = (path, options, callback) => {
2769
2773
*/
2770
2774
function mkdtemp ( prefix , options , callback ) {
2771
2775
callback = makeCallback ( typeof options === 'function' ? options : callback ) ;
2772
- options = getOptions ( options , { } ) ;
2776
+ options = getOptions ( options ) ;
2773
2777
2774
2778
validateString ( prefix , 'prefix' ) ;
2775
2779
nullCheck ( prefix , 'prefix' ) ;
@@ -2786,7 +2790,7 @@ function mkdtemp(prefix, options, callback) {
2786
2790
* @returns {string }
2787
2791
*/
2788
2792
function mkdtempSync ( prefix , options ) {
2789
- options = getOptions ( options , { } ) ;
2793
+ options = getOptions ( options ) ;
2790
2794
2791
2795
validateString ( prefix , 'prefix' ) ;
2792
2796
nullCheck ( prefix , 'prefix' ) ;
0 commit comments