diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 9f5ad9bf5f6c0e..40b224e58a14e0 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -12,6 +12,7 @@ const { NumberIsFinite, MathMin, MathRound, + ObjectDefineProperty, ObjectIs, ObjectSetPrototypeOf, ReflectApply, @@ -462,15 +463,51 @@ function BigIntStats(dev, mode, nlink, uid, gid, rdev, blksize, this.mtimeNs = mtimeNs; this.ctimeNs = ctimeNs; this.birthtimeNs = birthtimeNs; - this.atime = dateFromMs(this.atimeMs); - this.mtime = dateFromMs(this.mtimeMs); - this.ctime = dateFromMs(this.ctimeMs); - this.birthtime = dateFromMs(this.birthtimeMs); } ObjectSetPrototypeOf(BigIntStats.prototype, StatsBase.prototype); ObjectSetPrototypeOf(BigIntStats, StatsBase); +ObjectDefineProperty(BigIntStats.prototype, 'atime', { + __proto__: null, + enumerable: true, + get: function() { + const value = dateFromMs(this.atimeMs); + ObjectDefineProperty(this, 'atime', { __proto__: null, value }); + return this.atime; + }, +}); + +ObjectDefineProperty(BigIntStats.prototype, 'mtime', { + __proto__: null, + enumerable: true, + get: function() { + const value = dateFromMs(this.mtimeMs); + ObjectDefineProperty(this, 'mtime', { __proto__: null, value }); + return this.mtime; + }, +}); + +ObjectDefineProperty(BigIntStats.prototype, 'ctime', { + __proto__: null, + enumerable: true, + get: function() { + const value = dateFromMs(this.ctimeMs); + ObjectDefineProperty(this, 'ctime', { __proto__: null, value }); + return this.ctime; + }, +}); + +ObjectDefineProperty(BigIntStats.prototype, 'birthtime', { + __proto__: null, + enumerable: true, + get: function() { + const value = dateFromMs(this.birthtimeMs); + ObjectDefineProperty(this, 'birthtime', { __proto__: null, value }); + return this.birthtime; + }, +}); + BigIntStats.prototype._checkModeProperty = function(property) { if (isWindows && (property === S_IFIFO || property === S_IFBLK || property === S_IFSOCK)) { @@ -488,15 +525,51 @@ function Stats(dev, mode, nlink, uid, gid, rdev, blksize, this.mtimeMs = mtimeMs; this.ctimeMs = ctimeMs; this.birthtimeMs = birthtimeMs; - this.atime = dateFromMs(atimeMs); - this.mtime = dateFromMs(mtimeMs); - this.ctime = dateFromMs(ctimeMs); - this.birthtime = dateFromMs(birthtimeMs); } ObjectSetPrototypeOf(Stats.prototype, StatsBase.prototype); ObjectSetPrototypeOf(Stats, StatsBase); +ObjectDefineProperty(Stats.prototype, 'atime', { + __proto__: null, + enumerable: true, + get: function() { + const value = dateFromMs(this.atimeMs); + ObjectDefineProperty(this, 'atime', { __proto__: null, value }); + return this.atime; + }, +}); + +ObjectDefineProperty(Stats.prototype, 'mtime', { + __proto__: null, + enumerable: true, + get: function() { + const value = dateFromMs(this.mtimeMs); + ObjectDefineProperty(this, 'mtime', { __proto__: null, value }); + return this.mtime; + }, +}); + +ObjectDefineProperty(Stats.prototype, 'ctime', { + __proto__: null, + enumerable: true, + get: function() { + const value = dateFromMs(this.ctimeMs); + ObjectDefineProperty(this, 'ctime', { __proto__: null, value }); + return this.ctime; + }, +}); + +ObjectDefineProperty(Stats.prototype, 'birthtime', { + __proto__: null, + enumerable: true, + get: function() { + const value = dateFromMs(this.birthtimeMs); + ObjectDefineProperty(this, 'birthtime', { __proto__: null, value }); + return this.birthtime; + }, +}); + // HACK: Workaround for https://github.com/standard-things/esm/issues/821. // TODO(ronag): Remove this as soon as `esm` publishes a fixed version. Stats.prototype.isFile = StatsBase.prototype.isFile;