Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5de272c

Browse filesBrowse files
committed
lib: use static Number properties from primordials
PR-URL: #30686 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 2e81795 commit 5de272c
Copy full SHA for 5de272c
Expand file treeCollapse file tree

27 files changed

+84
-47
lines changed
Open diff view settings
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const {
2525
ArrayIsArray,
2626
Boolean,
27+
NumberIsFinite,
2728
ObjectAssign,
2829
ObjectKeys,
2930
ObjectSetPrototypeOf,
@@ -211,7 +212,7 @@ function ClientRequest(input, options, cb) {
211212
// but only if the Agent will actually reuse the connection!
212213
// If it's not a keepAlive agent, and the maxSockets==Infinity, then
213214
// there's never a case where this socket will actually be reused
214-
if (!this.agent.keepAlive && !Number.isFinite(this.agent.maxSockets)) {
215+
if (!this.agent.keepAlive && !NumberIsFinite(this.agent.maxSockets)) {
215216
this._last = true;
216217
this.shouldKeepAlive = false;
217218
} else {
Collapse file

‎lib/_stream_readable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_readable.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
const {
2525
ArrayIsArray,
26+
NumberIsInteger,
27+
NumberIsNaN,
2628
ObjectDefineProperty,
2729
ObjectSetPrototypeOf,
2830
} = primordials;
@@ -389,7 +391,7 @@ function howMuchToRead(n, state) {
389391
return 0;
390392
if (state.objectMode)
391393
return 1;
392-
if (Number.isNaN(n)) {
394+
if (NumberIsNaN(n)) {
393395
// Only flow one buffer at a time
394396
if (state.flowing && state.length)
395397
return state.buffer.first().length;
@@ -408,7 +410,7 @@ Readable.prototype.read = function(n) {
408410
// in this scenario, so we are doing it manually.
409411
if (n === undefined) {
410412
n = NaN;
411-
} else if (!Number.isInteger(n)) {
413+
} else if (!NumberIsInteger(n)) {
412414
n = parseInt(n, 10);
413415
}
414416
const state = this._readableState;
Collapse file

‎lib/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/async_hooks.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
NumberIsSafeInteger,
45
ReflectApply,
56
} = primordials;
67

@@ -147,7 +148,7 @@ class AsyncResource {
147148

148149
// Unlike emitInitScript, AsyncResource doesn't supports null as the
149150
// triggerAsyncId.
150-
if (!Number.isSafeInteger(triggerAsyncId) || triggerAsyncId < -1) {
151+
if (!NumberIsSafeInteger(triggerAsyncId) || triggerAsyncId < -1) {
151152
throw new ERR_INVALID_ASYNC_ID('triggerAsyncId', triggerAsyncId);
152153
}
153154

Collapse file

‎lib/buffer.js‎

Copy file name to clipboardExpand all lines: lib/buffer.js
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const {
2727
MathFloor,
2828
MathMin,
2929
MathTrunc,
30+
NumberIsNaN,
31+
NumberMAX_SAFE_INTEGER,
32+
NumberMIN_SAFE_INTEGER,
3033
ObjectCreate,
3134
ObjectDefineProperties,
3235
ObjectDefineProperty,
@@ -175,9 +178,9 @@ function showFlaggedDeprecation() {
175178

176179
function toInteger(n, defaultVal) {
177180
n = +n;
178-
if (!Number.isNaN(n) &&
179-
n >= Number.MIN_SAFE_INTEGER &&
180-
n <= Number.MAX_SAFE_INTEGER) {
181+
if (!NumberIsNaN(n) &&
182+
n >= NumberMIN_SAFE_INTEGER &&
183+
n <= NumberMAX_SAFE_INTEGER) {
181184
return ((n % 1) === 0 ? n : MathFloor(n));
182185
}
183186
return defaultVal;
@@ -442,7 +445,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
442445
byteOffset = 0;
443446
} else {
444447
byteOffset = +byteOffset;
445-
if (Number.isNaN(byteOffset))
448+
if (NumberIsNaN(byteOffset))
446449
byteOffset = 0;
447450
}
448451

@@ -890,7 +893,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
890893
// Coerce to Number. Values like null and [] become 0.
891894
byteOffset = +byteOffset;
892895
// If the offset is undefined, "foo", {}, coerces to NaN, search whole buffer.
893-
if (Number.isNaN(byteOffset)) {
896+
if (NumberIsNaN(byteOffset)) {
894897
byteOffset = dir ? 0 : buffer.length;
895898
}
896899
dir = !!dir; // Cast to bool.
@@ -1063,7 +1066,7 @@ function adjustOffset(offset, length) {
10631066
if (offset < length) {
10641067
return offset;
10651068
}
1066-
return Number.isNaN(offset) ? 0 : length;
1069+
return NumberIsNaN(offset) ? 0 : length;
10671070
}
10681071

10691072
Buffer.prototype.slice = function slice(start, end) {
Collapse file

‎lib/child_process.js‎

Copy file name to clipboardExpand all lines: lib/child_process.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const {
2525
ArrayIsArray,
26+
NumberIsInteger,
2627
ObjectAssign,
2728
ObjectDefineProperty,
2829
ObjectPrototypeHasOwnProperty,
@@ -670,7 +671,7 @@ function execSync(command, options) {
670671

671672

672673
function validateTimeout(timeout) {
673-
if (timeout != null && !(Number.isInteger(timeout) && timeout >= 0)) {
674+
if (timeout != null && !(NumberIsInteger(timeout) && timeout >= 0)) {
674675
throw new ERR_OUT_OF_RANGE('timeout', 'an unsigned integer', timeout);
675676
}
676677
}
Collapse file

‎lib/events.js‎

Copy file name to clipboardExpand all lines: lib/events.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const {
2525
Array,
2626
MathMin,
27+
NumberIsNaN,
2728
ObjectCreate,
2829
ObjectDefineProperty,
2930
ObjectGetPrototypeOf,
@@ -79,7 +80,7 @@ ObjectDefineProperty(EventEmitter, 'defaultMaxListeners', {
7980
return defaultMaxListeners;
8081
},
8182
set: function(arg) {
82-
if (typeof arg !== 'number' || arg < 0 || Number.isNaN(arg)) {
83+
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
8384
throw new ERR_OUT_OF_RANGE('defaultMaxListeners',
8485
'a non-negative number',
8586
arg);
@@ -102,7 +103,7 @@ EventEmitter.init = function() {
102103
// Obviously not all Emitters should be limited to 10. This function allows
103104
// that to be increased. Set to zero for unlimited.
104105
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
105-
if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) {
106+
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
106107
throw new ERR_OUT_OF_RANGE('n', 'a non-negative number', n);
107108
}
108109
this._maxListeners = n;
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
const {
2828
MathMax,
29+
NumberIsSafeInteger,
2930
ObjectCreate,
3031
ObjectDefineProperties,
3132
ObjectDefineProperty,
@@ -476,7 +477,7 @@ function read(fd, buffer, offset, length, position, callback) {
476477

477478
validateOffsetLengthRead(offset, length, buffer.byteLength);
478479

479-
if (!Number.isSafeInteger(position))
480+
if (!NumberIsSafeInteger(position))
480481
position = -1;
481482

482483
function wrapper(err, bytesRead) {
@@ -511,7 +512,7 @@ function readSync(fd, buffer, offset, length, position) {
511512

512513
validateOffsetLengthRead(offset, length, buffer.byteLength);
513514

514-
if (!Number.isSafeInteger(position))
515+
if (!NumberIsSafeInteger(position))
515516
position = -1;
516517

517518
const ctx = {};
Collapse file

‎lib/internal/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/internal/async_hooks.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
FunctionPrototypeBind,
5+
NumberIsSafeInteger,
56
ObjectDefineProperty,
67
} = primordials;
78

@@ -118,7 +119,7 @@ function validateAsyncId(asyncId, type) {
118119
// Skip validation when async_hooks is disabled
119120
if (async_hook_fields[kCheck] <= 0) return;
120121

121-
if (!Number.isSafeInteger(asyncId) || asyncId < -1) {
122+
if (!NumberIsSafeInteger(asyncId) || asyncId < -1) {
122123
fatalError(new ERR_INVALID_ASYNC_ID(type, asyncId));
123124
}
124125
}
@@ -299,7 +300,7 @@ function clearDefaultTriggerAsyncId() {
299300
function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) {
300301
if (triggerAsyncId === undefined)
301302
return block(...args);
302-
// CHECK(Number.isSafeInteger(triggerAsyncId))
303+
// CHECK(NumberIsSafeInteger(triggerAsyncId))
303304
// CHECK(triggerAsyncId > 0)
304305
const oldDefaultTriggerAsyncId = async_id_fields[kDefaultTriggerAsyncId];
305306
async_id_fields[kDefaultTriggerAsyncId] = triggerAsyncId;
Collapse file

‎lib/internal/crypto/random.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/random.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
MathMin,
5+
NumberIsNaN,
56
} = primordials;
67

78
const { AsyncWrap, Providers } = internalBinding('async_wrap');
@@ -23,7 +24,7 @@ function assertOffset(offset, elementSize, length) {
2324
offset *= elementSize;
2425

2526
const maxLength = MathMin(length, kMaxPossibleLength);
26-
if (Number.isNaN(offset) || offset > maxLength || offset < 0) {
27+
if (NumberIsNaN(offset) || offset > maxLength || offset < 0) {
2728
throw new ERR_OUT_OF_RANGE('offset', `>= 0 && <= ${maxLength}`, offset);
2829
}
2930

@@ -34,7 +35,7 @@ function assertSize(size, elementSize, offset, length) {
3435
validateNumber(size, 'size');
3536
size *= elementSize;
3637

37-
if (Number.isNaN(size) || size > kMaxPossibleLength || size < 0) {
38+
if (NumberIsNaN(size) || size > kMaxPossibleLength || size < 0) {
3839
throw new ERR_OUT_OF_RANGE('size',
3940
`>= 0 && <= ${kMaxPossibleLength}`, size);
4041
}
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
const {
1414
ArrayIsArray,
1515
MathAbs,
16+
NumberIsInteger,
1617
ObjectDefineProperty,
1718
ObjectKeys,
1819
} = primordials;
@@ -1113,7 +1114,7 @@ E('ERR_OUT_OF_RANGE',
11131114
let msg = replaceDefaultBoolean ? str :
11141115
`The value of "${str}" is out of range.`;
11151116
let received;
1116-
if (Number.isInteger(input) && MathAbs(input) > 2 ** 32) {
1117+
if (NumberIsInteger(input) && MathAbs(input) > 2 ** 32) {
11171118
received = addNumericalSeparator(String(input));
11181119
} else if (typeof input === 'bigint') {
11191120
received = String(input);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.