script/dom/webgpu/
gpuuncapturederrorevent.rs1use dom_struct::dom_struct;
6use js::rust::HandleObject;
7use stylo_atoms::Atom;
8
9use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
10use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
11 GPUUncapturedErrorEventInit, GPUUncapturedErrorEventMethods,
12};
13use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
14use crate::dom::bindings::root::{Dom, DomRoot};
15use crate::dom::bindings::str::DOMString;
16use crate::dom::event::Event;
17use crate::dom::globalscope::GlobalScope;
18use crate::dom::webgpu::gpuerror::GPUError;
19use crate::script_runtime::CanGc;
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 global: &GlobalScope,
38 event_type: Atom,
39 init: &GPUUncapturedErrorEventInit,
40 can_gc: CanGc,
41 ) -> DomRoot<Self> {
42 Self::new_with_proto(global, None, event_type, init, can_gc)
43 }
44
45 fn new_with_proto(
46 global: &GlobalScope,
47 proto: Option<HandleObject>,
48 event_type: Atom,
49 init: &GPUUncapturedErrorEventInit,
50 can_gc: CanGc,
51 ) -> DomRoot<Self> {
52 let event = reflect_dom_object_with_proto(
53 Box::new(GPUUncapturedErrorEvent::new_inherited(init)),
54 global,
55 proto,
56 can_gc,
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 global: &GlobalScope,
69 proto: Option<HandleObject>,
70 can_gc: CanGc,
71 event_type: DOMString,
72 init: &GPUUncapturedErrorEventInit,
73 ) -> DomRoot<Self> {
74 GPUUncapturedErrorEvent::new_with_proto(global, proto, event_type.into(), init, can_gc)
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}