File tree 4 files changed +12
-15
lines changed
4 files changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ const {
101
101
} = require ( 'internal/errors' ) ;
102
102
const {
103
103
validateBuffer,
104
+ validateNumber,
104
105
validateInteger,
105
106
validateString
106
107
} = require ( 'internal/validators' ) ;
@@ -345,9 +346,7 @@ ObjectSetPrototypeOf(Buffer, Uint8Array);
345
346
// occurs. This is done simply to keep the internal details of the
346
347
// implementation from bleeding out to users.
347
348
const assertSize = hideStackFrames ( ( size ) => {
348
- if ( typeof size !== 'number' ) {
349
- throw new ERR_INVALID_ARG_TYPE ( 'size' , 'number' , size ) ;
350
- }
349
+ validateNumber ( size , 'size' ) ;
351
350
if ( ! ( size >= 0 && size <= kMaxLength ) ) {
352
351
throw new ERR_INVALID_ARG_VALUE . RangeError ( 'size' , size ) ;
353
352
}
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ const {
42
42
43
43
const {
44
44
validateArray,
45
+ validateNumber,
45
46
validateString
46
47
} = require ( 'internal/validators' ) ;
47
48
@@ -104,8 +105,8 @@ const getCurves = cachedResult(() => filterDuplicateStrings(_getCurves()));
104
105
105
106
function setEngine ( id , flags ) {
106
107
validateString ( id , 'id' ) ;
107
- if ( flags && typeof flags !== 'number' )
108
- throw new ERR_INVALID_ARG_TYPE ( ' flags' , 'number' , flags ) ;
108
+ if ( flags )
109
+ validateNumber ( flags , 'flags' ) ;
109
110
flags = flags >>> 0 ;
110
111
111
112
// Use provided engine for everything by default
@@ -244,8 +245,7 @@ function hasAnyNotIn(set, ...check) {
244
245
245
246
function validateBitLength ( length , name , required = false ) {
246
247
if ( length !== undefined || required ) {
247
- if ( typeof length !== 'number' )
248
- throw new ERR_INVALID_ARG_TYPE ( name , 'number' , length ) ;
248
+ validateNumber ( length , name ) ;
249
249
if ( length < 0 )
250
250
throw new ERR_OUT_OF_RANGE ( name , '> 0' ) ;
251
251
if ( length % 8 ) {
Original file line number Diff line number Diff line change 7
7
const { format } = require ( 'util' ) ;
8
8
const { NumberIsNaN, SafeMap, Symbol } = primordials ;
9
9
10
- const {
11
- ERR_INVALID_ARG_TYPE ,
12
- ERR_INVALID_ARG_VALUE ,
13
- } = require ( 'internal/errors' ) . codes ;
10
+ const { ERR_INVALID_ARG_VALUE } = require ( 'internal/errors' ) . codes ;
11
+ const { validateNumber } = require ( 'internal/validators' ) ;
14
12
15
13
const kDestroy = Symbol ( 'kDestroy' ) ;
16
14
const kHandle = Symbol ( 'kHandle' ) ;
@@ -58,8 +56,7 @@ class Histogram {
58
56
}
59
57
60
58
percentile ( percentile ) {
61
- if ( typeof percentile !== 'number' )
62
- throw new ERR_INVALID_ARG_TYPE ( 'percentile' , 'number' , percentile ) ;
59
+ validateNumber ( percentile , 'percentile' ) ;
63
60
64
61
if ( NumberIsNaN ( percentile ) || percentile <= 0 || percentile > 100 )
65
62
throw new ERR_INVALID_ARG_VALUE . RangeError ( 'percentile' , percentile ) ;
Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ const { isUint8Array } = require('internal/util/types');
111
111
const {
112
112
validateAbortSignal,
113
113
validateInt32,
114
+ validateNumber,
114
115
validatePort,
115
116
validateString
116
117
} = require ( 'internal/validators' ) ;
@@ -987,8 +988,8 @@ function lookupAndConnect(self, options) {
987
988
throw new ERR_INVALID_IP_ADDRESS ( localAddress ) ;
988
989
}
989
990
990
- if ( localPort && typeof localPort !== 'number' ) {
991
- throw new ERR_INVALID_ARG_TYPE ( 'options. localPort' , 'number' , localPort ) ;
991
+ if ( localPort ) {
992
+ validateNumber ( localPort , 'options. localPort' ) ;
992
993
}
993
994
994
995
if ( typeof port !== 'undefined' ) {
You can’t perform that action at this time.
0 commit comments