Skip to main content

script/dom/webgpu/
gpuoutofmemoryerror.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;
9
10use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUOutOfMemoryError_Binding::GPUOutOfMemoryErrorMethods;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::bindings::str::DOMString;
13use crate::dom::globalscope::GlobalScope;
14use crate::dom::types::GPUError;
15
16#[dom_struct]
17pub(crate) struct GPUOutOfMemoryError {
18    gpu_error: GPUError,
19}
20
21impl GPUOutOfMemoryError {
22    fn new_inherited(message: DOMString) -> Self {
23        Self {
24            gpu_error: GPUError::new_inherited(message),
25        }
26    }
27
28    pub(crate) fn new_with_proto(
29        cx: &mut JSContext,
30        global: &GlobalScope,
31        proto: Option<HandleObject>,
32        message: DOMString,
33    ) -> DomRoot<Self> {
34        reflect_dom_object_with_proto(cx, Box::new(Self::new_inherited(message)), global, proto)
35    }
36}
37
38impl GPUOutOfMemoryErrorMethods<crate::DomTypeHolder> for GPUOutOfMemoryError {
39    /// <https://gpuweb.github.io/gpuweb/#dom-GPUOutOfMemoryError-GPUOutOfMemoryError>
40    fn Constructor(
41        cx: &mut JSContext,
42        global: &GlobalScope,
43        proto: Option<HandleObject>,
44        message: DOMString,
45    ) -> DomRoot<Self> {
46        Self::new_with_proto(cx, global, proto, message)
47    }
48}