2222'use strict' ;
2323
2424const {
25+ ArrayPrototypeIndexOf,
26+ ArrayPrototypePush,
27+ ArrayPrototypeShift,
28+ ArrayPrototypeSplice,
29+ ArrayPrototypeUnshift,
30+ FunctionPrototypeCall,
31+ JSONStringify,
2532 ObjectAssign,
2633 ObjectSetPrototypeOf,
27- JSONStringify ,
34+ ReflectConstruct ,
2835} = primordials ;
2936
3037require ( 'internal/util' ) . assertCrypto ( ) ;
@@ -64,7 +71,7 @@ function Server(opts, requestListener) {
6471 this [ kIncomingMessage ] = opts . IncomingMessage || IncomingMessage ;
6572 this [ kServerResponse ] = opts . ServerResponse || ServerResponse ;
6673
67- tls . Server . call ( this , opts , _connectionListener ) ;
74+ FunctionPrototypeCall ( tls . Server , this , opts , _connectionListener ) ;
6875
6976 this . httpAllowHalfOpen = false ;
7077
@@ -150,7 +157,7 @@ function Agent(options) {
150157 if ( ! ( this instanceof Agent ) )
151158 return new Agent ( options ) ;
152159
153- HttpAgent . call ( this , options ) ;
160+ FunctionPrototypeCall ( HttpAgent , this , options ) ;
154161 this . defaultPort = 443 ;
155162 this . protocol = 'https:' ;
156163 this . maxCachedSessions = this . options . maxCachedSessions ;
@@ -167,7 +174,7 @@ ObjectSetPrototypeOf(Agent, HttpAgent);
167174Agent . prototype . createConnection = createConnection ;
168175
169176Agent . prototype . getName = function getName ( options ) {
170- let name = HttpAgent . prototype . getName . call ( this , options ) ;
177+ let name = FunctionPrototypeCall ( HttpAgent . prototype . getName , this , options ) ;
171178
172179 name += ':' ;
173180 if ( options . ca )
@@ -269,21 +276,21 @@ Agent.prototype._cacheSession = function _cacheSession(key, session) {
269276
270277 // Put new entry
271278 if ( this . _sessionCache . list . length >= this . maxCachedSessions ) {
272- const oldKey = this . _sessionCache . list . shift ( ) ;
279+ const oldKey = ArrayPrototypeShift ( this . _sessionCache . list ) ;
273280 debug ( 'evicting %j' , oldKey ) ;
274281 delete this . _sessionCache . map [ oldKey ] ;
275282 }
276283
277- this . _sessionCache . list . push ( key ) ;
284+ ArrayPrototypePush ( this . _sessionCache . list , key ) ;
278285 this . _sessionCache . map [ key ] = session ;
279286} ;
280287
281288Agent . prototype . _evictSession = function _evictSession ( key ) {
282- const index = this . _sessionCache . list . indexOf ( key ) ;
289+ const index = ArrayPrototypeIndexOf ( this . _sessionCache . list , key ) ;
283290 if ( index === - 1 )
284291 return ;
285292
286- this . _sessionCache . list . splice ( index , 1 ) ;
293+ ArrayPrototypeSplice ( this . _sessionCache . list , index , 1 ) ;
287294 delete this . _sessionCache . map [ key ] ;
288295} ;
289296
@@ -294,7 +301,7 @@ function request(...args) {
294301 let options = { } ;
295302
296303 if ( typeof args [ 0 ] === 'string' ) {
297- const urlStr = args . shift ( ) ;
304+ const urlStr = ArrayPrototypeShift ( args ) ;
298305 try {
299306 options = urlToOptions ( new URL ( urlStr ) ) ;
300307 } catch ( err ) {
@@ -313,17 +320,17 @@ function request(...args) {
313320 } else if ( args [ 0 ] && args [ 0 ] [ searchParamsSymbol ] &&
314321 args [ 0 ] [ searchParamsSymbol ] [ searchParamsSymbol ] ) {
315322 // url.URL instance
316- options = urlToOptions ( args . shift ( ) ) ;
323+ options = urlToOptions ( ArrayPrototypeShift ( args ) ) ;
317324 }
318325
319326 if ( args [ 0 ] && typeof args [ 0 ] !== 'function' ) {
320- ObjectAssign ( options , args . shift ( ) ) ;
327+ ObjectAssign ( options , ArrayPrototypeShift ( args ) ) ;
321328 }
322329
323330 options . _defaultAgent = module . exports . globalAgent ;
324- args . unshift ( options ) ;
331+ ArrayPrototypeUnshift ( args , options ) ;
325332
326- return new ClientRequest ( ... args ) ;
333+ return ReflectConstruct ( ClientRequest , args ) ;
327334}
328335
329336function get ( input , options , cb ) {
0 commit comments