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

Function init

modules/llrt_buffer/src/lib.rs:67–92  ·  view source on GitHub ↗
(ctx: &Ctx<'js>)

Source from the content-addressed store, hash-verified

65 }
66}
67
68pub fn init<'js>(ctx: &Ctx<'js>) -> Result<()> {
69 let globals = ctx.globals();
70 BasePrimordials::init(ctx)?;
71
72 // Buffer extends the native Uint8Array: it forwards construction to the
73 // Uint8Array constructor and inherits its static and prototype members.
74 let uint8array = BasePrimordials::get(ctx)?.constructor_uint8array.clone();
75 let buffer_ctor = define_subclass(
76 ctx,
77 stringify!(Buffer),
78 &uint8array,
79 |ctx: Ctx<'js>, args: Rest<Value<'js>>| {
80 let uint8array = &BasePrimordials::get(&ctx)?.constructor_uint8array;
81 let mut ctor_args = Args::new(ctx.clone(), args.0.len());
82 ctor_args.push_args(args.0)?;
83 ctor_args.construct::<Value>(uint8array)
84 },
85 )?;
86 let buffer: Object = buffer_ctor.into_value().into_object().unwrap();
87 set_prototype(ctx, buffer)?;
88
89 BufferPrimordials::init(ctx)?;
90
91 // Blob
92 Class::<Blob>::define(&globals)?;
93
94 // File
95 Class::<File>::define(&globals)?;

Callers 4

test_subarrayFunction · 0.70
test_subarray_partialFunction · 0.70
test_read_int_32_beFunction · 0.70

Calls 2

set_prototypeFunction · 0.85
getFunction · 0.85

Tested by 4

test_subarrayFunction · 0.56
test_subarray_partialFunction · 0.56
test_read_int_32_beFunction · 0.56