Skip to content

Commit

Permalink
fs: load dates lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Nov 25, 2023
1 parent 7981e2e commit a16d5b4
Showing 1 changed file with 74 additions and 8 deletions.
82 changes: 74 additions & 8 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
NumberIsFinite,
MathMin,
MathRound,
ObjectDefineProperty,
ObjectIs,
ObjectSetPrototypeOf,
ReflectApply,
Expand Down Expand Up @@ -462,15 +463,47 @@ 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', {

Check failure on line 471 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Must use null-prototype object for property descriptors
enumerable: true,
get: function() {
const value = dateFromMs(this.atimeMs);
ObjectDefineProperty(this, 'atime', { __proto__: null, value });
return this.atime;
}

Check failure on line 477 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});

ObjectDefineProperty(BigIntStats.prototype, 'mtime', {

Check failure on line 480 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Must use null-prototype object for property descriptors
enumerable: true,
get: function() {
const value = dateFromMs(this.mtimeMs);
ObjectDefineProperty(this, 'mtime', { __proto__: null, value });
return this.mtime;
}

Check failure on line 486 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});

ObjectDefineProperty(BigIntStats.prototype, 'ctime', {

Check failure on line 489 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Must use null-prototype object for property descriptors
enumerable: true,
get: function() {
const value = dateFromMs(this.ctimeMs);
ObjectDefineProperty(this, 'ctime', { __proto__: null, value });
return this.ctime;
}

Check failure on line 495 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});

ObjectDefineProperty(BigIntStats.prototype, 'birthtime', {

Check failure on line 498 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Must use null-prototype object for property descriptors
enumerable: true,
get: function() {
const value = dateFromMs(this.birthtimeMs);
ObjectDefineProperty(this, 'birthtime', { __proto__: null, value });
return this.birthtime;
}

Check failure on line 504 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});

BigIntStats.prototype._checkModeProperty = function(property) {
if (isWindows && (property === S_IFIFO || property === S_IFBLK ||
property === S_IFSOCK)) {
Expand All @@ -488,15 +521,48 @@ 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', {

Check failure on line 529 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Must use null-prototype object for property descriptors
enumerable: true,
get: function() {
const value = dateFromMs(this.atimeMs);
ObjectDefineProperty(this, 'atime', { __proto__: null, value });
return this.atime;
}

Check failure on line 535 in lib/internal/fs/utils.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});

ObjectDefineProperty(Stats.prototype, 'mtime', {
enumerable: true,
get: function() {
console.log('getter called mtime')
const value = dateFromMs(this.mtimeMs);
ObjectDefineProperty(this, 'mtime', { __proto__: null, value });
return this.mtime;
}
});

ObjectDefineProperty(Stats.prototype, 'ctime', {
enumerable: true,
get: function() {
const value = dateFromMs(this.ctimeMs);
ObjectDefineProperty(this, 'ctime', { __proto__: null, value });
return this.ctime;
}
});

ObjectDefineProperty(Stats.prototype, 'birthtime', {
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;
Expand Down

0 comments on commit a16d5b4

Please sign in to comment.