Skip to content

Commit

Permalink
lib: use Number.parseInt from primordials
Browse files Browse the repository at this point in the history
PR-URL: #35499
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Ujjwal Sharma <[email protected]>
Reviewed-By: Shingo Inoue <[email protected]>
  • Loading branch information
targos authored and BethGriggs committed Oct 13, 2020
1 parent 77f1e1e commit 5d727f0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
ArrayIsArray,
NumberIsInteger,
NumberIsNaN,
NumberParseInt,
ObjectDefineProperties,
ObjectSetPrototypeOf,
Set,
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
Map,
NumberParseInt,
ObjectDefineProperty,
SafeWeakMap,
} = primordials;
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const {
ArrayIsArray,
ArrayPrototypePush,
NumberParseInt,
StringPrototypeReplace,
} = primordials;

const errors = require('internal/errors');
Expand Down Expand Up @@ -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]);
}
}

Expand All @@ -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)]);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const {
Number,
NumberIsNaN,
NumberParseInt,
ObjectCreate,
} = primordials;

Expand All @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
MathSqrt,
Number,
NumberIsNaN,
NumberParseInt,
NumberPrototypeValueOf,
Object,
ObjectAssign,
Expand Down Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
NumberIsInteger,
NumberMAX_SAFE_INTEGER,
NumberMIN_SAFE_INTEGER,
NumberParseInt,
String,
} = primordials;

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
Error,
Number,
NumberIsNaN,
NumberParseInt,
ObjectDefineProperty,
ObjectSetPrototypeOf,
Symbol,
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

const {
Float64Array,
NumberParseInt,
ObjectDefineProperties,
SymbolToPrimitive,
} = primordials;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5d727f0

Please sign in to comment.