| 65 | } |
| 66 | } |
| 67 | |
| 68 | pub 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)?; |