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,
21 mtype: GPUCompilationMessageType,
22 line_num: u64,
23 line_pos: u64,
24 offset: u64,
25 length: u64,
26}
27
28impl GPUCompilationMessage {
29 fn new_inherited(
30 message: DOMString,
31 mtype: GPUCompilationMessageType,
32 line_num: u64,
33 line_pos: u64,
34 offset: u64,
35 length: u64,
36 ) -> Self {
37 Self {
38 reflector_: Reflector::new(),
39 message,
40 mtype,
41 line_num,
42 line_pos,
43 offset,
44 length,
45 }
46 }
47
48 #[expect(clippy::too_many_arguments)]
49 pub(crate) fn new(
50 global: &GlobalScope,
51 message: DOMString,
52 mtype: GPUCompilationMessageType,
53 line_num: u64,
54 line_pos: u64,
55 offset: u64,
56 length: u64,
57 can_gc: CanGc,
58 ) -> DomRoot<Self> {
59 reflect_dom_object(
60 Box::new(Self::new_inherited(
61 message, mtype, line_num, line_pos, offset, length,
62 )),
63 global,
64 can_gc,
65 )
66 }
67
68 pub(crate) fn from(
69 global: &GlobalScope,
70 info: ShaderCompilationInfo,
71 can_gc: CanGc,
72 ) -> DomRoot<Self> {
73 GPUCompilationMessage::new(
74 global,
75 info.message.into(),
76 GPUCompilationMessageType::Error,
77 info.line_number,
78 info.line_pos,
79 info.offset,
80 info.length,
81 can_gc,
82 )
83 }
84}
85
86impl GPUCompilationMessageMethods<crate::DomTypeHolder> for GPUCompilationMessage {
87 fn Message(&self) -> DOMString {
89 self.message.to_owned()
90 }
91
92 fn Type(&self) -> GPUCompilationMessageType {
94 self.mtype
95 }
96
97 fn LineNum(&self) -> u64 {
99 self.line_num
100 }
101
102 fn LinePos(&self) -> u64 {
104 self.line_pos
105 }
106
107 fn Offset(&self) -> u64 {
109 self.offset
110 }
111
112 fn Length(&self) -> u64 {
114 self.length
115 }
116}