@@ -61,7 +61,7 @@ const {
61
61
} = process . binding ( 'config' ) ;
62
62
const {
63
63
ERR_BUFFER_OUT_OF_BOUNDS ,
64
- ERR_INDEX_OUT_OF_RANGE ,
64
+ ERR_OUT_OF_RANGE ,
65
65
ERR_INVALID_ARG_TYPE ,
66
66
ERR_INVALID_ARG_VALUE ,
67
67
ERR_INVALID_BUFFER_SIZE ,
@@ -692,50 +692,51 @@ Buffer.prototype[customInspectSymbol] = function inspect() {
692
692
Buffer . prototype . inspect = Buffer . prototype [ customInspectSymbol ] ;
693
693
694
694
Buffer . prototype . compare = function compare ( target ,
695
- start ,
696
- end ,
697
- thisStart ,
698
- thisEnd ) {
695
+ targetStart ,
696
+ targetEnd ,
697
+ sourceStart ,
698
+ sourceEnd ) {
699
699
if ( ! isUint8Array ( target ) ) {
700
700
throw new ERR_INVALID_ARG_TYPE ( 'target' , [ 'Buffer' , 'Uint8Array' ] , target ) ;
701
701
}
702
702
if ( arguments . length === 1 )
703
703
return _compare ( this , target ) ;
704
704
705
- if ( start === undefined )
706
- start = 0 ;
707
- else if ( start < 0 )
708
- throw new ERR_INDEX_OUT_OF_RANGE ( ) ;
705
+ if ( targetStart === undefined )
706
+ targetStart = 0 ;
707
+ else if ( targetStart < 0 )
708
+ throw new ERR_OUT_OF_RANGE ( 'targetStart' , '>= 0' , targetStart ) ;
709
709
else
710
- start >>>= 0 ;
710
+ targetStart >>>= 0 ;
711
711
712
- if ( end === undefined )
713
- end = target . length ;
714
- else if ( end > target . length )
715
- throw new ERR_INDEX_OUT_OF_RANGE ( ) ;
712
+ if ( targetEnd === undefined )
713
+ targetEnd = target . length ;
714
+ else if ( targetEnd > target . length )
715
+ throw new ERR_OUT_OF_RANGE ( 'targetEnd' , `<= ${ target . length } ` , targetEnd ) ;
716
716
else
717
- end >>>= 0 ;
717
+ targetEnd >>>= 0 ;
718
718
719
- if ( thisStart === undefined )
720
- thisStart = 0 ;
721
- else if ( thisStart < 0 )
722
- throw new ERR_INDEX_OUT_OF_RANGE ( ) ;
719
+ if ( sourceStart === undefined )
720
+ sourceStart = 0 ;
721
+ else if ( sourceStart < 0 )
722
+ throw new ERR_OUT_OF_RANGE ( 'sourceStart' , '>= 0' , sourceStart ) ;
723
723
else
724
- thisStart >>>= 0 ;
724
+ sourceStart >>>= 0 ;
725
725
726
- if ( thisEnd === undefined )
727
- thisEnd = this . length ;
728
- else if ( thisEnd > this . length )
729
- throw new ERR_INDEX_OUT_OF_RANGE ( ) ;
726
+ if ( sourceEnd === undefined )
727
+ sourceEnd = this . length ;
728
+ else if ( sourceEnd > this . length )
729
+ throw new ERR_OUT_OF_RANGE ( 'sourceEnd' , `<= ${ this . length } ` , sourceEnd ) ;
730
730
else
731
- thisEnd >>>= 0 ;
731
+ sourceEnd >>>= 0 ;
732
732
733
- if ( thisStart >= thisEnd )
734
- return ( start >= end ? 0 : - 1 ) ;
735
- else if ( start >= end )
733
+ if ( sourceStart >= sourceEnd )
734
+ return ( targetStart >= targetEnd ? 0 : - 1 ) ;
735
+ else if ( targetStart >= targetEnd )
736
736
return 1 ;
737
737
738
- return compareOffset ( this , target , start , thisStart , end , thisEnd ) ;
738
+ return compareOffset ( this , target , targetStart , sourceStart , targetEnd ,
739
+ sourceEnd ) ;
739
740
} ;
740
741
741
742
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
@@ -827,15 +828,15 @@ Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
827
828
// buffer.fill(number[, offset[, end]])
828
829
// buffer.fill(buffer[, offset[, end]])
829
830
// buffer.fill(string[, offset[, end]][, encoding])
830
- Buffer . prototype . fill = function fill ( val , start , end , encoding ) {
831
- return _fill ( this , val , start , end , encoding ) ;
831
+ Buffer . prototype . fill = function fill ( value , offset , end , encoding ) {
832
+ return _fill ( this , value , offset , end , encoding ) ;
832
833
} ;
833
834
834
- function _fill ( buf , val , start , end , encoding ) {
835
- if ( typeof val === 'string' ) {
836
- if ( start === undefined || typeof start === 'string' ) {
837
- encoding = start ;
838
- start = 0 ;
835
+ function _fill ( buf , value , offset , end , encoding ) {
836
+ if ( typeof value === 'string' ) {
837
+ if ( offset === undefined || typeof offset === 'string' ) {
838
+ encoding = offset ;
839
+ offset = 0 ;
839
840
end = buf . length ;
840
841
} else if ( typeof end === 'string' ) {
841
842
encoding = end ;
@@ -848,48 +849,48 @@ function _fill(buf, val, start, end, encoding) {
848
849
throw new ERR_UNKNOWN_ENCODING ( encoding ) ;
849
850
}
850
851
851
- if ( val . length === 0 ) {
852
- // If val === '' default to zero.
853
- val = 0 ;
854
- } else if ( val . length === 1 ) {
855
- // Fast path: If `val ` fits into a single byte, use that numeric value.
852
+ if ( value . length === 0 ) {
853
+ // If value === '' default to zero.
854
+ value = 0 ;
855
+ } else if ( value . length === 1 ) {
856
+ // Fast path: If `value ` fits into a single byte, use that numeric value.
856
857
if ( normalizedEncoding === 'utf8' ) {
857
- const code = val . charCodeAt ( 0 ) ;
858
+ const code = value . charCodeAt ( 0 ) ;
858
859
if ( code < 128 ) {
859
- val = code ;
860
+ value = code ;
860
861
}
861
862
} else if ( normalizedEncoding === 'latin1' ) {
862
- val = val . charCodeAt ( 0 ) ;
863
+ value = value . charCodeAt ( 0 ) ;
863
864
}
864
865
}
865
866
} else {
866
867
encoding = undefined ;
867
868
}
868
869
869
- if ( start === undefined ) {
870
- start = 0 ;
870
+ if ( offset === undefined ) {
871
+ offset = 0 ;
871
872
end = buf . length ;
872
873
} else {
873
874
// Invalid ranges are not set to a default, so can range check early.
875
+ if ( offset < 0 )
876
+ throw new ERR_OUT_OF_RANGE ( 'offset' , '>= 0' , offset ) ;
874
877
if ( end === undefined ) {
875
- if ( start < 0 )
876
- throw new ERR_INDEX_OUT_OF_RANGE ( ) ;
877
878
end = buf . length ;
878
879
} else {
879
- if ( start < 0 || end > buf . length || end < 0 )
880
- throw new ERR_INDEX_OUT_OF_RANGE ( ) ;
880
+ if ( end > buf . length || end < 0 )
881
+ throw new ERR_OUT_OF_RANGE ( 'end' , `>= 0 and <= ${ buf . length } ` , end ) ;
881
882
end = end >>> 0 ;
882
883
}
883
- start = start >>> 0 ;
884
- if ( start >= end )
884
+ offset = offset >>> 0 ;
885
+ if ( offset >= end )
885
886
return buf ;
886
887
}
887
888
888
- const res = bindingFill ( buf , val , start , end , encoding ) ;
889
+ const res = bindingFill ( buf , value , offset , end , encoding ) ;
889
890
if ( res < 0 ) {
890
891
if ( res === - 1 )
891
- throw new ERR_INVALID_ARG_VALUE ( 'value' , val ) ;
892
- throw new ERR_INDEX_OUT_OF_RANGE ( ) ;
892
+ throw new ERR_INVALID_ARG_VALUE ( 'value' , value ) ;
893
+ throw new ERR_BUFFER_OUT_OF_BOUNDS ( ) ;
893
894
}
894
895
895
896
return buf ;
0 commit comments