MCPcopy Create free account
hub / github.com/Ray-D-Song/lexe / copy

Function copy

modules/llrt_buffer/src/buffer.rs:319–354  ·  view source on GitHub ↗

Prototype Methods

(
    this: This<Object<'js>>,
    ctx: Ctx<'js>,
    target: ObjectBytes<'js>,
    args: Rest<usize>,
)

Source from the content-addressed store, hash-verified

317
318// Prototype Methods
319fn copy<'js>(
320 this: This<Object<'js>>,
321 ctx: Ctx<'js>,
322 target: ObjectBytes<'js>,
323 args: Rest<usize>,
324) -> Result<usize> {
325 let mut args_iter = args.0.into_iter();
326 let target_start = args_iter.next().unwrap_or_default();
327 let source_start = args_iter.next().unwrap_or_default();
328 let source_end = args_iter.next().unwrap_or_else(|| this.0.len());
329
330 let mut copyable_length = 0;
331
332 if source_start >= source_end {
333 return Ok(copyable_length);
334 }
335
336 let source_bytes = ObjectBytes::from(&ctx, this.0.as_inner())?;
337 let source_bytes = source_bytes.as_bytes(&ctx)?;
338
339 if let Some((array_buffer, _, _)) = target.get_array_buffer()? {
340 let raw = array_buffer
341 .as_raw()
342 .ok_or(ERROR_MSG_ARRAY_BUFFER_DETACHED)
343 .or_throw(&ctx)?;
344
345 let target_bytes = unsafe { slice::from_raw_parts_mut(raw.ptr.as_ptr(), raw.len) };
346
347 copyable_length = (source_end - source_start).min(raw.len - target_start);
348
349 target_bytes[target_start..target_start + copyable_length]
350 .copy_from_slice(&source_bytes[source_start..source_start + copyable_length]);
351 }
352
353 Ok(copyable_length)
354}
355
356fn subarray<'js>(
357 this: This<Object<'js>>,

Callers 2

compress_bytecodeFunction · 0.85
loader.rsFile · 0.85

Calls 6

fromFunction · 0.85
or_throwMethod · 0.80
nextMethod · 0.45
lenMethod · 0.45
as_bytesMethod · 0.45
get_array_bufferMethod · 0.45

Tested by

no test coverage detected