Skip to content

Commit ae6c704

Browse files
committed
Revert "lib: lazy instantiation of fs.Stats dates"
This reverts commit 9836cf5. Ref: npm/npm#16734 PR-URL: #13256 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent e710036 commit ae6c704

File tree

2 files changed

+4
-94
lines changed

2 files changed

+4
-94
lines changed

lib/fs.js

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -196,81 +196,13 @@ function Stats(
196196
this.ino = ino;
197197
this.size = size;
198198
this.blocks = blocks;
199-
this._atim_msec = atim_msec;
200-
this._mtim_msec = mtim_msec;
201-
this._ctim_msec = ctim_msec;
202-
this._birthtim_msec = birthtim_msec;
199+
this.atime = new Date(atim_msec + 0.5);
200+
this.mtime = new Date(mtim_msec + 0.5);
201+
this.ctime = new Date(ctim_msec + 0.5);
202+
this.birthtime = new Date(birthtim_msec + 0.5);
203203
}
204204
fs.Stats = Stats;
205205

206-
// defining the properties in this fashion (explicitly with no loop or factory)
207-
// has been shown to be the most performant on V8 contemp.
208-
// Ref: https://github.com/nodejs/node/pull/12818
209-
// + 0.5 is added to the Dates to protect values from being rounded down
210-
// Ref: https://github.com/nodejs/node/pull/12607
211-
Object.defineProperties(Stats.prototype, {
212-
atime: {
213-
configurable: true,
214-
enumerable: true,
215-
get() {
216-
return this._atime !== undefined ?
217-
this._atime :
218-
(this._atime = new Date(this._atim_msec + 0.5));
219-
},
220-
set(value) { return this._atime = value; }
221-
},
222-
mtime: {
223-
configurable: true,
224-
enumerable: true,
225-
get() {
226-
return this._mtime !== undefined ?
227-
this._mtime :
228-
(this._mtime = new Date(this._mtim_msec + 0.5));
229-
},
230-
set(value) { return this._mtime = value; }
231-
},
232-
ctime: {
233-
configurable: true,
234-
enumerable: true,
235-
get() {
236-
return this._ctime !== undefined ?
237-
this._ctime :
238-
(this._ctime = new Date(this._ctim_msec + 0.5));
239-
},
240-
set(value) { return this._ctime = value; }
241-
},
242-
birthtime: {
243-
configurable: true,
244-
enumerable: true,
245-
get() {
246-
return this._birthtime !== undefined ?
247-
this._birthtime :
248-
(this._birthtime = new Date(this._birthtim_msec + 0.5));
249-
},
250-
set(value) { return this._birthtime = value; }
251-
},
252-
});
253-
254-
Stats.prototype.toJSON = function toJSON() {
255-
return {
256-
dev: this.dev,
257-
mode: this.mode,
258-
nlink: this.nlink,
259-
uid: this.uid,
260-
gid: this.gid,
261-
rdev: this.rdev,
262-
blksize: this.blksize,
263-
ino: this.ino,
264-
size: this.size,
265-
blocks: this.blocks,
266-
atime: this.atime,
267-
ctime: this.ctime,
268-
mtime: this.mtime,
269-
birthtime: this.birthtime
270-
};
271-
};
272-
273-
274206
Stats.prototype._checkModeProperty = function(property) {
275207
return ((this.mode & S_IFMT) === property);
276208
};

test/parallel/test-fs-stat.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,5 @@ fs.stat(__filename, common.mustCall(function(err, s) {
9898
console.log(`isSymbolicLink: ${JSON.stringify(s.isSymbolicLink())}`);
9999
assert.strictEqual(false, s.isSymbolicLink());
100100

101-
assert.ok(s.atime instanceof Date);
102101
assert.ok(s.mtime instanceof Date);
103-
assert.ok(s.ctime instanceof Date);
104-
assert.ok(s.birthtime instanceof Date);
105-
}));
106-
107-
fs.stat(__filename, common.mustCall(function(err, s) {
108-
const json = JSON.parse(JSON.stringify(s));
109-
const keys = [
110-
'dev', 'mode', 'nlink', 'uid',
111-
'gid', 'rdev', 'ino',
112-
'size', 'atime', 'mtime',
113-
'ctime', 'birthtime'
114-
];
115-
if (!common.isWindows) {
116-
keys.push('blocks', 'blksize');
117-
}
118-
keys.forEach(function(k) {
119-
assert.ok(
120-
json[k] !== undefined && json[k] !== null,
121-
k + ' should not be null or undefined'
122-
);
123-
});
124102
}));

0 commit comments

Comments
 (0)