22
22
'use strict' ;
23
23
24
24
const {
25
+ ArrayPrototypeIndexOf,
26
+ ArrayPrototypePush,
27
+ ArrayPrototypeShift,
28
+ ArrayPrototypeSplice,
29
+ ArrayPrototypeUnshift,
30
+ FunctionPrototypeCall,
31
+ JSONStringify,
25
32
ObjectAssign,
26
33
ObjectSetPrototypeOf,
27
- JSONStringify ,
34
+ ReflectConstruct ,
28
35
} = primordials ;
29
36
30
37
require ( 'internal/util' ) . assertCrypto ( ) ;
@@ -64,7 +71,7 @@ function Server(opts, requestListener) {
64
71
this [ kIncomingMessage ] = opts . IncomingMessage || IncomingMessage ;
65
72
this [ kServerResponse ] = opts . ServerResponse || ServerResponse ;
66
73
67
- tls . Server . call ( this , opts , _connectionListener ) ;
74
+ FunctionPrototypeCall ( tls . Server , this , opts , _connectionListener ) ;
68
75
69
76
this . httpAllowHalfOpen = false ;
70
77
@@ -150,7 +157,7 @@ function Agent(options) {
150
157
if ( ! ( this instanceof Agent ) )
151
158
return new Agent ( options ) ;
152
159
153
- HttpAgent . call ( this , options ) ;
160
+ FunctionPrototypeCall ( HttpAgent , this , options ) ;
154
161
this . defaultPort = 443 ;
155
162
this . protocol = 'https:' ;
156
163
this . maxCachedSessions = this . options . maxCachedSessions ;
@@ -167,7 +174,7 @@ ObjectSetPrototypeOf(Agent, HttpAgent);
167
174
Agent . prototype . createConnection = createConnection ;
168
175
169
176
Agent . prototype . getName = function getName ( options ) {
170
- let name = HttpAgent . prototype . getName . call ( this , options ) ;
177
+ let name = FunctionPrototypeCall ( HttpAgent . prototype . getName , this , options ) ;
171
178
172
179
name += ':' ;
173
180
if ( options . ca )
@@ -269,21 +276,21 @@ Agent.prototype._cacheSession = function _cacheSession(key, session) {
269
276
270
277
// Put new entry
271
278
if ( this . _sessionCache . list . length >= this . maxCachedSessions ) {
272
- const oldKey = this . _sessionCache . list . shift ( ) ;
279
+ const oldKey = ArrayPrototypeShift ( this . _sessionCache . list ) ;
273
280
debug ( 'evicting %j' , oldKey ) ;
274
281
delete this . _sessionCache . map [ oldKey ] ;
275
282
}
276
283
277
- this . _sessionCache . list . push ( key ) ;
284
+ ArrayPrototypePush ( this . _sessionCache . list , key ) ;
278
285
this . _sessionCache . map [ key ] = session ;
279
286
} ;
280
287
281
288
Agent . prototype . _evictSession = function _evictSession ( key ) {
282
- const index = this . _sessionCache . list . indexOf ( key ) ;
289
+ const index = ArrayPrototypeIndexOf ( this . _sessionCache . list , key ) ;
283
290
if ( index === - 1 )
284
291
return ;
285
292
286
- this . _sessionCache . list . splice ( index , 1 ) ;
293
+ ArrayPrototypeSplice ( this . _sessionCache . list , index , 1 ) ;
287
294
delete this . _sessionCache . map [ key ] ;
288
295
} ;
289
296
@@ -294,7 +301,7 @@ function request(...args) {
294
301
let options = { } ;
295
302
296
303
if ( typeof args [ 0 ] === 'string' ) {
297
- const urlStr = args . shift ( ) ;
304
+ const urlStr = ArrayPrototypeShift ( args ) ;
298
305
try {
299
306
options = urlToOptions ( new URL ( urlStr ) ) ;
300
307
} catch ( err ) {
@@ -313,17 +320,17 @@ function request(...args) {
313
320
} else if ( args [ 0 ] && args [ 0 ] [ searchParamsSymbol ] &&
314
321
args [ 0 ] [ searchParamsSymbol ] [ searchParamsSymbol ] ) {
315
322
// url.URL instance
316
- options = urlToOptions ( args . shift ( ) ) ;
323
+ options = urlToOptions ( ArrayPrototypeShift ( args ) ) ;
317
324
}
318
325
319
326
if ( args [ 0 ] && typeof args [ 0 ] !== 'function' ) {
320
- ObjectAssign ( options , args . shift ( ) ) ;
327
+ ObjectAssign ( options , ArrayPrototypeShift ( args ) ) ;
321
328
}
322
329
323
330
options . _defaultAgent = module . exports . globalAgent ;
324
- args . unshift ( options ) ;
331
+ ArrayPrototypeUnshift ( args , options ) ;
325
332
326
- return new ClientRequest ( ... args ) ;
333
+ return ReflectConstruct ( ClientRequest , args ) ;
327
334
}
328
335
329
336
function get ( input , options , cb ) {
0 commit comments