From a1d05e49fee4881150c6f62bf19706f4ca75edf6 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 20 Feb 2019 10:47:40 -0500 Subject: [PATCH] timers: support name in validateTimerDuration() Allow passing a name to validateTimerDuration() so that error messages can reflect the name of the thing being validated. PR-URL: https://github.com/nodejs/node/pull/26215 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Anatoli Papirovski Reviewed-By: James M Snell --- lib/_http_client.js | 2 +- lib/internal/stream_base_commons.js | 2 +- lib/internal/timers.js | 6 +++--- lib/timers.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 93d07c4d7d04a5..e073e973bbf205 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -737,7 +737,7 @@ ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) { } listenSocketTimeout(this); - msecs = validateTimerDuration(msecs); + msecs = validateTimerDuration(msecs, 'msecs'); if (callback) this.once('timeout', callback); if (this.socket) { diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js index 6de03c09d83d1b..4740d5ae14d230 100644 --- a/lib/internal/stream_base_commons.js +++ b/lib/internal/stream_base_commons.js @@ -196,7 +196,7 @@ function setStreamTimeout(msecs, callback) { this.timeout = msecs; // Type checking identical to timers.enroll() - msecs = validateTimerDuration(msecs); + msecs = validateTimerDuration(msecs, 'msecs'); // Attempt to clear an existing timer in both cases - // even if it will be rescheduled we don't want to leak an existing timer. diff --git a/lib/internal/timers.js b/lib/internal/timers.js index 3eb7192e2b0a5d..6cd8fd72c02cbc 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -136,10 +136,10 @@ function setUnrefTimeout(callback, after, arg1, arg2, arg3) { } // Type checking used by timers.enroll() and Socket#setTimeout() -function validateTimerDuration(msecs) { - validateNumber(msecs, 'msecs'); +function validateTimerDuration(msecs, name) { + validateNumber(msecs, name); if (msecs < 0 || !isFinite(msecs)) { - throw new ERR_OUT_OF_RANGE('msecs', 'a non-negative finite number', msecs); + throw new ERR_OUT_OF_RANGE(name, 'a non-negative finite number', msecs); } // Ensure that msecs fits into signed int32 diff --git a/lib/timers.js b/lib/timers.js index 14151d6d81d63e..d0dd25e2623bf0 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -408,7 +408,7 @@ exports.unenroll = util.deprecate(unenroll, // This function does not start the timer, see `active()`. // Using existing objects as timers slightly reduces object overhead. function enroll(item, msecs) { - msecs = validateTimerDuration(msecs); + msecs = validateTimerDuration(msecs, 'msecs'); // if this item was already in a list somewhere // then we should unenroll it from that