use dom_struct::dom_struct;
use js::context::JSContext;
use js::rust::HandleObject;
use malloc_size_of_derive::MallocSizeOf;
use script_bindings::DomTypes;
use script_bindings::codegen::GenericBindings::WebGPUBinding::{
GPUUncapturedErrorEventInit, GPUUncapturedErrorEventMethods, GPUUncapturedErrorEventWrap,
};
use script_bindings::reflector::reflect_dom_object_with_proto_and_wrap;
use script_bindings::traits::DomEventTrait;
use stylo_atoms::Atom;
use crate::JSTraceable;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::gpuerror::GPUError;
use crate::traits::Equivalence;
#[dom_struct]
pub struct GPUUncapturedErrorEvent<D: DomTypes> {
event: D::Event,
#[ignore_malloc_size_of = "Because it is non-owning"]
gpu_error: Dom<GPUError<D>>,
}
impl<D> GPUUncapturedErrorEvent<D>
where
D: Equivalence,
{
fn new_inherited(init: &GPUUncapturedErrorEventInit<D>) -> Self {
Self {
gpu_error: Dom::from_ref(&init.error),
event: D::Event::new_inherited(),
}
}
pub(crate) fn new(
cx: &mut JSContext,
global: &D::GlobalScope,
event_type: Atom,
init: &GPUUncapturedErrorEventInit<D>,
) -> DomRoot<Self> {
Self::new_with_proto(cx, global, None, event_type, init)
}
fn new_with_proto(
cx: &mut JSContext,
global: &D::GlobalScope,
proto: Option<HandleObject>,
event_type: Atom,
init: &GPUUncapturedErrorEventInit<D>,
) -> DomRoot<Self> {
let event = reflect_dom_object_with_proto_and_wrap::<D, _, _>(
cx,
Box::new(GPUUncapturedErrorEvent::new_inherited(init)),
global,
proto,
GPUUncapturedErrorEventWrap::<D>,
);
event
.event
.init_event(event_type, init.parent.bubbles, init.parent.cancelable);
event
}
}
impl<D> GPUUncapturedErrorEventMethods<D> for GPUUncapturedErrorEvent<D>
where
D: Equivalence,
D::Event: DomEventTrait<D>,
{
fn Constructor(
cx: &mut js::context::JSContext,
global: &D::GlobalScope,
proto: Option<HandleObject>,
event_type: DOMString,
init: &GPUUncapturedErrorEventInit<D>,
) -> DomRoot<Self> {
GPUUncapturedErrorEvent::new_with_proto(cx, global, proto, event_type.into(), init)
}
fn Error(&self) -> DomRoot<GPUError<D>> {
DomRoot::from_ref(&self.gpu_error)
}
fn IsTrusted(&self) -> bool {
self.event.IsTrusted()
}
}