@@ -399,8 +399,8 @@ Buffer.copyBytesFrom = function copyBytesFrom(view, offset, length) {
399399
400400 if ( end <= start ) return new FastBuffer ( ) ;
401401
402- const byteLength = TypedArrayPrototypeGetByteLength ( view ) ;
403- const elementSize = byteLength / viewLength ;
402+ const viewByteLength = TypedArrayPrototypeGetByteLength ( view ) ;
403+ const elementSize = viewByteLength / viewLength ;
404404 const srcByteOffset = TypedArrayPrototypeGetByteOffset ( view ) +
405405 start * elementSize ;
406406 const srcByteLength = ( end - start ) * elementSize ;
@@ -898,17 +898,17 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
898898 return utf8Slice ( this , 0 , this . length ) ;
899899 }
900900
901- const len = this . length ;
901+ const bufferLength = TypedArrayPrototypeGetLength ( this ) ;
902902
903903 if ( start <= 0 )
904904 start = 0 ;
905- else if ( start >= len )
905+ else if ( start >= bufferLength )
906906 return '' ;
907907 else
908908 start = MathTrunc ( start ) || 0 ;
909909
910- if ( end === undefined || end > len )
911- end = len ;
910+ if ( end === undefined || end > bufferLength )
911+ end = bufferLength ;
912912 else
913913 end = MathTrunc ( end ) || 0 ;
914914
@@ -1171,7 +1171,7 @@ function _fill(buf, value, offset, end, encoding) {
11711171}
11721172
11731173Buffer . prototype . write = function write ( string , offset , length , encoding ) {
1174- const bufferLength = this . length ;
1174+ const bufferLength = TypedArrayPrototypeGetLength ( this ) ;
11751175 // Buffer#write(string);
11761176 if ( offset === undefined ) {
11771177 return utf8Write ( this , string , 0 , bufferLength ) ;
@@ -1212,10 +1212,10 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
12121212} ;
12131213
12141214Buffer . prototype . toJSON = function toJSON ( ) {
1215- const len = this . length ;
1216- if ( len > 0 ) {
1217- const data = new Array ( len ) ;
1218- for ( let i = 0 ; i < len ; ++ i )
1215+ const bufferLength = TypedArrayPrototypeGetLength ( this ) ;
1216+ if ( bufferLength > 0 ) {
1217+ const data = new Array ( bufferLength ) ;
1218+ for ( let i = 0 ; i < bufferLength ; ++ i )
12191219 data [ i ] = this [ i ] ;
12201220 return { type : 'Buffer' , data } ;
12211221 }
@@ -1240,7 +1240,7 @@ function adjustOffset(offset, length) {
12401240}
12411241
12421242Buffer . prototype . subarray = function subarray ( start , end ) {
1243- const srcLength = this . length ;
1243+ const srcLength = TypedArrayPrototypeGetLength ( this ) ;
12441244 start = adjustOffset ( start , srcLength ) ;
12451245 end = end !== undefined ? adjustOffset ( end , srcLength ) : srcLength ;
12461246 const newLength = end > start ? end - start : 0 ;
0 commit comments