@@ -26,6 +26,7 @@ const {
2626 ArrayBufferIsView,
2727 ArrayIsArray,
2828 ArrayPrototypeForEach,
29+ FunctionPrototypeCall,
2930 MathFloor,
3031 MathMin,
3132 MathTrunc,
@@ -133,6 +134,23 @@ FastBuffer.prototype.constructor = Buffer;
133134Buffer . prototype = FastBuffer . prototype ;
134135addBufferPrototypeMethods ( Buffer . prototype ) ;
135136
137+ const {
138+ asciiWrite,
139+ latin1Write,
140+ utf8Write,
141+ asciiSlice,
142+ base64Slice,
143+ base64urlSlice,
144+ latin1Slice,
145+ hexSlice,
146+ ucs2Slice,
147+ utf8Slice,
148+ base64Write,
149+ base64urlWrite,
150+ hexWrite,
151+ ucs2Write,
152+ } = Buffer . prototype ;
153+
136154const constants = ObjectDefineProperties ( { } , {
137155 MAX_LENGTH : {
138156 __proto__ : null ,
@@ -630,44 +648,44 @@ const encodingOps = {
630648 encoding : 'utf8' ,
631649 encodingVal : encodingsMap . utf8 ,
632650 byteLength : byteLengthUtf8 ,
633- write : ( buf , string , offset , len ) => buf . utf8Write ( string , offset , len ) ,
634- slice : ( buf , start , end ) => buf . utf8Slice ( start , end ) ,
651+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( utf8Write , buf , string , offset , len ) ,
652+ slice : ( buf , start , end ) => FunctionPrototypeCall ( utf8Slice , buf , start , end ) ,
635653 indexOf : ( buf , val , byteOffset , dir ) =>
636654 indexOfString ( buf , val , byteOffset , encodingsMap . utf8 , dir ) ,
637655 } ,
638656 ucs2 : {
639657 encoding : 'ucs2' ,
640658 encodingVal : encodingsMap . utf16le ,
641659 byteLength : ( string ) => string . length * 2 ,
642- write : ( buf , string , offset , len ) => buf . ucs2Write ( string , offset , len ) ,
643- slice : ( buf , start , end ) => buf . ucs2Slice ( start , end ) ,
660+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
661+ slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
644662 indexOf : ( buf , val , byteOffset , dir ) =>
645663 indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
646664 } ,
647665 utf16le : {
648666 encoding : 'utf16le' ,
649667 encodingVal : encodingsMap . utf16le ,
650668 byteLength : ( string ) => string . length * 2 ,
651- write : ( buf , string , offset , len ) => buf . ucs2Write ( string , offset , len ) ,
652- slice : ( buf , start , end ) => buf . ucs2Slice ( start , end ) ,
669+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
670+ slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
653671 indexOf : ( buf , val , byteOffset , dir ) =>
654672 indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
655673 } ,
656674 latin1 : {
657675 encoding : 'latin1' ,
658676 encodingVal : encodingsMap . latin1 ,
659677 byteLength : ( string ) => string . length ,
660- write : ( buf , string , offset , len ) => buf . latin1Write ( string , offset , len ) ,
661- slice : ( buf , start , end ) => buf . latin1Slice ( start , end ) ,
678+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( latin1Write , buf , string , offset , len ) ,
679+ slice : ( buf , start , end ) => FunctionPrototypeCall ( latin1Slice , buf , start , end ) ,
662680 indexOf : ( buf , val , byteOffset , dir ) =>
663681 indexOfString ( buf , val , byteOffset , encodingsMap . latin1 , dir ) ,
664682 } ,
665683 ascii : {
666684 encoding : 'ascii' ,
667685 encodingVal : encodingsMap . ascii ,
668686 byteLength : ( string ) => string . length ,
669- write : ( buf , string , offset , len ) => buf . asciiWrite ( string , offset , len ) ,
670- slice : ( buf , start , end ) => buf . asciiSlice ( start , end ) ,
687+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( asciiWrite , buf , string , offset , len ) ,
688+ slice : ( buf , start , end ) => FunctionPrototypeCall ( asciiSlice , buf , start , end ) ,
671689 indexOf : ( buf , val , byteOffset , dir ) =>
672690 indexOfBuffer ( buf ,
673691 fromStringFast ( val , encodingOps . ascii ) ,
@@ -679,8 +697,8 @@ const encodingOps = {
679697 encoding : 'base64' ,
680698 encodingVal : encodingsMap . base64 ,
681699 byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
682- write : ( buf , string , offset , len ) => buf . base64Write ( string , offset , len ) ,
683- slice : ( buf , start , end ) => buf . base64Slice ( start , end ) ,
700+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( base64Write , buf , string , offset , len ) ,
701+ slice : ( buf , start , end ) => FunctionPrototypeCall ( base64Slice , buf , start , end ) ,
684702 indexOf : ( buf , val , byteOffset , dir ) =>
685703 indexOfBuffer ( buf ,
686704 fromStringFast ( val , encodingOps . base64 ) ,
@@ -693,8 +711,8 @@ const encodingOps = {
693711 encodingVal : encodingsMap . base64url ,
694712 byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
695713 write : ( buf , string , offset , len ) =>
696- buf . base64urlWrite ( string , offset , len ) ,
697- slice : ( buf , start , end ) => buf . base64urlSlice ( start , end ) ,
714+ FunctionPrototypeCall ( base64urlWrite , buf , string , offset , len ) ,
715+ slice : ( buf , start , end ) => FunctionPrototypeCall ( base64urlSlice , buf , start , end ) ,
698716 indexOf : ( buf , val , byteOffset , dir ) =>
699717 indexOfBuffer ( buf ,
700718 fromStringFast ( val , encodingOps . base64url ) ,
@@ -706,8 +724,8 @@ const encodingOps = {
706724 encoding : 'hex' ,
707725 encodingVal : encodingsMap . hex ,
708726 byteLength : ( string ) => string . length >>> 1 ,
709- write : ( buf , string , offset , len ) => buf . hexWrite ( string , offset , len ) ,
710- slice : ( buf , start , end ) => buf . hexSlice ( start , end ) ,
727+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( hexWrite , buf , string , offset , len ) ,
728+ slice : ( buf , start , end ) => FunctionPrototypeCall ( hexSlice , buf , start , end ) ,
711729 indexOf : ( buf , val , byteOffset , dir ) =>
712730 indexOfBuffer ( buf ,
713731 fromStringFast ( val , encodingOps . hex ) ,
@@ -832,7 +850,7 @@ Buffer.prototype.copy =
832850// to their upper/lower bounds if the value passed is out of range.
833851Buffer . prototype . toString = function toString ( encoding , start , end ) {
834852 if ( arguments . length === 0 ) {
835- return this . utf8Slice ( 0 , this . length ) ;
853+ return FunctionPrototypeCall ( utf8Slice , this , 0 , this . length ) ;
836854 }
837855
838856 const len = this . length ;
@@ -853,7 +871,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
853871 return '' ;
854872
855873 if ( encoding === undefined )
856- return this . utf8Slice ( start , end ) ;
874+ return FunctionPrototypeCall ( utf8Slice , this , start , end ) ;
857875
858876 const ops = getEncodingOps ( encoding ) ;
859877 if ( ops === undefined )
@@ -884,7 +902,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
884902 const actualMax = MathMin ( max , this . length ) ;
885903 const remaining = this . length - max ;
886904 let str = StringPrototypeTrim ( RegExpPrototypeSymbolReplace (
887- / ( .{ 2 } ) / g, this . hexSlice ( 0 , actualMax ) , '$1 ' ) ) ;
905+ / ( .{ 2 } ) / g, FunctionPrototypeCall ( hexSlice , this , 0 , actualMax ) , '$1 ' ) ) ;
888906 if ( remaining > 0 )
889907 str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
890908 // Inspect special properties as well, if possible.
@@ -1023,7 +1041,7 @@ Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
10231041} ;
10241042
10251043Buffer . prototype . includes = function includes ( val , byteOffset , encoding ) {
1026- return this . indexOf ( val , byteOffset , encoding ) !== - 1 ;
1044+ return bidirectionalIndexOf ( this , val , byteOffset , encoding , true ) !== - 1 ;
10271045} ;
10281046
10291047// Usage:
@@ -1108,7 +1126,7 @@ function _fill(buf, value, offset, end, encoding) {
11081126Buffer . prototype . write = function write ( string , offset , length , encoding ) {
11091127 // Buffer#write(string);
11101128 if ( offset === undefined ) {
1111- return this . utf8Write ( string , 0 , this . length ) ;
1129+ return FunctionPrototypeCall ( utf8Write , this , string , 0 , this . length ) ;
11121130 }
11131131 // Buffer#write(string, encoding)
11141132 if ( length === undefined && typeof offset === 'string' ) {
@@ -1135,9 +1153,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
11351153 }
11361154
11371155 if ( ! encoding || encoding === 'utf8' )
1138- return this . utf8Write ( string , offset , length ) ;
1156+ return FunctionPrototypeCall ( utf8Write , this , string , offset , length ) ;
11391157 if ( encoding === 'ascii' )
1140- return this . asciiWrite ( string , offset , length ) ;
1158+ return FunctionPrototypeCall ( asciiWrite , this , string , offset , length ) ;
11411159
11421160 const ops = getEncodingOps ( encoding ) ;
11431161 if ( ops === undefined )
0 commit comments