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::reflector::{Reflector, reflect_dom_object_with_wrap};
15
16use crate::JSTraceable;
17use crate::dom::bindings::root::DomRoot;
18use crate::dom::bindings::str::DOMString;
19use crate::traits::Equivalence;
20
21#[dom_struct]
22pub struct GPUDeviceLostInfo<D: DomTypes> {
23 reflector_: Reflector,
24 message: DOMString,
25 reason: GPUDeviceLostReason,
26 #[no_trace = "PhantomData does not exist"]
27 phantom: PhantomData<D>,
28}
29
30impl<D: Equivalence> GPUDeviceLostInfo<D> {
31 fn new_inherited(message: DOMString, reason: GPUDeviceLostReason) -> Self {
32 Self {
33 reflector_: Reflector::new(),
34 message,
35 reason,
36 phantom: PhantomData,
37 }
38 }
39
40 pub fn new(
41 cx: &mut JSContext,
42 global: &D::GlobalScope,
43 message: DOMString,
44 reason: GPUDeviceLostReason,
45 ) -> DomRoot<Self> {
46 reflect_dom_object_with_wrap::<D, _, _>(
47 Box::new(GPUDeviceLostInfo::new_inherited(message, reason)),
48 global,
49 cx,
50 GPUDeviceLostInfoWrap::<D>,
51 )
52 }
53}
54
55impl<D: DomTypes> GPUDeviceLostInfoMethods<D> for GPUDeviceLostInfo<D> {
56 fn Message(&self) -> DOMString {
58 self.message.clone()
59 }
60
61 fn Reason(&self) -> GPUDeviceLostReason {
63 self.reason
64 }
65}