2222'use strict' ;
2323
2424const {
25- ArrayPrototypeIncludes,
26- ArrayPrototypeIndexOf,
27- ArrayPrototypePop,
28- ArrayPrototypePush,
29- ArrayPrototypeShift,
30- ArrayPrototypeSome,
31- ArrayPrototypeSplice,
32- FunctionPrototypeCall,
3325 NumberParseInt,
3426 ObjectKeys,
3527 ObjectSetPrototypeOf,
3628 ObjectValues,
37- RegExpPrototypeExec,
38- StringPrototypeIndexOf,
39- StringPrototypeSplit,
40- StringPrototypeStartsWith,
41- StringPrototypeSubstring,
4229 Symbol,
4330} = primordials ;
4431
@@ -92,7 +79,7 @@ function Agent(options) {
9279 if ( ! ( this instanceof Agent ) )
9380 return new Agent ( options ) ;
9481
95- FunctionPrototypeCall ( EventEmitter , this ) ;
82+ EventEmitter . call ( this ) ;
9683
9784 this . defaultPort = 80 ;
9885 this . protocol = 'http:' ;
@@ -139,7 +126,7 @@ function Agent(options) {
139126
140127 const requests = this . requests [ name ] ;
141128 if ( requests && requests . length ) {
142- const req = ArrayPrototypeShift ( requests ) ;
129+ const req = requests . shift ( ) ;
143130 const reqAsyncRes = req [ kRequestAsyncResource ] ;
144131 if ( reqAsyncRes ) {
145132 // Run request within the original async context.
@@ -185,7 +172,7 @@ function Agent(options) {
185172 this . removeSocket ( socket , options ) ;
186173
187174 socket . once ( 'error' , freeSocketErrorListener ) ;
188- ArrayPrototypePush ( freeSockets , socket ) ;
175+ freeSockets . push ( socket ) ;
189176 } ) ;
190177
191178 // Don't emit keylog events unless there is a listener for them.
@@ -264,11 +251,11 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
264251 let socket ;
265252 if ( freeSockets ) {
266253 while ( freeSockets . length && freeSockets [ 0 ] . destroyed ) {
267- ArrayPrototypeShift ( freeSockets ) ;
254+ freeSockets . shift ( ) ;
268255 }
269256 socket = this . scheduling === 'fifo' ?
270- ArrayPrototypeShift ( freeSockets ) :
271- ArrayPrototypePop ( freeSockets ) ;
257+ freeSockets . shift ( ) :
258+ freeSockets . pop ( ) ;
272259 if ( ! freeSockets . length )
273260 delete this . freeSockets [ name ] ;
274261 }
@@ -280,7 +267,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
280267 asyncResetHandle ( socket ) ;
281268 this . reuseSocket ( socket , req ) ;
282269 setRequestSocket ( this , req , socket ) ;
283- ArrayPrototypePush ( this . sockets [ name ] , socket ) ;
270+ this . sockets [ name ] . push ( socket ) ;
284271 } else if ( sockLen < this . maxSockets &&
285272 this . totalSocketCount < this . maxTotalSockets ) {
286273 debug ( 'call onSocket' , sockLen , freeLen ) ;
@@ -303,7 +290,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
303290 // Used to capture the original async context.
304291 req [ kRequestAsyncResource ] = new AsyncResource ( 'QueuedRequest' ) ;
305292
306- ArrayPrototypePush ( this . requests [ name ] , req ) ;
293+ this . requests [ name ] . push ( req ) ;
307294 }
308295} ;
309296
@@ -326,7 +313,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
326313 if ( ! this . sockets [ name ] ) {
327314 this . sockets [ name ] = [ ] ;
328315 }
329- ArrayPrototypePush ( this . sockets [ name ] , s ) ;
316+ this . sockets [ name ] . push ( s ) ;
330317 this . totalSocketCount ++ ;
331318 debug ( 'sockets' , name , this . sockets [ name ] . length , this . totalSocketCount ) ;
332319 installListeners ( this , s , options ) ;
@@ -357,16 +344,16 @@ function calculateServerName(options, req) {
357344 // abc:123 => abc
358345 // [::1] => ::1
359346 // [::1]:123 => ::1
360- if ( StringPrototypeStartsWith ( hostHeader , '[' ) ) {
361- const index = StringPrototypeIndexOf ( hostHeader , ']' ) ;
347+ if ( hostHeader . startsWith ( '[' ) ) {
348+ const index = hostHeader . indexOf ( ']' ) ;
362349 if ( index === - 1 ) {
363350 // Leading '[', but no ']'. Need to do something...
364351 servername = hostHeader ;
365352 } else {
366- servername = StringPrototypeSubstring ( hostHeader , 1 , index ) ;
353+ servername = hostHeader . substring ( 1 , index ) ;
367354 }
368355 } else {
369- servername = StringPrototypeSplit ( hostHeader , ':' , 1 ) [ 0 ] ;
356+ servername = hostHeader . split ( ':' , 1 ) [ 0 ] ;
370357 }
371358 }
372359 // Don't implicitly set invalid (IP) servernames.
@@ -398,9 +385,7 @@ function installListeners(agent, s, options) {
398385 // Destroy if in free list.
399386 // TODO(ronag): Always destroy, even if not in free list.
400387 const sockets = agent . freeSockets ;
401- if ( ArrayPrototypeSome ( ObjectKeys ( sockets ) , ( name ) =>
402- ArrayPrototypeIncludes ( sockets [ name ] , s ) ,
403- ) ) {
388+ if ( ObjectKeys ( sockets ) . some ( ( name ) => sockets [ name ] . includes ( s ) ) ) {
404389 return s . destroy ( ) ;
405390 }
406391 }
@@ -432,15 +417,15 @@ Agent.prototype.removeSocket = function removeSocket(s, options) {
432417
433418 // If the socket was destroyed, remove it from the free buffers too.
434419 if ( ! s . writable )
435- ArrayPrototypePush ( sets , this . freeSockets ) ;
420+ sets . push ( this . freeSockets ) ;
436421
437422 for ( let sk = 0 ; sk < sets . length ; sk ++ ) {
438423 const sockets = sets [ sk ] ;
439424
440425 if ( sockets [ name ] ) {
441- const index = ArrayPrototypeIndexOf ( sockets [ name ] , s ) ;
426+ const index = sockets [ name ] . indexOf ( s ) ;
442427 if ( index !== - 1 ) {
443- ArrayPrototypeSplice ( sockets [ name ] , index , 1 ) ;
428+ sockets [ name ] . splice ( index , 1 ) ;
444429 // Don't leak
445430 if ( sockets [ name ] . length === 0 )
446431 delete sockets [ name ] ;
@@ -493,7 +478,7 @@ Agent.prototype.keepSocketAlive = function keepSocketAlive(socket) {
493478 const keepAliveHint = socket . _httpMessage . res . headers [ 'keep-alive' ] ;
494479
495480 if ( keepAliveHint ) {
496- const hint = RegExpPrototypeExec ( / ^ t i m e o u t = ( \d + ) / , keepAliveHint ) ?. [ 1 ] ;
481+ const hint = / ^ t i m e o u t = ( \d + ) / . exec ( keepAliveHint ) ?. [ 1 ] ;
497482
498483 if ( hint ) {
499484 const serverHintTimeout = NumberParseInt ( hint ) * 1000 ;
0 commit comments