MCPcopy Create free account
hub / github.com/awslabs/llrt / copy

Function copy

modules/llrt_buffer/src/buffer.rs:329–364  ·  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

327 &ctx,
328 "value must be typed DataView, Buffer, ArrayBuffer, Uint8Array or interpretable as string",
329 ))
330}
331
332fn is_buffer<'js>(ctx: Ctx<'js>, value: Value<'js>) -> Result<bool> {
333 if let Some(object) = value.as_object() {
334 let constructor = BufferPrimordials::get(&ctx)?;
335 return Ok(object.is_instance_of(&constructor.constructor));
336 }
337
338 Ok(false)
339}
340
341fn is_encoding(value: Value) -> Result<bool> {
342 if let Some(js_string) = value.as_string() {
343 let std_string = js_string.to_string()?;
344 return Ok(Encoder::from_str(std_string.as_str()).is_ok());
345 }
346
347 Ok(false)
348}
349
350// Prototype Methods
351fn copy<'js>(
352 this: This<Object<'js>>,
353 ctx: Ctx<'js>,
354 target: ObjectBytes<'js>,
355 args: Rest<usize>,
356) -> Result<usize> {
357 let mut args_iter = args.0.into_iter();
358 let target_start = args_iter.next().unwrap_or_default();
359 let source_start = args_iter.next().unwrap_or_default();
360 let source_end = args_iter.next().unwrap_or_else(|| this.0.len());
361
362 let source_bytes = ObjectBytes::from(&ctx, this.0.as_inner())?;
363 let source_bytes = source_bytes.as_bytes(&ctx)?;
364
365 if source_start > source_bytes.len() {
366 return Err(Exception::throw_range(
367 &ctx,

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