script/dom/webgpu/
gpuuncapturederrorevent.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use js::rust::HandleObject;
8use script_bindings::reflector::reflect_dom_object_with_proto_and_cx;
9use stylo_atoms::Atom;
10
11use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
12use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
13 GPUUncapturedErrorEventInit, GPUUncapturedErrorEventMethods,
14};
15use crate::dom::bindings::root::{Dom, DomRoot};
16use crate::dom::bindings::str::DOMString;
17use crate::dom::event::Event;
18use crate::dom::globalscope::GlobalScope;
19use crate::dom::webgpu::gpuerror::GPUError;
20
21#[dom_struct]
22pub(crate) struct GPUUncapturedErrorEvent {
23 event: Event,
24 #[ignore_malloc_size_of = "Because it is non-owning"]
25 gpu_error: Dom<GPUError>,
26}
27
28impl GPUUncapturedErrorEvent {
29 fn new_inherited(init: &GPUUncapturedErrorEventInit) -> Self {
30 Self {
31 gpu_error: Dom::from_ref(&init.error),
32 event: Event::new_inherited(),
33 }
34 }
35
36 pub(crate) fn new(
37 cx: &mut JSContext,
38 global: &GlobalScope,
39 event_type: Atom,
40 init: &GPUUncapturedErrorEventInit,
41 ) -> DomRoot<Self> {
42 Self::new_with_proto(cx, global, None, event_type, init)
43 }
44
45 fn new_with_proto(
46 cx: &mut JSContext,
47 global: &GlobalScope,
48 proto: Option<HandleObject>,
49 event_type: Atom,
50 init: &GPUUncapturedErrorEventInit,
51 ) -> DomRoot<Self> {
52 let event = reflect_dom_object_with_proto_and_cx(
53 Box::new(GPUUncapturedErrorEvent::new_inherited(init)),
54 global,
55 proto,
56 cx,
57 );
58 event
59 .event
60 .init_event(event_type, init.parent.bubbles, init.parent.cancelable);
61 event
62 }
63}
64
65impl GPUUncapturedErrorEventMethods<crate::DomTypeHolder> for GPUUncapturedErrorEvent {
66 fn Constructor(
68 cx: &mut js::context::JSContext,
69 global: &GlobalScope,
70 proto: Option<HandleObject>,
71 event_type: DOMString,
72 init: &GPUUncapturedErrorEventInit,
73 ) -> DomRoot<Self> {
74 GPUUncapturedErrorEvent::new_with_proto(cx, global, proto, event_type.into(), init)
75 }
76
77 fn Error(&self) -> DomRoot<GPUError> {
79 DomRoot::from_ref(&self.gpu_error)
80 }
81
82 fn IsTrusted(&self) -> bool {
84 self.event.IsTrusted()
85 }
86}