timers: rename validateTimerDuration to getTimerDuration
The function did not only validate the timer but it caused side effects like a warning and potentially returned a different value than the input value. Thus the name `validate` did not seem to be appropriate. PR-URL: https://github.com/nodejs/node/pull/26809 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
6c913fb028
commit
9e8c9be3ff
@ -45,7 +45,7 @@ const {
|
|||||||
ERR_INVALID_PROTOCOL,
|
ERR_INVALID_PROTOCOL,
|
||||||
ERR_UNESCAPED_CHARACTERS
|
ERR_UNESCAPED_CHARACTERS
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
const { validateTimerDuration } = require('internal/timers');
|
const { getTimerDuration } = require('internal/timers');
|
||||||
const is_reused_symbol = require('internal/freelist').symbols.is_reused_symbol;
|
const is_reused_symbol = require('internal/freelist').symbols.is_reused_symbol;
|
||||||
const {
|
const {
|
||||||
DTRACE_HTTP_CLIENT_REQUEST,
|
DTRACE_HTTP_CLIENT_REQUEST,
|
||||||
@ -146,7 +146,7 @@ function ClientRequest(input, options, cb) {
|
|||||||
this.socketPath = options.socketPath;
|
this.socketPath = options.socketPath;
|
||||||
|
|
||||||
if (options.timeout !== undefined)
|
if (options.timeout !== undefined)
|
||||||
this.timeout = validateTimerDuration(options.timeout, 'timeout');
|
this.timeout = getTimerDuration(options.timeout, 'timeout');
|
||||||
|
|
||||||
var method = options.method;
|
var method = options.method;
|
||||||
var methodIsString = (typeof method === 'string');
|
var methodIsString = (typeof method === 'string');
|
||||||
@ -743,7 +743,7 @@ ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listenSocketTimeout(this);
|
listenSocketTimeout(this);
|
||||||
msecs = validateTimerDuration(msecs, 'msecs');
|
msecs = getTimerDuration(msecs, 'msecs');
|
||||||
if (callback) this.once('timeout', callback);
|
if (callback) this.once('timeout', callback);
|
||||||
|
|
||||||
if (this.socket) {
|
if (this.socket) {
|
||||||
|
@ -21,7 +21,7 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
|
|||||||
const {
|
const {
|
||||||
kTimeout,
|
kTimeout,
|
||||||
setUnrefTimeout,
|
setUnrefTimeout,
|
||||||
validateTimerDuration
|
getTimerDuration
|
||||||
} = require('internal/timers');
|
} = require('internal/timers');
|
||||||
|
|
||||||
const kMaybeDestroy = Symbol('kMaybeDestroy');
|
const kMaybeDestroy = Symbol('kMaybeDestroy');
|
||||||
@ -205,7 +205,7 @@ function setStreamTimeout(msecs, callback) {
|
|||||||
this.timeout = msecs;
|
this.timeout = msecs;
|
||||||
|
|
||||||
// Type checking identical to timers.enroll()
|
// Type checking identical to timers.enroll()
|
||||||
msecs = validateTimerDuration(msecs, 'msecs');
|
msecs = getTimerDuration(msecs, 'msecs');
|
||||||
|
|
||||||
// Attempt to clear an existing timer in both cases -
|
// Attempt to clear an existing timer in both cases -
|
||||||
// even if it will be rescheduled we don't want to leak an existing timer.
|
// even if it will be rescheduled we don't want to leak an existing timer.
|
||||||
|
@ -359,7 +359,7 @@ function setUnrefTimeout(callback, after) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Type checking used by timers.enroll() and Socket#setTimeout()
|
// Type checking used by timers.enroll() and Socket#setTimeout()
|
||||||
function validateTimerDuration(msecs, name) {
|
function getTimerDuration(msecs, name) {
|
||||||
validateNumber(msecs, name);
|
validateNumber(msecs, name);
|
||||||
if (msecs < 0 || !isFinite(msecs)) {
|
if (msecs < 0 || !isFinite(msecs)) {
|
||||||
throw new ERR_OUT_OF_RANGE(name, 'a non-negative finite number', msecs);
|
throw new ERR_OUT_OF_RANGE(name, 'a non-negative finite number', msecs);
|
||||||
@ -586,7 +586,7 @@ module.exports = {
|
|||||||
kRefed,
|
kRefed,
|
||||||
initAsyncResource,
|
initAsyncResource,
|
||||||
setUnrefTimeout,
|
setUnrefTimeout,
|
||||||
validateTimerDuration,
|
getTimerDuration,
|
||||||
immediateQueue,
|
immediateQueue,
|
||||||
getTimerCallbacks,
|
getTimerCallbacks,
|
||||||
immediateInfoFields: {
|
immediateInfoFields: {
|
||||||
|
@ -36,7 +36,7 @@ const {
|
|||||||
},
|
},
|
||||||
kRefed,
|
kRefed,
|
||||||
initAsyncResource,
|
initAsyncResource,
|
||||||
validateTimerDuration,
|
getTimerDuration,
|
||||||
timerListMap,
|
timerListMap,
|
||||||
timerListQueue,
|
timerListQueue,
|
||||||
immediateQueue,
|
immediateQueue,
|
||||||
@ -102,7 +102,7 @@ function unenroll(item) {
|
|||||||
// This function does not start the timer, see `active()`.
|
// This function does not start the timer, see `active()`.
|
||||||
// Using existing objects as timers slightly reduces object overhead.
|
// Using existing objects as timers slightly reduces object overhead.
|
||||||
function enroll(item, msecs) {
|
function enroll(item, msecs) {
|
||||||
msecs = validateTimerDuration(msecs, 'msecs');
|
msecs = getTimerDuration(msecs, 'msecs');
|
||||||
|
|
||||||
// If this item was already in a list somewhere
|
// If this item was already in a list somewhere
|
||||||
// then we should unenroll it from that
|
// then we should unenroll it from that
|
||||||
|
Loading…
x
Reference in New Issue
Block a user