Skip to content

Commit 99bed01

Browse files
committed
lib: use Number.parseInt from primordials
1 parent 5d6751b commit 99bed01

File tree

9 files changed

+20
-9
lines changed

9 files changed

+20
-9
lines changed

lib/.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ rules:
7171
message: "Use `const { WeakMap } = primordials;` instead of the global."
7272
- name: WeakSet
7373
message: "Use `const { WeakSet } = primordials;` instead of the global."
74+
- name: parseInt
75+
message: "Use `const { NumberParseInt } = primordials;` instead of the global."
7476
no-restricted-syntax:
7577
# Config copied from .eslintrc.js
7678
- error

lib/internal/bootstrap/pre_execution.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
Map,
5+
NumberParseInt,
56
ObjectDefineProperty,
67
SafeWeakMap,
78
} = primordials;
@@ -327,7 +328,7 @@ function setupChildProcessIpcChannel() {
327328
if (process.env.NODE_CHANNEL_FD) {
328329
const assert = require('internal/assert');
329330

330-
const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
331+
const fd = NumberParseInt(process.env.NODE_CHANNEL_FD, 10);
331332
assert(fd >= 0);
332333

333334
// Make sure it's not accidentally inherited by child processes.

lib/internal/dns/utils.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
ArrayIsArray,
5+
NumberParseInt,
56
} = primordials;
67

78
const errors = require('internal/errors');
@@ -79,7 +80,7 @@ class Resolver {
7980

8081
if (ipVersion !== 0) {
8182
const port =
82-
parseInt(serv.replace(addrSplitRE, '$2')) || IANA_DNS_PORT;
83+
NumberParseInt(serv.replace(addrSplitRE, '$2')) || IANA_DNS_PORT;
8384
return newSet.push([ipVersion, match[1], port]);
8485
}
8586
}
@@ -94,7 +95,7 @@ class Resolver {
9495
ipVersion = isIP(hostIP);
9596

9697
if (ipVersion !== 0) {
97-
return newSet.push([ipVersion, hostIP, parseInt(port)]);
98+
return newSet.push([ipVersion, hostIP, NumberParseInt(port)]);
9899
}
99100
}
100101

lib/internal/repl.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const {
44
Number,
55
NumberIsNaN,
6+
NumberParseInt,
67
ObjectCreate,
78
} = primordials;
89

@@ -25,7 +26,7 @@ function createRepl(env, opts, cb) {
2526
...opts
2627
};
2728

28-
if (parseInt(env.NODE_NO_READLINE)) {
29+
if (NumberParseInt(env.NODE_NO_READLINE)) {
2930
opts.terminal = false;
3031
}
3132

lib/internal/streams/readable.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const {
2525
NumberIsInteger,
2626
NumberIsNaN,
27+
NumberParseInt,
2728
ObjectDefineProperties,
2829
ObjectKeys,
2930
ObjectSetPrototypeOf,
@@ -388,7 +389,7 @@ Readable.prototype.read = function(n) {
388389
if (n === undefined) {
389390
n = NaN;
390391
} else if (!NumberIsInteger(n)) {
391-
n = parseInt(n, 10);
392+
n = NumberParseInt(n, 10);
392393
}
393394
const state = this._readableState;
394395
const nOrig = n;

lib/internal/util/inspect.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
MathSqrt,
3030
Number,
3131
NumberIsNaN,
32+
NumberParseInt,
3233
NumberPrototypeValueOf,
3334
Object,
3435
ObjectAssign,
@@ -1950,7 +1951,8 @@ function formatWithOptionsInternal(inspectOptions, ...args) {
19501951
} else if (typeof tempInteger === 'symbol') {
19511952
tempStr = 'NaN';
19521953
} else {
1953-
tempStr = formatNumber(stylizeNoColor, parseInt(tempInteger));
1954+
tempStr = formatNumber(stylizeNoColor,
1955+
NumberParseInt(tempInteger));
19541956
}
19551957
break;
19561958
case 102: // 'f'

lib/internal/validators.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
NumberIsInteger,
66
NumberMAX_SAFE_INTEGER,
77
NumberMIN_SAFE_INTEGER,
8+
NumberParseInt,
89
String,
910
} = primordials;
1011

@@ -65,7 +66,7 @@ function parseFileMode(value, name, def) {
6566
if (!octalReg.test(value)) {
6667
throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc);
6768
}
68-
return parseInt(value, 8);
69+
return NumberParseInt(value, 8);
6970
}
7071

7172
throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc);

lib/net.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const {
2727
Error,
2828
Number,
2929
NumberIsNaN,
30+
NumberParseInt,
3031
ObjectDefineProperty,
3132
ObjectSetPrototypeOf,
3233
Symbol,
@@ -1204,7 +1205,7 @@ function createServerHandle(address, port, addressType, fd, flags) {
12041205
} else if (port === -1 && addressType === -1) {
12051206
handle = new Pipe(PipeConstants.SERVER);
12061207
if (isWindows) {
1207-
const instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES);
1208+
const instances = NumberParseInt(process.env.NODE_PENDING_PIPE_INSTANCES);
12081209
if (!NumberIsNaN(instances)) {
12091210
handle.setPendingInstances(instances);
12101211
}

lib/os.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const {
2525
Float64Array,
26+
NumberParseInt,
2627
ObjectDefineProperties,
2728
SymbolToPrimitive,
2829
} = primordials;
@@ -179,7 +180,7 @@ function getCIDR(address, netmask, family) {
179180
const parts = netmask.split(split);
180181
for (var i = 0; i < parts.length; i++) {
181182
if (parts[i] !== '') {
182-
const binary = parseInt(parts[i], range);
183+
const binary = NumberParseInt(parts[i], range);
183184
const tmp = countBinaryOnes(binary);
184185
ones += tmp;
185186
if (hasZeros) {

0 commit comments

Comments
 (0)