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;
20use crate::traits::Equivalence;
21
22#[dom_struct]
23pub struct GPUCompilationMessage<D: DomTypes> {
24 reflector_: Reflector,
25 message: DOMString,
26 mtype: GPUCompilationMessageType,
27 line_num: u64,
28 line_pos: u64,
29 offset: u64,
30 length: u64,
31 #[no_trace = "PhantomData does not exist"]
32 phantom: PhantomData<D>,
33}
34
35impl<D: Equivalence> GPUCompilationMessage<D> {
36 fn new_inherited(
37 message: DOMString,
38 mtype: GPUCompilationMessageType,
39 line_num: u64,
40 line_pos: u64,
41 offset: u64,
42 length: u64,
43 ) -> Self {
44 Self {
45 reflector_: Reflector::new(),
46 message,
47 mtype,
48 line_num,
49 line_pos,
50 offset,
51 length,
52 phantom: PhantomData,
53 }
54 }
55
56 #[expect(clippy::too_many_arguments)]
57 pub(crate) fn new(
58 cx: &mut JSContext,
59 global: &D::GlobalScope,
60 message: DOMString,
61 mtype: GPUCompilationMessageType,
62 line_num: u64,
63 line_pos: u64,
64 offset: u64,
65 length: u64,
66 ) -> DomRoot<Self> {
67 reflect_dom_object_with_wrap::<D, _, _>(
68 Box::new(Self::new_inherited(
69 message, mtype, line_num, line_pos, offset, length,
70 )),
71 global,
72 cx,
73 GPUCompilationMessageWrap::<D>,
74 )
75 }
76
77 pub(crate) fn from(
78 cx: &mut JSContext,
79 global: &D::GlobalScope,
80 info: ShaderCompilationInfo,
81 ) -> DomRoot<Self> {
82 GPUCompilationMessage::new(
83 cx,
84 global,
85 info.message.into(),
86 GPUCompilationMessageType::Error,
87 info.line_number,
88 info.line_pos,
89 info.offset,
90 info.length,
91 )
92 }
93}
94
95impl<D: DomTypes> GPUCompilationMessageMethods<D> for GPUCompilationMessage<D> {
96 fn Message(&self) -> DOMString {
98 self.message.to_owned()
99 }
100
101 fn Type(&self) -> GPUCompilationMessageType {
103 self.mtype
104 }
105
106 fn LineNum(&self) -> u64 {
108 self.line_num
109 }
110
111 fn LinePos(&self) -> u64 {
113 self.line_pos
114 }
115
116 fn Offset(&self) -> u64 {
118 self.offset
119 }
120
121 fn Length(&self) -> u64 {
123 self.length
124 }
125}