@@ -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 ,
@@ -634,44 +652,44 @@ const encodingOps = {
634652 encoding : 'utf8' ,
635653 encodingVal : encodingsMap . utf8 ,
636654 byteLength : byteLengthUtf8 ,
637- write : ( buf , string , offset , len ) => buf . utf8Write ( string , offset , len ) ,
638- slice : ( buf , start , end ) => buf . utf8Slice ( start , end ) ,
655+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( utf8Write , buf , string , offset , len ) ,
656+ slice : ( buf , start , end ) => FunctionPrototypeCall ( utf8Slice , buf , start , end ) ,
639657 indexOf : ( buf , val , byteOffset , dir ) =>
640658 indexOfString ( buf , val , byteOffset , encodingsMap . utf8 , dir ) ,
641659 } ,
642660 ucs2 : {
643661 encoding : 'ucs2' ,
644662 encodingVal : encodingsMap . utf16le ,
645663 byteLength : ( string ) => string . length * 2 ,
646- write : ( buf , string , offset , len ) => buf . ucs2Write ( string , offset , len ) ,
647- slice : ( buf , start , end ) => buf . ucs2Slice ( start , end ) ,
664+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
665+ slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
648666 indexOf : ( buf , val , byteOffset , dir ) =>
649667 indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
650668 } ,
651669 utf16le : {
652670 encoding : 'utf16le' ,
653671 encodingVal : encodingsMap . utf16le ,
654672 byteLength : ( string ) => string . length * 2 ,
655- write : ( buf , string , offset , len ) => buf . ucs2Write ( string , offset , len ) ,
656- slice : ( buf , start , end ) => buf . ucs2Slice ( start , end ) ,
673+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
674+ slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
657675 indexOf : ( buf , val , byteOffset , dir ) =>
658676 indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
659677 } ,
660678 latin1 : {
661679 encoding : 'latin1' ,
662680 encodingVal : encodingsMap . latin1 ,
663681 byteLength : ( string ) => string . length ,
664- write : ( buf , string , offset , len ) => buf . latin1Write ( string , offset , len ) ,
665- slice : ( buf , start , end ) => buf . latin1Slice ( start , end ) ,
682+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( latin1Write , buf , string , offset , len ) ,
683+ slice : ( buf , start , end ) => FunctionPrototypeCall ( latin1Slice , buf , start , end ) ,
666684 indexOf : ( buf , val , byteOffset , dir ) =>
667685 indexOfString ( buf , val , byteOffset , encodingsMap . latin1 , dir ) ,
668686 } ,
669687 ascii : {
670688 encoding : 'ascii' ,
671689 encodingVal : encodingsMap . ascii ,
672690 byteLength : ( string ) => string . length ,
673- write : ( buf , string , offset , len ) => buf . asciiWrite ( string , offset , len ) ,
674- slice : ( buf , start , end ) => buf . asciiSlice ( start , end ) ,
691+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( asciiWrite , buf , string , offset , len ) ,
692+ slice : ( buf , start , end ) => FunctionPrototypeCall ( asciiSlice , buf , start , end ) ,
675693 indexOf : ( buf , val , byteOffset , dir ) =>
676694 indexOfBuffer ( buf ,
677695 fromStringFast ( val , encodingOps . ascii ) ,
@@ -683,8 +701,8 @@ const encodingOps = {
683701 encoding : 'base64' ,
684702 encodingVal : encodingsMap . base64 ,
685703 byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
686- write : ( buf , string , offset , len ) => buf . base64Write ( string , offset , len ) ,
687- slice : ( buf , start , end ) => buf . base64Slice ( start , end ) ,
704+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( base64Write , buf , string , offset , len ) ,
705+ slice : ( buf , start , end ) => FunctionPrototypeCall ( base64Slice , buf , start , end ) ,
688706 indexOf : ( buf , val , byteOffset , dir ) =>
689707 indexOfBuffer ( buf ,
690708 fromStringFast ( val , encodingOps . base64 ) ,
@@ -697,8 +715,8 @@ const encodingOps = {
697715 encodingVal : encodingsMap . base64url ,
698716 byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
699717 write : ( buf , string , offset , len ) =>
700- buf . base64urlWrite ( string , offset , len ) ,
701- slice : ( buf , start , end ) => buf . base64urlSlice ( start , end ) ,
718+ FunctionPrototypeCall ( base64urlWrite , buf , string , offset , len ) ,
719+ slice : ( buf , start , end ) => FunctionPrototypeCall ( base64urlSlice , buf , start , end ) ,
702720 indexOf : ( buf , val , byteOffset , dir ) =>
703721 indexOfBuffer ( buf ,
704722 fromStringFast ( val , encodingOps . base64url ) ,
@@ -710,8 +728,8 @@ const encodingOps = {
710728 encoding : 'hex' ,
711729 encodingVal : encodingsMap . hex ,
712730 byteLength : ( string ) => string . length >>> 1 ,
713- write : ( buf , string , offset , len ) => buf . hexWrite ( string , offset , len ) ,
714- slice : ( buf , start , end ) => buf . hexSlice ( start , end ) ,
731+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( hexWrite , buf , string , offset , len ) ,
732+ slice : ( buf , start , end ) => FunctionPrototypeCall ( hexSlice , buf , start , end ) ,
715733 indexOf : ( buf , val , byteOffset , dir ) =>
716734 indexOfBuffer ( buf ,
717735 fromStringFast ( val , encodingOps . hex ) ,
@@ -836,7 +854,7 @@ Buffer.prototype.copy =
836854// to their upper/lower bounds if the value passed is out of range.
837855Buffer . prototype . toString = function toString ( encoding , start , end ) {
838856 if ( arguments . length === 0 ) {
839- return this . utf8Slice ( 0 , this . length ) ;
857+ return FunctionPrototypeCall ( utf8Slice , this , 0 , this . length ) ;
840858 }
841859
842860 const len = this . length ;
@@ -857,7 +875,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
857875 return '' ;
858876
859877 if ( encoding === undefined )
860- return this . utf8Slice ( start , end ) ;
878+ return FunctionPrototypeCall ( utf8Slice , this , start , end ) ;
861879
862880 const ops = getEncodingOps ( encoding ) ;
863881 if ( ops === undefined )
@@ -888,7 +906,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
888906 const actualMax = MathMin ( max , this . length ) ;
889907 const remaining = this . length - max ;
890908 let str = StringPrototypeTrim ( RegExpPrototypeSymbolReplace (
891- / ( .{ 2 } ) / g, this . hexSlice ( 0 , actualMax ) , '$1 ' ) ) ;
909+ / ( .{ 2 } ) / g, FunctionPrototypeCall ( hexSlice , this , 0 , actualMax ) , '$1 ' ) ) ;
892910 if ( remaining > 0 )
893911 str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
894912 // Inspect special properties as well, if possible.
@@ -1027,7 +1045,7 @@ Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
10271045} ;
10281046
10291047Buffer . prototype . includes = function includes ( val , byteOffset , encoding ) {
1030- return this . indexOf ( val , byteOffset , encoding ) !== - 1 ;
1048+ return bidirectionalIndexOf ( this , val , byteOffset , encoding , true ) !== - 1 ;
10311049} ;
10321050
10331051// Usage:
@@ -1112,7 +1130,7 @@ function _fill(buf, value, offset, end, encoding) {
11121130Buffer . prototype . write = function write ( string , offset , length , encoding ) {
11131131 // Buffer#write(string);
11141132 if ( offset === undefined ) {
1115- return this . utf8Write ( string , 0 , this . length ) ;
1133+ return FunctionPrototypeCall ( utf8Write , this , string , 0 , this . length ) ;
11161134 }
11171135 // Buffer#write(string, encoding)
11181136 if ( length === undefined && typeof offset === 'string' ) {
@@ -1139,9 +1157,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
11391157 }
11401158
11411159 if ( ! encoding || encoding === 'utf8' )
1142- return this . utf8Write ( string , offset , length ) ;
1160+ return FunctionPrototypeCall ( utf8Write , this , string , offset , length ) ;
11431161 if ( encoding === 'ascii' )
1144- return this . asciiWrite ( string , offset , length ) ;
1162+ return FunctionPrototypeCall ( asciiWrite , this , string , offset , length ) ;
11451163
11461164 const ops = getEncodingOps ( encoding ) ;
11471165 if ( ops === undefined )
0 commit comments