script/dom/webgpu/
gpupipelineerror.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;
7
8use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
9    GPUPipelineErrorInit, GPUPipelineErrorMethods, GPUPipelineErrorReason,
10};
11use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::bindings::str::DOMString;
14use crate::dom::domexception::DOMException;
15use crate::dom::globalscope::GlobalScope;
16use crate::script_runtime::CanGc;
17
18/// <https://gpuweb.github.io/gpuweb/#gpupipelineerror>
19#[dom_struct]
20pub(crate) struct GPUPipelineError {
21    exception: DOMException,
22    reason: GPUPipelineErrorReason,
23}
24
25impl GPUPipelineError {
26    fn new_inherited(message: DOMString, reason: GPUPipelineErrorReason) -> Self {
27        Self {
28            exception: DOMException::new_inherited(message, "GPUPipelineError".into()),
29            reason,
30        }
31    }
32
33    pub(crate) fn new_with_proto(
34        global: &GlobalScope,
35        proto: Option<HandleObject>,
36        message: DOMString,
37        reason: GPUPipelineErrorReason,
38        can_gc: CanGc,
39    ) -> DomRoot<Self> {
40        reflect_dom_object_with_proto(
41            Box::new(Self::new_inherited(message, reason)),
42            global,
43            proto,
44            can_gc,
45        )
46    }
47
48    pub(crate) fn new(
49        global: &GlobalScope,
50        message: DOMString,
51        reason: GPUPipelineErrorReason,
52        can_gc: CanGc,
53    ) -> DomRoot<Self> {
54        Self::new_with_proto(global, None, message, reason, can_gc)
55    }
56}
57
58impl GPUPipelineErrorMethods<crate::DomTypeHolder> for GPUPipelineError {
59    /// <https://gpuweb.github.io/gpuweb/#dom-gpupipelineerror-constructor>
60    fn Constructor(
61        global: &GlobalScope,
62        proto: Option<HandleObject>,
63        can_gc: CanGc,
64        message: DOMString,
65        options: &GPUPipelineErrorInit,
66    ) -> DomRoot<Self> {
67        Self::new_with_proto(global, proto, message, options.reason, can_gc)
68    }
69
70    /// <https://gpuweb.github.io/gpuweb/#dom-gpupipelineerror-reason>
71    fn Reason(&self) -> GPUPipelineErrorReason {
72        self.reason
73    }
74}