Skip to content

Commit

Permalink
lib: replace Date.now function by primordial DateNow
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Tchoupinax authored and targos committed Dec 1, 2019
1 parent c09e3de commit ae2c7d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
ArrayIsArray,
DateNow,
ObjectSetPrototypeOf,
ReflectOwnKeys,
} = primordials;
Expand Down Expand Up @@ -487,7 +488,7 @@ function toUnixTimestamp(time, name = 'time') {
}
if (Number.isFinite(time)) {
if (time < 0) {
return Date.now() / 1000;
return DateNow() / 1000;
}
return time;
}
Expand Down
13 changes: 7 additions & 6 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'use strict';

const {
DateNow,
MathCeil,
MathFloor,
MathMax,
Expand Down Expand Up @@ -442,7 +443,7 @@ Interface.prototype._normalWrite = function(b) {
}
let string = this._decoder.write(b);
if (this._sawReturnAt &&
Date.now() - this._sawReturnAt <= this.crlfDelay) {
DateNow() - this._sawReturnAt <= this.crlfDelay) {
string = string.replace(/^\n/, '');
this._sawReturnAt = 0;
}
Expand All @@ -455,7 +456,7 @@ Interface.prototype._normalWrite = function(b) {
this._line_buffer = null;
}
if (newPartContainsEnding) {
this._sawReturnAt = string.endsWith('\r') ? Date.now() : 0;
this._sawReturnAt = string.endsWith('\r') ? DateNow() : 0;

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

switch (key.name) {
case 'return': // Carriage return, i.e. \r
this._sawReturnAt = Date.now();
this._sawReturnAt = DateNow();
this._line();
break;

case 'enter':
// When key interval > crlfDelay
if (this._sawReturnAt === 0 ||
Date.now() - this._sawReturnAt > this.crlfDelay) {
DateNow() - this._sawReturnAt > this.crlfDelay) {
this._line();
}
this._sawReturnAt = 0;
Expand Down Expand Up @@ -1019,14 +1020,14 @@ Interface.prototype._ttyWrite = function(s, key) {

switch (key.name) {
case 'return': // Carriage return, i.e. \r
this._sawReturnAt = Date.now();
this._sawReturnAt = DateNow();
this._line();
break;

case 'enter':
// When key interval > crlfDelay
if (this._sawReturnAt === 0 ||
Date.now() - this._sawReturnAt > this.crlfDelay) {
DateNow() - this._sawReturnAt > this.crlfDelay) {
this._line();
}
this._sawReturnAt = 0;
Expand Down

0 comments on commit ae2c7d0

Please sign in to comment.