Skip to content

Commit a1d05e4

Browse files
committedFeb 22, 2019
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: #26215 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 4804a18 commit a1d05e4

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed
 

‎lib/_http_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) {
737737
}
738738

739739
listenSocketTimeout(this);
740-
msecs = validateTimerDuration(msecs);
740+
msecs = validateTimerDuration(msecs, 'msecs');
741741
if (callback) this.once('timeout', callback);
742742

743743
if (this.socket) {

‎lib/internal/stream_base_commons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function setStreamTimeout(msecs, callback) {
196196
this.timeout = msecs;
197197

198198
// Type checking identical to timers.enroll()
199-
msecs = validateTimerDuration(msecs);
199+
msecs = validateTimerDuration(msecs, 'msecs');
200200

201201
// Attempt to clear an existing timer in both cases -
202202
// even if it will be rescheduled we don't want to leak an existing timer.

‎lib/internal/timers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ function setUnrefTimeout(callback, after, arg1, arg2, arg3) {
136136
}
137137

138138
// Type checking used by timers.enroll() and Socket#setTimeout()
139-
function validateTimerDuration(msecs) {
140-
validateNumber(msecs, 'msecs');
139+
function validateTimerDuration(msecs, name) {
140+
validateNumber(msecs, name);
141141
if (msecs < 0 || !isFinite(msecs)) {
142-
throw new ERR_OUT_OF_RANGE('msecs', 'a non-negative finite number', msecs);
142+
throw new ERR_OUT_OF_RANGE(name, 'a non-negative finite number', msecs);
143143
}
144144

145145
// Ensure that msecs fits into signed int32

‎lib/timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ exports.unenroll = util.deprecate(unenroll,
408408
// This function does not start the timer, see `active()`.
409409
// Using existing objects as timers slightly reduces object overhead.
410410
function enroll(item, msecs) {
411-
msecs = validateTimerDuration(msecs);
411+
msecs = validateTimerDuration(msecs, 'msecs');
412412

413413
// if this item was already in a list somewhere
414414
// then we should unenroll it from that

0 commit comments

Comments
 (0)
Please sign in to comment.