@@ -12,6 +12,8 @@ const {
12
12
NumberIsFinite,
13
13
MathMin,
14
14
MathRound,
15
+ ObjectDefineProperties,
16
+ ObjectDefineProperty,
15
17
ObjectIs,
16
18
ObjectSetPrototypeOf,
17
19
ReflectApply,
@@ -449,6 +451,62 @@ function dateFromMs(ms) {
449
451
return new Date ( MathRound ( Number ( ms ) ) ) ;
450
452
}
451
453
454
+ const lazyDateFields = {
455
+ __proto__ : null ,
456
+ atime : {
457
+ __proto__ : null ,
458
+ enumerable : true ,
459
+ configurable : true ,
460
+ get ( ) {
461
+ const value = dateFromMs ( this . atimeMs ) ;
462
+ ObjectDefineProperty ( this , 'atime' , { __proto__ : null , value } ) ;
463
+ return this . atime ;
464
+ } ,
465
+ set ( value ) {
466
+ this . atime = value ;
467
+ } ,
468
+ } ,
469
+ mtime : {
470
+ __proto__ : null ,
471
+ enumerable : true ,
472
+ configurable : true ,
473
+ get ( ) {
474
+ const value = dateFromMs ( this . mtimeMs ) ;
475
+ ObjectDefineProperty ( this , 'mtime' , { __proto__ : null , value } ) ;
476
+ return this . mtime ;
477
+ } ,
478
+ set ( value ) {
479
+ this . mtime = value ;
480
+ } ,
481
+ } ,
482
+ ctime : {
483
+ __proto__ : null ,
484
+ enumerable : true ,
485
+ configurable : true ,
486
+ get ( ) {
487
+ const value = dateFromMs ( this . ctimeMs ) ;
488
+ ObjectDefineProperty ( this , 'ctime' , { __proto__ : null , value } ) ;
489
+ return this . ctime ;
490
+ } ,
491
+ set ( value ) {
492
+ this . ctime = value ;
493
+ } ,
494
+ } ,
495
+ birthtime : {
496
+ __proto__ : null ,
497
+ enumerable : true ,
498
+ configurable : true ,
499
+ get ( ) {
500
+ const value = dateFromMs ( this . birthtimeMs ) ;
501
+ ObjectDefineProperty ( this , 'birthtime' , { __proto__ : null , value } ) ;
502
+ return this . birthtime ;
503
+ } ,
504
+ set ( value ) {
505
+ this . birthtime = value ;
506
+ } ,
507
+ } ,
508
+ } ;
509
+
452
510
function BigIntStats ( dev , mode , nlink , uid , gid , rdev , blksize ,
453
511
ino , size , blocks ,
454
512
atimeNs , mtimeNs , ctimeNs , birthtimeNs ) {
@@ -463,14 +521,11 @@ function BigIntStats(dev, mode, nlink, uid, gid, rdev, blksize,
463
521
this . mtimeNs = mtimeNs ;
464
522
this . ctimeNs = ctimeNs ;
465
523
this . birthtimeNs = birthtimeNs ;
466
- this . atime = dateFromMs ( this . atimeMs ) ;
467
- this . mtime = dateFromMs ( this . mtimeMs ) ;
468
- this . ctime = dateFromMs ( this . ctimeMs ) ;
469
- this . birthtime = dateFromMs ( this . birthtimeMs ) ;
470
524
}
471
525
472
526
ObjectSetPrototypeOf ( BigIntStats . prototype , StatsBase . prototype ) ;
473
527
ObjectSetPrototypeOf ( BigIntStats , StatsBase ) ;
528
+ ObjectDefineProperties ( BigIntStats . prototype , lazyDateFields ) ;
474
529
475
530
BigIntStats . prototype . _checkModeProperty = function ( property ) {
476
531
if ( isWindows && ( property === S_IFIFO || property === S_IFBLK ||
@@ -489,14 +544,11 @@ function Stats(dev, mode, nlink, uid, gid, rdev, blksize,
489
544
this . mtimeMs = mtimeMs ;
490
545
this . ctimeMs = ctimeMs ;
491
546
this . birthtimeMs = birthtimeMs ;
492
- this . atime = dateFromMs ( atimeMs ) ;
493
- this . mtime = dateFromMs ( mtimeMs ) ;
494
- this . ctime = dateFromMs ( ctimeMs ) ;
495
- this . birthtime = dateFromMs ( birthtimeMs ) ;
496
547
}
497
548
498
549
ObjectSetPrototypeOf ( Stats . prototype , StatsBase . prototype ) ;
499
550
ObjectSetPrototypeOf ( Stats , StatsBase ) ;
551
+ ObjectDefineProperties ( Stats . prototype , lazyDateFields ) ;
500
552
501
553
Stats . prototype . _checkModeProperty = function ( property ) {
502
554
if ( isWindows && ( property === S_IFIFO || property === S_IFBLK ||
0 commit comments