diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-13 00:56:35 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-16 18:09:56 +0100 |
commit | 96c57fbfaa8c1644648fa1414c9ad131b1320b60 (patch) | |
tree | 097e354fb106a2f6e454970309cea0222ee98802 /lib/events.js | |
parent | 43b8ce4ce741a8a6a435e4073ca5a9ec188d4515 (diff) | |
download | android-node-v8-96c57fbfaa8c1644648fa1414c9ad131b1320b60.tar.gz android-node-v8-96c57fbfaa8c1644648fa1414c9ad131b1320b60.tar.bz2 android-node-v8-96c57fbfaa8c1644648fa1414c9ad131b1320b60.zip |
lib: switch to Number.isNaN
Number.isNaN is now as fast as `val !== val`. Switch to the more
readable version. Also switch all `isNaN` to `Number.isNaN`.
PR-URL: https://github.com/nodejs/node/pull/18744
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib/events.js')
-rw-r--r-- | lib/events.js | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/events.js b/lib/events.js index 9ad5ec376f..aec30e7239 100644 --- a/lib/events.js +++ b/lib/events.js @@ -52,9 +52,7 @@ Object.defineProperty(EventEmitter, 'defaultMaxListeners', { return defaultMaxListeners; }, set: function(arg) { - // check whether the input is a positive number (whose value is zero or - // greater and not a NaN). - if (typeof arg !== 'number' || arg < 0 || arg !== arg) { + if (typeof arg !== 'number' || arg < 0 || Number.isNaN(arg)) { const errors = lazyErrors(); throw new errors.RangeError('ERR_OUT_OF_RANGE', 'defaultMaxListeners', @@ -79,7 +77,7 @@ EventEmitter.init = function() { // Obviously not all Emitters should be limited to 10. This function allows // that to be increased. Set to zero for unlimited. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { - if (typeof n !== 'number' || n < 0 || isNaN(n)) { + if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) { const errors = lazyErrors(); throw new errors.RangeError('ERR_OUT_OF_RANGE', 'n', 'a non-negative number', n); |