script/dom/webgpu/
gpuuncapturederrorevent.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use 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        type_: DOMString,
39        init: &GPUUncapturedErrorEventInit,
40        can_gc: CanGc,
41    ) -> DomRoot<Self> {
42        Self::new_with_proto(global, None, type_, init, can_gc)
43    }
44
45    fn new_with_proto(
46        global: &GlobalScope,
47        proto: Option<HandleObject>,
48        type_: DOMString,
49        init: &GPUUncapturedErrorEventInit,
50        can_gc: CanGc,
51    ) -> DomRoot<Self> {
52        let ev = reflect_dom_object_with_proto(
53            Box::new(GPUUncapturedErrorEvent::new_inherited(init)),
54            global,
55            proto,
56            can_gc,
57        );
58        ev.event.init_event(
59            Atom::from(type_),
60            init.parent.bubbles,
61            init.parent.cancelable,
62        );
63        ev
64    }
65}
66
67impl GPUUncapturedErrorEventMethods<crate::DomTypeHolder> for GPUUncapturedErrorEvent {
68    /// <https://gpuweb.github.io/gpuweb/#dom-gpuuncapturederrorevent-gpuuncapturederrorevent>
69    fn Constructor(
70        global: &GlobalScope,
71        proto: Option<HandleObject>,
72        can_gc: CanGc,
73        type_: DOMString,
74        init: &GPUUncapturedErrorEventInit,
75    ) -> DomRoot<Self> {
76        GPUUncapturedErrorEvent::new_with_proto(global, proto, type_, init, can_gc)
77    }
78
79    /// <https://gpuweb.github.io/gpuweb/#dom-gpuuncapturederrorevent-error>
80    fn Error(&self) -> DomRoot<GPUError> {
81        DomRoot::from_ref(&self.gpu_error)
82    }
83
84    /// <https://dom.spec.whatwg.org/#dom-event-istrusted>
85    fn IsTrusted(&self) -> bool {
86        self.event.IsTrusted()
87    }
88}