@@ -204,42 +204,6 @@ function toInteger(n, defaultVal) {
204204 return defaultVal ;
205205}
206206
207- function copyImpl ( source , target , targetStart , sourceStart , sourceEnd ) {
208- if ( ! ArrayBufferIsView ( source ) )
209- throw new ERR_INVALID_ARG_TYPE ( 'source' , [ 'Buffer' , 'Uint8Array' ] , source ) ;
210- if ( ! ArrayBufferIsView ( target ) )
211- throw new ERR_INVALID_ARG_TYPE ( 'target' , [ 'Buffer' , 'Uint8Array' ] , target ) ;
212-
213- if ( targetStart === undefined ) {
214- targetStart = 0 ;
215- } else {
216- targetStart = NumberIsInteger ( targetStart ) ? targetStart : toInteger ( targetStart , 0 ) ;
217- if ( targetStart < 0 )
218- throw new ERR_OUT_OF_RANGE ( 'targetStart' , '>= 0' , targetStart ) ;
219- }
220-
221- if ( sourceStart === undefined ) {
222- sourceStart = 0 ;
223- } else {
224- sourceStart = NumberIsInteger ( sourceStart ) ? sourceStart : toInteger ( sourceStart , 0 ) ;
225- if ( sourceStart < 0 || sourceStart > source . byteLength )
226- throw new ERR_OUT_OF_RANGE ( 'sourceStart' , `>= 0 && <= ${ source . byteLength } ` , sourceStart ) ;
227- }
228-
229- if ( sourceEnd === undefined ) {
230- sourceEnd = source . byteLength ;
231- } else {
232- sourceEnd = NumberIsInteger ( sourceEnd ) ? sourceEnd : toInteger ( sourceEnd , 0 ) ;
233- if ( sourceEnd < 0 )
234- throw new ERR_OUT_OF_RANGE ( 'sourceEnd' , '>= 0' , sourceEnd ) ;
235- }
236-
237- if ( targetStart >= target . byteLength || sourceStart >= sourceEnd )
238- return 0 ;
239-
240- return _copyActual ( source , target , targetStart , sourceStart , sourceEnd ) ;
241- }
242-
243207function _copyActual ( source , target , targetStart , sourceStart , sourceEnd ) {
244208 if ( sourceEnd - sourceStart > target . byteLength - targetStart )
245209 sourceEnd = sourceStart + target . byteLength - targetStart ;
@@ -821,10 +785,41 @@ ObjectDefineProperty(Buffer.prototype, 'offset', {
821785 } ,
822786} ) ;
823787
824- Buffer . prototype . copy =
825- function copy ( target , targetStart , sourceStart , sourceEnd ) {
826- return copyImpl ( this , target , targetStart , sourceStart , sourceEnd ) ;
827- } ;
788+ Buffer . prototype . copy = function copy ( target , targetStart , sourceStart , sourceEnd ) {
789+ if ( ! ArrayBufferIsView ( this ) )
790+ throw new ERR_INVALID_ARG_TYPE ( 'source' , [ 'Buffer' , 'Uint8Array' ] , this ) ;
791+ if ( ! ArrayBufferIsView ( target ) )
792+ throw new ERR_INVALID_ARG_TYPE ( 'target' , [ 'Buffer' , 'Uint8Array' ] , target ) ;
793+
794+ if ( targetStart === undefined ) {
795+ targetStart = 0 ;
796+ } else {
797+ targetStart = NumberIsInteger ( targetStart ) ? targetStart : toInteger ( targetStart , 0 ) ;
798+ if ( targetStart < 0 )
799+ throw new ERR_OUT_OF_RANGE ( 'targetStart' , '>= 0' , targetStart ) ;
800+ }
801+
802+ if ( sourceStart === undefined ) {
803+ sourceStart = 0 ;
804+ } else {
805+ sourceStart = NumberIsInteger ( sourceStart ) ? sourceStart : toInteger ( sourceStart , 0 ) ;
806+ if ( sourceStart < 0 || sourceStart > this . byteLength )
807+ throw new ERR_OUT_OF_RANGE ( 'sourceStart' , `>= 0 && <= ${ this . byteLength } ` , sourceStart ) ;
808+ }
809+
810+ if ( sourceEnd === undefined ) {
811+ sourceEnd = this . byteLength ;
812+ } else {
813+ sourceEnd = NumberIsInteger ( sourceEnd ) ? sourceEnd : toInteger ( sourceEnd , 0 ) ;
814+ if ( sourceEnd < 0 )
815+ throw new ERR_OUT_OF_RANGE ( 'sourceEnd' , '>= 0' , sourceEnd ) ;
816+ }
817+
818+ if ( targetStart >= target . byteLength || sourceStart >= sourceEnd )
819+ return 0 ;
820+
821+ return _copyActual ( this , target , targetStart , sourceStart , sourceEnd ) ;
822+ } ;
828823
829824// No need to verify that "buf.length <= MAX_UINT32" since it's a read-only
830825// property of a typed array.
0 commit comments