mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Make LayoutCharacterDataHelpers::data_for_layout be safe
This commit is contained in:
parent
00c5ec202c
commit
409bd3d989
4 changed files with 7 additions and 9 deletions
|
@ -828,7 +828,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
|||
.dom_children()
|
||||
.all(|node| match node.script_type_id() {
|
||||
NodeTypeId::Element(..) => false,
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => unsafe {
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => {
|
||||
node.node.downcast().unwrap().data_for_layout().is_empty()
|
||||
},
|
||||
_ => true,
|
||||
|
|
|
@ -835,7 +835,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
|||
.dom_children()
|
||||
.all(|node| match node.script_type_id() {
|
||||
NodeTypeId::Element(..) => false,
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => unsafe {
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => {
|
||||
node.node.downcast().unwrap().data_for_layout().is_empty()
|
||||
},
|
||||
_ => true,
|
||||
|
|
|
@ -280,16 +280,15 @@ impl CharacterDataMethods for CharacterData {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub trait LayoutCharacterDataHelpers<'dom> {
|
||||
unsafe fn data_for_layout(self) -> &'dom str;
|
||||
fn data_for_layout(self) -> &'dom str;
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl<'dom> LayoutCharacterDataHelpers<'dom> for LayoutDom<'dom, CharacterData> {
|
||||
#[allow(unsafe_code)]
|
||||
#[inline]
|
||||
unsafe fn data_for_layout(self) -> &'dom str {
|
||||
&(*self.unsafe_get()).data.borrow_for_layout()
|
||||
fn data_for_layout(self) -> &'dom str {
|
||||
unsafe { self.unsafe_get().data.borrow_for_layout() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1456,10 +1456,9 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
|||
val
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn text_content(self) -> String {
|
||||
if let Some(text) = self.downcast::<Text>() {
|
||||
return unsafe { text.upcast().data_for_layout().to_owned() };
|
||||
return text.upcast().data_for_layout().to_owned();
|
||||
}
|
||||
|
||||
if let Some(input) = self.downcast::<HTMLInputElement>() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue