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