diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index e778a56c1fe..2f502352d27 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -70,7 +70,6 @@ use servo_url::ServoUrl; use std::fmt; use std::fmt::Debug; use std::hash::{Hash, Hasher}; -use std::marker::PhantomData; use std::ptr::NonNull; use std::sync::atomic::Ordering; use std::sync::Arc as StdArc; @@ -100,12 +99,9 @@ pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) { } #[derive(Clone, Copy)] -pub struct ServoLayoutNode<'a> { +pub struct ServoLayoutNode<'dom> { /// The wrapped node. - node: LayoutDom, - - /// Being chained to a PhantomData prevents `LayoutNode`s from escaping. - chain: PhantomData<&'a ()>, + node: LayoutDom<'dom, Node>, } impl<'ln> Debug for ServoLayoutNode<'ln> { @@ -130,25 +126,14 @@ impl<'a> PartialEq for ServoLayoutNode<'a> { } impl<'ln> ServoLayoutNode<'ln> { - fn from_layout_js(n: LayoutDom) -> ServoLayoutNode<'ln> { - ServoLayoutNode { - node: n, - chain: PhantomData, - } + fn from_layout_js(n: LayoutDom<'ln, Node>) -> Self { + ServoLayoutNode { node: n } } pub unsafe fn new(address: &TrustedNodeAddress) -> Self { ServoLayoutNode::from_layout_js(LayoutDom::from_trusted_node_address(*address)) } - /// Creates a new layout node with the same lifetime as this layout node. - pub unsafe fn new_with_this_lifetime(&self, node: &LayoutDom) -> ServoLayoutNode<'ln> { - ServoLayoutNode { - node: *node, - chain: self.chain, - } - } - fn script_type_id(&self) -> NodeTypeId { unsafe { self.node.type_id_for_layout() } } @@ -166,12 +151,9 @@ impl<'ln> NodeInfo for ServoLayoutNode<'ln> { } #[derive(Clone, Copy, PartialEq)] -pub struct ServoShadowRoot<'a> { +pub struct ServoShadowRoot<'dom> { /// The wrapped shadow root. - shadow_root: LayoutDom, - - /// Being chained to a PhantomData prevents `ShadowRoot`s from escaping. - chain: PhantomData<&'a ()>, + shadow_root: LayoutDom<'dom, ShadowRoot>, } impl<'lr> Debug for ServoShadowRoot<'lr> { @@ -205,11 +187,8 @@ impl<'lr> TShadowRoot for ServoShadowRoot<'lr> { } impl<'lr> ServoShadowRoot<'lr> { - fn from_layout_js(shadow_root: LayoutDom) -> ServoShadowRoot<'lr> { - ServoShadowRoot { - shadow_root, - chain: PhantomData, - } + fn from_layout_js(shadow_root: LayoutDom<'lr, ShadowRoot>) -> Self { + ServoShadowRoot { shadow_root } } pub unsafe fn flush_stylesheets( @@ -232,40 +211,24 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { unsafe { self.node .composed_parent_node_ref() - .map(|node| self.new_with_this_lifetime(&node)) + .map(Self::from_layout_js) } } fn first_child(&self) -> Option { - unsafe { - self.node - .first_child_ref() - .map(|node| self.new_with_this_lifetime(&node)) - } + unsafe { self.node.first_child_ref().map(Self::from_layout_js) } } fn last_child(&self) -> Option { - unsafe { - self.node - .last_child_ref() - .map(|node| self.new_with_this_lifetime(&node)) - } + unsafe { self.node.last_child_ref().map(Self::from_layout_js) } } fn prev_sibling(&self) -> Option { - unsafe { - self.node - .prev_sibling_ref() - .map(|node| self.new_with_this_lifetime(&node)) - } + unsafe { self.node.prev_sibling_ref().map(Self::from_layout_js) } } fn next_sibling(&self) -> Option { - unsafe { - self.node - .next_sibling_ref() - .map(|node| self.new_with_this_lifetime(&node)) - } + unsafe { self.node.next_sibling_ref().map(Self::from_layout_js) } } fn owner_doc(&self) -> Self::ConcreteDocument { @@ -311,7 +274,7 @@ impl<'ln> LayoutNode<'ln> for ServoLayoutNode<'ln> { type ConcreteThreadSafeLayoutNode = ServoThreadSafeLayoutNode<'ln>; fn to_threadsafe(&self) -> Self::ConcreteThreadSafeLayoutNode { - ServoThreadSafeLayoutNode::new(self) + ServoThreadSafeLayoutNode::new(*self) } fn type_id(&self) -> LayoutNodeType { @@ -368,16 +331,15 @@ impl<'le> GetLayoutData<'le> for ServoThreadSafeLayoutElement<'le> { impl<'ln> ServoLayoutNode<'ln> { /// Returns the interior of this node as a `LayoutDom`. This is highly unsafe for layout to /// call and as such is marked `unsafe`. - pub unsafe fn get_jsmanaged(&self) -> &LayoutDom { - &self.node + pub unsafe fn get_jsmanaged(&self) -> LayoutDom<'ln, Node> { + self.node } } // A wrapper around documents that ensures ayout can only ever access safe properties. #[derive(Clone, Copy)] -pub struct ServoLayoutDocument<'ld> { - document: LayoutDom, - chain: PhantomData<&'ld ()>, +pub struct ServoLayoutDocument<'dom> { + document: LayoutDom<'dom, Document>, } impl<'ld> TDocument for ServoLayoutDocument<'ld> { @@ -446,19 +408,15 @@ impl<'ld> ServoLayoutDocument<'ld> { } } - pub fn from_layout_js(doc: LayoutDom) -> ServoLayoutDocument<'ld> { - ServoLayoutDocument { - document: doc, - chain: PhantomData, - } + pub fn from_layout_js(doc: LayoutDom<'ld, Document>) -> Self { + ServoLayoutDocument { document: doc } } } /// A wrapper around elements that ensures layout can only ever access safe properties. #[derive(Clone, Copy)] -pub struct ServoLayoutElement<'le> { - element: LayoutDom, - chain: PhantomData<&'le ()>, +pub struct ServoLayoutElement<'dom> { + element: LayoutDom<'dom, Element>, } impl<'le> fmt::Debug for ServoLayoutElement<'le> { @@ -739,11 +697,8 @@ impl<'le> Hash for ServoLayoutElement<'le> { impl<'le> Eq for ServoLayoutElement<'le> {} impl<'le> ServoLayoutElement<'le> { - fn from_layout_js(el: LayoutDom) -> ServoLayoutElement<'le> { - ServoLayoutElement { - element: el, - chain: PhantomData, - } + fn from_layout_js(el: LayoutDom<'le, Element>) -> Self { + ServoLayoutElement { element: el } } #[inline] @@ -789,7 +744,7 @@ impl<'le> ServoLayoutElement<'le> { } } -fn as_element<'le>(node: LayoutDom) -> Option> { +fn as_element<'dom>(node: LayoutDom<'dom, Node>) -> Option> { node.downcast().map(ServoLayoutElement::from_layout_js) } @@ -1044,29 +999,20 @@ impl<'ln> DangerousThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> unsafe fn dangerous_first_child(&self) -> Option { self.get_jsmanaged() .first_child_ref() - .map(|node| self.new_with_this_lifetime(&node)) + .map(ServoLayoutNode::from_layout_js) + .map(Self::new) } unsafe fn dangerous_next_sibling(&self) -> Option { self.get_jsmanaged() .next_sibling_ref() - .map(|node| self.new_with_this_lifetime(&node)) + .map(ServoLayoutNode::from_layout_js) + .map(Self::new) } } impl<'ln> ServoThreadSafeLayoutNode<'ln> { - /// Creates a new layout node with the same lifetime as this layout node. - pub unsafe fn new_with_this_lifetime( - &self, - node: &LayoutDom, - ) -> ServoThreadSafeLayoutNode<'ln> { - ServoThreadSafeLayoutNode { - node: self.node.new_with_this_lifetime(node), - pseudo: PseudoElementType::Normal, - } - } - /// Creates a new `ServoThreadSafeLayoutNode` from the given `ServoLayoutNode`. - pub fn new<'a>(node: &ServoLayoutNode<'a>) -> ServoThreadSafeLayoutNode<'a> { + pub fn new(node: ServoLayoutNode<'ln>) -> Self { ServoThreadSafeLayoutNode { node: node.clone(), pseudo: PseudoElementType::Normal, @@ -1075,7 +1021,7 @@ impl<'ln> ServoThreadSafeLayoutNode<'ln> { /// Returns the interior of this node as a `LayoutDom`. This is highly unsafe for layout to /// call and as such is marked `unsafe`. - unsafe fn get_jsmanaged(&self) -> &LayoutDom { + unsafe fn get_jsmanaged(&self) -> LayoutDom<'ln, Node> { self.node.get_jsmanaged() } } diff --git a/components/layout_thread_2020/dom_wrapper.rs b/components/layout_thread_2020/dom_wrapper.rs index 19960e03eb5..55277ea309c 100644 --- a/components/layout_thread_2020/dom_wrapper.rs +++ b/components/layout_thread_2020/dom_wrapper.rs @@ -70,7 +70,6 @@ use servo_url::ServoUrl; use std::fmt; use std::fmt::Debug; use std::hash::{Hash, Hasher}; -use std::marker::PhantomData; use std::ptr::NonNull; use std::sync::atomic::Ordering; use std::sync::Arc as StdArc; @@ -100,12 +99,9 @@ pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) { } #[derive(Clone, Copy)] -pub struct ServoLayoutNode<'a> { +pub struct ServoLayoutNode<'dom> { /// The wrapped node. - node: LayoutDom, - - /// Being chained to a PhantomData prevents `LayoutNode`s from escaping. - chain: PhantomData<&'a ()>, + node: LayoutDom<'dom, Node>, } // Those are supposed to be sound, but they aren't because the entire system @@ -137,25 +133,14 @@ impl<'a> PartialEq for ServoLayoutNode<'a> { } impl<'ln> ServoLayoutNode<'ln> { - fn from_layout_js(n: LayoutDom) -> ServoLayoutNode<'ln> { - ServoLayoutNode { - node: n, - chain: PhantomData, - } + fn from_layout_js(n: LayoutDom<'ln, Node>) -> Self { + ServoLayoutNode { node: n } } pub unsafe fn new(address: &TrustedNodeAddress) -> Self { ServoLayoutNode::from_layout_js(LayoutDom::from_trusted_node_address(*address)) } - /// Creates a new layout node with the same lifetime as this layout node. - pub unsafe fn new_with_this_lifetime(&self, node: &LayoutDom) -> ServoLayoutNode<'ln> { - ServoLayoutNode { - node: *node, - chain: self.chain, - } - } - fn script_type_id(&self) -> NodeTypeId { unsafe { self.node.type_id_for_layout() } } @@ -173,12 +158,9 @@ impl<'ln> NodeInfo for ServoLayoutNode<'ln> { } #[derive(Clone, Copy, PartialEq)] -pub struct ServoShadowRoot<'a> { +pub struct ServoShadowRoot<'dom> { /// The wrapped shadow root. - shadow_root: LayoutDom, - - /// Being chained to a PhantomData prevents `ShadowRoot`s from escaping. - chain: PhantomData<&'a ()>, + shadow_root: LayoutDom<'dom, ShadowRoot>, } impl<'lr> Debug for ServoShadowRoot<'lr> { @@ -212,11 +194,8 @@ impl<'lr> TShadowRoot for ServoShadowRoot<'lr> { } impl<'lr> ServoShadowRoot<'lr> { - fn from_layout_js(shadow_root: LayoutDom) -> ServoShadowRoot<'lr> { - ServoShadowRoot { - shadow_root, - chain: PhantomData, - } + fn from_layout_js(shadow_root: LayoutDom<'lr, ShadowRoot>) -> Self { + ServoShadowRoot { shadow_root } } pub unsafe fn flush_stylesheets( @@ -239,40 +218,24 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { unsafe { self.node .composed_parent_node_ref() - .map(|node| self.new_with_this_lifetime(&node)) + .map(Self::from_layout_js) } } fn first_child(&self) -> Option { - unsafe { - self.node - .first_child_ref() - .map(|node| self.new_with_this_lifetime(&node)) - } + unsafe { self.node.first_child_ref().map(Self::from_layout_js) } } fn last_child(&self) -> Option { - unsafe { - self.node - .last_child_ref() - .map(|node| self.new_with_this_lifetime(&node)) - } + unsafe { self.node.last_child_ref().map(Self::from_layout_js) } } fn prev_sibling(&self) -> Option { - unsafe { - self.node - .prev_sibling_ref() - .map(|node| self.new_with_this_lifetime(&node)) - } + unsafe { self.node.prev_sibling_ref().map(Self::from_layout_js) } } fn next_sibling(&self) -> Option { - unsafe { - self.node - .next_sibling_ref() - .map(|node| self.new_with_this_lifetime(&node)) - } + unsafe { self.node.next_sibling_ref().map(Self::from_layout_js) } } fn owner_doc(&self) -> Self::ConcreteDocument { @@ -318,7 +281,7 @@ impl<'ln> LayoutNode<'ln> for ServoLayoutNode<'ln> { type ConcreteThreadSafeLayoutNode = ServoThreadSafeLayoutNode<'ln>; fn to_threadsafe(&self) -> Self::ConcreteThreadSafeLayoutNode { - ServoThreadSafeLayoutNode::new(self) + ServoThreadSafeLayoutNode::new(*self) } fn type_id(&self) -> LayoutNodeType { @@ -375,16 +338,15 @@ impl<'le> GetLayoutData<'le> for ServoThreadSafeLayoutElement<'le> { impl<'ln> ServoLayoutNode<'ln> { /// Returns the interior of this node as a `LayoutDom`. This is highly unsafe for layout to /// call and as such is marked `unsafe`. - pub unsafe fn get_jsmanaged(&self) -> &LayoutDom { - &self.node + pub unsafe fn get_jsmanaged(&self) -> LayoutDom<'ln, Node> { + self.node } } // A wrapper around documents that ensures ayout can only ever access safe properties. #[derive(Clone, Copy)] -pub struct ServoLayoutDocument<'ld> { - document: LayoutDom, - chain: PhantomData<&'ld ()>, +pub struct ServoLayoutDocument<'dom> { + document: LayoutDom<'dom, Document>, } impl<'ld> TDocument for ServoLayoutDocument<'ld> { @@ -453,19 +415,15 @@ impl<'ld> ServoLayoutDocument<'ld> { } } - pub fn from_layout_js(doc: LayoutDom) -> ServoLayoutDocument<'ld> { - ServoLayoutDocument { - document: doc, - chain: PhantomData, - } + pub fn from_layout_js(doc: LayoutDom<'ld, Document>) -> Self { + ServoLayoutDocument { document: doc } } } /// A wrapper around elements that ensures layout can only ever access safe properties. #[derive(Clone, Copy)] -pub struct ServoLayoutElement<'le> { - element: LayoutDom, - chain: PhantomData<&'le ()>, +pub struct ServoLayoutElement<'dom> { + element: LayoutDom<'dom, Element>, } impl<'le> fmt::Debug for ServoLayoutElement<'le> { @@ -746,11 +704,8 @@ impl<'le> Hash for ServoLayoutElement<'le> { impl<'le> Eq for ServoLayoutElement<'le> {} impl<'le> ServoLayoutElement<'le> { - fn from_layout_js(el: LayoutDom) -> ServoLayoutElement<'le> { - ServoLayoutElement { - element: el, - chain: PhantomData, - } + fn from_layout_js(el: LayoutDom<'le, Element>) -> Self { + ServoLayoutElement { element: el } } #[inline] @@ -796,7 +751,7 @@ impl<'le> ServoLayoutElement<'le> { } } -fn as_element<'le>(node: LayoutDom) -> Option> { +fn as_element<'dom>(node: LayoutDom<'dom, Node>) -> Option> { node.downcast().map(ServoLayoutElement::from_layout_js) } @@ -1051,29 +1006,20 @@ impl<'ln> DangerousThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> unsafe fn dangerous_first_child(&self) -> Option { self.get_jsmanaged() .first_child_ref() - .map(|node| self.new_with_this_lifetime(&node)) + .map(ServoLayoutNode::from_layout_js) + .map(Self::new) } unsafe fn dangerous_next_sibling(&self) -> Option { self.get_jsmanaged() .next_sibling_ref() - .map(|node| self.new_with_this_lifetime(&node)) + .map(ServoLayoutNode::from_layout_js) + .map(Self::new) } } impl<'ln> ServoThreadSafeLayoutNode<'ln> { - /// Creates a new layout node with the same lifetime as this layout node. - pub unsafe fn new_with_this_lifetime( - &self, - node: &LayoutDom, - ) -> ServoThreadSafeLayoutNode<'ln> { - ServoThreadSafeLayoutNode { - node: self.node.new_with_this_lifetime(node), - pseudo: PseudoElementType::Normal, - } - } - /// Creates a new `ServoThreadSafeLayoutNode` from the given `ServoLayoutNode`. - pub fn new<'a>(node: &ServoLayoutNode<'a>) -> ServoThreadSafeLayoutNode<'a> { + pub fn new(node: ServoLayoutNode<'ln>) -> Self { ServoThreadSafeLayoutNode { node: node.clone(), pseudo: PseudoElementType::Normal, @@ -1082,7 +1028,7 @@ impl<'ln> ServoThreadSafeLayoutNode<'ln> { /// Returns the interior of this node as a `LayoutDom`. This is highly unsafe for layout to /// call and as such is marked `unsafe`. - unsafe fn get_jsmanaged(&self) -> &LayoutDom { + unsafe fn get_jsmanaged(&self) -> LayoutDom<'ln, Node> { self.node.get_jsmanaged() } } diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 259a0d560c2..7dcc76e6caf 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -241,7 +241,7 @@ pub trait AttrHelpersForLayout { } #[allow(unsafe_code)] -impl AttrHelpersForLayout for LayoutDom { +impl AttrHelpersForLayout for LayoutDom<'_, Attr> { #[inline] unsafe fn value_forever(&self) -> &'static AttrValue { // This transmute is used to cheat the lifetime restriction. diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 0ba69687dba..b1739ac27c3 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -331,6 +331,7 @@ impl Dom { debug_assert!(thread_state::get().is_layout()); LayoutDom { ptr: self.ptr.clone(), + marker: PhantomData, } } } @@ -413,13 +414,17 @@ where /// An unrooted reference to a DOM object for use in layout. `Layout*Helpers` /// traits must be implemented on this. #[unrooted_must_root_lint::allow_unrooted_interior] -pub struct LayoutDom { +pub struct LayoutDom<'dom, T> { ptr: ptr::NonNull, + marker: PhantomData<&'dom T>, } -impl LayoutDom { +impl<'dom, T> LayoutDom<'dom, T> +where + T: Castable, +{ /// Cast a DOM object root upwards to one of the interfaces it derives from. - pub fn upcast(&self) -> LayoutDom + pub fn upcast(&self) -> LayoutDom<'dom, U> where U: Castable, T: DerivedFrom, @@ -428,11 +433,12 @@ impl LayoutDom { let ptr: *mut T = self.ptr.as_ptr(); LayoutDom { ptr: unsafe { ptr::NonNull::new_unchecked(ptr as *mut U) }, + marker: PhantomData, } } /// Cast a DOM object downwards to one of the interfaces it might implement. - pub fn downcast(&self) -> Option> + pub fn downcast(&self) -> Option> where U: DerivedFrom, { @@ -442,6 +448,7 @@ impl LayoutDom { let ptr: *mut T = self.ptr.as_ptr(); Some(LayoutDom { ptr: ptr::NonNull::new_unchecked(ptr as *mut U), + marker: PhantomData, }) } else { None @@ -450,7 +457,10 @@ impl LayoutDom { } } -impl LayoutDom { +impl LayoutDom<'_, T> +where + T: DomObject, +{ /// Get the reflector. pub unsafe fn get_jsobject(&self) -> *mut JSObject { debug_assert!(thread_state::get().is_layout()); @@ -458,7 +468,7 @@ impl LayoutDom { } } -impl Copy for LayoutDom {} +impl Copy for LayoutDom<'_, T> {} impl PartialEq for Dom { fn eq(&self, other: &Dom) -> bool { @@ -474,13 +484,13 @@ impl<'a, T: DomObject> PartialEq<&'a T> for Dom { impl Eq for Dom {} -impl PartialEq for LayoutDom { - fn eq(&self, other: &LayoutDom) -> bool { +impl PartialEq for LayoutDom<'_, T> { + fn eq(&self, other: &Self) -> bool { self.ptr.as_ptr() == other.ptr.as_ptr() } } -impl Eq for LayoutDom {} +impl Eq for LayoutDom<'_, T> {} impl Hash for Dom { fn hash(&self, state: &mut H) { @@ -488,7 +498,7 @@ impl Hash for Dom { } } -impl Hash for LayoutDom { +impl Hash for LayoutDom<'_, T> { fn hash(&self, state: &mut H) { self.ptr.as_ptr().hash(state) } @@ -497,7 +507,7 @@ impl Hash for LayoutDom { impl Clone for Dom { #[inline] #[allow(unrooted_must_root)] - fn clone(&self) -> Dom { + fn clone(&self) -> Self { debug_assert!(thread_state::get().is_script()); Dom { ptr: self.ptr.clone(), @@ -505,24 +515,26 @@ impl Clone for Dom { } } -impl Clone for LayoutDom { +impl Clone for LayoutDom<'_, T> { #[inline] - fn clone(&self) -> LayoutDom { + fn clone(&self) -> Self { debug_assert!(thread_state::get().is_layout()); LayoutDom { ptr: self.ptr.clone(), + marker: PhantomData, } } } -impl LayoutDom { +impl LayoutDom<'_, Node> { /// Create a new JS-owned value wrapped from an address known to be a /// `Node` pointer. - pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> LayoutDom { + pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> Self { debug_assert!(thread_state::get().is_layout()); let TrustedNodeAddress(addr) = inner; LayoutDom { ptr: ptr::NonNull::new_unchecked(addr as *const Node as *mut Node), + marker: PhantomData, } } } @@ -624,7 +636,7 @@ impl MutNullableDom { #[allow(unrooted_must_root)] pub unsafe fn get_inner_as_layout(&self) -> Option> { debug_assert!(thread_state::get().is_layout()); - ptr::read(self.ptr.get()).map(|js| js.to_layout()) + (*self.ptr.get()).as_ref().map(|js| js.to_layout()) } /// Get a rooted value out of this object @@ -732,7 +744,10 @@ unsafe impl JSTraceable for DomOnceCell { } } -impl LayoutDom { +impl<'dom, T> LayoutDom<'dom, T> +where + T: 'dom + DomObject, +{ /// Returns an unsafe pointer to the interior of this JS object. This is /// the only method that be safely accessed from layout. (The fact that /// this is unsafe is what necessitates the layout wrappers.) diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index fc34cab49eb..d6c01c6a145 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -157,7 +157,7 @@ pub trait LayoutCanvasRenderingContext2DHelpers { unsafe fn get_canvas_id(&self) -> CanvasId; } -impl LayoutCanvasRenderingContext2DHelpers for LayoutDom { +impl LayoutCanvasRenderingContext2DHelpers for LayoutDom<'_, CanvasRenderingContext2D> { #[allow(unsafe_code)] unsafe fn get_ipc_renderer(&self) -> IpcSender { (*self.unsafe_get()) diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index 6baa6a855d9..81456cfb60b 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -286,7 +286,7 @@ pub trait LayoutCharacterDataHelpers { } #[allow(unsafe_code)] -impl LayoutCharacterDataHelpers for LayoutDom { +impl LayoutCharacterDataHelpers for LayoutDom<'_, CharacterData> { #[inline] unsafe fn data_for_layout(&self) -> &str { &(*self.unsafe_get()).data.borrow_for_layout() diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 18d6e0cbd59..f119429e01f 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -2617,7 +2617,7 @@ pub trait LayoutDocumentHelpers { } #[allow(unsafe_code)] -impl LayoutDocumentHelpers for LayoutDom { +impl LayoutDocumentHelpers for LayoutDom<'_, Document> { #[inline] unsafe fn is_html_document_for_layout(&self) -> bool { (*self.unsafe_get()).is_html_document diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 9f20d31dbc6..70000fd95f7 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -567,11 +567,11 @@ pub trait RawLayoutElementHelpers { #[inline] #[allow(unsafe_code)] -pub unsafe fn get_attr_for_layout<'a>( - elem: &'a Element, +pub unsafe fn get_attr_for_layout<'dom>( + elem: &'dom Element, namespace: &Namespace, name: &LocalName, -) -> Option> { +) -> Option> { // cast to point to T in RefCell directly let attrs = elem.attrs.borrow_for_layout(); attrs @@ -620,7 +620,7 @@ impl RawLayoutElementHelpers for Element { } } -pub trait LayoutElementHelpers { +pub trait LayoutElementHelpers<'dom> { #[allow(unsafe_code)] unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool; #[allow(unsafe_code)] @@ -646,10 +646,10 @@ pub trait LayoutElementHelpers { fn has_selector_flags(&self, flags: ElementSelectorFlags) -> bool; /// The shadow root this element is a host of. #[allow(unsafe_code)] - unsafe fn get_shadow_root_for_layout(&self) -> Option>; + unsafe fn get_shadow_root_for_layout(&self) -> Option>; } -impl LayoutElementHelpers for LayoutDom { +impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> { #[allow(unsafe_code)] #[inline] unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool { @@ -1095,7 +1095,7 @@ impl LayoutElementHelpers for LayoutDom { #[inline] #[allow(unsafe_code)] - unsafe fn get_shadow_root_for_layout(&self) -> Option> { + unsafe fn get_shadow_root_for_layout(&self) -> Option> { (*self.unsafe_get()) .rare_data_for_layout() .as_ref()? diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index cc2e20e68a9..0f3a0d51e15 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -99,7 +99,7 @@ pub trait HTMLBodyElementLayoutHelpers { fn get_background(&self) -> Option; } -impl HTMLBodyElementLayoutHelpers for LayoutDom { +impl HTMLBodyElementLayoutHelpers for LayoutDom<'_, HTMLBodyElement> { #[allow(unsafe_code)] fn get_background_color(&self) -> Option { unsafe { diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 21a07120b77..208ee2d2bfa 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -120,7 +120,7 @@ pub trait LayoutHTMLCanvasElementHelpers { fn get_canvas_id_for_layout(&self) -> CanvasId; } -impl LayoutHTMLCanvasElementHelpers for LayoutDom { +impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> { #[allow(unsafe_code)] fn data(&self) -> HTMLCanvasData { unsafe { diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs index fe7b52c1100..cb130530703 100644 --- a/components/script/dom/htmlfontelement.rs +++ b/components/script/dom/htmlfontelement.rs @@ -106,7 +106,7 @@ pub trait HTMLFontElementLayoutHelpers { fn get_size(&self) -> Option; } -impl HTMLFontElementLayoutHelpers for LayoutDom { +impl HTMLFontElementLayoutHelpers for LayoutDom<'_, HTMLFontElement> { #[allow(unsafe_code)] fn get_color(&self) -> Option { unsafe { diff --git a/components/script/dom/htmlhrelement.rs b/components/script/dom/htmlhrelement.rs index 557e4fbcc19..a53d30e700b 100644 --- a/components/script/dom/htmlhrelement.rs +++ b/components/script/dom/htmlhrelement.rs @@ -70,7 +70,7 @@ pub trait HTMLHRLayoutHelpers { fn get_width(&self) -> LengthOrPercentageOrAuto; } -impl HTMLHRLayoutHelpers for LayoutDom { +impl HTMLHRLayoutHelpers for LayoutDom<'_, HTMLHRElement> { #[allow(unsafe_code)] fn get_color(&self) -> Option { unsafe { diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 17e38aec157..16c5c1433b6 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -486,7 +486,7 @@ pub trait HTMLIFrameElementLayoutMethods { fn get_height(&self) -> LengthOrPercentageOrAuto; } -impl HTMLIFrameElementLayoutMethods for LayoutDom { +impl HTMLIFrameElementLayoutMethods for LayoutDom<'_, HTMLIFrameElement> { #[inline] #[allow(unsafe_code)] fn pipeline_id(&self) -> Option { diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 3b4052e6b73..386a77041ac 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -1382,7 +1382,7 @@ pub trait LayoutHTMLImageElementHelpers { fn get_height(&self) -> LengthOrPercentageOrAuto; } -impl LayoutHTMLImageElementHelpers for LayoutDom { +impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> { #[allow(unsafe_code)] unsafe fn image(&self) -> Option> { (*self.unsafe_get()) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 083e977a566..05eca7b35eb 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -726,11 +726,14 @@ unsafe fn get_raw_textinput_value(input: LayoutDom) -> DOMStri .get_content() } -impl LayoutHTMLInputElementHelpers for LayoutDom { +impl LayoutHTMLInputElementHelpers for LayoutDom<'_, HTMLInputElement> { #[allow(unsafe_code)] unsafe fn value_for_layout(self) -> String { #[allow(unsafe_code)] - unsafe fn get_raw_attr_value(input: LayoutDom, default: &str) -> String { + unsafe fn get_raw_attr_value( + input: LayoutDom<'_, HTMLInputElement>, + default: &str, + ) -> String { let elem = input.upcast::(); let value = (*elem.unsafe_get()) .get_attr_val_for_layout(&ns!(), &local_name!("value")) diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index f8c686d34f2..f4833de4e51 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -2447,7 +2447,7 @@ pub trait LayoutHTMLMediaElementHelpers { fn data(&self) -> HTMLMediaData; } -impl LayoutHTMLMediaElementHelpers for LayoutDom { +impl LayoutHTMLMediaElementHelpers for LayoutDom<'_, HTMLMediaElement> { #[allow(unsafe_code)] fn data(&self) -> HTMLMediaData { let media = unsafe { &*self.unsafe_get() }; diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs index 95ccde45d81..aa3db5733bc 100644 --- a/components/script/dom/htmltablecellelement.rs +++ b/components/script/dom/htmltablecellelement.rs @@ -105,7 +105,7 @@ pub trait HTMLTableCellElementLayoutHelpers { } #[allow(unsafe_code)] -impl HTMLTableCellElementLayoutHelpers for LayoutDom { +impl HTMLTableCellElementLayoutHelpers for LayoutDom<'_, HTMLTableCellElement> { fn get_background_color(&self) -> Option { unsafe { (&*self.upcast::().unsafe_get()) diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index d25b81cb13f..5bdb7f75281 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -412,7 +412,7 @@ pub trait HTMLTableElementLayoutHelpers { fn get_width(&self) -> LengthOrPercentageOrAuto; } -impl HTMLTableElementLayoutHelpers for LayoutDom { +impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> { #[allow(unsafe_code)] fn get_background_color(&self) -> Option { unsafe { diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs index a99ecea162e..9a6b5b875cc 100644 --- a/components/script/dom/htmltablerowelement.rs +++ b/components/script/dom/htmltablerowelement.rs @@ -150,7 +150,7 @@ pub trait HTMLTableRowElementLayoutHelpers { } #[allow(unsafe_code)] -impl HTMLTableRowElementLayoutHelpers for LayoutDom { +impl HTMLTableRowElementLayoutHelpers for LayoutDom<'_, HTMLTableRowElement> { fn get_background_color(&self) -> Option { unsafe { (&*self.upcast::().unsafe_get()) diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs index 1410e0ee1a4..c680da2ad23 100644 --- a/components/script/dom/htmltablesectionelement.rs +++ b/components/script/dom/htmltablesectionelement.rs @@ -88,7 +88,7 @@ pub trait HTMLTableSectionElementLayoutHelpers { } #[allow(unsafe_code)] -impl HTMLTableSectionElementLayoutHelpers for LayoutDom { +impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElement> { fn get_background_color(&self) -> Option { unsafe { (&*self.upcast::().unsafe_get()) diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 0708b553442..8ee42bc2c86 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -66,7 +66,7 @@ pub trait LayoutHTMLTextAreaElementHelpers { fn get_rows(self) -> u32; } -impl LayoutHTMLTextAreaElementHelpers for LayoutDom { +impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> { #[allow(unrooted_must_root)] #[allow(unsafe_code)] unsafe fn value_for_layout(self) -> String { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 2d6b4b581f6..08fe3282be1 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1304,17 +1304,17 @@ pub unsafe fn from_untrusted_node_address( } #[allow(unsafe_code)] -pub trait LayoutNodeHelpers { +pub trait LayoutNodeHelpers<'dom> { unsafe fn type_id_for_layout(&self) -> NodeTypeId; - unsafe fn composed_parent_node_ref(&self) -> Option>; - unsafe fn first_child_ref(&self) -> Option>; - unsafe fn last_child_ref(&self) -> Option>; - unsafe fn prev_sibling_ref(&self) -> Option>; - unsafe fn next_sibling_ref(&self) -> Option>; + unsafe fn composed_parent_node_ref(&self) -> Option>; + unsafe fn first_child_ref(&self) -> Option>; + unsafe fn last_child_ref(&self) -> Option>; + unsafe fn prev_sibling_ref(&self) -> Option>; + unsafe fn next_sibling_ref(&self) -> Option>; - unsafe fn owner_doc_for_layout(&self) -> LayoutDom; - unsafe fn containing_shadow_root_for_layout(&self) -> Option>; + unsafe fn owner_doc_for_layout(&self) -> LayoutDom<'dom, Document>; + unsafe fn containing_shadow_root_for_layout(&self) -> Option>; unsafe fn is_element_for_layout(&self) -> bool; unsafe fn get_flag(&self, flag: NodeFlags) -> bool; @@ -1339,7 +1339,7 @@ pub trait LayoutNodeHelpers { fn opaque(&self) -> OpaqueNode; } -impl LayoutNodeHelpers for LayoutDom { +impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> { #[inline] #[allow(unsafe_code)] unsafe fn type_id_for_layout(&self) -> NodeTypeId { @@ -1354,7 +1354,7 @@ impl LayoutNodeHelpers for LayoutDom { #[inline] #[allow(unsafe_code)] - unsafe fn composed_parent_node_ref(&self) -> Option> { + unsafe fn composed_parent_node_ref(&self) -> Option> { let parent = (*self.unsafe_get()).parent_node.get_inner_as_layout(); if let Some(ref parent) = parent { if let Some(shadow_root) = parent.downcast::() { @@ -1366,31 +1366,31 @@ impl LayoutNodeHelpers for LayoutDom { #[inline] #[allow(unsafe_code)] - unsafe fn first_child_ref(&self) -> Option> { + unsafe fn first_child_ref(&self) -> Option> { (*self.unsafe_get()).first_child.get_inner_as_layout() } #[inline] #[allow(unsafe_code)] - unsafe fn last_child_ref(&self) -> Option> { + unsafe fn last_child_ref(&self) -> Option> { (*self.unsafe_get()).last_child.get_inner_as_layout() } #[inline] #[allow(unsafe_code)] - unsafe fn prev_sibling_ref(&self) -> Option> { + unsafe fn prev_sibling_ref(&self) -> Option> { (*self.unsafe_get()).prev_sibling.get_inner_as_layout() } #[inline] #[allow(unsafe_code)] - unsafe fn next_sibling_ref(&self) -> Option> { + unsafe fn next_sibling_ref(&self) -> Option> { (*self.unsafe_get()).next_sibling.get_inner_as_layout() } #[inline] #[allow(unsafe_code)] - unsafe fn owner_doc_for_layout(&self) -> LayoutDom { + unsafe fn owner_doc_for_layout(&self) -> LayoutDom<'dom, Document> { (*self.unsafe_get()) .owner_doc .get_inner_as_layout() @@ -1399,7 +1399,7 @@ impl LayoutNodeHelpers for LayoutDom { #[inline] #[allow(unsafe_code)] - unsafe fn containing_shadow_root_for_layout(&self) -> Option> { + unsafe fn containing_shadow_root_for_layout(&self) -> Option> { (*self.unsafe_get()) .rare_data_for_layout() .as_ref()? diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index 2324a685042..71db09f4671 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -239,8 +239,8 @@ impl ShadowRootMethods for ShadowRoot { } #[allow(unsafe_code)] -pub trait LayoutShadowRootHelpers { - unsafe fn get_host_for_layout(&self) -> LayoutDom; +pub trait LayoutShadowRootHelpers<'dom> { + unsafe fn get_host_for_layout(&self) -> LayoutDom<'dom, Element>; unsafe fn get_style_data_for_layout<'a, E: TElement>( &self, ) -> &'a AuthorStyles; @@ -252,10 +252,10 @@ pub trait LayoutShadowRootHelpers { ); } -impl LayoutShadowRootHelpers for LayoutDom { +impl<'dom> LayoutShadowRootHelpers<'dom> for LayoutDom<'dom, ShadowRoot> { #[inline] #[allow(unsafe_code)] - unsafe fn get_host_for_layout(&self) -> LayoutDom { + unsafe fn get_host_for_layout(&self) -> LayoutDom<'dom, Element> { (*self.unsafe_get()) .host .get_inner_as_layout() diff --git a/components/script/dom/svgsvgelement.rs b/components/script/dom/svgsvgelement.rs index 8671f8a9027..8c8c1dbb834 100644 --- a/components/script/dom/svgsvgelement.rs +++ b/components/script/dom/svgsvgelement.rs @@ -52,7 +52,7 @@ pub trait LayoutSVGSVGElementHelpers { fn data(&self) -> SVGSVGData; } -impl LayoutSVGSVGElementHelpers for LayoutDom { +impl LayoutSVGSVGElementHelpers for LayoutDom<'_, SVGSVGElement> { #[allow(unsafe_code, non_snake_case)] fn data(&self) -> SVGSVGData { unsafe { diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index fef9b062123..80f8d1bc0f5 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -3884,7 +3884,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { } } -impl LayoutCanvasWebGLRenderingContextHelpers for LayoutDom { +impl LayoutCanvasWebGLRenderingContextHelpers for LayoutDom<'_, WebGL2RenderingContext> { #[allow(unsafe_code)] unsafe fn canvas_data_source(&self) -> HTMLCanvasDataSource { let this = &*self.unsafe_get(); diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index dab9cf6dcf1..45d2f145e41 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -4450,7 +4450,7 @@ pub trait LayoutCanvasWebGLRenderingContextHelpers { unsafe fn canvas_data_source(&self) -> HTMLCanvasDataSource; } -impl LayoutCanvasWebGLRenderingContextHelpers for LayoutDom { +impl LayoutCanvasWebGLRenderingContextHelpers for LayoutDom<'_, WebGLRenderingContext> { #[allow(unsafe_code)] unsafe fn canvas_data_source(&self) -> HTMLCanvasDataSource { (*self.unsafe_get()).layout_handle()