Skip to content

Commit 91f94ab

Browse files
Lxxyxruyadorno
authored andcommitted
lib: refactor to use validateArray
PR-URL: #36982 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6125701 commit 91f94ab

6 files changed

Lines changed: 20 additions & 27 deletions

File tree

‎lib/buffer.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const {
100100
hideStackFrames
101101
}=require('internal/errors');
102102
const{
103+
validateArray,
103104
validateBuffer,
104105
validateInteger,
105106
validateString
@@ -534,9 +535,7 @@ Buffer.isEncoding = function isEncoding(encoding) {
534535
Buffer[kIsEncodingSymbol]=Buffer.isEncoding;
535536

536537
Buffer.concat=functionconcat(list,length){
537-
if(!ArrayIsArray(list)){
538-
thrownewERR_INVALID_ARG_TYPE('list','Array',list);
539-
}
538+
validateArray(list,'list');
540539

541540
if(list.length===0)
542541
returnnewFastBuffer();

‎lib/internal/bootstrap/switches/does_own_process_state.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ if (credentials.implementsPosixCredentials) {
2424

2525
const{
2626
parseFileMode,
27+
validateArray,
2728
validateString
2829
}=require('internal/validators');
2930

3031
functionwrapPosixCredentialSetters(credentials){
31-
const{
32-
ArrayIsArray,
33-
}=primordials;
3432
const{
3533
codes: {
3634
ERR_INVALID_ARG_TYPE,
@@ -63,9 +61,7 @@ function wrapPosixCredentialSetters(credentials) {
6361
}
6462

6563
functionsetgroups(groups){
66-
if(!ArrayIsArray(groups)){
67-
thrownewERR_INVALID_ARG_TYPE('groups','Array',groups);
68-
}
64+
validateArray(groups,'groups');
6965
for(leti=0;i<groups.length;i++){
7066
validateId(groups[i],`groups[${i}]`);
7167
}

‎lib/internal/child_process.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ const {
2929
ERR_MISSING_ARGS
3030
}
3131
}=require('internal/errors');
32-
const{ validateString, validateOneOf }=require('internal/validators');
32+
const{
33+
validateArray,
34+
validateOneOf,
35+
validateString,
36+
}=require('internal/validators');
3337
constEventEmitter=require('events');
3438
constnet=require('net');
3539
constdgram=require('dgram');
@@ -377,12 +381,12 @@ ChildProcess.prototype.spawn = function(options) {
377381
validateString(options.file,'options.file');
378382
this.spawnfile=options.file;
379383

380-
if(ArrayIsArray(options.args))
381-
this.spawnargs=options.args;
382-
elseif(options.args===undefined)
384+
if(options.args===undefined){
383385
this.spawnargs=[];
384-
else
385-
thrownewERR_INVALID_ARG_TYPE('options.args','Array',options.args);
386+
}else{
387+
validateArray(options.args,'options.args');
388+
this.spawnargs=options.args;
389+
}
386390

387391
consterr=this._handle.spawn(options);
388392

‎lib/internal/dns/utils.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const{
4-
ArrayIsArray,
54
ArrayPrototypeForEach,
65
ArrayPrototypeJoin,
76
ArrayPrototypeMap,
@@ -14,7 +13,7 @@ const {
1413

1514
consterrors=require('internal/errors');
1615
const{ isIP }=require('internal/net');
17-
const{ validateInt32 }=require('internal/validators');
16+
const{validateArray,validateInt32 }=require('internal/validators');
1817
const{
1918
ChannelWrap,
2019
strerror,
@@ -60,9 +59,7 @@ class Resolver {
6059
}
6160

6261
setServers(servers){
63-
if(!ArrayIsArray(servers)){
64-
thrownewERR_INVALID_ARG_TYPE('servers','Array',servers);
65-
}
62+
validateArray(servers,'servers');
6663

6764
// Cache the original servers because in the event of an error while
6865
// setting the servers, c-ares won't have any servers available for

‎lib/internal/process/per_thread.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// thread and the worker threads.
66

77
const{
8-
ArrayIsArray,
98
ArrayPrototypeMap,
109
ArrayPrototypePush,
1110
ArrayPrototypeSplice,
@@ -35,6 +34,7 @@ const {
3534
}
3635
}=require('internal/errors');
3736
constformat=require('internal/util/inspect').format;
37+
const{ validateArray }=require('internal/validators');
3838
constconstants=internalBinding('constants').os.signals;
3939

4040
functionassert(x,msg){
@@ -55,9 +55,7 @@ function getFastAPIs(binding) {
5555
_hrtime.hrtime();
5656

5757
if(time!==undefined){
58-
if(!ArrayIsArray(time)){
59-
thrownewERR_INVALID_ARG_TYPE('time','Array',time);
60-
}
58+
validateArray(time,'time');
6159
if(time.length!==2){
6260
thrownewERR_OUT_OF_RANGE('time',2,time.length);
6361
}

‎lib/internal/worker.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const {
5757
}=workerIo;
5858
const{ deserializeError }=require('internal/error_serdes');
5959
const{ fileURLToPath, isURLInstance, pathToFileURL }=require('internal/url');
60+
const{ validateArray }=require('internal/validators');
6061

6162
const{
6263
ownsProcessState,
@@ -109,9 +110,7 @@ class Worker extends EventEmitter {
109110
}
110111
letargv;
111112
if(options.argv){
112-
if(!ArrayIsArray(options.argv)){
113-
thrownewERR_INVALID_ARG_TYPE('options.argv','Array',options.argv);
114-
}
113+
validateArray(options.argv,'options.argv');
115114
argv=ArrayPrototypeMap(options.argv,String);
116115
}
117116

0 commit comments

Comments
 (0)