| 364 | let source_bytes = ObjectBytes::from(&ctx, this.0.as_inner())?; |
| 365 | let source_bytes = source_bytes.as_bytes(&ctx)?; |
| 366 | |
| 367 | if source_start > source_bytes.len() { |
| 368 | return Err(Exception::throw_range( |
| 369 | &ctx, |
| 370 | "The value of \"sourceStart\" is out of range", |
| 371 | )); |
| 372 | } |
| 373 | |
| 374 | // sourceEnd is clamped (not an error), unlike sourceStart above. |
| 375 | let source_end = source_end.min(source_bytes.len()); |
| 376 | |
| 377 | let mut copyable_length = 0; |
| 378 | |
| 379 | if source_start >= source_end { |
| 380 | return Ok(copyable_length); |
| 381 | } |
| 382 | |
| 383 | if let Some((array_buffer, target_byte_length, target_byte_offset)) = |
| 384 | target.get_array_buffer()? |
| 385 | { |
| 386 | let target_bytes = |
| 387 | resolve_view_bytes(&ctx, array_buffer, target_byte_length, target_byte_offset)?; |
| 388 | |
| 389 | if target_start <= target_bytes.len() { |
| 390 | copyable_length = (source_end - source_start).min(target_bytes.len() - target_start); |
| 391 | |
| 392 | target_bytes[target_start..target_start + copyable_length] |
| 393 | .copy_from_slice(&source_bytes[source_start..source_start + copyable_length]); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | Ok(copyable_length) |
| 398 | } |
| 399 | |
| 400 | fn subarray<'js>( |
| 401 | this: This<Object<'js>>, |