@@ -35,7 +35,6 @@ const {
35
35
const { signals } = internalBinding ( 'constants' ) . os ;
36
36
37
37
/**
38
- * @callback isInt32
39
38
* @param {number } value
40
39
* @returns {boolean }
41
40
*/
@@ -44,7 +43,6 @@ function isInt32(value) {
44
43
}
45
44
46
45
/**
47
- * @callback isUint32
48
46
* @param {number } value
49
47
* @returns {boolean }
50
48
*/
@@ -179,7 +177,7 @@ function validateNumber(value, name, min = undefined, max) {
179
177
throw new ERR_INVALID_ARG_TYPE ( name , 'number' , value ) ;
180
178
181
179
if ( ( min != null && value < min ) || ( max != null && value > max ) ||
182
- ( ( min != null || max != null ) && NumberIsNaN ( value ) ) ) {
180
+ ( ( min != null || max != null ) && NumberIsNaN ( value ) ) ) {
183
181
throw new ERR_OUT_OF_RANGE (
184
182
name ,
185
183
`${ min != null ? `>= ${ min } ` : '' } ${ min != null && max != null ? ' && ' : '' } ${ max != null ? `<= ${ max } ` : '' } ` ,
@@ -230,7 +228,11 @@ function getOwnPropertyValueOrDefault(options, key, defaultValue) {
230
228
* @callback validateObject
231
229
* @param {* } value
232
230
* @param {string } name
233
- * @param {{allowArray: boolean=, allowFunction: boolean=, nullable: boolean=} } [options]
231
+ * @param {{
232
+ * allowArray: boolean=,
233
+ * allowFunction: boolean=,
234
+ * nullable: boolean=
235
+ * }} [options]
234
236
*/
235
237
236
238
/** @type {validateObject } */
@@ -240,10 +242,10 @@ const validateObject = hideStackFrames(
240
242
const allowFunction = getOwnPropertyValueOrDefault ( options , 'allowFunction' , false ) ;
241
243
const nullable = getOwnPropertyValueOrDefault ( options , 'nullable' , false ) ;
242
244
if ( ( ! nullable && value === null ) ||
243
- ( ! allowArray && ArrayIsArray ( value ) ) ||
244
- ( typeof value !== 'object' && (
245
- ! allowFunction || typeof value !== 'function'
246
- ) ) ) {
245
+ ( ! allowArray && ArrayIsArray ( value ) ) ||
246
+ ( typeof value !== 'object' && (
247
+ ! allowFunction || typeof value !== 'function'
248
+ ) ) ) {
247
249
throw new ERR_INVALID_ARG_TYPE ( name , 'Object' , value ) ;
248
250
}
249
251
} ) ;
@@ -253,7 +255,7 @@ const validateObject = hideStackFrames(
253
255
* @param {* } value
254
256
* @param {string } name
255
257
* @param {number } [minLength]
256
- * @returns {asserts value is unknown [] }
258
+ * @returns {asserts value is any [] }
257
259
*/
258
260
259
261
/** @type {validateArray } */
@@ -270,24 +272,23 @@ const validateArray = hideStackFrames((value, name, minLength = 0) => {
270
272
} ) ;
271
273
272
274
/**
273
- * @callback validateSignalName
274
275
* @param {* } signal
275
276
* @param {string } name
276
277
* @returns {asserts signal is keyof signals }
277
278
*/
278
-
279
- /** @type {validateSignalName } */
280
279
function validateSignalName ( signal , name = 'signal' ) {
281
280
validateString ( signal , name ) ;
282
281
283
282
if ( signals [ signal ] === undefined ) {
284
283
if ( signals [ StringPrototypeToUpperCase ( signal ) ] !== undefined ) {
285
284
throw new ERR_UNKNOWN_SIGNAL ( signal +
286
- ' (signals must use all capital letters)' ) ;
285
+ ' (signals must use all capital letters)' ) ;
287
286
}
288
287
289
288
throw new ERR_UNKNOWN_SIGNAL ( signal ) ;
290
289
}
290
+
291
+ return true ;
291
292
}
292
293
293
294
/**
@@ -299,29 +300,28 @@ function validateSignalName(signal, name = 'signal') {
299
300
/** @type {validateBuffer } */
300
301
const validateBuffer = hideStackFrames ( ( buffer , name = 'buffer' ) => {
301
302
if ( ! isArrayBufferView ( buffer ) ) {
302
- throw new ERR_INVALID_ARG_TYPE ( name , [ 'Buffer' , 'TypedArray' , 'DataView' ] , buffer ) ;
303
+ throw new ERR_INVALID_ARG_TYPE ( name ,
304
+ [ 'Buffer' , 'TypedArray' , 'DataView' ] ,
305
+ buffer ) ;
303
306
}
304
307
} ) ;
305
308
306
309
/**
307
- * @callback validateEncoding
308
310
* @param {string } data
309
311
* @param {string } encoding
310
312
*/
311
-
312
- /** @type {validateEncoding } */
313
313
function validateEncoding ( data , encoding ) {
314
314
const normalizedEncoding = normalizeEncoding ( encoding ) ;
315
315
const length = data . length ;
316
316
317
317
if ( normalizedEncoding === 'hex' && length % 2 !== 0 ) {
318
- throw new ERR_INVALID_ARG_VALUE ( 'encoding' , encoding , `is invalid for data of length ${ length } ` ) ;
318
+ throw new ERR_INVALID_ARG_VALUE ( 'encoding' , encoding ,
319
+ `is invalid for data of length ${ length } ` ) ;
319
320
}
320
321
}
321
322
322
323
/**
323
- * @callback validatePort
324
- * @description Check that the port number is not NaN when coerced to a number,
324
+ * Check that the port number is not NaN when coerced to a number,
325
325
* is an integer and that it falls within the legal range of port numbers.
326
326
* @param {* } port
327
327
* @param {string } [name='Port']
@@ -330,25 +330,27 @@ function validateEncoding(data, encoding) {
330
330
*/
331
331
function validatePort ( port , name = 'Port' , allowZero = true ) {
332
332
if ( ( typeof port !== 'number' && typeof port !== 'string' ) ||
333
- ( typeof port === 'string' && StringPrototypeTrim ( port ) . length === 0 ) ||
334
- + port !== ( + port >>> 0 ) ||
335
- port > 0xFFFF ||
336
- ( port === 0 && ! allowZero ) ) {
333
+ ( typeof port === 'string' && StringPrototypeTrim ( port ) . length === 0 ) ||
334
+ + port !== ( + port >>> 0 ) ||
335
+ port > 0xFFFF ||
336
+ ( port === 0 && ! allowZero ) ) {
337
337
throw new ERR_SOCKET_BAD_PORT ( name , port , allowZero ) ;
338
338
}
339
339
return port | 0 ;
340
340
}
341
341
342
342
/**
343
343
* @callback validateAbortSignal
344
- * @param {string } signal
344
+ * @param {string= } signal
345
345
* @param {string } name
346
346
*/
347
+
348
+ /** @type {validateAbortSignal } */
347
349
const validateAbortSignal = hideStackFrames ( ( signal , name ) => {
348
350
if ( signal !== undefined &&
349
- ( signal === null ||
350
- typeof signal !== 'object' ||
351
- ! ( 'aborted' in signal ) ) ) {
351
+ ( signal === null ||
352
+ typeof signal !== 'object' ||
353
+ ! ( 'aborted' in signal ) ) ) {
352
354
throw new ERR_INVALID_ARG_TYPE ( name , 'AbortSignal' , signal ) ;
353
355
}
354
356
} ) ;
@@ -393,14 +395,11 @@ const validateUndefined = hideStackFrames((value, name) => {
393
395
} ) ;
394
396
395
397
/**
396
- * @callback validateUnion
397
398
* @template T
398
399
* @param {T } value
399
400
* @param {string } name
400
401
* @param {T[] } union
401
402
*/
402
-
403
- /** @type {validateUnion } */
404
403
function validateUnion ( value , name , union ) {
405
404
if ( ! ArrayPrototypeIncludes ( union , value ) ) {
406
405
throw new ERR_INVALID_ARG_TYPE ( name , `('${ ArrayPrototypeJoin ( union , '|' ) } ')` , value ) ;
0 commit comments