Skip to content

Commit b87ca79

Browse files
cjihrigindutny
authored andcommitted
lib: remove and restructure calls to isNaN()
Switch condition order to check for null before calling isNaN(). Also remove two unnecessary calls to isNaN() that are already covered by calls to isFinite(). This commit targets v0.10, as opposed to nodejs#7891, which targets master (suggested by @bnoordhuis). Closes nodejs#7840. Signed-off-by: Fedor Indutny <fedor@indutny.com>
1 parent 71fc4d9 commit b87ca79

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

lib/_stream_readable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function howMuchToRead(n, state) {
218218
if (state.objectMode)
219219
return n === 0 ? 0 : 1;
220220

221-
if (isNaN(n) || n === null) {
221+
if (n === null || isNaN(n)) {
222222
// only flow one buffer at a time
223223
if (state.flowing && state.buffer.length)
224224
return state.buffer[0].length;

lib/assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function replacer(key, value) {
5454
if (value === undefined) {
5555
return '' + value;
5656
}
57-
if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
57+
if (typeof value === 'number' && !isFinite(value)) {
5858
return value.toString();
5959
}
6060
if (typeof value === 'function' || value instanceof RegExp) {

lib/net.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Socket.prototype.listen = function() {
306306

307307

308308
Socket.prototype.setTimeout = function(msecs, callback) {
309-
if (msecs > 0 && !isNaN(msecs) && isFinite(msecs)) {
309+
if (msecs > 0 && isFinite(msecs)) {
310310
timers.enroll(this, msecs);
311311
timers._unrefActive(this);
312312
if (callback) {

0 commit comments

Comments
 (0)