| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3000e5d commit 99f96eb
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,8 +4,13 @@ The file `lib/internal/per_context/primordials.js` subclasses and stores the JS | |||
| 4 | 4 | built-ins that come from the VM so that Node.js built-in modules do not need to | |
| 5 | 5 | later look these up from the global proxy, which can be mutated by users. | |
| 6 | 6 | ||
| 7 | - Usage of primordials should be preferred for any new code, but replacing current | ||
| 8 | - code with primordials should be | ||
| 7 | + For some area of the codebase, performance and code readability are deemed more | ||
| 8 | + important than reliability against prototype pollution: | ||
| 9 | + | ||
| 10 | + * `node:http2` | ||
| 11 | + | ||
| 12 | + Usage of primordials should be preferred for new code in other areas, but | ||
| 13 | + replacing current code with primordials should be | ||
| 9 | 14 | [done with care](#primordials-with-known-performance-issues). It is highly | |
| 10 | 15 | recommended to ping the relevant team when reviewing a pull request that touches | |
| 11 | 16 | one of the subsystems they "own". | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,19 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | ArrayIsArray, | |
| 5 | - ArrayPrototypePush, | ||
| 6 | 5 | Boolean, | |
| 7 | - FunctionPrototypeBind, | ||
| 8 | 6 | ObjectAssign, | |
| 7 | + ObjectHasOwn, | ||
| 9 | 8 | ObjectKeys, | |
| 10 | - ObjectPrototypeHasOwnProperty, | ||
| 11 | 9 | Proxy, | |
| 12 | 10 | ReflectApply, | |
| 13 | 11 | ReflectGetPrototypeOf, | |
| 14 | - StringPrototypeIncludes, | ||
| 15 | - SafeArrayIterator, | ||
| 16 | - StringPrototypeToLowerCase, | ||
| 17 | - StringPrototypeTrim, | ||
| 18 | 12 | Symbol, | |
| 19 | 13 | } = primordials; | |
| 20 | 14 | ||
@@ -89,7 +83,7 @@ let statusConnectionHeaderWarned = false; | |||
| 89 | 83 | const assertValidHeader = hideStackFrames((name, value) => { | |
| 90 | 84 | if (name === '' || | |
| 91 | 85 | typeof name !== 'string' || | |
| 92 | - StringPrototypeIncludes(name, ' ')) { | ||
| 86 | + name.includes(' ')) { | ||
| 93 | 87 | throw new ERR_INVALID_HTTP_TOKEN.HideStackFramesError('Header name', name); | |
| 94 | 88 | } | |
| 95 | 89 | if (isPseudoHeader(name)) { | |
@@ -153,8 +147,7 @@ function onStreamTrailers(trailers, flags, rawTrailers) { | |||
| 153 | 147 | const request = this[kRequest]; | |
| 154 | 148 | if (request !== undefined) { | |
| 155 | 149 | ObjectAssign(request[kTrailers], trailers); | |
| 156 | - ArrayPrototypePush(request[kRawTrailers], | ||
| 157 | - ...new SafeArrayIterator(rawTrailers)); | ||
| 150 | + request[kRawTrailers].push(...rawTrailers); | ||
| 158 | 151 | } | |
| 159 | 152 | } | |
| 160 | 153 | ||
@@ -216,7 +209,7 @@ const proxySocketHandler = { | |||
| 216 | 209 | case 'end': | |
| 217 | 210 | case 'emit': | |
| 218 | 211 | case 'destroy': | |
| 219 | - return FunctionPrototypeBind(stream[prop], stream); | ||
| 212 | + return stream[prop].bind(stream); | ||
| 220 | 213 | case 'writable': | |
| 221 | 214 | case 'destroyed': | |
| 222 | 215 | return stream[prop]; | |
@@ -229,8 +222,8 @@ const proxySocketHandler = { | |||
| 229 | 222 | case 'setTimeout': { | |
| 230 | 223 | const session = stream.session; | |
| 231 | 224 | if (session !== undefined) | |
| 232 | - return FunctionPrototypeBind(session.setTimeout, session); | ||
| 233 | - return FunctionPrototypeBind(stream.setTimeout, stream); | ||
| 225 | + return session.setTimeout.bind(session); | ||
| 226 | + return stream.setTimeout.bind(stream); | ||
| 234 | 227 | } | |
| 235 | 228 | case 'write': | |
| 236 | 229 | case 'read': | |
@@ -242,7 +235,7 @@ const proxySocketHandler = { | |||
| 242 | 235 | stream.session[kSocket] : stream; | |
| 243 | 236 | const value = ref[prop]; | |
| 244 | 237 | return typeof value === 'function' ? | |
| 245 | - FunctionPrototypeBind(value, ref) : | ||
| 238 | + value.bind(ref) : | ||
| 246 | 239 | value; | |
| 247 | 240 | } | |
| 248 | 241 | } | |
@@ -417,7 +410,7 @@ class Http2ServerRequest extends Readable { | |||
| 417 | 410 | ||
| 418 | 411 | set method(method) { | |
| 419 | 412 | validateString(method, 'method'); | |
| 420 | - if (StringPrototypeTrim(method) === '') | ||
| 413 | + if (method.trim() === '') | ||
| 421 | 414 | throw new ERR_INVALID_ARG_VALUE('method', method); | |
| 422 | 415 | ||
| 423 | 416 | this[kHeaders][HTTP2_HEADER_METHOD] = method; | |
@@ -578,7 +571,7 @@ class Http2ServerResponse extends Stream { | |||
| 578 | 571 | ||
| 579 | 572 | setTrailer(name, value) { | |
| 580 | 573 | validateString(name, 'name'); | |
| 581 | - name = StringPrototypeToLowerCase(StringPrototypeTrim(name)); | ||
| 574 | + name = name.trim().toLowerCase(); | ||
| 582 | 575 | assertValidHeader(name, value); | |
| 583 | 576 | this[kTrailers][name] = value; | |
| 584 | 577 | } | |
@@ -594,7 +587,7 @@ class Http2ServerResponse extends Stream { | |||
| 594 | 587 | ||
| 595 | 588 | getHeader(name) { | |
| 596 | 589 | validateString(name, 'name'); | |
| 597 | - name = StringPrototypeToLowerCase(StringPrototypeTrim(name)); | ||
| 590 | + name = name.trim().toLowerCase(); | ||
| 598 | 591 | return this[kHeaders][name]; | |
| 599 | 592 | } | |
| 600 | 593 | ||
@@ -609,16 +602,16 @@ class Http2ServerResponse extends Stream { | |||
| 609 | 602 | ||
| 610 | 603 | hasHeader(name) { | |
| 611 | 604 | validateString(name, 'name'); | |
| 612 | - name = StringPrototypeToLowerCase(StringPrototypeTrim(name)); | ||
| 613 | - return ObjectPrototypeHasOwnProperty(this[kHeaders], name); | ||
| 605 | + name = name.trim().toLowerCase(); | ||
| 606 | + return ObjectHasOwn(this[kHeaders], name); | ||
| 614 | 607 | } | |
| 615 | 608 | ||
| 616 | 609 | removeHeader(name) { | |
| 617 | 610 | validateString(name, 'name'); | |
| 618 | 611 | if (this[kStream].headersSent) | |
| 619 | 612 | throw new ERR_HTTP2_HEADERS_SENT(); | |
| 620 | 613 | ||
| 621 | - name = StringPrototypeToLowerCase(StringPrototypeTrim(name)); | ||
| 614 | + name = name.trim().toLowerCase(); | ||
| 622 | 615 | ||
| 623 | 616 | if (name === 'date') { | |
| 624 | 617 | this[kState].sendDate = false; | |
@@ -638,7 +631,7 @@ class Http2ServerResponse extends Stream { | |||
| 638 | 631 | } | |
| 639 | 632 | ||
| 640 | 633 | [kSetHeader](name, value) { | |
| 641 | - name = StringPrototypeToLowerCase(StringPrototypeTrim(name)); | ||
| 634 | + name = name.trim().toLowerCase(); | ||
| 642 | 635 | assertValidHeader(name, value); | |
| 643 | 636 | ||
| 644 | 637 | if (!isConnectionHeaderAllowed(name, value)) { | |
@@ -662,7 +655,7 @@ class Http2ServerResponse extends Stream { | |||
| 662 | 655 | } | |
| 663 | 656 | ||
| 664 | 657 | [kAppendHeader](name, value) { | |
| 665 | - name = StringPrototypeToLowerCase(StringPrototypeTrim(name)); | ||
| 658 | + name = name.trim().toLowerCase(); | ||
| 666 | 659 | assertValidHeader(name, value); | |
| 667 | 660 | ||
| 668 | 661 | if (!isConnectionHeaderAllowed(name, value)) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments