File tree 6 files changed +20
-27
lines changed
6 files changed +20
-27
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ const {
100
100
hideStackFrames
101
101
} = require ( 'internal/errors' ) ;
102
102
const {
103
+ validateArray,
103
104
validateBuffer,
104
105
validateInteger,
105
106
validateString
@@ -534,9 +535,7 @@ Buffer.isEncoding = function isEncoding(encoding) {
534
535
Buffer [ kIsEncodingSymbol ] = Buffer . isEncoding ;
535
536
536
537
Buffer . concat = function concat ( list , length ) {
537
- if ( ! ArrayIsArray ( list ) ) {
538
- throw new ERR_INVALID_ARG_TYPE ( 'list' , 'Array' , list ) ;
539
- }
538
+ validateArray ( list , 'list' ) ;
540
539
541
540
if ( list . length === 0 )
542
541
return new FastBuffer ( ) ;
Original file line number Diff line number Diff line change @@ -24,13 +24,11 @@ if (credentials.implementsPosixCredentials) {
24
24
25
25
const {
26
26
parseFileMode,
27
+ validateArray,
27
28
validateString
28
29
} = require ( 'internal/validators' ) ;
29
30
30
31
function wrapPosixCredentialSetters ( credentials ) {
31
- const {
32
- ArrayIsArray,
33
- } = primordials ;
34
32
const {
35
33
codes : {
36
34
ERR_INVALID_ARG_TYPE ,
@@ -63,9 +61,7 @@ function wrapPosixCredentialSetters(credentials) {
63
61
}
64
62
65
63
function setgroups ( groups ) {
66
- if ( ! ArrayIsArray ( groups ) ) {
67
- throw new ERR_INVALID_ARG_TYPE ( 'groups' , 'Array' , groups ) ;
68
- }
64
+ validateArray ( groups , 'groups' ) ;
69
65
for ( let i = 0 ; i < groups . length ; i ++ ) {
70
66
validateId ( groups [ i ] , `groups[${ i } ]` ) ;
71
67
}
Original file line number Diff line number Diff line change @@ -29,7 +29,11 @@ const {
29
29
ERR_MISSING_ARGS
30
30
}
31
31
} = require ( 'internal/errors' ) ;
32
- const { validateString, validateOneOf } = require ( 'internal/validators' ) ;
32
+ const {
33
+ validateArray,
34
+ validateOneOf,
35
+ validateString,
36
+ } = require ( 'internal/validators' ) ;
33
37
const EventEmitter = require ( 'events' ) ;
34
38
const net = require ( 'net' ) ;
35
39
const dgram = require ( 'dgram' ) ;
@@ -377,12 +381,12 @@ ChildProcess.prototype.spawn = function(options) {
377
381
validateString ( options . file , 'options.file' ) ;
378
382
this . spawnfile = options . file ;
379
383
380
- if ( ArrayIsArray ( options . args ) )
381
- this . spawnargs = options . args ;
382
- else if ( options . args === undefined )
384
+ if ( options . args === undefined ) {
383
385
this . spawnargs = [ ] ;
384
- else
385
- throw new ERR_INVALID_ARG_TYPE ( 'options.args' , 'Array' , options . args ) ;
386
+ } else {
387
+ validateArray ( options . args , 'options.args' ) ;
388
+ this . spawnargs = options . args ;
389
+ }
386
390
387
391
const err = this . _handle . spawn ( options ) ;
388
392
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const {
4
- ArrayIsArray,
5
4
ArrayPrototypeForEach,
6
5
ArrayPrototypeJoin,
7
6
ArrayPrototypeMap,
@@ -14,7 +13,7 @@ const {
14
13
15
14
const errors = require ( 'internal/errors' ) ;
16
15
const { isIP } = require ( 'internal/net' ) ;
17
- const { validateInt32 } = require ( 'internal/validators' ) ;
16
+ const { validateArray , validateInt32 } = require ( 'internal/validators' ) ;
18
17
const {
19
18
ChannelWrap,
20
19
strerror,
@@ -60,9 +59,7 @@ class Resolver {
60
59
}
61
60
62
61
setServers ( servers ) {
63
- if ( ! ArrayIsArray ( servers ) ) {
64
- throw new ERR_INVALID_ARG_TYPE ( 'servers' , 'Array' , servers ) ;
65
- }
62
+ validateArray ( servers , 'servers' ) ;
66
63
67
64
// Cache the original servers because in the event of an error while
68
65
// setting the servers, c-ares won't have any servers available for
Original file line number Diff line number Diff line change 5
5
// thread and the worker threads.
6
6
7
7
const {
8
- ArrayIsArray,
9
8
ArrayPrototypeMap,
10
9
ArrayPrototypePush,
11
10
ArrayPrototypeSplice,
@@ -35,6 +34,7 @@ const {
35
34
}
36
35
} = require ( 'internal/errors' ) ;
37
36
const format = require ( 'internal/util/inspect' ) . format ;
37
+ const { validateArray } = require ( 'internal/validators' ) ;
38
38
const constants = internalBinding ( 'constants' ) . os . signals ;
39
39
40
40
function assert ( x , msg ) {
@@ -55,9 +55,7 @@ function getFastAPIs(binding) {
55
55
_hrtime . hrtime ( ) ;
56
56
57
57
if ( time !== undefined ) {
58
- if ( ! ArrayIsArray ( time ) ) {
59
- throw new ERR_INVALID_ARG_TYPE ( 'time' , 'Array' , time ) ;
60
- }
58
+ validateArray ( time , 'time' ) ;
61
59
if ( time . length !== 2 ) {
62
60
throw new ERR_OUT_OF_RANGE ( 'time' , 2 , time . length ) ;
63
61
}
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ const {
57
57
} = workerIo ;
58
58
const { deserializeError } = require ( 'internal/error_serdes' ) ;
59
59
const { fileURLToPath, isURLInstance, pathToFileURL } = require ( 'internal/url' ) ;
60
+ const { validateArray } = require ( 'internal/validators' ) ;
60
61
61
62
const {
62
63
ownsProcessState,
@@ -109,9 +110,7 @@ class Worker extends EventEmitter {
109
110
}
110
111
let argv ;
111
112
if ( options . argv ) {
112
- if ( ! ArrayIsArray ( options . argv ) ) {
113
- throw new ERR_INVALID_ARG_TYPE ( 'options.argv' , 'Array' , options . argv ) ;
114
- }
113
+ validateArray ( options . argv , 'options.argv' ) ;
115
114
argv = ArrayPrototypeMap ( options . argv , String ) ;
116
115
}
117
116
You can’t perform that action at this time.
0 commit comments