script/dom/webgpu/
gpucompilationmessage.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
8use webgpu_traits::ShaderCompilationInfo;
9
10use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
11 GPUCompilationMessageMethods, GPUCompilationMessageType,
12};
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::bindings::str::DOMString;
15use crate::dom::types::GlobalScope;
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 cx: &mut JSContext,
51 global: &GlobalScope,
52 message: DOMString,
53 mtype: GPUCompilationMessageType,
54 line_num: u64,
55 line_pos: u64,
56 offset: u64,
57 length: u64,
58 ) -> DomRoot<Self> {
59 reflect_dom_object_with_cx(
60 Box::new(Self::new_inherited(
61 message, mtype, line_num, line_pos, offset, length,
62 )),
63 global,
64 cx,
65 )
66 }
67
68 pub(crate) fn from(
69 cx: &mut JSContext,
70 global: &GlobalScope,
71 info: ShaderCompilationInfo,
72 ) -> DomRoot<Self> {
73 GPUCompilationMessage::new(
74 cx,
75 global,
76 info.message.into(),
77 GPUCompilationMessageType::Error,
78 info.line_number,
79 info.line_pos,
80 info.offset,
81 info.length,
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}