Skip to content

Commit ae2c7d0

Browse files
Tchoupinaxtargos
authored andcommitted
lib: replace Date.now function by primordial DateNow
PR-URL: #30689 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent c09e3de commit ae2c7d0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/internal/fs/utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
ArrayIsArray,
5+
DateNow,
56
ObjectSetPrototypeOf,
67
ReflectOwnKeys,
78
} = primordials;
@@ -487,7 +488,7 @@ function toUnixTimestamp(time, name = 'time') {
487488
}
488489
if (Number.isFinite(time)) {
489490
if (time < 0) {
490-
return Date.now() / 1000;
491+
return DateNow() / 1000;
491492
}
492493
return time;
493494
}

lib/readline.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'use strict';
2929

3030
const {
31+
DateNow,
3132
MathCeil,
3233
MathFloor,
3334
MathMax,
@@ -442,7 +443,7 @@ Interface.prototype._normalWrite = function(b) {
442443
}
443444
let string = this._decoder.write(b);
444445
if (this._sawReturnAt &&
445-
Date.now() - this._sawReturnAt <= this.crlfDelay) {
446+
DateNow() - this._sawReturnAt <= this.crlfDelay) {
446447
string = string.replace(/^\n/, '');
447448
this._sawReturnAt = 0;
448449
}
@@ -455,7 +456,7 @@ Interface.prototype._normalWrite = function(b) {
455456
this._line_buffer = null;
456457
}
457458
if (newPartContainsEnding) {
458-
this._sawReturnAt = string.endsWith('\r') ? Date.now() : 0;
459+
this._sawReturnAt = string.endsWith('\r') ? DateNow() : 0;
459460

460461
// Got one or more newlines; process into "line" events
461462
const lines = string.split(lineEnding);
@@ -838,14 +839,14 @@ function _ttyWriteDumb(s, key) {
838839

839840
switch (key.name) {
840841
case 'return': // Carriage return, i.e. \r
841-
this._sawReturnAt = Date.now();
842+
this._sawReturnAt = DateNow();
842843
this._line();
843844
break;
844845

845846
case 'enter':
846847
// When key interval > crlfDelay
847848
if (this._sawReturnAt === 0 ||
848-
Date.now() - this._sawReturnAt > this.crlfDelay) {
849+
DateNow() - this._sawReturnAt > this.crlfDelay) {
849850
this._line();
850851
}
851852
this._sawReturnAt = 0;
@@ -1019,14 +1020,14 @@ Interface.prototype._ttyWrite = function(s, key) {
10191020

10201021
switch (key.name) {
10211022
case 'return': // Carriage return, i.e. \r
1022-
this._sawReturnAt = Date.now();
1023+
this._sawReturnAt = DateNow();
10231024
this._line();
10241025
break;
10251026

10261027
case 'enter':
10271028
// When key interval > crlfDelay
10281029
if (this._sawReturnAt === 0 ||
1029-
Date.now() - this._sawReturnAt > this.crlfDelay) {
1030+
DateNow() - this._sawReturnAt > this.crlfDelay) {
10301031
this._line();
10311032
}
10321033
this._sawReturnAt = 0;

0 commit comments

Comments
 (0)