| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 99f96eb commit 6e13a7b
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ later look these up from the global proxy, which can be mutated by users. | |||
| 7 | 7 | For some area of the codebase, performance and code readability are deemed more | |
| 8 | 8 | important than reliability against prototype pollution: | |
| 9 | 9 | ||
| 10 | + * `node:http` | ||
| 10 | 11 | * `node:http2` | |
| 11 | 12 | ||
| 12 | 13 | Usage of primordials should be preferred for new code in other areas, but | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,23 +22,10 @@ | |||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | ||
| 24 | 24 | const { | |
| 25 | - ArrayPrototypeIncludes, | ||
| 26 | - ArrayPrototypeIndexOf, | ||
| 27 | - ArrayPrototypePop, | ||
| 28 | - ArrayPrototypePush, | ||
| 29 | - ArrayPrototypeShift, | ||
| 30 | - ArrayPrototypeSome, | ||
| 31 | - ArrayPrototypeSplice, | ||
| 32 | - FunctionPrototypeCall, | ||
| 33 | 25 | NumberParseInt, | |
| 34 | 26 | ObjectKeys, | |
| 35 | 27 | ObjectSetPrototypeOf, | |
| 36 | 28 | ObjectValues, | |
| 37 | - RegExpPrototypeExec, | ||
| 38 | - StringPrototypeIndexOf, | ||
| 39 | - StringPrototypeSplit, | ||
| 40 | - StringPrototypeStartsWith, | ||
| 41 | - StringPrototypeSubstring, | ||
| 42 | 29 | Symbol, | |
| 43 | 30 | } = primordials; | |
| 44 | 31 | ||
@@ -92,7 +79,7 @@ function Agent(options) { | |||
| 92 | 79 | if (!(this instanceof Agent)) | |
| 93 | 80 | return new Agent(options); | |
| 94 | 81 | ||
| 95 | - FunctionPrototypeCall(EventEmitter, this); | ||
| 82 | + EventEmitter.call(this); | ||
| 96 | 83 | ||
| 97 | 84 | this.defaultPort = 80; | |
| 98 | 85 | this.protocol = 'http:'; | |
@@ -139,7 +126,7 @@ function Agent(options) { | |||
| 139 | 126 | ||
| 140 | 127 | const requests = this.requests[name]; | |
| 141 | 128 | if (requests && requests.length) { | |
| 142 | - const req = ArrayPrototypeShift(requests); | ||
| 129 | + const req = requests.shift(); | ||
| 143 | 130 | const reqAsyncRes = req[kRequestAsyncResource]; | |
| 144 | 131 | if (reqAsyncRes) { | |
| 145 | 132 | // Run request within the original async context. | |
@@ -185,7 +172,7 @@ function Agent(options) { | |||
| 185 | 172 | this.removeSocket(socket, options); | |
| 186 | 173 | ||
| 187 | 174 | socket.once('error', freeSocketErrorListener); | |
| 188 | - ArrayPrototypePush(freeSockets, socket); | ||
| 175 | + freeSockets.push(socket); | ||
| 189 | 176 | }); | |
| 190 | 177 | ||
| 191 | 178 | // 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 */, | |||
| 264 | 251 | let socket; | |
| 265 | 252 | if (freeSockets) { | |
| 266 | 253 | while (freeSockets.length && freeSockets[0].destroyed) { | |
| 267 | - ArrayPrototypeShift(freeSockets); | ||
| 254 | + freeSockets.shift(); | ||
| 268 | 255 | } | |
| 269 | 256 | socket = this.scheduling === 'fifo' ? | |
| 270 | - ArrayPrototypeShift(freeSockets) : | ||
| 271 | - ArrayPrototypePop(freeSockets); | ||
| 257 | + freeSockets.shift() : | ||
| 258 | + freeSockets.pop(); | ||
| 272 | 259 | if (!freeSockets.length) | |
| 273 | 260 | delete this.freeSockets[name]; | |
| 274 | 261 | } | |
@@ -280,7 +267,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */, | |||
| 280 | 267 | asyncResetHandle(socket); | |
| 281 | 268 | this.reuseSocket(socket, req); | |
| 282 | 269 | setRequestSocket(this, req, socket); | |
| 283 | - ArrayPrototypePush(this.sockets[name], socket); | ||
| 270 | + this.sockets[name].push(socket); | ||
| 284 | 271 | } else if (sockLen < this.maxSockets && | |
| 285 | 272 | this.totalSocketCount < this.maxTotalSockets) { | |
| 286 | 273 | debug('call onSocket', sockLen, freeLen); | |
@@ -303,7 +290,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */, | |||
| 303 | 290 | // Used to capture the original async context. | |
| 304 | 291 | req[kRequestAsyncResource] = new AsyncResource('QueuedRequest'); | |
| 305 | 292 | ||
| 306 | - ArrayPrototypePush(this.requests[name], req); | ||
| 293 | + this.requests[name].push(req); | ||
| 307 | 294 | } | |
| 308 | 295 | }; | |
| 309 | 296 | ||
@@ -326,7 +313,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) { | |||
| 326 | 313 | if (!this.sockets[name]) { | |
| 327 | 314 | this.sockets[name] = []; | |
| 328 | 315 | } | |
| 329 | - ArrayPrototypePush(this.sockets[name], s); | ||
| 316 | + this.sockets[name].push(s); | ||
| 330 | 317 | this.totalSocketCount++; | |
| 331 | 318 | debug('sockets', name, this.sockets[name].length, this.totalSocketCount); | |
| 332 | 319 | installListeners(this, s, options); | |
@@ -357,16 +344,16 @@ function calculateServerName(options, req) { | |||
| 357 | 344 | // abc:123 => abc | |
| 358 | 345 | // [::1] => ::1 | |
| 359 | 346 | // [::1]:123 => ::1 | |
| 360 | - if (StringPrototypeStartsWith(hostHeader, '[')) { | ||
| 361 | - const index = StringPrototypeIndexOf(hostHeader, ']'); | ||
| 347 | + if (hostHeader.startsWith('[')) { | ||
| 348 | + const index = hostHeader.indexOf(']'); | ||
| 362 | 349 | if (index === -1) { | |
| 363 | 350 | // Leading '[', but no ']'. Need to do something... | |
| 364 | 351 | servername = hostHeader; | |
| 365 | 352 | } else { | |
| 366 | - servername = StringPrototypeSubstring(hostHeader, 1, index); | ||
| 353 | + servername = hostHeader.substring(1, index); | ||
| 367 | 354 | } | |
| 368 | 355 | } else { | |
| 369 | - servername = StringPrototypeSplit(hostHeader, ':', 1)[0]; | ||
| 356 | + servername = hostHeader.split(':', 1)[0]; | ||
| 370 | 357 | } | |
| 371 | 358 | } | |
| 372 | 359 | // Don't implicitly set invalid (IP) servernames. | |
@@ -398,9 +385,7 @@ function installListeners(agent, s, options) { | |||
| 398 | 385 | // Destroy if in free list. | |
| 399 | 386 | // TODO(ronag): Always destroy, even if not in free list. | |
| 400 | 387 | 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))) { | ||
| 404 | 389 | return s.destroy(); | |
| 405 | 390 | } | |
| 406 | 391 | } | |
@@ -432,15 +417,15 @@ Agent.prototype.removeSocket = function removeSocket(s, options) { | |||
| 432 | 417 | ||
| 433 | 418 | // If the socket was destroyed, remove it from the free buffers too. | |
| 434 | 419 | if (!s.writable) | |
| 435 | - ArrayPrototypePush(sets, this.freeSockets); | ||
| 420 | + sets.push(this.freeSockets); | ||
| 436 | 421 | ||
| 437 | 422 | for (let sk = 0; sk < sets.length; sk++) { | |
| 438 | 423 | const sockets = sets[sk]; | |
| 439 | 424 | ||
| 440 | 425 | if (sockets[name]) { | |
| 441 | - const index = ArrayPrototypeIndexOf(sockets[name], s); | ||
| 426 | + const index = sockets[name].indexOf(s); | ||
| 442 | 427 | if (index !== -1) { | |
| 443 | - ArrayPrototypeSplice(sockets[name], index, 1); | ||
| 428 | + sockets[name].splice(index, 1); | ||
| 444 | 429 | // Don't leak | |
| 445 | 430 | if (sockets[name].length === 0) | |
| 446 | 431 | delete sockets[name]; | |
@@ -493,7 +478,7 @@ Agent.prototype.keepSocketAlive = function keepSocketAlive(socket) { | |||
| 493 | 478 | const keepAliveHint = socket._httpMessage.res.headers['keep-alive']; | |
| 494 | 479 | ||
| 495 | 480 | if (keepAliveHint) { | |
| 496 | - const hint = RegExpPrototypeExec(/^timeout=(\d+)/, keepAliveHint)?.[1]; | ||
| 481 | + const hint = /^timeout=(\d+)/.exec(keepAliveHint)?.[1]; | ||
| 497 | 482 | ||
| 498 | 483 | if (hint) { | |
| 499 | 484 | const serverHintTimeout = NumberParseInt(hint) * 1000; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,20 +25,13 @@ const { | |||
| 25 | 25 | ArrayIsArray, | |
| 26 | 26 | Boolean, | |
| 27 | 27 | Error, | |
| 28 | - FunctionPrototypeCall, | ||
| 29 | 28 | NumberIsFinite, | |
| 30 | 29 | ObjectAssign, | |
| 31 | 30 | ObjectKeys, | |
| 32 | 31 | ObjectSetPrototypeOf, | |
| 33 | 32 | ReflectApply, | |
| 34 | - RegExpPrototypeExec, | ||
| 35 | 33 | String, | |
| 36 | - StringPrototypeCharCodeAt, | ||
| 37 | - StringPrototypeIncludes, | ||
| 38 | - StringPrototypeIndexOf, | ||
| 39 | - StringPrototypeToUpperCase, | ||
| 40 | 34 | Symbol, | |
| 41 | - TypedArrayPrototypeSlice, | ||
| 42 | 35 | } = primordials; | |
| 43 | 36 | ||
| 44 | 37 | const net = require('net'); | |
@@ -139,7 +132,7 @@ class HTTPClientAsyncResource { | |||
| 139 | 132 | } | |
| 140 | 133 | ||
| 141 | 134 | function ClientRequest(input, options, cb) { | |
| 142 | - FunctionPrototypeCall(OutgoingMessage, this); | ||
| 135 | + OutgoingMessage.call(this); | ||
| 143 | 136 | ||
| 144 | 137 | if (typeof input === 'string') { | |
| 145 | 138 | const urlStr = input; | |
@@ -184,7 +177,7 @@ function ClientRequest(input, options, cb) { | |||
| 184 | 177 | ||
| 185 | 178 | if (options.path) { | |
| 186 | 179 | const path = String(options.path); | |
| 187 | - if (RegExpPrototypeExec(INVALID_PATH_REGEX, path) !== null) { | ||
| 180 | + if (INVALID_PATH_REGEX.test(path)) { | ||
| 188 | 181 | debug('Path contains unescaped characters: "%s"', path); | |
| 189 | 182 | throw new ERR_UNESCAPED_CHARACTERS('Request path'); | |
| 190 | 183 | } | |
@@ -225,7 +218,7 @@ function ClientRequest(input, options, cb) { | |||
| 225 | 218 | if (!checkIsHttpToken(method)) { | |
| 226 | 219 | throw new ERR_INVALID_HTTP_TOKEN('Method', method); | |
| 227 | 220 | } | |
| 228 | - method = this.method = StringPrototypeToUpperCase(method); | ||
| 221 | + method = this.method = method.toUpperCase(); | ||
| 229 | 222 | } else { | |
| 230 | 223 | method = this.method = 'GET'; | |
| 231 | 224 | } | |
@@ -307,10 +300,10 @@ function ClientRequest(input, options, cb) { | |||
| 307 | 300 | // For the Host header, ensure that IPv6 addresses are enclosed | |
| 308 | 301 | // in square brackets, as defined by URI formatting | |
| 309 | 302 | // https://tools.ietf.org/html/rfc3986#section-3.2.2 | |
| 310 | - const posColon = StringPrototypeIndexOf(hostHeader, ':'); | ||
| 303 | + const posColon = hostHeader.indexOf(':'); | ||
| 311 | 304 | if (posColon !== -1 && | |
| 312 | - StringPrototypeIncludes(hostHeader, ':', posColon + 1) && | ||
| 313 | - StringPrototypeCharCodeAt(hostHeader, 0) !== 91/* '[' */) { | ||
| 305 | + hostHeader.includes(':', posColon + 1) && | ||
| 306 | + hostHeader.charCodeAt(0) !== 91/* '[' */) { | ||
| 314 | 307 | hostHeader = `[${hostHeader}]`; | |
| 315 | 308 | } | |
| 316 | 309 | ||
@@ -383,7 +376,7 @@ ObjectSetPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype); | |||
| 383 | 376 | ObjectSetPrototypeOf(ClientRequest, OutgoingMessage); | |
| 384 | 377 | ||
| 385 | 378 | ClientRequest.prototype._finish = function _finish() { | |
| 386 | - FunctionPrototypeCall(OutgoingMessage.prototype._finish, this); | ||
| 379 | + OutgoingMessage.prototype._finish.call(this); | ||
| 387 | 380 | if (hasObserver('http')) { | |
| 388 | 381 | startPerf(this, kClientRequestStatistics, { | |
| 389 | 382 | type: 'http', | |
@@ -574,7 +567,7 @@ function socketOnData(d) { | |||
| 574 | 567 | parser.finish(); | |
| 575 | 568 | freeParser(parser, req, socket); | |
| 576 | 569 | ||
| 577 | - const bodyHead = TypedArrayPrototypeSlice(d, bytesParsed, d.length); | ||
| 570 | + const bodyHead = d.slice(bytesParsed, d.length); | ||
| 578 | 571 | ||
| 579 | 572 | const eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade'; | |
| 580 | 573 | if (req.listenerCount(eventName) > 0) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,6 @@ | |||
| 24 | 24 | const { | |
| 25 | 25 | MathMin, | |
| 26 | 26 | Symbol, | |
| 27 | - RegExpPrototypeExec, | ||
| 28 | 27 | } = primordials; | |
| 29 | 28 | const { setImmediate } = require('timers'); | |
| 30 | 29 | ||
@@ -210,7 +209,7 @@ const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/; | |||
| 210 | 209 | * See https://tools.ietf.org/html/rfc7230#section-3.2.6 | |
| 211 | 210 | */ | |
| 212 | 211 | function checkIsHttpToken(val) { | |
| 213 | - return RegExpPrototypeExec(tokenRegExp, val) !== null; | ||
| 212 | + return tokenRegExp.test(val); | ||
| 214 | 213 | } | |
| 215 | 214 | ||
| 216 | 215 | const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/; | |
@@ -221,7 +220,7 @@ const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/; | |||
| 221 | 220 | * field-vchar = VCHAR / obs-text | |
| 222 | 221 | */ | |
| 223 | 222 | function checkInvalidHeaderChar(val) { | |
| 224 | - return RegExpPrototypeExec(headerCharRegex, val) !== null; | ||
| 223 | + return headerCharRegex.test(val); | ||
| 225 | 224 | } | |
| 226 | 225 | ||
| 227 | 226 | function cleanParser(parser) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,9 +24,6 @@ | |||
| 24 | 24 | const { | |
| 25 | 25 | ObjectDefineProperty, | |
| 26 | 26 | ObjectSetPrototypeOf, | |
| 27 | - StringPrototypeCharCodeAt, | ||
| 28 | - StringPrototypeSlice, | ||
| 29 | - StringPrototypeToLowerCase, | ||
| 30 | 27 | Symbol, | |
| 31 | 28 | } = primordials; | |
| 32 | 29 | ||
@@ -370,7 +367,7 @@ function matchKnownFields(field, lowercased) { | |||
| 370 | 367 | if (lowercased) { | |
| 371 | 368 | return '\u0000' + field; | |
| 372 | 369 | } | |
| 373 | - return matchKnownFields(StringPrototypeToLowerCase(field), true); | ||
| 370 | + return matchKnownFields(field.toLowerCase(), true); | ||
| 374 | 371 | } | |
| 375 | 372 | // Add the given (field, value) pair to the message | |
| 376 | 373 | // | |
@@ -384,9 +381,9 @@ function matchKnownFields(field, lowercased) { | |||
| 384 | 381 | IncomingMessage.prototype._addHeaderLine = _addHeaderLine; | |
| 385 | 382 | function _addHeaderLine(field, value, dest) { | |
| 386 | 383 | field = matchKnownFields(field); | |
| 387 | - const flag = StringPrototypeCharCodeAt(field, 0); | ||
| 384 | + const flag = field.charCodeAt(0); | ||
| 388 | 385 | if (flag === 0 || flag === 2) { | |
| 389 | - field = StringPrototypeSlice(field, 1); | ||
| 386 | + field = field.slice(1); | ||
| 390 | 387 | // Make a delimited list | |
| 391 | 388 | if (typeof dest[field] === 'string') { | |
| 392 | 389 | dest[field] += (flag === 0 ? ', ' : '; ') + value; | |
@@ -418,7 +415,7 @@ function _addHeaderLine(field, value, dest) { | |||
| 418 | 415 | ||
| 419 | 416 | IncomingMessage.prototype._addHeaderLineDistinct = _addHeaderLineDistinct; | |
| 420 | 417 | function _addHeaderLineDistinct(field, value, dest) { | |
| 421 | - field = StringPrototypeToLowerCase(field); | ||
| 418 | + field = field.toLowerCase(); | ||
| 422 | 419 | if (!dest[field]) { | |
| 423 | 420 | dest[field] = [value]; | |
| 424 | 421 | } else { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments