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::{
GPUPipelineErrorInit, GPUPipelineErrorMethods, GPUPipelineErrorReason, GPUPipelineErrorWrap,
};
use script_bindings::conversions::DerivedFrom;
use script_bindings::inheritance::Castable;
use script_bindings::reflector::reflect_dom_object_with_proto_and_wrap;
use script_bindings::traits::DomExceptionTrait;
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 GPUPipelineError<D: DomTypes> {
exception: D::DOMException,
reason: GPUPipelineErrorReason,
}
impl<D> GPUPipelineError<D>
where
D: Equivalence,
D::GPUError: Castable,
D::GPUValidationError: DerivedFrom<GPUError<D>>,
D::GPUOutOfMemoryError: DerivedFrom<GPUError<D>>,
D::GPUInternalError: DerivedFrom<GPUError<D>>,
D::DOMException: DomExceptionTrait,
{
fn new_inherited(message: DOMString, reason: GPUPipelineErrorReason) -> Self {
Self {
exception: D::DOMException::new_inherited(
message,
DOMString::from_static("GPUPipelineError"),
),
reason,
}
}
pub(crate) fn new_with_proto(
cx: &mut JSContext,
global: &D::GlobalScope,
proto: Option<HandleObject>,
message: DOMString,
reason: GPUPipelineErrorReason,
) -> DomRoot<Self> {
reflect_dom_object_with_proto_and_wrap::<D, _, _>(
cx,
Box::new(Self::new_inherited(message, reason)),
global,
proto,
GPUPipelineErrorWrap::<D>,
)
}
pub fn new(
cx: &mut JSContext,
global: &D::GlobalScope,
message: DOMString,
reason: GPUPipelineErrorReason,
) -> DomRoot<Self> {
Self::new_with_proto(cx, global, None, message, reason)
}
}
impl<D> GPUPipelineErrorMethods<D> for GPUPipelineError<D>
where
D: Equivalence,
D::GPUError: Castable,
D::GPUValidationError: DerivedFrom<GPUError<D>>,
D::GPUOutOfMemoryError: DerivedFrom<GPUError<D>>,
D::GPUInternalError: DerivedFrom<GPUError<D>>,
D::DOMException: DomExceptionTrait,
{
fn Constructor(
cx: &mut JSContext,
global: &D::GlobalScope,
proto: Option<HandleObject>,
message: DOMString,
options: &GPUPipelineErrorInit,
) -> DomRoot<Self> {
Self::new_with_proto(cx, global, proto, message, options.reason)
}
fn Reason(&self) -> GPUPipelineErrorReason {
self.reason
}
}