Make LayoutShadowRootHelpers::get_host_for_layout be safe

This commit is contained in:
Anthony Ramine 2020-03-31 22:30:42 +02:00
parent 68d5cfffd5
commit f712b0bcf8
3 changed files with 10 additions and 8 deletions

View file

@ -170,7 +170,7 @@ impl<'lr> TShadowRoot for ServoShadowRoot<'lr> {
} }
fn host(&self) -> ServoLayoutElement<'lr> { fn host(&self) -> ServoLayoutElement<'lr> {
ServoLayoutElement::from_layout_js(unsafe { self.shadow_root.get_host_for_layout() }) ServoLayoutElement::from_layout_js(self.shadow_root.get_host_for_layout())
} }
fn style_data<'a>(&self) -> Option<&'a CascadeData> fn style_data<'a>(&self) -> Option<&'a CascadeData>

View file

@ -177,7 +177,7 @@ impl<'lr> TShadowRoot for ServoShadowRoot<'lr> {
} }
fn host(&self) -> ServoLayoutElement<'lr> { fn host(&self) -> ServoLayoutElement<'lr> {
ServoLayoutElement::from_layout_js(unsafe { self.shadow_root.get_host_for_layout() }) ServoLayoutElement::from_layout_js(self.shadow_root.get_host_for_layout())
} }
fn style_data<'a>(&self) -> Option<&'a CascadeData> fn style_data<'a>(&self) -> Option<&'a CascadeData>

View file

@ -240,7 +240,7 @@ impl ShadowRootMethods for ShadowRoot {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub trait LayoutShadowRootHelpers<'dom> { pub trait LayoutShadowRootHelpers<'dom> {
unsafe fn get_host_for_layout(self) -> LayoutDom<'dom, Element>; fn get_host_for_layout(self) -> LayoutDom<'dom, Element>;
unsafe fn get_style_data_for_layout(self) -> &'dom AuthorStyles<StyleSheetInDocument>; unsafe fn get_style_data_for_layout(self) -> &'dom AuthorStyles<StyleSheetInDocument>;
unsafe fn flush_stylesheets<E: TElement>( unsafe fn flush_stylesheets<E: TElement>(
self, self,
@ -253,11 +253,13 @@ pub trait LayoutShadowRootHelpers<'dom> {
impl<'dom> LayoutShadowRootHelpers<'dom> for LayoutDom<'dom, ShadowRoot> { impl<'dom> LayoutShadowRootHelpers<'dom> for LayoutDom<'dom, ShadowRoot> {
#[inline] #[inline]
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn get_host_for_layout(self) -> LayoutDom<'dom, Element> { fn get_host_for_layout(self) -> LayoutDom<'dom, Element> {
(*self.unsafe_get()) unsafe {
.host self.unsafe_get()
.get_inner_as_layout() .host
.expect("We should never do layout on a detached shadow root") .get_inner_as_layout()
.expect("We should never do layout on a detached shadow root")
}
} }
#[inline] #[inline]