mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
* script: Feature-gate all crown support. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Use cfg(crown) instead of a cargo feature. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
86 lines
2.5 KiB
Rust
86 lines
2.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
// check-tidy: no specs after this line
|
|
|
|
use dom_struct::dom_struct;
|
|
use indexmap::IndexSet;
|
|
use js::rust::HandleObject;
|
|
use webgpu::wgc::naga::front::wgsl::ImplementedLanguageExtension;
|
|
|
|
use crate::dom::bindings::cell::DomRefCell;
|
|
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::WGSLLanguageFeaturesMethods;
|
|
use crate::dom::bindings::like::Setlike;
|
|
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, Reflector};
|
|
use crate::dom::bindings::root::DomRoot;
|
|
use crate::dom::bindings::str::DOMString;
|
|
use crate::dom::globalscope::GlobalScope;
|
|
use crate::script_runtime::CanGc;
|
|
|
|
#[dom_struct]
|
|
pub struct WGSLLanguageFeatures {
|
|
reflector: Reflector,
|
|
// internal storage for features
|
|
#[custom_trace]
|
|
internal: DomRefCell<IndexSet<DOMString>>,
|
|
}
|
|
|
|
impl WGSLLanguageFeatures {
|
|
pub(crate) fn new(
|
|
global: &GlobalScope,
|
|
proto: Option<HandleObject>,
|
|
can_gc: CanGc,
|
|
) -> DomRoot<Self> {
|
|
let set = ImplementedLanguageExtension::all()
|
|
.iter()
|
|
.map(|le| le.to_ident().into())
|
|
.collect();
|
|
reflect_dom_object_with_proto(
|
|
Box::new(Self {
|
|
reflector: Reflector::new(),
|
|
internal: DomRefCell::new(set),
|
|
}),
|
|
global,
|
|
proto,
|
|
can_gc,
|
|
)
|
|
}
|
|
}
|
|
|
|
impl WGSLLanguageFeaturesMethods<crate::DomTypeHolder> for WGSLLanguageFeatures {
|
|
fn Size(&self) -> u32 {
|
|
self.internal.size()
|
|
}
|
|
}
|
|
|
|
// this error is wrong because if we inline Self::Key and Self::Value all errors are gone
|
|
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
|
impl Setlike for WGSLLanguageFeatures {
|
|
type Key = DOMString;
|
|
|
|
#[inline(always)]
|
|
fn get_index(&self, index: u32) -> Option<Self::Key> {
|
|
self.internal.get_index(index)
|
|
}
|
|
#[inline(always)]
|
|
fn size(&self) -> u32 {
|
|
self.internal.size()
|
|
}
|
|
#[inline(always)]
|
|
fn add(&self, _key: Self::Key) {
|
|
unreachable!("readonly");
|
|
}
|
|
#[inline(always)]
|
|
fn has(&self, key: Self::Key) -> bool {
|
|
self.internal.has(key)
|
|
}
|
|
#[inline(always)]
|
|
fn clear(&self) {
|
|
unreachable!("readonly");
|
|
}
|
|
#[inline(always)]
|
|
fn delete(&self, _key: Self::Key) -> bool {
|
|
unreachable!("readonly");
|
|
}
|
|
}
|