Skip to content

Commit

Permalink
Don't borrow CharacterData.data from layout.
Browse files Browse the repository at this point in the history
This should fix the most frequent intermittent wpt failure.
  • Loading branch information
Ms2ger committed Oct 14, 2014
1 parent fd70b36 commit 16e0711
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/layout/wrapper.rs
Expand Up @@ -189,7 +189,7 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> {
unsafe {
if self.get().is_text() {
let text: JS<Text> = self.get_jsmanaged().transmute_copy();
(*text.unsafe_get()).characterdata().data().clone()
(*text.unsafe_get()).characterdata().data_for_layout().to_string()
} else if self.get().is_htmlinputelement() {
let input: JS<HTMLInputElement> = self.get_jsmanaged().transmute_copy();
input.get_value_for_layout()
Expand Down Expand Up @@ -765,7 +765,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
Some(TextNodeTypeId) => {
unsafe {
let text: JS<Text> = self.get_jsmanaged().transmute_copy();
if !is_whitespace((*text.unsafe_get()).characterdata().data().as_slice()) {
if !is_whitespace((*text.unsafe_get()).characterdata().data_for_layout()) {
return false
}

Expand Down
7 changes: 7 additions & 0 deletions components/script/dom/characterdata.rs
Expand Up @@ -15,6 +15,7 @@ use dom::node::{CommentNodeTypeId, Node, NodeTypeId, TextNodeTypeId, ProcessingI
use servo_util::str::DOMString;

use std::cell::{Ref, RefCell};
use std::mem;

#[jstraceable]
#[must_root]
Expand Down Expand Up @@ -57,6 +58,12 @@ impl CharacterData {
pub fn set_data(&self, data: DOMString) {
*self.data.borrow_mut() = data;
}

#[inline]
pub unsafe fn data_for_layout<'a>(&'a self) -> &'a str {
mem::transmute::<&RefCell<DOMString>, &DOMString>(&self.data).as_slice()
}

}

impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
Expand Down

5 comments on commit 16e0711

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from Manishearth
at Ms2ger@16e0711

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Ms2ger/servo/no-text-borrow = 16e0711 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ms2ger/servo/no-text-borrow = 16e0711 merged ok, testing candidate = 083bf27

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 083bf27

Please sign in to comment.