script_webgpu/
gpudevicelostinfo.rs1use std::marker::PhantomData;
6
7use dom_struct::dom_struct;
8use js::context::JSContext;
9use malloc_size_of_derive::MallocSizeOf;
10use script_bindings::DomTypes;
11use script_bindings::codegen::GenericBindings::WebGPUBinding::{
12 GPUDeviceLostInfoMethods, GPUDeviceLostInfoWrap, GPUDeviceLostReason,
13};
14use script_bindings::domstring::TracedDOMString;
15use script_bindings::reflector::{Reflector, reflect_dom_object_with_wrap};
16
17use crate::JSTraceable;
18use crate::dom::bindings::root::DomRoot;
19use crate::dom::bindings::str::DOMString;
20use crate::traits::Equivalence;
21
22#[dom_struct]
23pub struct GPUDeviceLostInfo<D: DomTypes> {
24 reflector_: Reflector,
25 message: TracedDOMString,
26 reason: GPUDeviceLostReason,
27 #[no_trace = "PhantomData does not exist"]
28 phantom: PhantomData<D>,
29}
30
31impl<D: Equivalence> GPUDeviceLostInfo<D> {
32 fn new_inherited(message: DOMString, reason: GPUDeviceLostReason) -> Self {
33 Self {
34 reflector_: Reflector::new(),
35 message: message.traced(),
36 reason,
37 phantom: PhantomData,
38 }
39 }
40
41 pub(crate) fn new(
42 cx: &mut JSContext,
43 global: &D::GlobalScope,
44 message: DOMString,
45 reason: GPUDeviceLostReason,
46 ) -> DomRoot<Self> {
47 reflect_dom_object_with_wrap::<D, _, _>(
48 cx,
49 Box::new(GPUDeviceLostInfo::new_inherited(message, reason)),
50 global,
51 GPUDeviceLostInfoWrap::<D>,
52 )
53 }
54}
55
56impl<D: DomTypes> GPUDeviceLostInfoMethods<D> for GPUDeviceLostInfo<D> {
57 fn Message(&self) -> DOMString {
59 self.message.clone().root()
60 }
61
62 fn Reason(&self) -> GPUDeviceLostReason {
64 self.reason
65 }
66}