From 099edea144d913db2697da027a8a2a70bd9d6321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 27 Nov 2019 19:59:29 +0100 Subject: [PATCH] lib: use static Number properties from primordials PR-URL: https://github.com/nodejs/node/pull/30686 Reviewed-By: Trivikram Kamat Reviewed-By: Anna Henningsen --- lib/_http_client.js | 3 ++- lib/_stream_readable.js | 6 ++++-- lib/async_hooks.js | 3 ++- lib/buffer.js | 15 +++++++++------ lib/child_process.js | 3 ++- lib/events.js | 5 +++-- lib/fs.js | 5 +++-- lib/internal/async_hooks.js | 5 +++-- lib/internal/crypto/random.js | 5 +++-- lib/internal/errors.js | 3 ++- lib/internal/fs/promises.js | 3 ++- lib/internal/fs/streams.js | 6 ++++-- lib/internal/fs/utils.js | 3 ++- lib/internal/process/per_thread.js | 3 ++- lib/internal/readline/utils.js | 7 ++++--- lib/internal/repl.js | 3 ++- lib/internal/streams/state.js | 3 ++- lib/internal/timers.js | 3 ++- lib/internal/util/inspect.js | 3 ++- lib/internal/validators.js | 15 ++++++++++----- lib/net.js | 3 ++- lib/perf_hooks.js | 3 ++- lib/readline.js | 6 ++++-- lib/repl.js | 3 ++- lib/tty.js | 3 ++- lib/util.js | 3 ++- lib/zlib.js | 8 +++++--- 27 files changed, 84 insertions(+), 47 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 170f4ded0d6bac..5721508ba1c6f1 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -24,6 +24,7 @@ const { ArrayIsArray, Boolean, + NumberIsFinite, ObjectAssign, ObjectKeys, ObjectSetPrototypeOf, @@ -219,7 +220,7 @@ function ClientRequest(input, options, cb) { // but only if the Agent will actually reuse the connection! // If it's not a keepAlive agent, and the maxSockets==Infinity, then // there's never a case where this socket will actually be reused - if (!this.agent.keepAlive && !Number.isFinite(this.agent.maxSockets)) { + if (!this.agent.keepAlive && !NumberIsFinite(this.agent.maxSockets)) { this._last = true; this.shouldKeepAlive = false; } else { diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index cc55c0aff4231f..50cafe41c30eec 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -23,6 +23,8 @@ const { ArrayIsArray, + NumberIsInteger, + NumberIsNaN, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; @@ -389,7 +391,7 @@ function howMuchToRead(n, state) { return 0; if (state.objectMode) return 1; - if (Number.isNaN(n)) { + if (NumberIsNaN(n)) { // Only flow one buffer at a time if (state.flowing && state.length) return state.buffer.first().length; @@ -408,7 +410,7 @@ Readable.prototype.read = function(n) { // in this scenario, so we are doing it manually. if (n === undefined) { n = NaN; - } else if (!Number.isInteger(n)) { + } else if (!NumberIsInteger(n)) { n = parseInt(n, 10); } const state = this._readableState; diff --git a/lib/async_hooks.js b/lib/async_hooks.js index a567e1599f7eea..a7ca5af7ef8105 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -1,6 +1,7 @@ 'use strict'; const { + NumberIsSafeInteger, ReflectApply, } = primordials; @@ -147,7 +148,7 @@ class AsyncResource { // Unlike emitInitScript, AsyncResource doesn't supports null as the // triggerAsyncId. - if (!Number.isSafeInteger(triggerAsyncId) || triggerAsyncId < -1) { + if (!NumberIsSafeInteger(triggerAsyncId) || triggerAsyncId < -1) { throw new ERR_INVALID_ASYNC_ID('triggerAsyncId', triggerAsyncId); } diff --git a/lib/buffer.js b/lib/buffer.js index ac8c134739f985..8cbc0af538dbba 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -27,6 +27,9 @@ const { MathFloor, MathMin, MathTrunc, + NumberIsNaN, + NumberMAX_SAFE_INTEGER, + NumberMIN_SAFE_INTEGER, ObjectCreate, ObjectDefineProperties, ObjectDefineProperty, @@ -175,9 +178,9 @@ function showFlaggedDeprecation() { function toInteger(n, defaultVal) { n = +n; - if (!Number.isNaN(n) && - n >= Number.MIN_SAFE_INTEGER && - n <= Number.MAX_SAFE_INTEGER) { + if (!NumberIsNaN(n) && + n >= NumberMIN_SAFE_INTEGER && + n <= NumberMAX_SAFE_INTEGER) { return ((n % 1) === 0 ? n : MathFloor(n)); } return defaultVal; @@ -442,7 +445,7 @@ function fromArrayBuffer(obj, byteOffset, length) { byteOffset = 0; } else { byteOffset = +byteOffset; - if (Number.isNaN(byteOffset)) + if (NumberIsNaN(byteOffset)) byteOffset = 0; } @@ -890,7 +893,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { // Coerce to Number. Values like null and [] become 0. byteOffset = +byteOffset; // If the offset is undefined, "foo", {}, coerces to NaN, search whole buffer. - if (Number.isNaN(byteOffset)) { + if (NumberIsNaN(byteOffset)) { byteOffset = dir ? 0 : buffer.length; } dir = !!dir; // Cast to bool. @@ -1063,7 +1066,7 @@ function adjustOffset(offset, length) { if (offset < length) { return offset; } - return Number.isNaN(offset) ? 0 : length; + return NumberIsNaN(offset) ? 0 : length; } Buffer.prototype.slice = function slice(start, end) { diff --git a/lib/child_process.js b/lib/child_process.js index cc6ca4c6438ba2..5e11e43c697115 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -23,6 +23,7 @@ const { ArrayIsArray, + NumberIsInteger, ObjectAssign, ObjectDefineProperty, ObjectPrototypeHasOwnProperty, @@ -670,7 +671,7 @@ function execSync(command, options) { function validateTimeout(timeout) { - if (timeout != null && !(Number.isInteger(timeout) && timeout >= 0)) { + if (timeout != null && !(NumberIsInteger(timeout) && timeout >= 0)) { throw new ERR_OUT_OF_RANGE('timeout', 'an unsigned integer', timeout); } } diff --git a/lib/events.js b/lib/events.js index f8c268ee1cd843..a09333af443534 100644 --- a/lib/events.js +++ b/lib/events.js @@ -24,6 +24,7 @@ const { Array, MathMin, + NumberIsNaN, ObjectCreate, ObjectDefineProperty, ObjectGetPrototypeOf, @@ -79,7 +80,7 @@ ObjectDefineProperty(EventEmitter, 'defaultMaxListeners', { return defaultMaxListeners; }, set: function(arg) { - if (typeof arg !== 'number' || arg < 0 || Number.isNaN(arg)) { + if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) { throw new ERR_OUT_OF_RANGE('defaultMaxListeners', 'a non-negative number', arg); @@ -102,7 +103,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 || Number.isNaN(n)) { + if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) { throw new ERR_OUT_OF_RANGE('n', 'a non-negative number', n); } this._maxListeners = n; diff --git a/lib/fs.js b/lib/fs.js index 2d58e48425c2a8..5e3ab2ed2dee46 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -26,6 +26,7 @@ const { MathMax, + NumberIsSafeInteger, ObjectCreate, ObjectDefineProperties, ObjectDefineProperty, @@ -476,7 +477,7 @@ function read(fd, buffer, offset, length, position, callback) { validateOffsetLengthRead(offset, length, buffer.byteLength); - if (!Number.isSafeInteger(position)) + if (!NumberIsSafeInteger(position)) position = -1; function wrapper(err, bytesRead) { @@ -511,7 +512,7 @@ function readSync(fd, buffer, offset, length, position) { validateOffsetLengthRead(offset, length, buffer.byteLength); - if (!Number.isSafeInteger(position)) + if (!NumberIsSafeInteger(position)) position = -1; const ctx = {}; diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 441b0bfb034ec8..b17406c78241cd 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -2,6 +2,7 @@ const { FunctionPrototypeBind, + NumberIsSafeInteger, ObjectDefineProperty, } = primordials; @@ -118,7 +119,7 @@ function validateAsyncId(asyncId, type) { // Skip validation when async_hooks is disabled if (async_hook_fields[kCheck] <= 0) return; - if (!Number.isSafeInteger(asyncId) || asyncId < -1) { + if (!NumberIsSafeInteger(asyncId) || asyncId < -1) { fatalError(new ERR_INVALID_ASYNC_ID(type, asyncId)); } } @@ -299,7 +300,7 @@ function clearDefaultTriggerAsyncId() { function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) { if (triggerAsyncId === undefined) return block(...args); - // CHECK(Number.isSafeInteger(triggerAsyncId)) + // CHECK(NumberIsSafeInteger(triggerAsyncId)) // CHECK(triggerAsyncId > 0) const oldDefaultTriggerAsyncId = async_id_fields[kDefaultTriggerAsyncId]; async_id_fields[kDefaultTriggerAsyncId] = triggerAsyncId; diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index 425b65e2684d4e..85855a709e89fd 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -2,6 +2,7 @@ const { MathMin, + NumberIsNaN, } = primordials; const { AsyncWrap, Providers } = internalBinding('async_wrap'); @@ -23,7 +24,7 @@ function assertOffset(offset, elementSize, length) { offset *= elementSize; const maxLength = MathMin(length, kMaxPossibleLength); - if (Number.isNaN(offset) || offset > maxLength || offset < 0) { + if (NumberIsNaN(offset) || offset > maxLength || offset < 0) { throw new ERR_OUT_OF_RANGE('offset', `>= 0 && <= ${maxLength}`, offset); } @@ -34,7 +35,7 @@ function assertSize(size, elementSize, offset, length) { validateNumber(size, 'size'); size *= elementSize; - if (Number.isNaN(size) || size > kMaxPossibleLength || size < 0) { + if (NumberIsNaN(size) || size > kMaxPossibleLength || size < 0) { throw new ERR_OUT_OF_RANGE('size', `>= 0 && <= ${kMaxPossibleLength}`, size); } diff --git a/lib/internal/errors.js b/lib/internal/errors.js index f6a17e1a6a1772..e87fa115ab7145 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -13,6 +13,7 @@ const { ArrayIsArray, MathAbs, + NumberIsInteger, ObjectDefineProperty, ObjectKeys, } = primordials; @@ -1113,7 +1114,7 @@ E('ERR_OUT_OF_RANGE', let msg = replaceDefaultBoolean ? str : `The value of "${str}" is out of range.`; let received; - if (Number.isInteger(input) && MathAbs(input) > 2 ** 32) { + if (NumberIsInteger(input) && MathAbs(input) > 2 ** 32) { received = addNumericalSeparator(String(input)); } else if (typeof input === 'bigint') { received = String(input); diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index b078091acb1b3f..4bc518ea36047e 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -3,6 +3,7 @@ const { MathMax, MathMin, + NumberIsSafeInteger, } = primordials; const { @@ -230,7 +231,7 @@ async function read(handle, buffer, offset, length, position) { validateOffsetLengthRead(offset, length, buffer.length); - if (!Number.isSafeInteger(position)) + if (!NumberIsSafeInteger(position)) position = -1; const bytesRead = (await binding.read(handle.fd, buffer, offset, length, diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 3ec52cd8f206a8..ada5dc829859c3 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -3,6 +3,8 @@ const { Array, MathMin, + NumberIsInteger, + NumberIsSafeInteger, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; @@ -40,9 +42,9 @@ function allocNewPool(poolSize) { // Check the `this.start` and `this.end` of stream. function checkPosition(pos, name) { - if (!Number.isSafeInteger(pos)) { + if (!NumberIsSafeInteger(pos)) { validateNumber(pos, name); - if (!Number.isInteger(pos)) + if (!NumberIsInteger(pos)) throw new ERR_OUT_OF_RANGE(name, 'an integer', pos); throw new ERR_OUT_OF_RANGE(name, '>= 0 and <= 2 ** 53 - 1', pos); } diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index e90df6aec81953..2a2ff813785376 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -3,6 +3,7 @@ const { ArrayIsArray, DateNow, + NumberIsFinite, ObjectSetPrototypeOf, ReflectOwnKeys, } = primordials; @@ -486,7 +487,7 @@ function toUnixTimestamp(time, name = 'time') { if (typeof time === 'string' && +time == time) { return +time; } - if (Number.isFinite(time)) { + if (NumberIsFinite(time)) { if (time < 0) { return DateNow() / 1000; } diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 7b1cd9eabeb498..2ead72781d53f0 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -6,6 +6,7 @@ const { ArrayIsArray, + NumberMAX_SAFE_INTEGER, ObjectDefineProperties, ObjectDefineProperty, ObjectFreeze, @@ -102,7 +103,7 @@ function wrapProcessMethods(binding) { // implementation always returns numbers <= Number.MAX_SAFE_INTEGER. function previousValueIsValid(num) { return typeof num === 'number' && - num <= Number.MAX_SAFE_INTEGER && + num <= NumberMAX_SAFE_INTEGER && num >= 0; } diff --git a/lib/internal/readline/utils.js b/lib/internal/readline/utils.js index 27110f82797c41..510acf221831a0 100644 --- a/lib/internal/readline/utils.js +++ b/lib/internal/readline/utils.js @@ -2,6 +2,7 @@ const { Boolean, + NumberIsInteger, } = primordials; // Regex used for ansi escape code splitting @@ -38,7 +39,7 @@ if (internalBinding('config').hasIntl) { const icu = internalBinding('icu'); getStringWidth = function getStringWidth(str, options) { options = options || {}; - if (Number.isInteger(str)) { + if (NumberIsInteger(str)) { // Provide information about the character with code point 'str'. return icu.getStringWidth( str, @@ -76,7 +77,7 @@ if (internalBinding('config').hasIntl) { * Returns the number of columns required to display the given string. */ getStringWidth = function getStringWidth(str) { - if (Number.isInteger(str)) + if (NumberIsInteger(str)) return isFullWidthCodePoint(str) ? 2 : 1; let width = 0; @@ -107,7 +108,7 @@ if (internalBinding('config').hasIntl) { isFullWidthCodePoint = function isFullWidthCodePoint(code) { // Code points are derived from: // http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt - return Number.isInteger(code) && code >= 0x1100 && ( + return NumberIsInteger(code) && code >= 0x1100 && ( code <= 0x115f || // Hangul Jamo code === 0x2329 || // LEFT-POINTING ANGLE BRACKET code === 0x232a || // RIGHT-POINTING ANGLE BRACKET diff --git a/lib/internal/repl.js b/lib/internal/repl.js index a5f5cd25f25561..75a68c8ea859ef 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -1,6 +1,7 @@ 'use strict'; const { + NumberIsNaN, ObjectCreate, } = primordials; @@ -39,7 +40,7 @@ function createRepl(env, opts, cb) { } const historySize = Number(env.NODE_REPL_HISTORY_SIZE); - if (!Number.isNaN(historySize) && historySize > 0) { + if (!NumberIsNaN(historySize) && historySize > 0) { opts.historySize = historySize; } else { opts.historySize = 1000; diff --git a/lib/internal/streams/state.js b/lib/internal/streams/state.js index aa16a0a6b8afb7..fa902ef429b553 100644 --- a/lib/internal/streams/state.js +++ b/lib/internal/streams/state.js @@ -2,6 +2,7 @@ const { MathFloor, + NumberIsInteger, } = primordials; const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes; @@ -18,7 +19,7 @@ function getDefaultHighWaterMark(objectMode) { function getHighWaterMark(state, options, duplexKey, isDuplex) { const hwm = highWaterMarkFrom(options, isDuplex, duplexKey); if (hwm != null) { - if (!Number.isInteger(hwm) || hwm < 0) { + if (!NumberIsInteger(hwm) || hwm < 0) { const name = isDuplex ? duplexKey : 'highWaterMark'; throw new ERR_INVALID_OPT_VALUE(name, hwm); } diff --git a/lib/internal/timers.js b/lib/internal/timers.js index e55e17b53702a1..84b3c34d87cfaf 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -75,6 +75,7 @@ const { MathMax, MathTrunc, + NumberMIN_SAFE_INTEGER, ObjectCreate, } = primordials; @@ -121,7 +122,7 @@ const kHasOutstanding = 2; // Timeout values > TIMEOUT_MAX are set to 1. const TIMEOUT_MAX = 2 ** 31 - 1; -let timerListId = Number.MIN_SAFE_INTEGER; +let timerListId = NumberMIN_SAFE_INTEGER; const kRefed = Symbol('refed'); diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 5ece8cab680240..6f5bde940fb75c 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -16,6 +16,7 @@ const { MathMin, MathRound, MathSqrt, + NumberIsNaN, NumberPrototypeValueOf, ObjectAssign, ObjectCreate, @@ -715,7 +716,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { return ctx.stylize(base, 'regexp'); } else if (isDate(value)) { // Make dates with properties first say the date - base = Number.isNaN(DatePrototypeGetTime(value)) ? + base = NumberIsNaN(DatePrototypeGetTime(value)) ? DatePrototypeToString(value) : DatePrototypeToISOString(value); const prefix = getPrefix(constructor, tag, 'Date'); diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 67219479a490b6..c768f7cef06c92 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -1,5 +1,11 @@ 'use strict'; +const { + NumberIsInteger, + NumberMAX_SAFE_INTEGER, + NumberMIN_SAFE_INTEGER, +} = primordials; + const { hideStackFrames, codes: { @@ -13,7 +19,6 @@ const { isArrayBufferView } = require('internal/util/types'); const { signals } = internalBinding('constants').os; -const { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } = Number; function isInt32(value) { return value === (value | 0); @@ -62,10 +67,10 @@ function parseMode(value, name, def) { } const validateInteger = hideStackFrames( - (value, name, min = MIN_SAFE_INTEGER, max = MAX_SAFE_INTEGER) => { + (value, name, min = NumberMIN_SAFE_INTEGER, max = NumberMAX_SAFE_INTEGER) => { if (typeof value !== 'number') throw new ERR_INVALID_ARG_TYPE(name, 'number', value); - if (!Number.isInteger(value)) + if (!NumberIsInteger(value)) throw new ERR_OUT_OF_RANGE(name, 'an integer', value); if (value < min || value > max) throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value); @@ -79,7 +84,7 @@ const validateInt32 = hideStackFrames( if (typeof value !== 'number') { throw new ERR_INVALID_ARG_TYPE(name, 'number', value); } - if (!Number.isInteger(value)) { + if (!NumberIsInteger(value)) { throw new ERR_OUT_OF_RANGE(name, 'an integer', value); } throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value); @@ -95,7 +100,7 @@ const validateUint32 = hideStackFrames((value, name, positive) => { if (typeof value !== 'number') { throw new ERR_INVALID_ARG_TYPE(name, 'number', value); } - if (!Number.isInteger(value)) { + if (!NumberIsInteger(value)) { throw new ERR_OUT_OF_RANGE(name, 'an integer', value); } const min = positive ? 1 : 0; diff --git a/lib/net.js b/lib/net.js index 3370ecf117046f..db63a0cc9da516 100644 --- a/lib/net.js +++ b/lib/net.js @@ -24,6 +24,7 @@ const { ArrayIsArray, Boolean, + NumberIsNaN, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; @@ -1222,7 +1223,7 @@ function createServerHandle(address, port, addressType, fd, flags) { handle = new Pipe(PipeConstants.SERVER); if (process.platform === 'win32') { const instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); - if (!Number.isNaN(instances)) { + if (!NumberIsNaN(instances)) { handle.setPendingInstances(instances); } } diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index cf0015a0224080..e6fdc66eb39c85 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -3,6 +3,7 @@ const { ArrayIsArray, Boolean, + NumberIsSafeInteger, ObjectDefineProperties, ObjectDefineProperty, ObjectKeys, @@ -607,7 +608,7 @@ function monitorEventLoopDelay(options = {}) { throw new ERR_INVALID_ARG_TYPE('options.resolution', 'number', resolution); } - if (resolution <= 0 || !Number.isSafeInteger(resolution)) { + if (resolution <= 0 || !NumberIsSafeInteger(resolution)) { throw new ERR_INVALID_OPT_VALUE.RangeError('resolution', resolution); } return new ELDHistogram(new _ELDHistogram(resolution)); diff --git a/lib/readline.js b/lib/readline.js index 6cbbaca860baee..480389009b64e9 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -32,6 +32,8 @@ const { MathCeil, MathFloor, MathMax, + NumberIsFinite, + NumberIsNaN, ObjectDefineProperty, ObjectSetPrototypeOf, } = primordials; @@ -113,7 +115,7 @@ function Interface(input, output, completer, terminal) { prompt = input.prompt; } if (input.escapeCodeTimeout !== undefined) { - if (Number.isFinite(input.escapeCodeTimeout)) { + if (NumberIsFinite(input.escapeCodeTimeout)) { this.escapeCodeTimeout = input.escapeCodeTimeout; } else { throw new ERR_INVALID_OPT_VALUE( @@ -135,7 +137,7 @@ function Interface(input, output, completer, terminal) { } if (typeof historySize !== 'number' || - Number.isNaN(historySize) || + NumberIsNaN(historySize) || historySize < 0) { throw new ERR_INVALID_OPT_VALUE.RangeError('historySize', historySize); } diff --git a/lib/repl.js b/lib/repl.js index 526c81161289ab..592b037f67fc69 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -45,6 +45,7 @@ const { ArrayIsArray, MathMax, + NumberIsNaN, ObjectAssign, ObjectCreate, ObjectDefineProperty, @@ -709,7 +710,7 @@ function REPLServer(prompt, // display next prompt and return. if (trimmedCmd) { if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) !== '.' && - Number.isNaN(parseFloat(trimmedCmd))) { + NumberIsNaN(parseFloat(trimmedCmd))) { const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/); const keyword = matches && matches[1]; const rest = matches && matches[2]; diff --git a/lib/tty.js b/lib/tty.js index 95f2624708bc17..583cc1329830c9 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -23,6 +23,7 @@ const { Array, + NumberIsInteger, ObjectSetPrototypeOf, } = primordials; @@ -39,7 +40,7 @@ const { let readline; function isatty(fd) { - return Number.isInteger(fd) && fd >= 0 && isTTY(fd); + return NumberIsInteger(fd) && fd >= 0 && isTTY(fd); } function ReadStream(fd, options) { diff --git a/lib/util.js b/lib/util.js index 7329b8d715674c..e2b738052daa4d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -23,6 +23,7 @@ const { ArrayIsArray, + NumberIsSafeInteger, ObjectDefineProperties, ObjectDefineProperty, ObjectGetOwnPropertyDescriptors, @@ -225,7 +226,7 @@ function callbackify(original) { function getSystemErrorName(err) { validateNumber(err, 'err'); - if (err >= 0 || !Number.isSafeInteger(err)) { + if (err >= 0 || !NumberIsSafeInteger(err)) { throw new ERR_OUT_OF_RANGE('err', 'a negative integer', err); } return internalErrorName(err); diff --git a/lib/zlib.js b/lib/zlib.js index 8892abaddb6344..187e6dddcc8469 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -23,6 +23,8 @@ const { MathMax, + NumberIsFinite, + NumberIsNaN, ObjectDefineProperties, ObjectDefineProperty, ObjectFreeze, @@ -191,11 +193,11 @@ const checkFiniteNumber = hideStackFrames((number, name) => { return false; } - if (Number.isFinite(number)) { + if (NumberIsFinite(number)) { return true; // Is a valid number } - if (Number.isNaN(number)) { + if (NumberIsNaN(number)) { return false; } @@ -788,7 +790,7 @@ function Brotli(opts, mode) { if (opts && opts.params) { for (const origKey of ObjectKeys(opts.params)) { const key = +origKey; - if (Number.isNaN(key) || key < 0 || key > kMaxBrotliParam || + if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam || (brotliInitParamsArray[key] | 0) !== -1) { throw new ERR_BROTLI_INVALID_PARAM(origKey); }