Skip to main content

script_webgpu/
gpuinternalerror.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    GPUInternalErrorMethods, GPUInternalErrorWrap,
12};
13use script_bindings::conversions::DerivedFrom;
14use script_bindings::inheritance::Castable;
15use script_bindings::reflector::reflect_dom_object_with_proto_and_wrap;
16
17use crate::JSTraceable;
18use crate::dom::bindings::root::DomRoot;
19use crate::dom::bindings::str::DOMString;
20use crate::gpuerror::GPUError;
21use crate::traits::Equivalence;
22
23#[dom_struct]
24pub struct GPUInternalError<D: DomTypes> {
25    gpu_error: GPUError<D>,
26}
27
28impl<D> GPUInternalError<D>
29where
30    D: Equivalence,
31    D::GPUError: Castable,
32    D::GPUValidationError: DerivedFrom<GPUError<D>>,
33    D::GPUOutOfMemoryError: DerivedFrom<GPUError<D>>,
34    D::GPUInternalError: DerivedFrom<GPUError<D>>,
35{
36    fn new_inherited(message: DOMString) -> Self {
37        Self {
38            gpu_error: GPUError::new_inherited(message),
39        }
40    }
41
42    pub(crate) fn new_with_proto(
43        cx: &mut JSContext,
44        global: &D::GlobalScope,
45        proto: Option<HandleObject>,
46        message: DOMString,
47    ) -> DomRoot<Self> {
48        reflect_dom_object_with_proto_and_wrap::<D, _, _>(
49            Box::new(Self::new_inherited(message)),
50            global,
51            proto,
52            cx,
53            GPUInternalErrorWrap::<D>,
54        )
55    }
56}
57
58impl<D> GPUInternalErrorMethods<D> for GPUInternalError<D>
59where
60    D: Equivalence,
61    D::GPUError: Castable,
62    D::GPUValidationError: DerivedFrom<GPUError<D>>,
63    D::GPUOutOfMemoryError: DerivedFrom<GPUError<D>>,
64    D::GPUInternalError: DerivedFrom<GPUError<D>>,
65{
66    /// <https://gpuweb.github.io/gpuweb/#dom-GPUInternalError-GPUInternalError>
67    fn Constructor(
68        cx: &mut JSContext,
69        global: &D::GlobalScope,
70        proto: Option<HandleObject>,
71        message: DOMString,
72    ) -> DomRoot<Self> {
73        Self::new_with_proto(cx, global, proto, message)
74    }
75}