Skip to main content

script_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 malloc_size_of_derive::MallocSizeOf;
9use script_bindings::DomTypes;
10use script_bindings::codegen::GenericBindings::WebGPUBinding::{
11    GPUPipelineErrorInit, GPUPipelineErrorMethods, GPUPipelineErrorReason, GPUPipelineErrorWrap,
12};
13use script_bindings::conversions::DerivedFrom;
14use script_bindings::inheritance::Castable;
15use script_bindings::reflector::reflect_dom_object_with_proto_and_wrap;
16use script_bindings::traits::DomExceptionTrait;
17
18use crate::JSTraceable;
19use crate::dom::bindings::root::DomRoot;
20use crate::dom::bindings::str::DOMString;
21use crate::gpuerror::GPUError;
22use crate::traits::Equivalence;
23
24/// <https://gpuweb.github.io/gpuweb/#gpupipelineerror>
25#[dom_struct]
26pub struct GPUPipelineError<D: DomTypes> {
27    exception: D::DOMException,
28    reason: GPUPipelineErrorReason,
29}
30
31impl<D> GPUPipelineError<D>
32where
33    D: Equivalence,
34    D::GPUError: Castable,
35    D::GPUValidationError: DerivedFrom<GPUError<D>>,
36    D::GPUOutOfMemoryError: DerivedFrom<GPUError<D>>,
37    D::GPUInternalError: DerivedFrom<GPUError<D>>,
38    D::DOMException: DomExceptionTrait,
39{
40    fn new_inherited(message: DOMString, reason: GPUPipelineErrorReason) -> Self {
41        Self {
42            exception: D::DOMException::new_inherited(
43                message,
44                DOMString::from_static("GPUPipelineError"),
45            ),
46            reason,
47        }
48    }
49
50    pub(crate) fn new_with_proto(
51        cx: &mut JSContext,
52        global: &D::GlobalScope,
53        proto: Option<HandleObject>,
54        message: DOMString,
55        reason: GPUPipelineErrorReason,
56    ) -> DomRoot<Self> {
57        reflect_dom_object_with_proto_and_wrap::<D, _, _>(
58            Box::new(Self::new_inherited(message, reason)),
59            global,
60            proto,
61            cx,
62            GPUPipelineErrorWrap::<D>,
63        )
64    }
65
66    pub fn new(
67        cx: &mut JSContext,
68        global: &D::GlobalScope,
69        message: DOMString,
70        reason: GPUPipelineErrorReason,
71    ) -> DomRoot<Self> {
72        Self::new_with_proto(cx, global, None, message, reason)
73    }
74}
75
76impl<D> GPUPipelineErrorMethods<D> for GPUPipelineError<D>
77where
78    D: Equivalence,
79    D::GPUError: Castable,
80    D::GPUValidationError: DerivedFrom<GPUError<D>>,
81    D::GPUOutOfMemoryError: DerivedFrom<GPUError<D>>,
82    D::GPUInternalError: DerivedFrom<GPUError<D>>,
83    D::DOMException: DomExceptionTrait,
84{
85    /// <https://gpuweb.github.io/gpuweb/#dom-gpupipelineerror-constructor>
86    fn Constructor(
87        cx: &mut JSContext,
88        global: &D::GlobalScope,
89        proto: Option<HandleObject>,
90        message: DOMString,
91        options: &GPUPipelineErrorInit,
92    ) -> DomRoot<Self> {
93        Self::new_with_proto(cx, global, proto, message, options.reason)
94    }
95
96    /// <https://gpuweb.github.io/gpuweb/#dom-gpupipelineerror-reason>
97    fn Reason(&self) -> GPUPipelineErrorReason {
98        self.reason
99    }
100}