diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index e82897d076748a..29099193bb089e 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -71,6 +71,8 @@ rules: message: "Use `const { WeakMap } = primordials;` instead of the global." - name: WeakSet message: "Use `const { WeakSet } = primordials;` instead of the global." + - name: parseInt + message: "Use `const { NumberParseInt } = primordials;` instead of the global." no-restricted-syntax: # Config copied from .eslintrc.js - error diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index af8786198674cb..1ac553154853c6 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -25,6 +25,7 @@ const { ArrayIsArray, NumberIsInteger, NumberIsNaN, + NumberParseInt, ObjectDefineProperties, ObjectSetPrototypeOf, Set, @@ -387,12 +388,12 @@ function howMuchToRead(n, state) { // You can override either this method, or the async _read(n) below. Readable.prototype.read = function(n) { debug('read', n); - // Same as parseInt(undefined, 10), however V8 7.3 performance regressed + // Same as NumberParseInt(undefined, 10), however V8 7.3 performance regressed // in this scenario, so we are doing it manually. if (n === undefined) { n = NaN; } else if (!NumberIsInteger(n)) { - n = parseInt(n, 10); + n = NumberParseInt(n, 10); } const state = this._readableState; const nOrig = n; diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index dfbefa955cab8a..9689e2a9edf695 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -2,6 +2,7 @@ const { Map, + NumberParseInt, ObjectDefineProperty, SafeWeakMap, } = primordials; @@ -321,7 +322,7 @@ function setupChildProcessIpcChannel() { if (process.env.NODE_CHANNEL_FD) { const assert = require('internal/assert'); - const fd = parseInt(process.env.NODE_CHANNEL_FD, 10); + const fd = NumberParseInt(process.env.NODE_CHANNEL_FD, 10); assert(fd >= 0); // Make sure it's not accidentally inherited by child processes. diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index 6642a4f090bf67..3857bf21754e5b 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -2,6 +2,9 @@ const { ArrayIsArray, + ArrayPrototypePush, + NumberParseInt, + StringPrototypeReplace, } = primordials; const errors = require('internal/errors'); @@ -78,9 +81,9 @@ class Resolver { ipVersion = isIP(match[1]); if (ipVersion !== 0) { - const port = - parseInt(serv.replace(addrSplitRE, '$2')) || IANA_DNS_PORT; - return newSet.push([ipVersion, match[1], port]); + const port = NumberParseInt( + StringPrototypeReplace(serv, addrSplitRE, '$2')) || IANA_DNS_PORT; + return ArrayPrototypePush(newSet, [ipVersion, match[1], port]); } } @@ -94,7 +97,8 @@ class Resolver { ipVersion = isIP(hostIP); if (ipVersion !== 0) { - return newSet.push([ipVersion, hostIP, parseInt(port)]); + return ArrayPrototypePush( + newSet, [ipVersion, hostIP, NumberParseInt(port)]); } } diff --git a/lib/internal/repl.js b/lib/internal/repl.js index 565ab049c71487..5eeb2e349031b2 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -3,6 +3,7 @@ const { Number, NumberIsNaN, + NumberParseInt, ObjectCreate, } = primordials; @@ -25,7 +26,7 @@ function createRepl(env, opts, cb) { ...opts }; - if (parseInt(env.NODE_NO_READLINE)) { + if (NumberParseInt(env.NODE_NO_READLINE)) { opts.terminal = false; } diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index b5315fc1527246..b5b2b8ce4f234a 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -29,6 +29,7 @@ const { MathSqrt, Number, NumberIsNaN, + NumberParseInt, NumberPrototypeValueOf, Object, ObjectAssign, @@ -1950,7 +1951,8 @@ function formatWithOptionsInternal(inspectOptions, ...args) { } else if (typeof tempInteger === 'symbol') { tempStr = 'NaN'; } else { - tempStr = formatNumber(stylizeNoColor, parseInt(tempInteger)); + tempStr = formatNumber(stylizeNoColor, + NumberParseInt(tempInteger)); } break; case 102: // 'f' diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 0a4c8b6b576af2..c1655fb1a843fe 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -5,6 +5,7 @@ const { NumberIsInteger, NumberMAX_SAFE_INTEGER, NumberMIN_SAFE_INTEGER, + NumberParseInt, String, } = primordials; @@ -66,7 +67,7 @@ function parseFileMode(value, name, def) { if (!octalReg.test(value)) { throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc); } - return parseInt(value, 8); + return NumberParseInt(value, 8); } throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc); diff --git a/lib/net.js b/lib/net.js index ec45f381abfeb2..48e97ffd713951 100644 --- a/lib/net.js +++ b/lib/net.js @@ -27,6 +27,7 @@ const { Error, Number, NumberIsNaN, + NumberParseInt, ObjectDefineProperty, ObjectSetPrototypeOf, Symbol, @@ -1232,7 +1233,7 @@ function createServerHandle(address, port, addressType, fd, flags) { } else if (port === -1 && addressType === -1) { handle = new Pipe(PipeConstants.SERVER); if (isWindows) { - const instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); + const instances = NumberParseInt(process.env.NODE_PENDING_PIPE_INSTANCES); if (!NumberIsNaN(instances)) { handle.setPendingInstances(instances); } diff --git a/lib/os.js b/lib/os.js index dc0d08376f2da0..d03be051d09144 100644 --- a/lib/os.js +++ b/lib/os.js @@ -23,6 +23,7 @@ const { Float64Array, + NumberParseInt, ObjectDefineProperties, SymbolToPrimitive, } = primordials; @@ -179,7 +180,7 @@ function getCIDR(address, netmask, family) { const parts = netmask.split(split); for (var i = 0; i < parts.length; i++) { if (parts[i] !== '') { - const binary = parseInt(parts[i], range); + const binary = NumberParseInt(parts[i], range); const tmp = countBinaryOnes(binary); ones += tmp; if (hasZeros) {