Skip to content

Commit 6e13a7b

Browse files
aduh95anonrig
authored andcommittedSep 21, 2024
http: remove prototype primordials
Co-authored-by: Yagiz Nizipli <yagiz@nizipli.com> PR-URL: #53698 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>

File tree

9 files changed

+60
-96
lines changed

9 files changed

+60
-96
lines changed
 

Diff for: ‎doc/contributing/primordials.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ later look these up from the global proxy, which can be mutated by users.
77
For some area of the codebase, performance and code readability are deemed more
88
important than reliability against prototype pollution:
99

10+
* `node:http`
1011
* `node:http2`
1112

1213
Usage of primordials should be preferred for new code in other areas, but

Diff for: ‎lib/_http_agent.js

+18-33
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,10 @@
2222
'use strict';
2323

2424
const {
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(/^timeout=(\d+)/, keepAliveHint)?.[1];
481+
const hint = /^timeout=(\d+)/.exec(keepAliveHint)?.[1];
497482

498483
if (hint) {
499484
const serverHintTimeout = NumberParseInt(hint) * 1000;

Diff for: ‎lib/_http_client.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,13 @@ const {
2525
ArrayIsArray,
2626
Boolean,
2727
Error,
28-
FunctionPrototypeCall,
2928
NumberIsFinite,
3029
ObjectAssign,
3130
ObjectKeys,
3231
ObjectSetPrototypeOf,
3332
ReflectApply,
34-
RegExpPrototypeExec,
3533
String,
36-
StringPrototypeCharCodeAt,
37-
StringPrototypeIncludes,
38-
StringPrototypeIndexOf,
39-
StringPrototypeToUpperCase,
4034
Symbol,
41-
TypedArrayPrototypeSlice,
4235
} = primordials;
4336

4437
const net = require('net');
@@ -139,7 +132,7 @@ class HTTPClientAsyncResource {
139132
}
140133

141134
function ClientRequest(input, options, cb) {
142-
FunctionPrototypeCall(OutgoingMessage, this);
135+
OutgoingMessage.call(this);
143136

144137
if (typeof input === 'string') {
145138
const urlStr = input;
@@ -184,7 +177,7 @@ function ClientRequest(input, options, cb) {
184177

185178
if (options.path) {
186179
const path = String(options.path);
187-
if (RegExpPrototypeExec(INVALID_PATH_REGEX, path) !== null) {
180+
if (INVALID_PATH_REGEX.test(path)) {
188181
debug('Path contains unescaped characters: "%s"', path);
189182
throw new ERR_UNESCAPED_CHARACTERS('Request path');
190183
}
@@ -225,7 +218,7 @@ function ClientRequest(input, options, cb) {
225218
if (!checkIsHttpToken(method)) {
226219
throw new ERR_INVALID_HTTP_TOKEN('Method', method);
227220
}
228-
method = this.method = StringPrototypeToUpperCase(method);
221+
method = this.method = method.toUpperCase();
229222
} else {
230223
method = this.method = 'GET';
231224
}
@@ -307,10 +300,10 @@ function ClientRequest(input, options, cb) {
307300
// For the Host header, ensure that IPv6 addresses are enclosed
308301
// in square brackets, as defined by URI formatting
309302
// https://tools.ietf.org/html/rfc3986#section-3.2.2
310-
const posColon = StringPrototypeIndexOf(hostHeader, ':');
303+
const posColon = hostHeader.indexOf(':');
311304
if (posColon !== -1 &&
312-
StringPrototypeIncludes(hostHeader, ':', posColon + 1) &&
313-
StringPrototypeCharCodeAt(hostHeader, 0) !== 91/* '[' */) {
305+
hostHeader.includes(':', posColon + 1) &&
306+
hostHeader.charCodeAt(0) !== 91/* '[' */) {
314307
hostHeader = `[${hostHeader}]`;
315308
}
316309

@@ -383,7 +376,7 @@ ObjectSetPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
383376
ObjectSetPrototypeOf(ClientRequest, OutgoingMessage);
384377

385378
ClientRequest.prototype._finish = function _finish() {
386-
FunctionPrototypeCall(OutgoingMessage.prototype._finish, this);
379+
OutgoingMessage.prototype._finish.call(this);
387380
if (hasObserver('http')) {
388381
startPerf(this, kClientRequestStatistics, {
389382
type: 'http',
@@ -574,7 +567,7 @@ function socketOnData(d) {
574567
parser.finish();
575568
freeParser(parser, req, socket);
576569

577-
const bodyHead = TypedArrayPrototypeSlice(d, bytesParsed, d.length);
570+
const bodyHead = d.slice(bytesParsed, d.length);
578571

579572
const eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
580573
if (req.listenerCount(eventName) > 0) {

Diff for: ‎lib/_http_common.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
const {
2525
MathMin,
2626
Symbol,
27-
RegExpPrototypeExec,
2827
} = primordials;
2928
const { setImmediate } = require('timers');
3029

@@ -210,7 +209,7 @@ const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
210209
* See https://tools.ietf.org/html/rfc7230#section-3.2.6
211210
*/
212211
function checkIsHttpToken(val) {
213-
return RegExpPrototypeExec(tokenRegExp, val) !== null;
212+
return tokenRegExp.test(val);
214213
}
215214

216215
const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
@@ -221,7 +220,7 @@ const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
221220
* field-vchar = VCHAR / obs-text
222221
*/
223222
function checkInvalidHeaderChar(val) {
224-
return RegExpPrototypeExec(headerCharRegex, val) !== null;
223+
return headerCharRegex.test(val);
225224
}
226225

227226
function cleanParser(parser) {

Diff for: ‎lib/_http_incoming.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
const {
2525
ObjectDefineProperty,
2626
ObjectSetPrototypeOf,
27-
StringPrototypeCharCodeAt,
28-
StringPrototypeSlice,
29-
StringPrototypeToLowerCase,
3027
Symbol,
3128
} = primordials;
3229

@@ -370,7 +367,7 @@ function matchKnownFields(field, lowercased) {
370367
if (lowercased) {
371368
return '\u0000' + field;
372369
}
373-
return matchKnownFields(StringPrototypeToLowerCase(field), true);
370+
return matchKnownFields(field.toLowerCase(), true);
374371
}
375372
// Add the given (field, value) pair to the message
376373
//
@@ -384,9 +381,9 @@ function matchKnownFields(field, lowercased) {
384381
IncomingMessage.prototype._addHeaderLine = _addHeaderLine;
385382
function _addHeaderLine(field, value, dest) {
386383
field = matchKnownFields(field);
387-
const flag = StringPrototypeCharCodeAt(field, 0);
384+
const flag = field.charCodeAt(0);
388385
if (flag === 0 || flag === 2) {
389-
field = StringPrototypeSlice(field, 1);
386+
field = field.slice(1);
390387
// Make a delimited list
391388
if (typeof dest[field] === 'string') {
392389
dest[field] += (flag === 0 ? ', ' : '; ') + value;
@@ -418,7 +415,7 @@ function _addHeaderLine(field, value, dest) {
418415

419416
IncomingMessage.prototype._addHeaderLineDistinct = _addHeaderLineDistinct;
420417
function _addHeaderLineDistinct(field, value, dest) {
421-
field = StringPrototypeToLowerCase(field);
418+
field = field.toLowerCase();
422419
if (!dest[field]) {
423420
dest[field] = [value];
424421
} else {

Diff for: ‎lib/_http_outgoing.js

+20-24
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@
2424
const {
2525
Array,
2626
ArrayIsArray,
27-
ArrayPrototypeJoin,
2827
MathFloor,
29-
NumberPrototypeToString,
3028
ObjectDefineProperty,
29+
ObjectHasOwn,
3130
ObjectKeys,
32-
ObjectValues,
33-
ObjectPrototypeHasOwnProperty,
3431
ObjectSetPrototypeOf,
35-
RegExpPrototypeExec,
32+
ObjectValues,
3633
SafeSet,
37-
StringPrototypeToLowerCase,
3834
Symbol,
3935
} = primordials;
4036

@@ -96,11 +92,11 @@ const RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
9692
// against the word "cookie." As of V8 6.6 this is faster than handrolling or
9793
// using a case-insensitive RegExp.
9894
function isCookieField(s) {
99-
return s.length === 6 && StringPrototypeToLowerCase(s) === 'cookie';
95+
return s.length === 6 && s.toLowerCase() === 'cookie';
10096
}
10197

10298
function isContentDispositionField(s) {
103-
return s.length === 19 && StringPrototypeToLowerCase(s) === 'content-disposition';
99+
return s.length === 19 && s.toLowerCase() === 'content-disposition';
104100
}
105101

106102
function OutgoingMessage(options) {
@@ -226,7 +222,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, '_headers', {
226222
// Refs: https://github.com/nodejs/node/pull/30958
227223
for (let i = 0; i < keys.length; ++i) {
228224
const name = keys[i];
229-
headers[StringPrototypeToLowerCase(name)] = [name, val[name]];
225+
headers[name.toLowerCase()] = [name, val[name]];
230226
}
231227
}
232228
}, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066'),
@@ -447,7 +443,7 @@ function _storeHeader(firstLine, headers) {
447443
}
448444
} else {
449445
for (const key in headers) {
450-
if (ObjectPrototypeHasOwnProperty(headers, key)) {
446+
if (ObjectHasOwn(headers, key)) {
451447
processHeader(this, state, key, headers[key], true);
452448
}
453449
}
@@ -569,15 +565,15 @@ function processHeader(self, state, key, value, validate) {
569565
if (ArrayIsArray(value)) {
570566
if (
571567
(value.length < 2 || !isCookieField(key)) &&
572-
(!self[kUniqueHeaders] || !self[kUniqueHeaders].has(StringPrototypeToLowerCase(key)))
568+
(!self[kUniqueHeaders] || !self[kUniqueHeaders].has(key.toLowerCase()))
573569
) {
574570
// Retain for(;;) loop for performance reasons
575571
// Refs: https://github.com/nodejs/node/pull/30958
576572
for (let i = 0; i < value.length; i++)
577573
storeHeader(self, state, key, value[i], validate);
578574
return;
579575
}
580-
value = ArrayPrototypeJoin(value, '; ');
576+
value = value.join('; ');
581577
}
582578
storeHeader(self, state, key, value, validate);
583579
}
@@ -592,20 +588,20 @@ function storeHeader(self, state, key, value, validate) {
592588
function matchHeader(self, state, field, value) {
593589
if (field.length < 4 || field.length > 17)
594590
return;
595-
field = StringPrototypeToLowerCase(field);
591+
field = field.toLowerCase();
596592
switch (field) {
597593
case 'connection':
598594
state.connection = true;
599595
self._removedConnection = false;
600-
if (RegExpPrototypeExec(RE_CONN_CLOSE, value) !== null)
596+
if (RE_CONN_CLOSE.test(value))
601597
self._last = true;
602598
else
603599
self.shouldKeepAlive = true;
604600
break;
605601
case 'transfer-encoding':
606602
state.te = true;
607603
self._removedTE = false;
608-
if (RegExpPrototypeExec(RE_TE_CHUNKED, value) !== null)
604+
if (RE_TE_CHUNKED.test(value))
609605
self.chunkedEncoding = true;
610606
break;
611607
case 'content-length':
@@ -648,7 +644,7 @@ function parseUniqueHeadersOption(headers) {
648644
const unique = new SafeSet();
649645
const l = headers.length;
650646
for (let i = 0; i < l; i++) {
651-
unique.add(StringPrototypeToLowerCase(headers[i]));
647+
unique.add(headers[i].toLowerCase());
652648
}
653649

654650
return unique;
@@ -665,7 +661,7 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
665661
if (headers === null)
666662
this[kOutHeaders] = headers = { __proto__: null };
667663

668-
headers[StringPrototypeToLowerCase(name)] = [name, value];
664+
headers[name.toLowerCase()] = [name, value];
669665
return this;
670666
};
671667

@@ -717,7 +713,7 @@ OutgoingMessage.prototype.appendHeader = function appendHeader(name, value) {
717713
validateHeaderName(name);
718714
validateHeaderValue(name, value);
719715

720-
const field = StringPrototypeToLowerCase(name);
716+
const field = name.toLowerCase();
721717
const headers = this[kOutHeaders];
722718
if (headers === null || !headers[field]) {
723719
return this.setHeader(name, value);
@@ -748,7 +744,7 @@ OutgoingMessage.prototype.getHeader = function getHeader(name) {
748744
if (headers === null)
749745
return;
750746

751-
const entry = headers[StringPrototypeToLowerCase(name)];
747+
const entry = headers[name.toLowerCase()];
752748
return entry && entry[1];
753749
};
754750

@@ -797,7 +793,7 @@ OutgoingMessage.prototype.getHeaders = function getHeaders() {
797793
OutgoingMessage.prototype.hasHeader = function hasHeader(name) {
798794
validateString(name, 'name');
799795
return this[kOutHeaders] !== null &&
800-
!!this[kOutHeaders][StringPrototypeToLowerCase(name)];
796+
!!this[kOutHeaders][name.toLowerCase()];
801797
};
802798

803799

@@ -808,7 +804,7 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
808804
throw new ERR_HTTP_HEADERS_SENT('remove');
809805
}
810806

811-
const key = StringPrototypeToLowerCase(name);
807+
const key = name.toLowerCase();
812808

813809
switch (key) {
814810
case 'connection':
@@ -964,7 +960,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
964960
let ret;
965961
if (msg.chunkedEncoding && chunk.length !== 0) {
966962
len ??= typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.byteLength;
967-
msg._send(NumberPrototypeToString(len, 16), 'latin1', null);
963+
msg._send(len.toString(16), 'latin1', null);
968964
msg._send(crlf_buf, null, null);
969965
msg._send(chunk, encoding, null, len);
970966
ret = msg._send(crlf_buf, null, callback);
@@ -1003,7 +999,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
1003999
const isArrayValue = ArrayIsArray(value);
10041000
if (
10051001
isArrayValue && value.length > 1 &&
1006-
(!this[kUniqueHeaders] || !this[kUniqueHeaders].has(StringPrototypeToLowerCase(field)))
1002+
(!this[kUniqueHeaders] || !this[kUniqueHeaders].has(field.toLowerCase()))
10071003
) {
10081004
for (let j = 0, l = value.length; j < l; j++) {
10091005
if (checkInvalidHeaderChar(value[j])) {
@@ -1014,7 +1010,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
10141010
}
10151011
} else {
10161012
if (isArrayValue) {
1017-
value = ArrayPrototypeJoin(value, '; ');
1013+
value = value.join('; ');
10181014
}
10191015

10201016
if (checkInvalidHeaderChar(value)) {

Diff for: ‎lib/_http_server.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
const {
2525
ArrayIsArray,
2626
Error,
27-
FunctionPrototypeCall,
2827
MathMin,
2928
ObjectKeys,
3029
ObjectSetPrototypeOf,
31-
RegExpPrototypeExec,
3230
ReflectApply,
3331
Symbol,
3432
SymbolAsyncDispose,
@@ -203,8 +201,7 @@ function ServerResponse(req, options) {
203201
this._expect_continue = false;
204202

205203
if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
206-
this.useChunkedEncodingByDefault = RegExpPrototypeExec(chunkExpression,
207-
req.headers.te) !== null;
204+
this.useChunkedEncodingByDefault = chunkExpression.test(req.headers.te);
208205
this.shouldKeepAlive = false;
209206
}
210207

@@ -568,7 +565,7 @@ Server.prototype.close = function() {
568565
};
569566

570567
Server.prototype[SymbolAsyncDispose] = async function() {
571-
return FunctionPrototypeCall(promisify(this.close), this);
568+
return promisify(this.close).call(this);
572569
};
573570

574571
Server.prototype.closeAllConnections = function() {
@@ -1119,7 +1116,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
11191116
} else if (req.headers.expect !== undefined) {
11201117
handled = true;
11211118

1122-
if (RegExpPrototypeExec(continueExpression, req.headers.expect) !== null) {
1119+
if (continueExpression.test(req.headers.expect)) {
11231120
res._expect_continue = true;
11241121
if (server.listenerCount('checkContinue') > 0) {
11251122
server.emit('checkContinue', req, res);

Diff for: ‎lib/http.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
'use strict';
2323

2424
const {
25-
ArrayPrototypeSlice,
26-
ArrayPrototypeSort,
2725
ObjectDefineProperty,
2826
} = primordials;
2927

@@ -118,7 +116,7 @@ function get(url, options, cb) {
118116

119117
module.exports = {
120118
_connectionListener,
121-
METHODS: ArrayPrototypeSort(ArrayPrototypeSlice(methods)),
119+
METHODS: methods.toSorted(),
122120
STATUS_CODES,
123121
Agent: httpAgent.Agent,
124122
ClientRequest,

Diff for: ‎lib/internal/http.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
22

33
const {
4-
Symbol,
54
Date,
6-
DatePrototypeGetMilliseconds,
7-
DatePrototypeToUTCString,
5+
Symbol,
86
} = primordials;
97

108
const { setUnrefTimeout } = require('internal/timers');
@@ -23,8 +21,8 @@ function utcDate() {
2321

2422
function cache() {
2523
const d = new Date();
26-
utcCache = DatePrototypeToUTCString(d);
27-
setUnrefTimeout(resetCache, 1000 - DatePrototypeGetMilliseconds(d));
24+
utcCache = d.toUTCString();
25+
setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
2826
}
2927

3028
function resetCache() {

0 commit comments

Comments
 (0)
Please sign in to comment.