2323
2424const {
2525 Array,
26+ ArrayBufferIsView,
2627 ArrayIsArray,
2728 ArrayPrototypeForEach,
2829 MathFloor,
@@ -201,9 +202,9 @@ function toInteger(n, defaultVal) {
201202}
202203
203204function _copy ( source , target , targetStart , sourceStart , sourceEnd ) {
204- if ( ! isUint8Array ( source ) )
205+ if ( ! ArrayBufferIsView ( source ) )
205206 throw new ERR_INVALID_ARG_TYPE ( 'source' , [ 'Buffer' , 'Uint8Array' ] , source ) ;
206- if ( ! isUint8Array ( target ) )
207+ if ( ! ArrayBufferIsView ( target ) )
207208 throw new ERR_INVALID_ARG_TYPE ( 'target' , [ 'Buffer' , 'Uint8Array' ] , target ) ;
208209
209210 if ( targetStart === undefined ) {
@@ -218,34 +219,34 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) {
218219 sourceStart = 0 ;
219220 } else {
220221 sourceStart = NumberIsInteger ( sourceStart ) ? sourceStart : toInteger ( sourceStart , 0 ) ;
221- if ( sourceStart < 0 || sourceStart > source . length )
222- throw new ERR_OUT_OF_RANGE ( 'sourceStart' , `>= 0 && <= ${ source . length } ` , sourceStart ) ;
222+ if ( sourceStart < 0 || sourceStart > source . byteLength )
223+ throw new ERR_OUT_OF_RANGE ( 'sourceStart' , `>= 0 && <= ${ source . byteLength } ` , sourceStart ) ;
223224 }
224225
225226 if ( sourceEnd === undefined ) {
226- sourceEnd = source . length ;
227+ sourceEnd = source . byteLength ;
227228 } else {
228229 sourceEnd = NumberIsInteger ( sourceEnd ) ? sourceEnd : toInteger ( sourceEnd , 0 ) ;
229230 if ( sourceEnd < 0 )
230231 throw new ERR_OUT_OF_RANGE ( 'sourceEnd' , '>= 0' , sourceEnd ) ;
231232 }
232233
233- if ( targetStart >= target . length || sourceStart >= sourceEnd )
234+ if ( targetStart >= target . byteLength || sourceStart >= sourceEnd )
234235 return 0 ;
235236
236237 return _copyActual ( source , target , targetStart , sourceStart , sourceEnd ) ;
237238}
238239
239240function _copyActual ( source , target , targetStart , sourceStart , sourceEnd ) {
240- if ( sourceEnd - sourceStart > target . length - targetStart )
241- sourceEnd = sourceStart + target . length - targetStart ;
241+ if ( sourceEnd - sourceStart > target . byteLength - targetStart )
242+ sourceEnd = sourceStart + target . byteLength - targetStart ;
242243
243244 let nb = sourceEnd - sourceStart ;
244- const sourceLen = source . length - sourceStart ;
245+ const sourceLen = source . byteLength - sourceStart ;
245246 if ( nb > sourceLen )
246247 nb = sourceLen ;
247248
248- if ( sourceStart !== 0 || sourceEnd < source . length )
249+ if ( sourceStart !== 0 || sourceEnd < source . byteLength )
249250 source = new Uint8Array ( source . buffer , source . byteOffset + sourceStart , nb ) ;
250251
251252 TypedArrayPrototypeSet ( target , source , targetStart ) ;
0 commit comments