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) {
9279if ( ! ( this instanceof Agent ) )
9380return new Agent ( options ) ;
9481
95- FunctionPrototypeCall ( EventEmitter , this ) ;
82+ EventEmitter . call ( this ) ;
9683
9784this . defaultPort = 80 ;
9885this . protocol = 'http:' ;
@@ -139,7 +126,7 @@ function Agent(options) {
139126
140127const requests = this . requests [ name ] ;
141128if ( requests && requests . length ) {
142- const req = ArrayPrototypeShift ( requests ) ;
129+ const req = requests . shift ( ) ;
143130const reqAsyncRes = req [ kRequestAsyncResource ] ;
144131if ( reqAsyncRes ) {
145132// Run request within the original async context.
@@ -185,7 +172,7 @@ function Agent(options) {
185172this . removeSocket ( socket , options ) ;
186173
187174socket . 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 */,
264251let socket ;
265252if ( freeSockets ) {
266253while ( freeSockets . length && freeSockets [ 0 ] . destroyed ) {
267- ArrayPrototypeShift ( freeSockets ) ;
254+ freeSockets . shift ( ) ;
268255}
269256socket = this . scheduling === 'fifo' ?
270- ArrayPrototypeShift ( freeSockets ) :
271- ArrayPrototypePop ( freeSockets ) ;
257+ freeSockets . shift ( ) :
258+ freeSockets . pop ( ) ;
272259if ( ! freeSockets . length )
273260delete this . freeSockets [ name ] ;
274261}
@@ -280,7 +267,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
280267asyncResetHandle ( socket ) ;
281268this . reuseSocket ( socket , req ) ;
282269setRequestSocket ( this , req , socket ) ;
283- ArrayPrototypePush ( this . sockets [ name ] , socket ) ;
270+ this . sockets [ name ] . push ( socket ) ;
284271} else if ( sockLen < this . maxSockets &&
285272this . totalSocketCount < this . maxTotalSockets ) {
286273debug ( '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.
304291req [ 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) {
326313if ( ! this . sockets [ name ] ) {
327314this . sockets [ name ] = [ ] ;
328315}
329- ArrayPrototypePush ( this . sockets [ name ] , s ) ;
316+ this . sockets [ name ] . push ( s ) ;
330317this . totalSocketCount ++ ;
331318debug ( 'sockets' , name , this . sockets [ name ] . length , this . totalSocketCount ) ;
332319installListeners ( 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 ( ']' ) ;
362349if ( index === - 1 ) {
363350// Leading '[', but no ']'. Need to do something...
364351servername = 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.
400387const 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 ) ) ) {
404389return 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.
434419if ( ! s . writable )
435- ArrayPrototypePush ( sets , this . freeSockets ) ;
420+ sets . push ( this . freeSockets ) ;
436421
437422for ( let sk = 0 ; sk < sets . length ; sk ++ ) {
438423const sockets = sets [ sk ] ;
439424
440425if ( sockets [ name ] ) {
441- const index = ArrayPrototypeIndexOf ( sockets [ name ] , s ) ;
426+ const index = sockets [ name ] . indexOf ( s ) ;
442427if ( index !== - 1 ) {
443- ArrayPrototypeSplice ( sockets [ name ] , index , 1 ) ;
428+ sockets [ name ] . splice ( index , 1 ) ;
444429// Don't leak
445430if ( sockets [ name ] . length === 0 )
446431delete sockets [ name ] ;
@@ -493,7 +478,7 @@ Agent.prototype.keepSocketAlive = function keepSocketAlive(socket) {
493478const keepAliveHint = socket . _httpMessage . res . headers [ 'keep-alive' ] ;
494479
495480if ( 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
498483if ( hint ) {
499484const serverHintTimeout = NumberParseInt ( hint ) * 1000 ;
0 commit comments