script_webgpu/
gpucompilationmessage.rs1use std::marker::PhantomData;
6
7use dom_struct::dom_struct;
8use js::context::JSContext;
9use malloc_size_of_derive::MallocSizeOf;
10use script_bindings::DomTypes;
11use script_bindings::codegen::GenericBindings::WebGPUBinding::{
12 GPUCompilationMessageMethods, GPUCompilationMessageType, GPUCompilationMessageWrap,
13};
14use script_bindings::reflector::{Reflector, reflect_dom_object_with_wrap};
15use webgpu_traits::ShaderCompilationInfo;
16
17use crate::JSTraceable;
18use crate::dom::bindings::root::DomRoot;
19use crate::dom::bindings::str::DOMString;
20
21#[dom_struct]
22pub struct GPUCompilationMessage<D: DomTypes> {
23 reflector_: Reflector,
24 message: DOMString,
25 mtype: GPUCompilationMessageType,
26 line_num: u64,
27 line_pos: u64,
28 offset: u64,
29 length: u64,
30 #[no_trace = "PhantomData does not exist"]
31 phantom: PhantomData<D>,
32}
33
34impl<D> GPUCompilationMessage<D>
35where
36 D: DomTypes<GPUCompilationMessage = GPUCompilationMessage<D>>,
37{
38 fn new_inherited(
39 message: DOMString,
40 mtype: GPUCompilationMessageType,
41 line_num: u64,
42 line_pos: u64,
43 offset: u64,
44 length: u64,
45 ) -> Self {
46 Self {
47 reflector_: Reflector::new(),
48 message,
49 mtype,
50 line_num,
51 line_pos,
52 offset,
53 length,
54 phantom: PhantomData,
55 }
56 }
57
58 #[expect(clippy::too_many_arguments)]
59 pub(crate) fn new(
60 cx: &mut JSContext,
61 global: &D::GlobalScope,
62 message: DOMString,
63 mtype: GPUCompilationMessageType,
64 line_num: u64,
65 line_pos: u64,
66 offset: u64,
67 length: u64,
68 ) -> DomRoot<Self> {
69 reflect_dom_object_with_wrap::<D, _, _>(
70 Box::new(Self::new_inherited(
71 message, mtype, line_num, line_pos, offset, length,
72 )),
73 global,
74 cx,
75 GPUCompilationMessageWrap::<D>,
76 )
77 }
78
79 pub(crate) fn from(
80 cx: &mut JSContext,
81 global: &D::GlobalScope,
82 info: ShaderCompilationInfo,
83 ) -> DomRoot<Self> {
84 GPUCompilationMessage::new(
85 cx,
86 global,
87 info.message.into(),
88 GPUCompilationMessageType::Error,
89 info.line_number,
90 info.line_pos,
91 info.offset,
92 info.length,
93 )
94 }
95}
96
97impl<D: DomTypes> GPUCompilationMessageMethods<D> for GPUCompilationMessage<D> {
98 fn Message(&self) -> DOMString {
100 self.message.to_owned()
101 }
102
103 fn Type(&self) -> GPUCompilationMessageType {
105 self.mtype
106 }
107
108 fn LineNum(&self) -> u64 {
110 self.line_num
111 }
112
113 fn LinePos(&self) -> u64 {
115 self.line_pos
116 }
117
118 fn Offset(&self) -> u64 {
120 self.offset
121 }
122
123 fn Length(&self) -> u64 {
125 self.length
126 }
127}