mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Make layout methods accessing rare data be safe
They don't do anything fancy so there is no additional unsafety calling them compared to using LayoutDom in the first place, the usual story of all those changes.
This commit is contained in:
parent
414d477b54
commit
9c8540af5c
4 changed files with 36 additions and 41 deletions
|
@ -649,21 +649,17 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
|||
|
||||
/// The shadow root this element is a host of.
|
||||
fn shadow_root(&self) -> Option<ServoShadowRoot<'le>> {
|
||||
unsafe {
|
||||
self.element
|
||||
.get_shadow_root_for_layout()
|
||||
.map(ServoShadowRoot::from_layout_js)
|
||||
}
|
||||
self.element
|
||||
.get_shadow_root_for_layout()
|
||||
.map(ServoShadowRoot::from_layout_js)
|
||||
}
|
||||
|
||||
/// The shadow root which roots the subtree this element is contained in.
|
||||
fn containing_shadow(&self) -> Option<ServoShadowRoot<'le>> {
|
||||
unsafe {
|
||||
self.element
|
||||
.upcast()
|
||||
.containing_shadow_root_for_layout()
|
||||
.map(ServoShadowRoot::from_layout_js)
|
||||
}
|
||||
self.element
|
||||
.upcast()
|
||||
.containing_shadow_root_for_layout()
|
||||
.map(ServoShadowRoot::from_layout_js)
|
||||
}
|
||||
|
||||
fn local_name(&self) -> &LocalName {
|
||||
|
|
|
@ -656,21 +656,17 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
|||
|
||||
/// The shadow root this element is a host of.
|
||||
fn shadow_root(&self) -> Option<ServoShadowRoot<'le>> {
|
||||
unsafe {
|
||||
self.element
|
||||
.get_shadow_root_for_layout()
|
||||
.map(ServoShadowRoot::from_layout_js)
|
||||
}
|
||||
self.element
|
||||
.get_shadow_root_for_layout()
|
||||
.map(ServoShadowRoot::from_layout_js)
|
||||
}
|
||||
|
||||
/// The shadow root which roots the subtree this element is contained in.
|
||||
fn containing_shadow(&self) -> Option<ServoShadowRoot<'le>> {
|
||||
unsafe {
|
||||
self.element
|
||||
.upcast()
|
||||
.containing_shadow_root_for_layout()
|
||||
.map(ServoShadowRoot::from_layout_js)
|
||||
}
|
||||
self.element
|
||||
.upcast()
|
||||
.containing_shadow_root_for_layout()
|
||||
.map(ServoShadowRoot::from_layout_js)
|
||||
}
|
||||
|
||||
fn local_name(&self) -> &LocalName {
|
||||
|
|
|
@ -583,8 +583,7 @@ pub trait LayoutElementHelpers<'dom> {
|
|||
fn insert_selector_flags(self, flags: ElementSelectorFlags);
|
||||
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<LayoutDom<'dom, ShadowRoot>>;
|
||||
fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||
fn get_attr_for_layout(
|
||||
self,
|
||||
namespace: &Namespace,
|
||||
|
@ -1038,14 +1037,16 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
|||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>> {
|
||||
self.unsafe_get()
|
||||
.rare_data
|
||||
.borrow_for_layout()
|
||||
.as_ref()?
|
||||
.shadow_root
|
||||
.as_ref()
|
||||
.map(|sr| sr.to_layout())
|
||||
fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>> {
|
||||
unsafe {
|
||||
self.unsafe_get()
|
||||
.rare_data
|
||||
.borrow_for_layout()
|
||||
.as_ref()?
|
||||
.shadow_root
|
||||
.as_ref()
|
||||
.map(|sr| sr.to_layout())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1314,7 +1314,7 @@ pub trait LayoutNodeHelpers<'dom> {
|
|||
unsafe fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||
|
||||
unsafe fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>;
|
||||
unsafe fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||
fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||
|
||||
unsafe fn is_element_for_layout(self) -> bool;
|
||||
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
|
||||
|
@ -1399,14 +1399,16 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
|||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>> {
|
||||
self.unsafe_get()
|
||||
.rare_data
|
||||
.borrow_for_layout()
|
||||
.as_ref()?
|
||||
.containing_shadow_root
|
||||
.as_ref()
|
||||
.map(|sr| sr.to_layout())
|
||||
fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>> {
|
||||
unsafe {
|
||||
self.unsafe_get()
|
||||
.rare_data
|
||||
.borrow_for_layout()
|
||||
.as_ref()?
|
||||
.containing_shadow_root
|
||||
.as_ref()
|
||||
.map(|sr| sr.to_layout())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue