quickjs-jit-stdlib 0.14.2

LLRT's standard modules for quickjs-jit, vendored into one crate
Documentation
// Vendored from LLRT d9fd873e793c (modules/llrt_events/src/custom_event.rs); module paths and
// feature names adapted by scripts/import-stdlib.py.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
use rquickjs::{prelude::Opt, Ctx, IntoJs, Null, Result, Value};

use crate::utils::object::ObjectExt;

#[rquickjs::class]
#[derive(rquickjs::class::Trace, rquickjs::JsLifetime)]
pub struct CustomEvent<'js> {
    event_type: String,
    detail: Option<Value<'js>>,
}

#[rquickjs::methods]
impl<'js> CustomEvent<'js> {
    #[qjs(constructor)]
    pub fn new(event_type: String, options: Opt<Value<'js>>) -> Result<Self> {
        let mut detail = None;
        if let Some(options) = options.0 {
            if let Some(opt) = options.get_optional("detail")? {
                detail = opt;
            }
        }
        Ok(Self { event_type, detail })
    }

    #[qjs(get)]
    pub fn detail(&self, ctx: Ctx<'js>) -> Result<Value<'js>> {
        if let Some(detail) = &self.detail {
            return Ok(detail.clone());
        }
        Null.into_js(&ctx)
    }

    #[qjs(get, rename = "type")]
    pub fn event_type(&self) -> String {
        self.event_type.clone()
    }
}