script/dom/webgpu/
gpudevicelostinfo.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
5#![allow(dead_code)]
6
7use dom_struct::dom_struct;
8
9use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
10    GPUDeviceLostInfoMethods, GPUDeviceLostReason,
11};
12use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::bindings::str::DOMString;
15use crate::dom::globalscope::GlobalScope;
16use crate::script_runtime::CanGc;
17
18#[dom_struct]
19pub(crate) struct GPUDeviceLostInfo {
20    reflector_: Reflector,
21    message: DOMString,
22    reason: GPUDeviceLostReason,
23}
24
25impl GPUDeviceLostInfo {
26    fn new_inherited(message: DOMString, reason: GPUDeviceLostReason) -> Self {
27        Self {
28            reflector_: Reflector::new(),
29            message,
30            reason,
31        }
32    }
33
34    pub(crate) fn new(
35        global: &GlobalScope,
36        message: DOMString,
37        reason: GPUDeviceLostReason,
38        can_gc: CanGc,
39    ) -> DomRoot<Self> {
40        reflect_dom_object(
41            Box::new(GPUDeviceLostInfo::new_inherited(message, reason)),
42            global,
43            can_gc,
44        )
45    }
46}
47
48impl GPUDeviceLostInfoMethods<crate::DomTypeHolder> for GPUDeviceLostInfo {
49    /// <https://gpuweb.github.io/gpuweb/#dom-gpudevicelostinfo-message>
50    fn Message(&self) -> DOMString {
51        self.message.clone()
52    }
53
54    /// <https://gpuweb.github.io/gpuweb/#dom-gpudevicelostinfo-reason>
55    fn Reason(&self) -> GPUDeviceLostReason {
56        self.reason
57    }
58}