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 pub(crate) fn new(
33 global: &GlobalScope,
34 msg: Vec<DomRoot<GPUCompilationMessage>>,
35 can_gc: CanGc,
36 ) -> DomRoot<Self> {
37 reflect_dom_object_with_proto(Box::new(Self::new_inherited(msg)), global, None, can_gc)
38 }
39
40 pub(crate) fn from(
41 global: &GlobalScope,
42 error: Option<ShaderCompilationInfo>,
43 can_gc: CanGc,
44 ) -> DomRoot<Self> {
45 Self::new(
46 global,
47 if let Some(error) = error {
48 vec![GPUCompilationMessage::from(global, error, can_gc)]
49 } else {
50 Vec::new()
51 },
52 can_gc,
53 )
54 }
55}
56
57impl GPUCompilationInfoMethods<crate::DomTypeHolder> for GPUCompilationInfo {
58 fn Messages(&self, cx: JSContext, can_gc: CanGc, retval: MutableHandleValue) {
60 to_frozen_array(self.msg.as_slice(), cx, retval, can_gc)
61 }
62}