mirror of
https://github.com/nodejs/node.git
synced 2026-12-06 10:18:46 -05:00
lib: use Number.parseInt from primordials
PR-URL: https://github.com/nodejs/node/pull/35499 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
This commit is contained in:
1 parent
4bc4f88ca1
commit
a073f532da
9 files changed
+25
-11
No files matched your search
@@ -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
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const {
|
||||
Map,
|
||||
NumberParseInt,
|
||||
ObjectDefineProperty,
|
||||
SafeWeakMap,
|
||||
} = primordials;
|
||||
@@ -327,7 +328,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.
|
||||
|
||||
@@ -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)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
const {
|
||||
NumberIsInteger,
|
||||
NumberIsNaN,
|
||||
NumberParseInt,
|
||||
ObjectDefineProperties,
|
||||
ObjectKeys,
|
||||
ObjectSetPrototypeOf,
|
||||
@@ -388,7 +389,7 @@ Readable.prototype.read = function(n) {
|
||||
if (n === undefined) {
|
||||
n = NaN;
|
||||
} else if (!NumberIsInteger(n)) {
|
||||
n = parseInt(n, 10);
|
||||
n = NumberParseInt(n, 10);
|
||||
}
|
||||
const state = this._readableState;
|
||||
const nOrig = n;
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -5,6 +5,7 @@ const {
|
||||
NumberIsInteger,
|
||||
NumberMAX_SAFE_INTEGER,
|
||||
NumberMIN_SAFE_INTEGER,
|
||||
NumberParseInt,
|
||||
String,
|
||||
} = primordials;
|
||||
|
||||
@@ -65,7 +66,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);
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ const {
|
||||
Error,
|
||||
Number,
|
||||
NumberIsNaN,
|
||||
NumberParseInt,
|
||||
ObjectDefineProperty,
|
||||
ObjectSetPrototypeOf,
|
||||
Symbol,
|
||||
@@ -1204,7 +1205,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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user