Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: replace Date.now function by primordial DateNow
  • Loading branch information
Tchoupinax committed Nov 27, 2019
commit 08f7d826e97160f0c38b6d65c3276ed72eca831b
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