22
22
'use strict' ;
23
23
24
24
const {
25
+ ArrayPrototypeIncludes,
26
+ ArrayPrototypeIndexOf,
27
+ ArrayPrototypePop,
28
+ ArrayPrototypePush,
29
+ ArrayPrototypeShift,
30
+ ArrayPrototypeSplice,
31
+ FunctionPrototypeCall,
25
32
NumberIsNaN,
26
33
ObjectKeys,
27
34
ObjectSetPrototypeOf,
28
35
ObjectValues,
36
+ StringPrototypeIndexOf,
37
+ StringPrototypeSplit,
38
+ StringPrototypeStartsWith,
39
+ StringPrototypeSubstr,
29
40
Symbol,
30
41
} = primordials ;
31
42
@@ -78,7 +89,7 @@ function Agent(options) {
78
89
if ( ! ( this instanceof Agent ) )
79
90
return new Agent ( options ) ;
80
91
81
- EventEmitter . call ( this ) ;
92
+ FunctionPrototypeCall ( EventEmitter , this ) ;
82
93
83
94
this . defaultPort = 80 ;
84
95
this . protocol = 'http:' ;
@@ -125,7 +136,7 @@ function Agent(options) {
125
136
126
137
const requests = this . requests [ name ] ;
127
138
if ( requests && requests . length ) {
128
- const req = requests . shift ( ) ;
139
+ const req = ArrayPrototypeShift ( requests ) ;
129
140
const reqAsyncRes = req [ kRequestAsyncResource ] ;
130
141
if ( reqAsyncRes ) {
131
142
// Run request within the original async context.
@@ -171,7 +182,7 @@ function Agent(options) {
171
182
this . removeSocket ( socket , options ) ;
172
183
173
184
socket . once ( 'error' , freeSocketErrorListener ) ;
174
- freeSockets . push ( socket ) ;
185
+ ArrayPrototypePush ( freeSockets , socket ) ;
175
186
} ) ;
176
187
177
188
// Don't emit keylog events unless there is a listener for them.
@@ -249,11 +260,11 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
249
260
let socket ;
250
261
if ( freeSockets ) {
251
262
while ( freeSockets . length && freeSockets [ 0 ] . destroyed ) {
252
- freeSockets . shift ( ) ;
263
+ ArrayPrototypeShift ( freeSockets ) ;
253
264
}
254
265
socket = this . scheduling === 'fifo' ?
255
- freeSockets . shift ( ) :
256
- freeSockets . pop ( ) ;
266
+ ArrayPrototypeShift ( freeSockets ) :
267
+ ArrayPrototypePop ( freeSockets ) ;
257
268
if ( ! freeSockets . length )
258
269
delete this . freeSockets [ name ] ;
259
270
}
@@ -265,7 +276,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
265
276
asyncResetHandle ( socket ) ;
266
277
this . reuseSocket ( socket , req ) ;
267
278
setRequestSocket ( this , req , socket ) ;
268
- this . sockets [ name ] . push ( socket ) ;
279
+ ArrayPrototypePush ( this . sockets [ name ] , socket ) ;
269
280
this . totalSocketCount ++ ;
270
281
} else if ( sockLen < this . maxSockets &&
271
282
this . totalSocketCount < this . maxTotalSockets ) {
@@ -289,7 +300,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
289
300
// Used to capture the original async context.
290
301
req [ kRequestAsyncResource ] = new AsyncResource ( 'QueuedRequest' ) ;
291
302
292
- this . requests [ name ] . push ( req ) ;
303
+ ArrayPrototypePush ( this . requests [ name ] , req ) ;
293
304
}
294
305
} ;
295
306
@@ -313,7 +324,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
313
324
if ( ! this . sockets [ name ] ) {
314
325
this . sockets [ name ] = [ ] ;
315
326
}
316
- this . sockets [ name ] . push ( s ) ;
327
+ ArrayPrototypePush ( this . sockets [ name ] , s ) ;
317
328
this . totalSocketCount ++ ;
318
329
debug ( 'sockets' , name , this . sockets [ name ] . length , this . totalSocketCount ) ;
319
330
installListeners ( this , s , options ) ;
@@ -338,16 +349,16 @@ function calculateServerName(options, req) {
338
349
// abc:123 => abc
339
350
// [::1] => ::1
340
351
// [::1]:123 => ::1
341
- if ( hostHeader . startsWith ( '[' ) ) {
342
- const index = hostHeader . indexOf ( ']' ) ;
352
+ if ( StringPrototypeStartsWith ( hostHeader , '[' ) ) {
353
+ const index = StringPrototypeIndexOf ( hostHeader , ']' ) ;
343
354
if ( index === - 1 ) {
344
355
// Leading '[', but no ']'. Need to do something...
345
356
servername = hostHeader ;
346
357
} else {
347
- servername = hostHeader . substr ( 1 , index - 1 ) ;
358
+ servername = StringPrototypeSubstr ( hostHeader , 1 , index - 1 ) ;
348
359
}
349
360
} else {
350
- servername = hostHeader . split ( ':' , 1 ) [ 0 ] ;
361
+ servername = StringPrototypeSplit ( hostHeader , ':' , 1 ) [ 0 ] ;
351
362
}
352
363
}
353
364
// Don't implicitly set invalid (IP) servernames.
@@ -379,7 +390,7 @@ function installListeners(agent, s, options) {
379
390
// TODO(ronag): Always destroy, even if not in free list.
380
391
const sockets = agent . freeSockets ;
381
392
for ( const name of ObjectKeys ( sockets ) ) {
382
- if ( sockets [ name ] . includes ( s ) ) {
393
+ if ( ArrayPrototypeIncludes ( sockets [ name ] , s ) ) {
383
394
return s . destroy ( ) ;
384
395
}
385
396
}
@@ -411,13 +422,13 @@ Agent.prototype.removeSocket = function removeSocket(s, options) {
411
422
412
423
// If the socket was destroyed, remove it from the free buffers too.
413
424
if ( ! s . writable )
414
- sets . push ( this . freeSockets ) ;
425
+ ArrayPrototypePush ( sets , this . freeSockets ) ;
415
426
416
427
for ( const sockets of sets ) {
417
428
if ( sockets [ name ] ) {
418
- const index = sockets [ name ] . indexOf ( s ) ;
429
+ const index = ArrayPrototypeIndexOf ( sockets [ name ] , s ) ;
419
430
if ( index !== - 1 ) {
420
- sockets [ name ] . splice ( index , 1 ) ;
431
+ ArrayPrototypeSplice ( sockets [ name ] , index , 1 ) ;
421
432
// Don't leak
422
433
if ( sockets [ name ] . length === 0 )
423
434
delete sockets [ name ] ;
0 commit comments