script/dom/webgpu/
gpucompilationmessage.rs1use 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 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 fn Message(&self) -> DOMString {
90 self.message.to_owned()
91 }
92
93 fn Type(&self) -> GPUCompilationMessageType {
95 self.mtype
96 }
97
98 fn LineNum(&self) -> u64 {
100 self.line_num
101 }
102
103 fn LinePos(&self) -> u64 {
105 self.line_pos
106 }
107
108 fn Offset(&self) -> u64 {
110 self.offset
111 }
112
113 fn Length(&self) -> u64 {
115 self.length
116 }
117}