diff options
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/root.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 9afb421abbb..4f4d376e951 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -441,6 +441,15 @@ where debug_assert!(thread_state::get().is_layout()); self.value.downcast::<U>().map(|value| LayoutDom { value }) } + + /// Returns whether this inner object is a U. + pub fn is<U>(&self) -> bool + where + U: DerivedFrom<T>, + { + debug_assert!(thread_state::get().is_layout()); + self.value.is::<U>() + } } impl<T> LayoutDom<'_, T> @@ -736,6 +745,15 @@ where debug_assert!(thread_state::get().is_layout()); self.value } + + /// Transforms a slice of Dom<T> into a slice of LayoutDom<T>. + // FIXME(nox): This should probably be done through a ToLayout trait. + pub unsafe fn to_layout_slice(slice: &'dom [Dom<T>]) -> &'dom [LayoutDom<'dom, T>] { + // This doesn't compile if Dom and LayoutDom don't have the same + // representation. + let _ = mem::transmute::<Dom<T>, LayoutDom<T>>; + &*(slice as *const [Dom<T>] as *const [LayoutDom<T>]) + } } /// Helper trait for safer manipulations of `Option<Heap<T>>` values. |