(
this: This<Object<'js>>,
ctx: Ctx<'js>,
string: String,
args: Rest<Value<'js>>,
)
| 424 | }); |
| 425 | |
| 426 | let length = (end_index - start_index).max(0) as usize; |
| 427 | let new_offset = (view_offset + start_index).max(0) as usize; |
| 428 | |
| 429 | Buffer::from_array_buffer_offset_length(&ctx, array_buffer, new_offset, length) |
| 430 | } |
| 431 | |
| 432 | fn to_string( |
| 433 | this: This<Object<'_>>, |
| 434 | ctx: Ctx, |
| 435 | encoding: Opt<String>, |
| 436 | start: Opt<i32>, |
| 437 | end: Opt<i32>, |
| 438 | ) -> Result<String> { |
| 439 | let typed_array = TypedArray::<u8>::from_object(this.0)?; |
| 440 | let bytes: &[u8] = typed_array.as_ref(); |
| 441 | |
| 442 | let start = start |
| 443 | .0 |
| 444 | .map(|s| s.max(0) as usize) |
| 445 | .unwrap_or(0) |
| 446 | .min(bytes.len()); |
| 447 | let end = end |
| 448 | .0 |
| 449 | .map(|e| e.max(0) as usize) |
| 450 | .unwrap_or(bytes.len()) |
| 451 | .min(bytes.len()); |
| 452 | let bytes = &bytes[start..end]; |
| 453 | |
| 454 | let encoder = Encoder::from_optional_str(encoding.as_deref()).or_throw(&ctx)?; |
| 455 | encoder.encode_to_string(bytes, true).or_throw(&ctx) |
| 456 | } |
| 457 | |
| 458 | fn write<'js>( |
| 459 | this: This<Object<'js>>, |
| 460 | ctx: Ctx<'js>, |
| 461 | string: String, |
| 462 | args: Rest<Value<'js>>, |
| 463 | ) -> Result<usize> { |
| 464 | let (offset, length, encoding) = get_write_parameters(&ctx, &args, this.0.len())?; |
no test coverage detected