diff --git a/lib/https.js b/lib/https.js index e1f0936b631ade..a7fcf06a95f273 100644 --- a/lib/https.js +++ b/lib/https.js @@ -22,9 +22,16 @@ 'use strict'; const { + ArrayPrototypeIndexOf, + ArrayPrototypePush, + ArrayPrototypeShift, + ArrayPrototypeSplice, + ArrayPrototypeUnshift, + FunctionPrototypeCall, + JSONStringify, ObjectAssign, ObjectSetPrototypeOf, - JSONStringify, + ReflectConstruct, } = primordials; require('internal/util').assertCrypto(); @@ -64,7 +71,7 @@ function Server(opts, requestListener) { this[kIncomingMessage] = opts.IncomingMessage || IncomingMessage; this[kServerResponse] = opts.ServerResponse || ServerResponse; - tls.Server.call(this, opts, _connectionListener); + FunctionPrototypeCall(tls.Server, this, opts, _connectionListener); this.httpAllowHalfOpen = false; @@ -150,7 +157,7 @@ function Agent(options) { if (!(this instanceof Agent)) return new Agent(options); - HttpAgent.call(this, options); + FunctionPrototypeCall(HttpAgent, this, options); this.defaultPort = 443; this.protocol = 'https:'; this.maxCachedSessions = this.options.maxCachedSessions; @@ -167,7 +174,7 @@ ObjectSetPrototypeOf(Agent, HttpAgent); Agent.prototype.createConnection = createConnection; Agent.prototype.getName = function getName(options) { - let name = HttpAgent.prototype.getName.call(this, options); + let name = FunctionPrototypeCall(HttpAgent.prototype.getName, this, options); name += ':'; if (options.ca) @@ -269,21 +276,21 @@ Agent.prototype._cacheSession = function _cacheSession(key, session) { // Put new entry if (this._sessionCache.list.length >= this.maxCachedSessions) { - const oldKey = this._sessionCache.list.shift(); + const oldKey = ArrayPrototypeShift(this._sessionCache.list); debug('evicting %j', oldKey); delete this._sessionCache.map[oldKey]; } - this._sessionCache.list.push(key); + ArrayPrototypePush(this._sessionCache.list, key); this._sessionCache.map[key] = session; }; Agent.prototype._evictSession = function _evictSession(key) { - const index = this._sessionCache.list.indexOf(key); + const index = ArrayPrototypeIndexOf(this._sessionCache.list, key); if (index === -1) return; - this._sessionCache.list.splice(index, 1); + ArrayPrototypeSplice(this._sessionCache.list, index, 1); delete this._sessionCache.map[key]; }; @@ -294,7 +301,7 @@ function request(...args) { let options = {}; if (typeof args[0] === 'string') { - const urlStr = args.shift(); + const urlStr = ArrayPrototypeShift(args); try { options = urlToOptions(new URL(urlStr)); } catch (err) { @@ -313,17 +320,17 @@ function request(...args) { } else if (args[0] && args[0][searchParamsSymbol] && args[0][searchParamsSymbol][searchParamsSymbol]) { // url.URL instance - options = urlToOptions(args.shift()); + options = urlToOptions(ArrayPrototypeShift(args)); } if (args[0] && typeof args[0] !== 'function') { - ObjectAssign(options, args.shift()); + ObjectAssign(options, ArrayPrototypeShift(args)); } options._defaultAgent = module.exports.globalAgent; - args.unshift(options); + ArrayPrototypeUnshift(args, options); - return new ClientRequest(...args); + return ReflectConstruct(ClientRequest, args); } function get(input, options, cb) {