Skip to main content

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::context::JSContext;
7use js::rust::HandleObject;
8use script_bindings::reflector::reflect_dom_object_with_proto_and_cx;
9
10use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
11    GPUPipelineErrorInit, GPUPipelineErrorMethods, GPUPipelineErrorReason,
12};
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::bindings::str::DOMString;
15use crate::dom::domexception::DOMException;
16use crate::dom::globalscope::GlobalScope;
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        cx: &mut JSContext,
35        global: &GlobalScope,
36        proto: Option<HandleObject>,
37        message: DOMString,
38        reason: GPUPipelineErrorReason,
39    ) -> DomRoot<Self> {
40        reflect_dom_object_with_proto_and_cx(
41            Box::new(Self::new_inherited(message, reason)),
42            global,
43            proto,
44            cx,
45        )
46    }
47
48    pub(crate) fn new(
49        cx: &mut JSContext,
50        global: &GlobalScope,
51        message: DOMString,
52        reason: GPUPipelineErrorReason,
53    ) -> DomRoot<Self> {
54        Self::new_with_proto(cx, global, None, message, reason)
55    }
56}
57
58impl GPUPipelineErrorMethods<crate::DomTypeHolder> for GPUPipelineError {
59    /// <https://gpuweb.github.io/gpuweb/#dom-gpupipelineerror-constructor>
60    fn Constructor(
61        cx: &mut JSContext,
62        global: &GlobalScope,
63        proto: Option<HandleObject>,
64        message: DOMString,
65        options: &GPUPipelineErrorInit,
66    ) -> DomRoot<Self> {
67        Self::new_with_proto(cx, global, proto, message, options.reason)
68    }
69
70    /// <https://gpuweb.github.io/gpuweb/#dom-gpupipelineerror-reason>
71    fn Reason(&self) -> GPUPipelineErrorReason {
72        self.reason
73    }
74}