script/dom/webgpu/
gpucompilationmessage.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 webgpu_traits::ShaderCompilationInfo;
7
8use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
9    GPUCompilationMessageMethods, GPUCompilationMessageType,
10};
11use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::bindings::str::DOMString;
14use crate::dom::types::GlobalScope;
15use crate::script_runtime::CanGc;
16
17#[dom_struct]
18pub(crate) struct GPUCompilationMessage {
19    reflector_: Reflector,
20    // #[ignore_malloc_size_of = "defined in wgpu-types"]
21    message: DOMString,
22    mtype: GPUCompilationMessageType,
23    line_num: u64,
24    line_pos: u64,
25    offset: u64,
26    length: u64,
27}
28
29impl GPUCompilationMessage {
30    fn new_inherited(
31        message: DOMString,
32        mtype: GPUCompilationMessageType,
33        line_num: u64,
34        line_pos: u64,
35        offset: u64,
36        length: u64,
37    ) -> Self {
38        Self {
39            reflector_: Reflector::new(),
40            message,
41            mtype,
42            line_num,
43            line_pos,
44            offset,
45            length,
46        }
47    }
48
49    #[allow(clippy::too_many_arguments)]
50    pub(crate) fn new(
51        global: &GlobalScope,
52        message: DOMString,
53        mtype: GPUCompilationMessageType,
54        line_num: u64,
55        line_pos: u64,
56        offset: u64,
57        length: u64,
58        can_gc: CanGc,
59    ) -> DomRoot<Self> {
60        reflect_dom_object(
61            Box::new(Self::new_inherited(
62                message, mtype, line_num, line_pos, offset, length,
63            )),
64            global,
65            can_gc,
66        )
67    }
68
69    pub(crate) fn from(
70        global: &GlobalScope,
71        info: ShaderCompilationInfo,
72        can_gc: CanGc,
73    ) -> DomRoot<Self> {
74        GPUCompilationMessage::new(
75            global,
76            info.message.into(),
77            GPUCompilationMessageType::Error,
78            info.line_number,
79            info.line_pos,
80            info.offset,
81            info.length,
82            can_gc,
83        )
84    }
85}
86
87impl GPUCompilationMessageMethods<crate::DomTypeHolder> for GPUCompilationMessage {
88    /// <https://gpuweb.github.io/gpuweb/#dom-gpucompilationmessage-message>
89    fn Message(&self) -> DOMString {
90        self.message.to_owned()
91    }
92
93    /// <https://gpuweb.github.io/gpuweb/#dom-gpucompilationmessage-type>
94    fn Type(&self) -> GPUCompilationMessageType {
95        self.mtype
96    }
97
98    /// <https://gpuweb.github.io/gpuweb/#dom-gpucompilationmessage-linenum>
99    fn LineNum(&self) -> u64 {
100        self.line_num
101    }
102
103    /// <https://gpuweb.github.io/gpuweb/#dom-gpucompilationmessage-linepos>
104    fn LinePos(&self) -> u64 {
105        self.line_pos
106    }
107
108    /// <https://gpuweb.github.io/gpuweb/#dom-gpucompilationmessage-offset>
109    fn Offset(&self) -> u64 {
110        self.offset
111    }
112
113    /// <https://gpuweb.github.io/gpuweb/#dom-gpucompilationmessage-length>
114    fn Length(&self) -> u64 {
115        self.length
116    }
117}