fn nodecontext_to_js_value(
    ctx: &{{ context_type_path }},
) -> wasm_bindgen::JsValue {
    let obj = js_sys::Object::new();
{{ context_field_lines }}
    obj.into()
}

pub struct {{ struct_name }} {
    js_obj: wasm_bindgen::JsValue,
}

impl std::fmt::Debug for {{ struct_name }} {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{{ struct_name }}")
    }
}

impl {{ struct_name }} {
    pub fn new(js_obj: wasm_bindgen::JsValue) -> Self {
        Self { js_obj }
    }
}

// SAFETY: WebAssembly is single-threaded — there is exactly one thread per wasm
// instance, so `JsValue` is never actually accessed from multiple threads
// simultaneously. These impls are required to satisfy bridge handle aliases backed
// by `Arc<Mutex<dyn Trait + Send>>`.
unsafe impl Send for {{ struct_name }} {}
// SAFETY: see Send impl above.
unsafe impl Sync for {{ struct_name }} {}

impl {{ trait_path }} for {{ struct_name }} {
{%- for method in methods %}
    {{ method.code }}
{%- endfor %}
}
