servo-script-webgpu 0.7.0

A component of the servo web-engine.
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use dom_struct::dom_struct;
use js::context::JSContext;
use js::rust::HandleObject;
use malloc_size_of_derive::MallocSizeOf;
use script_bindings::DomTypes;
use script_bindings::codegen::GenericBindings::WebGPUBinding::{
    GPUValidationErrorMethods, GPUValidationErrorWrap,
};
use script_bindings::conversions::DerivedFrom;
use script_bindings::inheritance::Castable;
use script_bindings::reflector::reflect_dom_object_with_proto_and_wrap;

use crate::JSTraceable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::gpuerror::GPUError;
use crate::traits::Equivalence;

#[dom_struct]
pub struct GPUValidationError<D: DomTypes> {
    gpu_error: GPUError<D>,
}

impl<D> GPUValidationError<D>
where
    D: Equivalence,
    D::GPUError: Castable,
    D::GPUValidationError: DerivedFrom<GPUError<D>>,
    D::GPUOutOfMemoryError: DerivedFrom<GPUError<D>>,
    D::GPUInternalError: DerivedFrom<GPUError<D>>,
{
    fn new_inherited(message: DOMString) -> Self {
        Self {
            gpu_error: GPUError::new_inherited(message),
        }
    }

    pub(crate) fn new_with_proto(
        cx: &mut JSContext,
        global: &D::GlobalScope,
        proto: Option<HandleObject>,
        message: DOMString,
    ) -> DomRoot<Self> {
        reflect_dom_object_with_proto_and_wrap::<D, _, _>(
            cx,
            Box::new(Self::new_inherited(message)),
            global,
            proto,
            GPUValidationErrorWrap::<D>,
        )
    }
}

impl<D> GPUValidationErrorMethods<D> for GPUValidationError<D>
where
    D: Equivalence,
    D::GPUError: Castable,
    D::GPUValidationError: DerivedFrom<GPUError<D>>,
    D::GPUOutOfMemoryError: DerivedFrom<GPUError<D>>,
    D::GPUInternalError: DerivedFrom<GPUError<D>>,
{
    /// <https://gpuweb.github.io/gpuweb/#dom-gpuvalidationerror-gpuvalidationerror>
    fn Constructor(
        cx: &mut js::context::JSContext,
        global: &D::GlobalScope,
        proto: Option<HandleObject>,
        message: DOMString,
    ) -> DomRoot<Self> {
        Self::new_with_proto(cx, global, proto, message)
    }
}