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