@@ -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 ,
@@ -621,44 +639,44 @@ const encodingOps = {
621639 encoding : 'utf8' ,
622640 encodingVal : encodingsMap . utf8 ,
623641 byteLength : byteLengthUtf8 ,
624- write : ( buf , string , offset , len ) => buf . utf8Write ( string , offset , len ) ,
625- slice : ( buf , start , end ) => buf . utf8Slice ( start , end ) ,
642+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( utf8Write , buf , string , offset , len ) ,
643+ slice : ( buf , start , end ) => FunctionPrototypeCall ( utf8Slice , buf , start , end ) ,
626644 indexOf : ( buf , val , byteOffset , dir ) =>
627645 indexOfString ( buf , val , byteOffset , encodingsMap . utf8 , dir ) ,
628646 } ,
629647 ucs2 : {
630648 encoding : 'ucs2' ,
631649 encodingVal : encodingsMap . utf16le ,
632650 byteLength : ( string ) => string . length * 2 ,
633- write : ( buf , string , offset , len ) => buf . ucs2Write ( string , offset , len ) ,
634- slice : ( buf , start , end ) => buf . ucs2Slice ( start , end ) ,
651+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
652+ slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
635653 indexOf : ( buf , val , byteOffset , dir ) =>
636654 indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
637655 } ,
638656 utf16le : {
639657 encoding : 'utf16le' ,
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 latin1 : {
648666 encoding : 'latin1' ,
649667 encodingVal : encodingsMap . latin1 ,
650668 byteLength : ( string ) => string . length ,
651- write : ( buf , string , offset , len ) => buf . latin1Write ( string , offset , len ) ,
652- slice : ( buf , start , end ) => buf . latin1Slice ( start , end ) ,
669+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( latin1Write , buf , string , offset , len ) ,
670+ slice : ( buf , start , end ) => FunctionPrototypeCall ( latin1Slice , buf , start , end ) ,
653671 indexOf : ( buf , val , byteOffset , dir ) =>
654672 indexOfString ( buf , val , byteOffset , encodingsMap . latin1 , dir ) ,
655673 } ,
656674 ascii : {
657675 encoding : 'ascii' ,
658676 encodingVal : encodingsMap . ascii ,
659677 byteLength : ( string ) => string . length ,
660- write : ( buf , string , offset , len ) => buf . asciiWrite ( string , offset , len ) ,
661- slice : ( buf , start , end ) => buf . asciiSlice ( start , end ) ,
678+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( asciiWrite , buf , string , offset , len ) ,
679+ slice : ( buf , start , end ) => FunctionPrototypeCall ( asciiSlice , buf , start , end ) ,
662680 indexOf : ( buf , val , byteOffset , dir ) =>
663681 indexOfBuffer ( buf ,
664682 fromStringFast ( val , encodingOps . ascii ) ,
@@ -670,8 +688,8 @@ const encodingOps = {
670688 encoding : 'base64' ,
671689 encodingVal : encodingsMap . base64 ,
672690 byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
673- write : ( buf , string , offset , len ) => buf . base64Write ( string , offset , len ) ,
674- slice : ( buf , start , end ) => buf . base64Slice ( start , end ) ,
691+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( base64Write , buf , string , offset , len ) ,
692+ slice : ( buf , start , end ) => FunctionPrototypeCall ( base64Slice , buf , start , end ) ,
675693 indexOf : ( buf , val , byteOffset , dir ) =>
676694 indexOfBuffer ( buf ,
677695 fromStringFast ( val , encodingOps . base64 ) ,
@@ -684,8 +702,8 @@ const encodingOps = {
684702 encodingVal : encodingsMap . base64url ,
685703 byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
686704 write : ( buf , string , offset , len ) =>
687- buf . base64urlWrite ( string , offset , len ) ,
688- slice : ( buf , start , end ) => buf . base64urlSlice ( start , end ) ,
705+ FunctionPrototypeCall ( base64urlWrite , buf , string , offset , len ) ,
706+ slice : ( buf , start , end ) => FunctionPrototypeCall ( base64urlSlice , buf , start , end ) ,
689707 indexOf : ( buf , val , byteOffset , dir ) =>
690708 indexOfBuffer ( buf ,
691709 fromStringFast ( val , encodingOps . base64url ) ,
@@ -697,8 +715,8 @@ const encodingOps = {
697715 encoding : 'hex' ,
698716 encodingVal : encodingsMap . hex ,
699717 byteLength : ( string ) => string . length >>> 1 ,
700- write : ( buf , string , offset , len ) => buf . hexWrite ( string , offset , len ) ,
701- slice : ( buf , start , end ) => buf . hexSlice ( start , end ) ,
718+ write : ( buf , string , offset , len ) => FunctionPrototypeCall ( hexWrite , buf , string , offset , len ) ,
719+ slice : ( buf , start , end ) => FunctionPrototypeCall ( hexSlice , buf , start , end ) ,
702720 indexOf : ( buf , val , byteOffset , dir ) =>
703721 indexOfBuffer ( buf ,
704722 fromStringFast ( val , encodingOps . hex ) ,
@@ -823,7 +841,7 @@ Buffer.prototype.copy =
823841// to their upper/lower bounds if the value passed is out of range.
824842Buffer . prototype . toString = function toString ( encoding , start , end ) {
825843 if ( arguments . length === 0 ) {
826- return this . utf8Slice ( 0 , this . length ) ;
844+ return FunctionPrototypeCall ( utf8Slice , this , 0 , this . length ) ;
827845 }
828846
829847 const len = this . length ;
@@ -844,7 +862,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
844862 return '' ;
845863
846864 if ( encoding === undefined )
847- return this . utf8Slice ( start , end ) ;
865+ return FunctionPrototypeCall ( utf8Slice , this , start , end ) ;
848866
849867 const ops = getEncodingOps ( encoding ) ;
850868 if ( ops === undefined )
@@ -875,7 +893,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
875893 const actualMax = MathMin ( max , this . length ) ;
876894 const remaining = this . length - max ;
877895 let str = StringPrototypeTrim ( RegExpPrototypeSymbolReplace (
878- / ( .{ 2 } ) / g, this . hexSlice ( 0 , actualMax ) , '$1 ' ) ) ;
896+ / ( .{ 2 } ) / g, FunctionPrototypeCall ( hexSlice , this , 0 , actualMax ) , '$1 ' ) ) ;
879897 if ( remaining > 0 )
880898 str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
881899 // Inspect special properties as well, if possible.
@@ -1014,7 +1032,7 @@ Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
10141032} ;
10151033
10161034Buffer . prototype . includes = function includes ( val , byteOffset , encoding ) {
1017- return this . indexOf ( val , byteOffset , encoding ) !== - 1 ;
1035+ return bidirectionalIndexOf ( this , val , byteOffset , encoding , true ) !== - 1 ;
10181036} ;
10191037
10201038// Usage:
@@ -1099,7 +1117,7 @@ function _fill(buf, value, offset, end, encoding) {
10991117Buffer . prototype . write = function write ( string , offset , length , encoding ) {
11001118 // Buffer#write(string);
11011119 if ( offset === undefined ) {
1102- return this . utf8Write ( string , 0 , this . length ) ;
1120+ return FunctionPrototypeCall ( utf8Write , this , string , 0 , this . length ) ;
11031121 }
11041122 // Buffer#write(string, encoding)
11051123 if ( length === undefined && typeof offset === 'string' ) {
@@ -1126,9 +1144,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
11261144 }
11271145
11281146 if ( ! encoding || encoding === 'utf8' )
1129- return this . utf8Write ( string , offset , length ) ;
1147+ return FunctionPrototypeCall ( utf8Write , this , string , offset , length ) ;
11301148 if ( encoding === 'ascii' )
1131- return this . asciiWrite ( string , offset , length ) ;
1149+ return FunctionPrototypeCall ( asciiWrite , this , string , offset , length ) ;
11321150
11331151 const ops = getEncodingOps ( encoding ) ;
11341152 if ( ops === undefined )
0 commit comments