From 875e3870049d2523ec349724d692a11665562d40 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sat, 18 Jan 2025 16:36:15 -0500 Subject: script: Feature-gate all crown support. (#35055) * script: Feature-gate all crown support. Signed-off-by: Josh Matthews * script: Use cfg(crown) instead of a cargo feature. Signed-off-by: Josh Matthews --------- Signed-off-by: Josh Matthews --- components/script/dom/bindings/root.rs | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'components/script/dom/bindings/root.rs') diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index b182c917b98..142e981120c 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -43,8 +43,8 @@ use crate::dom::bindings::trace::{trace_reflector, JSTraceable}; use crate::dom::node::Node; /// A rooted value. -#[allow(crown::unrooted_must_root)] -#[crown::unrooted_must_root_lint::allow_unrooted_interior] +#[cfg_attr(crown, allow(crown::unrooted_must_root))] +#[cfg_attr(crown, crown::unrooted_must_root_lint::allow_unrooted_interior)] pub(crate) struct Root { /// The value to root. value: T, @@ -59,7 +59,7 @@ where /// Create a new stack-bounded root for the provided value. /// It cannot outlive its associated `RootCollection`, and it gives /// out references which cannot outlive this new `Root`. - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] pub(crate) unsafe fn new(value: T) -> Self { unsafe fn add_to_root_list(object: *const dyn JSTraceable) -> *const RootCollection { assert_in_script(); @@ -99,7 +99,7 @@ where // The JSTraceable impl for Reflector doesn't actually do anything, // so we need this shenanigan to actually trace the reflector of the // T pointer in Dom. - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] struct ReflectorStackRoot(Reflector); unsafe impl JSTraceable for ReflectorStackRoot { unsafe fn trace(&self, tracer: *mut JSTracer) { @@ -118,7 +118,7 @@ where // The JSTraceable impl for Reflector doesn't actually do anything, // so we need this shenanigan to actually trace the reflector of the // T pointer in Dom. - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] struct MaybeUnreflectedStackRoot(T); unsafe impl JSTraceable for MaybeUnreflectedStackRoot where @@ -197,7 +197,7 @@ impl DomRoot { /// /// This should never be used to create on-stack values. Instead these values should always /// end up as members of other DOM objects. - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] pub(crate) fn as_traced(&self) -> Dom { Dom::from_ref(self) } @@ -335,7 +335,7 @@ where /// on the stack, the `Dom` can point to freed memory. /// /// This should only be used as a field in other DOM objects. -#[crown::unrooted_must_root_lint::must_root] +#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)] pub(crate) struct Dom { ptr: ptr::NonNull, } @@ -364,7 +364,7 @@ impl Dom { impl Dom { /// Create a `Dom` from a `&T` - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] pub(crate) fn from_ref(obj: &T) -> Dom { assert_in_script(); Dom { @@ -403,7 +403,7 @@ unsafe impl JSTraceable for Dom { } /// A traced reference to a DOM object that may not be reflected yet. -#[crown::unrooted_must_root_lint::must_root] +#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)] pub(crate) struct MaybeUnreflectedDom { ptr: ptr::NonNull, } @@ -412,7 +412,7 @@ impl MaybeUnreflectedDom where T: DomObject, { - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] pub(crate) unsafe fn from_box(value: Box) -> Self { Self { ptr: Box::leak(value).into(), @@ -444,7 +444,7 @@ where /// An unrooted reference to a DOM object for use in layout. `Layout*Helpers` /// traits must be implemented on this. -#[crown::unrooted_must_root_lint::allow_unrooted_interior] +#[cfg_attr(crown, crown::unrooted_must_root_lint::allow_unrooted_interior)] pub(crate) struct LayoutDom<'dom, T> { value: &'dom T, } @@ -533,7 +533,7 @@ impl Hash for LayoutDom<'_, T> { impl Clone for Dom { #[inline] - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] fn clone(&self) -> Self { assert_in_script(); Dom { ptr: self.ptr } @@ -566,7 +566,7 @@ impl LayoutDom<'_, Node> { /// /// This should only be used as a field in other DOM objects; see warning /// on `Dom`. -#[crown::unrooted_must_root_lint::must_root] +#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)] #[derive(JSTraceable)] pub(crate) struct MutDom { val: UnsafeCell>, @@ -629,7 +629,7 @@ pub(crate) fn assert_in_layout() { /// /// This should only be used as a field in other DOM objects; see warning /// on `Dom`. -#[crown::unrooted_must_root_lint::must_root] +#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)] #[derive(JSTraceable)] pub(crate) struct MutNullableDom { ptr: UnsafeCell>>, @@ -663,14 +663,14 @@ impl MutNullableDom { /// Retrieve a copy of the inner optional `Dom` as `LayoutDom`. /// For use by layout, which can't use safe types like Temporary. - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] pub(crate) unsafe fn get_inner_as_layout(&self) -> Option> { assert_in_layout(); (*self.ptr.get()).as_ref().map(|js| js.to_layout()) } /// Get a rooted value out of this object - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] pub(crate) fn get(&self) -> Option> { assert_in_script(); unsafe { ptr::read(self.ptr.get()).map(|o| DomRoot::from_ref(&*o)) } @@ -705,7 +705,7 @@ impl PartialEq> for MutNullableDom { } impl Default for MutNullableDom { - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] fn default() -> MutNullableDom { assert_in_script(); MutNullableDom { @@ -727,7 +727,7 @@ impl MallocSizeOf for MutNullableDom { /// /// This should only be used as a field in other DOM objects; see warning /// on `Dom`. -#[crown::unrooted_must_root_lint::must_root] +#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)] pub(crate) struct DomOnceCell { ptr: OnceCell>, } @@ -738,7 +738,7 @@ where { /// Retrieve a copy of the current inner value. If it is `None`, it is /// initialized with the result of `cb` first. - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] pub(crate) fn init_once(&self, cb: F) -> &T where F: FnOnce() -> DomRoot, @@ -749,7 +749,7 @@ where } impl Default for DomOnceCell { - #[allow(crown::unrooted_must_root)] + #[cfg_attr(crown, allow(crown::unrooted_must_root))] fn default() -> DomOnceCell { assert_in_script(); DomOnceCell { @@ -765,7 +765,7 @@ impl MallocSizeOf for DomOnceCell { } } -#[allow(crown::unrooted_must_root)] +#[cfg_attr(crown, allow(crown::unrooted_must_root))] unsafe impl JSTraceable for DomOnceCell { unsafe fn trace(&self, trc: *mut JSTracer) { if let Some(ptr) = self.ptr.get() { -- cgit v1.2.3