script/dom/webgpu/
gpucompilationinfo.rs1use dom_struct::dom_struct;
6use js::rust::MutableHandleValue;
7use webgpu_traits::ShaderCompilationInfo;
8
9use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUCompilationInfoMethods;
10use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto};
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::bindings::utils::to_frozen_array;
13use crate::dom::globalscope::GlobalScope;
14use crate::dom::types::GPUCompilationMessage;
15use crate::script_runtime::{CanGc, JSContext};
16
17#[dom_struct]
18pub(crate) struct GPUCompilationInfo {
19 reflector_: Reflector,
20 msg: Vec<DomRoot<GPUCompilationMessage>>,
22}
23
24impl GPUCompilationInfo {
25 pub(crate) fn new_inherited(msg: Vec<DomRoot<GPUCompilationMessage>>) -> Self {
26 Self {
27 reflector_: Reflector::new(),
28 msg,
29 }
30 }
31
32 #[allow(dead_code)]
33 pub(crate) fn new(
34 global: &GlobalScope,
35 msg: Vec<DomRoot<GPUCompilationMessage>>,
36 can_gc: CanGc,
37 ) -> DomRoot<Self> {
38 reflect_dom_object_with_proto(Box::new(Self::new_inherited(msg)), global, None, can_gc)
39 }
40
41 pub(crate) fn from(
42 global: &GlobalScope,
43 error: Option<ShaderCompilationInfo>,
44 can_gc: CanGc,
45 ) -> DomRoot<Self> {
46 Self::new(
47 global,
48 if let Some(error) = error {
49 vec![GPUCompilationMessage::from(global, error, can_gc)]
50 } else {
51 Vec::new()
52 },
53 can_gc,
54 )
55 }
56}
57
58impl GPUCompilationInfoMethods<crate::DomTypeHolder> for GPUCompilationInfo {
59 fn Messages(&self, cx: JSContext, can_gc: CanGc, retval: MutableHandleValue) {
61 to_frozen_array(self.msg.as_slice(), cx, retval, can_gc)
62 }
63}