23
23
24
24
const {
25
25
Array,
26
+ ArrayBufferIsView,
26
27
ArrayIsArray,
27
28
ArrayPrototypeForEach,
28
29
MathFloor,
@@ -202,9 +203,9 @@ function toInteger(n, defaultVal) {
202
203
}
203
204
204
205
function copyImpl ( source , target , targetStart , sourceStart , sourceEnd ) {
205
- if ( ! isUint8Array ( source ) )
206
+ if ( ! ArrayBufferIsView ( source ) )
206
207
throw new ERR_INVALID_ARG_TYPE ( 'source' , [ 'Buffer' , 'Uint8Array' ] , source ) ;
207
- if ( ! isUint8Array ( target ) )
208
+ if ( ! ArrayBufferIsView ( target ) )
208
209
throw new ERR_INVALID_ARG_TYPE ( 'target' , [ 'Buffer' , 'Uint8Array' ] , target ) ;
209
210
210
211
if ( targetStart === undefined ) {
@@ -219,30 +220,30 @@ function copyImpl(source, target, targetStart, sourceStart, sourceEnd) {
219
220
sourceStart = 0 ;
220
221
} else {
221
222
sourceStart = NumberIsInteger ( sourceStart ) ? sourceStart : toInteger ( sourceStart , 0 ) ;
222
- if ( sourceStart < 0 || sourceStart > source . length )
223
- throw new ERR_OUT_OF_RANGE ( 'sourceStart' , `>= 0 && <= ${ source . length } ` , sourceStart ) ;
223
+ if ( sourceStart < 0 || sourceStart > source . byteLength )
224
+ throw new ERR_OUT_OF_RANGE ( 'sourceStart' , `>= 0 && <= ${ source . byteLength } ` , sourceStart ) ;
224
225
}
225
226
226
227
if ( sourceEnd === undefined ) {
227
- sourceEnd = source . length ;
228
+ sourceEnd = source . byteLength ;
228
229
} else {
229
230
sourceEnd = NumberIsInteger ( sourceEnd ) ? sourceEnd : toInteger ( sourceEnd , 0 ) ;
230
231
if ( sourceEnd < 0 )
231
232
throw new ERR_OUT_OF_RANGE ( 'sourceEnd' , '>= 0' , sourceEnd ) ;
232
233
}
233
234
234
- if ( targetStart >= target . length || sourceStart >= sourceEnd )
235
+ if ( targetStart >= target . byteLength || sourceStart >= sourceEnd )
235
236
return 0 ;
236
237
237
238
return _copyActual ( source , target , targetStart , sourceStart , sourceEnd ) ;
238
239
}
239
240
240
241
function _copyActual ( source , target , targetStart , sourceStart , sourceEnd ) {
241
- if ( sourceEnd - sourceStart > target . length - targetStart )
242
- sourceEnd = sourceStart + target . length - targetStart ;
242
+ if ( sourceEnd - sourceStart > target . byteLength - targetStart )
243
+ sourceEnd = sourceStart + target . byteLength - targetStart ;
243
244
244
245
let nb = sourceEnd - sourceStart ;
245
- const sourceLen = source . length - sourceStart ;
246
+ const sourceLen = source . byteLength - sourceStart ;
246
247
if ( nb > sourceLen )
247
248
nb = sourceLen ;
248
249
0 commit comments