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::rust::HandleObject;
7
8use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUOutOfMemoryError_Binding::GPUOutOfMemoryErrorMethods;
9use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::bindings::str::DOMString;
12use crate::dom::globalscope::GlobalScope;
13use crate::dom::types::GPUError;
14use crate::script_runtime::CanGc;
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        global: &GlobalScope,
30        proto: Option<HandleObject>,
31        message: DOMString,
32        can_gc: CanGc,
33    ) -> DomRoot<Self> {
34        reflect_dom_object_with_proto(
35            Box::new(Self::new_inherited(message)),
36            global,
37            proto,
38            can_gc,
39        )
40    }
41}
42
43impl GPUOutOfMemoryErrorMethods<crate::DomTypeHolder> for GPUOutOfMemoryError {
44    /// <https://gpuweb.github.io/gpuweb/#dom-GPUOutOfMemoryError-GPUOutOfMemoryError>
45    fn Constructor(
46        global: &GlobalScope,
47        proto: Option<HandleObject>,
48        can_gc: CanGc,
49        message: DOMString,
50    ) -> DomRoot<Self> {
51        Self::new_with_proto(global, proto, message, can_gc)
52    }
53}