@@ -26,6 +26,7 @@ const {
26
26
ArrayBufferIsView,
27
27
ArrayIsArray,
28
28
ArrayPrototypeForEach,
29
+ FunctionPrototypeCall,
29
30
MathFloor,
30
31
MathMin,
31
32
MathTrunc,
@@ -135,6 +136,23 @@ FastBuffer.prototype.constructor = Buffer;
135
136
Buffer . prototype = FastBuffer . prototype ;
136
137
addBufferPrototypeMethods ( Buffer . prototype ) ;
137
138
139
+ const {
140
+ asciiWrite,
141
+ latin1Write,
142
+ utf8Write,
143
+ asciiSlice,
144
+ base64Slice,
145
+ base64urlSlice,
146
+ latin1Slice,
147
+ hexSlice,
148
+ ucs2Slice,
149
+ utf8Slice,
150
+ base64Write,
151
+ base64urlWrite,
152
+ hexWrite,
153
+ ucs2Write,
154
+ } = Buffer . prototype ;
155
+
138
156
const constants = ObjectDefineProperties ( { } , {
139
157
MAX_LENGTH : {
140
158
__proto__ : null ,
@@ -633,44 +651,44 @@ const encodingOps = {
633
651
encoding : 'utf8' ,
634
652
encodingVal : encodingsMap . utf8 ,
635
653
byteLength : byteLengthUtf8 ,
636
- write : ( buf , string , offset , len ) => buf . utf8Write ( string , offset , len ) ,
637
- slice : ( buf , start , end ) => buf . utf8Slice ( start , end ) ,
654
+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( utf8Write , buf , string , offset , len ) ,
655
+ slice : ( buf , start , end ) => FunctionPrototypeCall ( utf8Slice , buf , start , end ) ,
638
656
indexOf : ( buf , val , byteOffset , dir ) =>
639
657
indexOfString ( buf , val , byteOffset , encodingsMap . utf8 , dir ) ,
640
658
} ,
641
659
ucs2 : {
642
660
encoding : 'ucs2' ,
643
661
encodingVal : encodingsMap . utf16le ,
644
662
byteLength : ( string ) => string . length * 2 ,
645
- write : ( buf , string , offset , len ) => buf . ucs2Write ( string , offset , len ) ,
646
- slice : ( buf , start , end ) => buf . ucs2Slice ( start , end ) ,
663
+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
664
+ slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
647
665
indexOf : ( buf , val , byteOffset , dir ) =>
648
666
indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
649
667
} ,
650
668
utf16le : {
651
669
encoding : 'utf16le' ,
652
670
encodingVal : encodingsMap . utf16le ,
653
671
byteLength : ( string ) => string . length * 2 ,
654
- write : ( buf , string , offset , len ) => buf . ucs2Write ( string , offset , len ) ,
655
- slice : ( buf , start , end ) => buf . ucs2Slice ( start , end ) ,
672
+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
673
+ slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
656
674
indexOf : ( buf , val , byteOffset , dir ) =>
657
675
indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
658
676
} ,
659
677
latin1 : {
660
678
encoding : 'latin1' ,
661
679
encodingVal : encodingsMap . latin1 ,
662
680
byteLength : ( string ) => string . length ,
663
- write : ( buf , string , offset , len ) => buf . latin1Write ( string , offset , len ) ,
664
- slice : ( buf , start , end ) => buf . latin1Slice ( start , end ) ,
681
+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( latin1Write , buf , string , offset , len ) ,
682
+ slice : ( buf , start , end ) => FunctionPrototypeCall ( latin1Slice , buf , start , end ) ,
665
683
indexOf : ( buf , val , byteOffset , dir ) =>
666
684
indexOfString ( buf , val , byteOffset , encodingsMap . latin1 , dir ) ,
667
685
} ,
668
686
ascii : {
669
687
encoding : 'ascii' ,
670
688
encodingVal : encodingsMap . ascii ,
671
689
byteLength : ( string ) => string . length ,
672
- write : ( buf , string , offset , len ) => buf . asciiWrite ( string , offset , len ) ,
673
- slice : ( buf , start , end ) => buf . asciiSlice ( start , end ) ,
690
+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( asciiWrite , buf , string , offset , len ) ,
691
+ slice : ( buf , start , end ) => FunctionPrototypeCall ( asciiSlice , buf , start , end ) ,
674
692
indexOf : ( buf , val , byteOffset , dir ) =>
675
693
indexOfBuffer ( buf ,
676
694
fromStringFast ( val , encodingOps . ascii ) ,
@@ -682,8 +700,8 @@ const encodingOps = {
682
700
encoding : 'base64' ,
683
701
encodingVal : encodingsMap . base64 ,
684
702
byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
685
- write : ( buf , string , offset , len ) => buf . base64Write ( string , offset , len ) ,
686
- slice : ( buf , start , end ) => buf . base64Slice ( start , end ) ,
703
+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( base64Write , buf , string , offset , len ) ,
704
+ slice : ( buf , start , end ) => FunctionPrototypeCall ( base64Slice , buf , start , end ) ,
687
705
indexOf : ( buf , val , byteOffset , dir ) =>
688
706
indexOfBuffer ( buf ,
689
707
fromStringFast ( val , encodingOps . base64 ) ,
@@ -696,8 +714,8 @@ const encodingOps = {
696
714
encodingVal : encodingsMap . base64url ,
697
715
byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
698
716
write : ( buf , string , offset , len ) =>
699
- buf . base64urlWrite ( string , offset , len ) ,
700
- slice : ( buf , start , end ) => buf . base64urlSlice ( start , end ) ,
717
+ FunctionPrototypeCall ( base64urlWrite , buf , string , offset , len ) ,
718
+ slice : ( buf , start , end ) => FunctionPrototypeCall ( base64urlSlice , buf , start , end ) ,
701
719
indexOf : ( buf , val , byteOffset , dir ) =>
702
720
indexOfBuffer ( buf ,
703
721
fromStringFast ( val , encodingOps . base64url ) ,
@@ -709,8 +727,8 @@ const encodingOps = {
709
727
encoding : 'hex' ,
710
728
encodingVal : encodingsMap . hex ,
711
729
byteLength : ( string ) => string . length >>> 1 ,
712
- write : ( buf , string , offset , len ) => buf . hexWrite ( string , offset , len ) ,
713
- slice : ( buf , start , end ) => buf . hexSlice ( start , end ) ,
730
+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( hexWrite , buf , string , offset , len ) ,
731
+ slice : ( buf , start , end ) => FunctionPrototypeCall ( hexSlice , buf , start , end ) ,
714
732
indexOf : ( buf , val , byteOffset , dir ) =>
715
733
indexOfBuffer ( buf ,
716
734
fromStringFast ( val , encodingOps . hex ) ,
@@ -835,7 +853,7 @@ Buffer.prototype.copy =
835
853
// to their upper/lower bounds if the value passed is out of range.
836
854
Buffer . prototype . toString = function toString ( encoding , start , end ) {
837
855
if ( arguments . length === 0 ) {
838
- return this . utf8Slice ( 0 , this . length ) ;
856
+ return FunctionPrototypeCall ( utf8Slice , this , 0 , this . length ) ;
839
857
}
840
858
841
859
const len = this . length ;
@@ -856,7 +874,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
856
874
return '' ;
857
875
858
876
if ( encoding === undefined )
859
- return this . utf8Slice ( start , end ) ;
877
+ return FunctionPrototypeCall ( utf8Slice , this , start , end ) ;
860
878
861
879
const ops = getEncodingOps ( encoding ) ;
862
880
if ( ops === undefined )
@@ -887,7 +905,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
887
905
const actualMax = MathMin ( max , this . length ) ;
888
906
const remaining = this . length - max ;
889
907
let str = StringPrototypeTrim ( RegExpPrototypeSymbolReplace (
890
- / ( .{ 2 } ) / g, this . hexSlice ( 0 , actualMax ) , '$1 ' ) ) ;
908
+ / ( .{ 2 } ) / g, FunctionPrototypeCall ( hexSlice , this , 0 , actualMax ) , '$1 ' ) ) ;
891
909
if ( remaining > 0 )
892
910
str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
893
911
// Inspect special properties as well, if possible.
@@ -1026,7 +1044,7 @@ Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
1026
1044
} ;
1027
1045
1028
1046
Buffer . prototype . includes = function includes ( val , byteOffset , encoding ) {
1029
- return this . indexOf ( val , byteOffset , encoding ) !== - 1 ;
1047
+ return bidirectionalIndexOf ( this , val , byteOffset , encoding ) !== - 1 ;
1030
1048
} ;
1031
1049
1032
1050
// Usage:
@@ -1111,7 +1129,7 @@ function _fill(buf, value, offset, end, encoding) {
1111
1129
Buffer . prototype . write = function write ( string , offset , length , encoding ) {
1112
1130
// Buffer#write(string);
1113
1131
if ( offset === undefined ) {
1114
- return this . utf8Write ( string , 0 , this . length ) ;
1132
+ return FunctionPrototypeCall ( utf8Write , this , string , 0 , this . length ) ;
1115
1133
}
1116
1134
// Buffer#write(string, encoding)
1117
1135
if ( length === undefined && typeof offset === 'string' ) {
@@ -1138,9 +1156,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
1138
1156
}
1139
1157
1140
1158
if ( ! encoding || encoding === 'utf8' )
1141
- return this . utf8Write ( string , offset , length ) ;
1159
+ return FunctionPrototypeCall ( utf8Write , this , string , offset , length ) ;
1142
1160
if ( encoding === 'ascii' )
1143
- return this . asciiWrite ( string , offset , length ) ;
1161
+ return FunctionPrototypeCall ( asciiWrite , this , string , offset , length ) ;
1144
1162
1145
1163
const ops = getEncodingOps ( encoding ) ;
1146
1164
if ( ops === undefined )
0 commit comments