aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-07-21 22:22:16 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-07-22 00:00:15 +0530
commit511e3337fb3b1839ac00039d56ef6861762ed5d1 (patch)
treecb639c29061d2ff689be088abf80538e0a1b924b /components/script/dom
parentf6f0a7e4aaaa3c1ec7aca3876b0b0fe9e5fca9aa (diff)
downloadservo-511e3337fb3b1839ac00039d56ef6861762ed5d1.tar.gz
servo-511e3337fb3b1839ac00039d56ef6861762ed5d1.zip
Fix rooting in script
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/js.rs6
-rw-r--r--components/script/dom/node.rs29
2 files changed, 21 insertions, 14 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index a4f21a2a43d..e5e9561a092 100644
--- a/components/script/dom/bindings/js.rs
+++ b/components/script/dom/bindings/js.rs
@@ -270,6 +270,12 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
pub unsafe fn get_inner_as_layout(&self) -> Option<LayoutJS<T>> {
self.ptr.get().map(|js| js.to_layout())
}
+
+ /// Get a rooted value out of this object
+ // FIXME(#6684)
+ pub fn get_rooted(&self) -> Option<Root<T>> {
+ self.get().map(|o| o.root())
+ }
}
impl<T: HeapGCValue+Copy> Default for MutNullableHeap<T> {
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index d7432c570b0..cdcc0b844af 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -328,14 +328,14 @@ impl<'a> PrivateNodeHelpers for &'a Node {
match before {
Some(ref before) => {
assert!(before.parent_node.get().map(Root::from_rooted).r() == Some(self));
- match before.prev_sibling.get() {
+ let prev_sibling = before.prev_sibling.get_rooted();
+ match prev_sibling {
None => {
assert!(Some(*before) == self.first_child.get().map(Root::from_rooted).r());
self.first_child.set(Some(JS::from_ref(new_child)));
},
Some(ref prev_sibling) => {
- let prev_sibling = prev_sibling.root();
- prev_sibling.r().next_sibling.set(Some(JS::from_ref(new_child)));
+ prev_sibling.next_sibling.set(Some(JS::from_ref(new_child)));
new_child.prev_sibling.set(Some(JS::from_ref(prev_sibling.r())));
},
}
@@ -343,11 +343,11 @@ impl<'a> PrivateNodeHelpers for &'a Node {
new_child.next_sibling.set(Some(JS::from_ref(before)));
},
None => {
- match self.last_child.get() {
+ let last_child = self.last_child.get_rooted();
+ match last_child {
None => self.first_child.set(Some(JS::from_ref(new_child))),
Some(ref last_child) => {
- let last_child = last_child.root();
- assert!(last_child.r().next_sibling.get().is_none());
+ assert!(last_child.next_sibling.get().is_none());
last_child.r().next_sibling.set(Some(JS::from_ref(new_child)));
new_child.prev_sibling.set(Some(JS::from_rooted(&last_child)));
}
@@ -365,22 +365,22 @@ impl<'a> PrivateNodeHelpers for &'a Node {
/// Fails unless `child` is a child of this node.
fn remove_child(self, child: &Node) {
assert!(child.parent_node.get().map(Root::from_rooted).r() == Some(self));
-
- match child.prev_sibling.get() {
+ let prev_sibling = child.prev_sibling.get_rooted();
+ match prev_sibling {
None => {
self.first_child.set(child.next_sibling.get());
}
Some(ref prev_sibling) => {
- prev_sibling.root().r().next_sibling.set(child.next_sibling.get());
+ prev_sibling.next_sibling.set(child.next_sibling.get());
}
}
-
- match child.next_sibling.get() {
+ let next_sibling = child.next_sibling.get_rooted();
+ match next_sibling {
None => {
self.last_child.set(child.prev_sibling.get());
}
Some(ref next_sibling) => {
- next_sibling.root().r().prev_sibling.set(child.prev_sibling.get());
+ next_sibling.prev_sibling.set(child.prev_sibling.get());
}
}
@@ -1476,9 +1476,10 @@ impl Node {
// https://dom.spec.whatwg.org/#concept-node-adopt
pub fn adopt(node: &Node, document: &Document) {
// Step 1.
- match node.parent_node.get() {
+ let parent_node = node.parent_node.get_rooted();
+ match parent_node {
Some(ref parent) => {
- Node::remove(node, parent.root().r(), SuppressObserver::Unsuppressed);
+ Node::remove(node, parent, SuppressObserver::Unsuppressed);
}
None => (),
}