| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,12 +35,20 @@ const { | |||
| 35 | 35 | ObjectDefineProperties, | |
| 36 | 36 | ObjectDefineProperty, | |
| 37 | 37 | ObjectGetOwnPropertyDescriptor, | |
| 38 | - ObjectGetPrototypeOf, | ||
| 39 | 38 | ObjectSetPrototypeOf, | |
| 39 | + StringPrototypeCharCodeAt, | ||
| 40 | + StringPrototypeReplace, | ||
| 41 | + StringPrototypeSlice, | ||
| 42 | + StringPrototypeToLowerCase, | ||
| 43 | + StringPrototypeTrim, | ||
| 40 | 44 | SymbolSpecies, | |
| 41 | 45 | SymbolToPrimitive, | |
| 46 | + TypedArrayPrototype, | ||
| 47 | + TypedArrayPrototypeFill, | ||
| 48 | + TypedArrayPrototypeSet, | ||
| 42 | 49 | Uint8Array, | |
| 43 | 50 | Uint8ArrayPrototype, | |
| 51 | + uncurryThis, | ||
| 44 | 52 | } = primordials; | |
| 45 | 53 | ||
| 46 | 54 | const { | |
@@ -108,12 +116,9 @@ const { | |||
| 108 | 116 | createUnsafeBuffer | |
| 109 | 117 | } = require('internal/buffer'); | |
| 110 | 118 | ||
| 111 | - const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8ArrayPrototype); | ||
| 112 | - | ||
| 113 | - const TypedArrayProto_byteLength = | ||
| 114 | - ObjectGetOwnPropertyDescriptor(TypedArrayPrototype, | ||
| 115 | - 'byteLength').get; | ||
| 116 | - const TypedArrayFill = TypedArrayPrototype.fill; | ||
| 119 | + const TypedArrayProto_byteLength = uncurryThis( | ||
| 120 | + ObjectGetOwnPropertyDescriptor(TypedArrayPrototype, | ||
| 121 | + 'byteLength').get); | ||
| 117 | 122 | ||
| 118 | 123 | FastBuffer.prototype.constructor = Buffer; | |
| 119 | 124 | Buffer.prototype = FastBuffer.prototype; | |
@@ -246,7 +251,7 @@ function _copyActual(source, target, targetStart, sourceStart, sourceEnd) { | |||
| 246 | 251 | if (sourceStart !== 0 || sourceEnd < source.length) | |
| 247 | 252 | source = new Uint8Array(source.buffer, source.byteOffset + sourceStart, nb); | |
| 248 | 253 | ||
| 249 | - target.set(source, targetStart); | ||
| 254 | + TypedArrayPrototypeSet(target, source, targetStart); | ||
| 250 | 255 | ||
| 251 | 256 | return nb; | |
| 252 | 257 | } | |
@@ -480,7 +485,7 @@ function fromArrayLike(obj) { | |||
| 480 | 485 | if (obj.length > (poolSize - poolOffset)) | |
| 481 | 486 | createPool(); | |
| 482 | 487 | const b = new FastBuffer(allocPool, poolOffset, obj.length); | |
| 483 | - b.set(obj, 0); | ||
| 488 | + TypedArrayPrototypeSet(b, obj, 0); | ||
| 484 | 489 | poolOffset += obj.length; | |
| 485 | 490 | alignPool(); | |
| 486 | 491 | return b; | |
@@ -566,17 +571,17 @@ Buffer.concat = function concat(list, length) { | |||
| 566 | 571 | // Zero-fill the remaining bytes if the specified `length` was more than | |
| 567 | 572 | // the actual total length, i.e. if we have some remaining allocated bytes | |
| 568 | 573 | // there were not initialized. | |
| 569 | - TypedArrayFill.call(buffer, 0, pos, length); | ||
| 574 | + TypedArrayPrototypeFill(buffer, 0, pos, length); | ||
| 570 | 575 | } | |
| 571 | 576 | ||
| 572 | 577 | return buffer; | |
| 573 | 578 | }; | |
| 574 | 579 | ||
| 575 | 580 | function base64ByteLength(str, bytes) { | |
| 576 | 581 | // Handle padding | |
| 577 | - if (str.charCodeAt(bytes - 1) === 0x3D) | ||
| 582 | + if (StringPrototypeCharCodeAt(str, bytes - 1) === 0x3D) | ||
| 578 | 583 | bytes--; | |
| 579 | - if (bytes > 1 && str.charCodeAt(bytes - 1) === 0x3D) | ||
| 584 | + if (bytes > 1 && StringPrototypeCharCodeAt(str, bytes - 1) === 0x3D) | ||
| 580 | 585 | bytes--; | |
| 581 | 586 | ||
| 582 | 587 | // Base64 ratio: 3/4 | |
@@ -666,38 +671,40 @@ function getEncodingOps(encoding) { | |||
| 666 | 671 | case 4: | |
| 667 | 672 | if (encoding === 'utf8') return encodingOps.utf8; | |
| 668 | 673 | if (encoding === 'ucs2') return encodingOps.ucs2; | |
| 669 | - encoding = encoding.toLowerCase(); | ||
| 674 | + encoding = StringPrototypeToLowerCase(encoding); | ||
| 670 | 675 | if (encoding === 'utf8') return encodingOps.utf8; | |
| 671 | 676 | if (encoding === 'ucs2') return encodingOps.ucs2; | |
| 672 | 677 | break; | |
| 673 | 678 | case 5: | |
| 674 | 679 | if (encoding === 'utf-8') return encodingOps.utf8; | |
| 675 | 680 | if (encoding === 'ascii') return encodingOps.ascii; | |
| 676 | 681 | if (encoding === 'ucs-2') return encodingOps.ucs2; | |
| 677 | - encoding = encoding.toLowerCase(); | ||
| 682 | + encoding = StringPrototypeToLowerCase(encoding); | ||
| 678 | 683 | if (encoding === 'utf-8') return encodingOps.utf8; | |
| 679 | 684 | if (encoding === 'ascii') return encodingOps.ascii; | |
| 680 | 685 | if (encoding === 'ucs-2') return encodingOps.ucs2; | |
| 681 | 686 | break; | |
| 682 | 687 | case 7: | |
| 683 | - if (encoding === 'utf16le' || encoding.toLowerCase() === 'utf16le') | ||
| 688 | + if (encoding === 'utf16le' || | ||
| 689 | + StringPrototypeToLowerCase(encoding) === 'utf16le') | ||
| 684 | 690 | return encodingOps.utf16le; | |
| 685 | 691 | break; | |
| 686 | 692 | case 8: | |
| 687 | - if (encoding === 'utf-16le' || encoding.toLowerCase() === 'utf-16le') | ||
| 693 | + if (encoding === 'utf-16le' || | ||
| 694 | + StringPrototypeToLowerCase(encoding) === 'utf-16le') | ||
| 688 | 695 | return encodingOps.utf16le; | |
| 689 | 696 | break; | |
| 690 | 697 | case 6: | |
| 691 | 698 | if (encoding === 'latin1' || encoding === 'binary') | |
| 692 | 699 | return encodingOps.latin1; | |
| 693 | 700 | if (encoding === 'base64') return encodingOps.base64; | |
| 694 | - encoding = encoding.toLowerCase(); | ||
| 701 | + encoding = StringPrototypeToLowerCase(encoding); | ||
| 695 | 702 | if (encoding === 'latin1' || encoding === 'binary') | |
| 696 | 703 | return encodingOps.latin1; | |
| 697 | 704 | if (encoding === 'base64') return encodingOps.base64; | |
| 698 | 705 | break; | |
| 699 | 706 | case 3: | |
| 700 | - if (encoding === 'hex' || encoding.toLowerCase() === 'hex') | ||
| 707 | + if (encoding === 'hex' || StringPrototypeToLowerCase(encoding) === 'hex') | ||
| 701 | 708 | return encodingOps.hex; | |
| 702 | 709 | break; | |
| 703 | 710 | } | |
@@ -810,7 +817,8 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) { | |||
| 810 | 817 | const max = INSPECT_MAX_BYTES; | |
| 811 | 818 | const actualMax = MathMin(max, this.length); | |
| 812 | 819 | const remaining = this.length - max; | |
| 813 | - let str = this.hexSlice(0, actualMax).replace(/(.{2})/g, '$1 ').trim(); | ||
| 820 | + let str = StringPrototypeTrim(StringPrototypeReplace( | ||
| 821 | + this.hexSlice(0, actualMax), /(.{2})/g, '$1 ')); | ||
| 814 | 822 | if (remaining > 0) | |
| 815 | 823 | str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`; | |
| 816 | 824 | // Inspect special properties as well, if possible. | |
@@ -827,11 +835,11 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) { | |||
| 827 | 835 | str += ', '; | |
| 828 | 836 | // '[Object: null prototype] {'.length === 26 | |
| 829 | 837 | // This is guarded with a test. | |
| 830 | - str += utilInspect(obj, { | ||
| 838 | + str += StringPrototypeSlice(utilInspect(obj, { | ||
| 831 | 839 | ...ctx, | |
| 832 | 840 | breakLength: Infinity, | |
| 833 | 841 | compact: true | |
| 834 | - }).slice(27, -2); | ||
| 842 | + }), 27, -2); | ||
| 835 | 843 | } | |
| 836 | 844 | } | |
| 837 | 845 | return `<${this.constructor.name} ${str}>`; | |
@@ -975,12 +983,12 @@ function _fill(buf, value, offset, end, encoding) { | |||
| 975 | 983 | } else if (value.length === 1) { | |
| 976 | 984 | // Fast path: If `value` fits into a single byte, use that numeric value. | |
| 977 | 985 | if (normalizedEncoding === 'utf8') { | |
| 978 | - const code = value.charCodeAt(0); | ||
| 986 | + const code = StringPrototypeCharCodeAt(value, 0); | ||
| 979 | 987 | if (code < 128) { | |
| 980 | 988 | value = code; | |
| 981 | 989 | } | |
| 982 | 990 | } else if (normalizedEncoding === 'latin1') { | |
| 983 | - value = value.charCodeAt(0); | ||
| 991 | + value = StringPrototypeCharCodeAt(value, 0); | ||
| 984 | 992 | } | |
| 985 | 993 | } | |
| 986 | 994 | } else { | |
@@ -1005,12 +1013,12 @@ function _fill(buf, value, offset, end, encoding) { | |||
| 1005 | 1013 | ||
| 1006 | 1014 | if (typeof value === 'number') { | |
| 1007 | 1015 | // OOB check | |
| 1008 | - const byteLen = TypedArrayProto_byteLength.call(buf); | ||
| 1016 | + const byteLen = TypedArrayProto_byteLength(buf); | ||
| 1009 | 1017 | const fillLength = end - offset; | |
| 1010 | 1018 | if (offset > end || fillLength + offset > byteLen) | |
| 1011 | 1019 | throw new ERR_BUFFER_OUT_OF_BOUNDS(); | |
| 1012 | 1020 | ||
| 1013 | - TypedArrayFill.call(buf, value, offset, end); | ||
| 1021 | + TypedArrayPrototypeFill(buf, value, offset, end); | ||
| 1014 | 1022 | } else { | |
| 1015 | 1023 | const res = bindingFill(buf, value, offset, end, encoding); | |
| 1016 | 1024 | if (res < 0) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments