script_webgpu/
gpucompilationinfo.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use js::rust::MutableHandleValue;
8use malloc_size_of_derive::MallocSizeOf;
9use script_bindings::DomTypes;
10use script_bindings::codegen::GenericBindings::WebGPUBinding::{
11 GPUCompilationInfoMethods, GPUCompilationInfoWrap,
12};
13use script_bindings::reflector::{Reflector, reflect_dom_object_with_proto_and_wrap};
14use script_bindings::utils::to_frozen_array;
15use webgpu_traits::ShaderCompilationInfo;
16
17use crate::JSTraceable;
18use crate::dom::bindings::root::{Dom, DomRoot};
19use crate::gpucompilationmessage::GPUCompilationMessage;
20use crate::traits::Equivalence;
21
22#[dom_struct]
23pub struct GPUCompilationInfo<D: DomTypes> {
24 reflector_: Reflector,
25 msg: Vec<Dom<GPUCompilationMessage<D>>>,
27}
28
29impl<D: Equivalence> GPUCompilationInfo<D> {
30 pub(crate) fn new_inherited(msg: Vec<DomRoot<GPUCompilationMessage<D>>>) -> Self {
31 Self {
32 reflector_: Reflector::new(),
33 msg: msg.into_iter().map(|event| event.as_traced()).collect(),
34 }
35 }
36
37 pub(crate) fn new(
38 cx: &mut JSContext,
39 global: &D::GlobalScope,
40 msg: Vec<DomRoot<GPUCompilationMessage<D>>>,
41 ) -> DomRoot<Self> {
42 reflect_dom_object_with_proto_and_wrap::<D, _, _>(
43 Box::new(Self::new_inherited(msg)),
44 global,
45 None,
46 cx,
47 GPUCompilationInfoWrap::<D>,
48 )
49 }
50
51 pub fn from(
52 cx: &mut JSContext,
53 global: &D::GlobalScope,
54 error: Option<ShaderCompilationInfo>,
55 ) -> DomRoot<Self> {
56 let msg = error
57 .map(|error| vec![GPUCompilationMessage::from(cx, global, error)])
58 .unwrap_or_default();
59 Self::new(cx, global, msg)
60 }
61}
62
63impl<D: DomTypes> GPUCompilationInfoMethods<D> for GPUCompilationInfo<D> {
64 fn Messages(&self, cx: &mut JSContext, retval: MutableHandleValue) {
66 let messages: Vec<DomRoot<GPUCompilationMessage<D>>> =
67 self.msg.iter().map(|msg| msg.as_rooted()).collect();
68 to_frozen_array(cx, messages.as_slice(), retval)
69 }
70}