Skip to content

Commit 5d727f0

Browse files
targosBethGriggs
authored andcommitted
lib: use Number.parseInt from primordials
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]>
1 parent 77f1e1e commit 5d727f0

File tree

9 files changed

+26
-12
lines changed

9 files changed

+26
-12
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/_stream_readable.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
ArrayIsArray,
2626
NumberIsInteger,
2727
NumberIsNaN,
28+
NumberParseInt,
2829
ObjectDefineProperties,
2930
ObjectSetPrototypeOf,
3031
Set,
@@ -387,12 +388,12 @@ function howMuchToRead(n, state) {
387388
// You can override either this method, or the async _read(n) below.
388389
Readable.prototype.read = function(n) {
389390
debug('read', n);
390-
// Same as parseInt(undefined, 10), however V8 7.3 performance regressed
391+
// Same as NumberParseInt(undefined, 10), however V8 7.3 performance regressed
391392
// in this scenario, so we are doing it manually.
392393
if (n === undefined) {
393394
n = NaN;
394395
} else if (!NumberIsInteger(n)) {
395-
n = parseInt(n, 10);
396+
n = NumberParseInt(n, 10);
396397
}
397398
const state = this._readableState;
398399
const nOrig = n;

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;
@@ -321,7 +322,7 @@ function setupChildProcessIpcChannel() {
321322
if (process.env.NODE_CHANNEL_FD) {
322323
const assert = require('internal/assert');
323324

324-
const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
325+
const fd = NumberParseInt(process.env.NODE_CHANNEL_FD, 10);
325326
assert(fd >= 0);
326327

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

lib/internal/dns/utils.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const {
44
ArrayIsArray,
5+
ArrayPrototypePush,
6+
NumberParseInt,
7+
StringPrototypeReplace,
58
} = primordials;
69

710
const errors = require('internal/errors');
@@ -78,9 +81,9 @@ class Resolver {
7881
ipVersion = isIP(match[1]);
7982

8083
if (ipVersion !== 0) {
81-
const port =
82-
parseInt(serv.replace(addrSplitRE, '$2')) || IANA_DNS_PORT;
83-
return newSet.push([ipVersion, match[1], port]);
84+
const port = NumberParseInt(
85+
StringPrototypeReplace(serv, addrSplitRE, '$2')) || IANA_DNS_PORT;
86+
return ArrayPrototypePush(newSet, [ipVersion, match[1], port]);
8487
}
8588
}
8689

@@ -94,7 +97,8 @@ class Resolver {
9497
ipVersion = isIP(hostIP);
9598

9699
if (ipVersion !== 0) {
97-
return newSet.push([ipVersion, hostIP, parseInt(port)]);
100+
return ArrayPrototypePush(
101+
newSet, [ipVersion, hostIP, NumberParseInt(port)]);
98102
}
99103
}
100104

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/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

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

7273
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,
@@ -1232,7 +1233,7 @@ function createServerHandle(address, port, addressType, fd, flags) {
12321233
} else if (port === -1 && addressType === -1) {
12331234
handle = new Pipe(PipeConstants.SERVER);
12341235
if (isWindows) {
1235-
const instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES);
1236+
const instances = NumberParseInt(process.env.NODE_PENDING_PIPE_INSTANCES);
12361237
if (!NumberIsNaN(instances)) {
12371238
handle.setPendingInstances(instances);
12381239
}

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)