script/dom/webgpu/
gpucompilationmessage.rs1#![allow(dead_code)] use dom_struct::dom_struct;
8use webgpu_traits::ShaderCompilationInfo;
9
10use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
11 GPUCompilationMessageMethods, GPUCompilationMessageType,
12};
13use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
14use crate::dom::bindings::root::DomRoot;
15use crate::dom::bindings::str::DOMString;
16use crate::dom::types::GlobalScope;
17use crate::script_runtime::CanGc;
18
19#[dom_struct]
20pub(crate) struct GPUCompilationMessage {
21 reflector_: Reflector,
22 message: DOMString,
24 mtype: GPUCompilationMessageType,
25 line_num: u64,
26 line_pos: u64,
27 offset: u64,
28 length: u64,
29}
30
31impl GPUCompilationMessage {
32 fn new_inherited(
33 message: DOMString,
34 mtype: GPUCompilationMessageType,
35 line_num: u64,
36 line_pos: u64,
37 offset: u64,
38 length: u64,
39 ) -> Self {
40 Self {
41 reflector_: Reflector::new(),
42 message,
43 mtype,
44 line_num,
45 line_pos,
46 offset,
47 length,
48 }
49 }
50
51 #[allow(clippy::too_many_arguments)]
52 pub(crate) fn new(
53 global: &GlobalScope,
54 message: DOMString,
55 mtype: GPUCompilationMessageType,
56 line_num: u64,
57 line_pos: u64,
58 offset: u64,
59 length: u64,
60 can_gc: CanGc,
61 ) -> DomRoot<Self> {
62 reflect_dom_object(
63 Box::new(Self::new_inherited(
64 message, mtype, line_num, line_pos, offset, length,
65 )),
66 global,
67 can_gc,
68 )
69 }
70
71 pub(crate) fn from(
72 global: &GlobalScope,
73 info: ShaderCompilationInfo,
74 can_gc: CanGc,
75 ) -> DomRoot<Self> {
76 GPUCompilationMessage::new(
77 global,
78 info.message.into(),
79 GPUCompilationMessageType::Error,
80 info.line_number,
81 info.line_pos,
82 info.offset,
83 info.length,
84 can_gc,
85 )
86 }
87}
88
89impl GPUCompilationMessageMethods<crate::DomTypeHolder> for GPUCompilationMessage {
90 fn Message(&self) -> DOMString {
92 self.message.to_owned()
93 }
94
95 fn Type(&self) -> GPUCompilationMessageType {
97 self.mtype
98 }
99
100 fn LineNum(&self) -> u64 {
102 self.line_num
103 }
104
105 fn LinePos(&self) -> u64 {
107 self.line_pos
108 }
109
110 fn Offset(&self) -> u64 {
112 self.offset
113 }
114
115 fn Length(&self) -> u64 {
117 self.length
118 }
119}