mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Ensure that it's safe to modify the DOM node pointers before doing so. Fixes #1224.
This commit is contained in:
parent
7dbabdd9e4
commit
f9f9c42ab7
3 changed files with 20 additions and 7 deletions
|
@ -274,7 +274,7 @@ impl Document {
|
||||||
}
|
}
|
||||||
has_title = true;
|
has_title = true;
|
||||||
for title_child in child.children() {
|
for title_child in child.children() {
|
||||||
child.remove_child(title_child);
|
child.RemoveChild(title_child);
|
||||||
}
|
}
|
||||||
child.AppendChild(self.CreateTextNode(abstract_self, title.clone()));
|
child.AppendChild(self.CreateTextNode(abstract_self, title.clone()));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -212,6 +212,8 @@ impl<'self> Element {
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.node.wait_until_safe_to_modify_dom();
|
||||||
|
|
||||||
// FIXME: reduce the time of `value.clone()`.
|
// FIXME: reduce the time of `value.clone()`.
|
||||||
let win = self.node.owner_doc().document().window;
|
let win = self.node.owner_doc().document().window;
|
||||||
let new_attr = Attr::new_ns(win, local_name.clone(), value.clone(),
|
let new_attr = Attr::new_ns(win, local_name.clone(), value.clone(),
|
||||||
|
|
|
@ -220,18 +220,28 @@ impl<View> TreeNodeRef<Node<View>> for AbstractNode<View> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_parent_node(node: &mut Node<View>, new_parent_node: Option<AbstractNode<View>>) {
|
fn set_parent_node(node: &mut Node<View>, new_parent_node: Option<AbstractNode<View>>) {
|
||||||
|
let doc = node.owner_doc();
|
||||||
|
doc.document().wait_until_safe_to_modify_dom();
|
||||||
node.parent_node = new_parent_node
|
node.parent_node = new_parent_node
|
||||||
}
|
}
|
||||||
fn set_first_child(node: &mut Node<View>, new_first_child: Option<AbstractNode<View>>) {
|
fn set_first_child(node: &mut Node<View>, new_first_child: Option<AbstractNode<View>>) {
|
||||||
|
let doc = node.owner_doc();
|
||||||
|
doc.document().wait_until_safe_to_modify_dom();
|
||||||
node.first_child = new_first_child
|
node.first_child = new_first_child
|
||||||
}
|
}
|
||||||
fn set_last_child(node: &mut Node<View>, new_last_child: Option<AbstractNode<View>>) {
|
fn set_last_child(node: &mut Node<View>, new_last_child: Option<AbstractNode<View>>) {
|
||||||
|
let doc = node.owner_doc();
|
||||||
|
doc.document().wait_until_safe_to_modify_dom();
|
||||||
node.last_child = new_last_child
|
node.last_child = new_last_child
|
||||||
}
|
}
|
||||||
fn set_prev_sibling(node: &mut Node<View>, new_prev_sibling: Option<AbstractNode<View>>) {
|
fn set_prev_sibling(node: &mut Node<View>, new_prev_sibling: Option<AbstractNode<View>>) {
|
||||||
|
let doc = node.owner_doc();
|
||||||
|
doc.document().wait_until_safe_to_modify_dom();
|
||||||
node.prev_sibling = new_prev_sibling
|
node.prev_sibling = new_prev_sibling
|
||||||
}
|
}
|
||||||
fn set_next_sibling(node: &mut Node<View>, new_next_sibling: Option<AbstractNode<View>>) {
|
fn set_next_sibling(node: &mut Node<View>, new_next_sibling: Option<AbstractNode<View>>) {
|
||||||
|
let doc = node.owner_doc();
|
||||||
|
doc.document().wait_until_safe_to_modify_dom();
|
||||||
node.next_sibling = new_next_sibling
|
node.next_sibling = new_next_sibling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,6 +553,10 @@ impl AbstractNode<ScriptView> {
|
||||||
self.node().AppendChild(self, node)
|
self.node().AppendChild(self, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn RemoveChild(self, node: AbstractNode<ScriptView>) -> Fallible<AbstractNode<ScriptView>> {
|
||||||
|
self.node().RemoveChild(self, node)
|
||||||
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#node-is-inserted
|
// http://dom.spec.whatwg.org/#node-is-inserted
|
||||||
fn node_inserted(self) {
|
fn node_inserted(self) {
|
||||||
assert!(self.parent_node().is_some());
|
assert!(self.parent_node().is_some());
|
||||||
|
@ -1072,8 +1086,6 @@ impl Node<ScriptView> {
|
||||||
pub fn SetTextContent(&mut self,
|
pub fn SetTextContent(&mut self,
|
||||||
abstract_self: AbstractNode<ScriptView>,
|
abstract_self: AbstractNode<ScriptView>,
|
||||||
value: Option<DOMString>) -> ErrorResult {
|
value: Option<DOMString>) -> ErrorResult {
|
||||||
self.wait_until_safe_to_modify_dom();
|
|
||||||
|
|
||||||
let value = null_str_as_empty(&value);
|
let value = null_str_as_empty(&value);
|
||||||
match self.type_id {
|
match self.type_id {
|
||||||
DocumentFragmentNodeTypeId | ElementNodeTypeId(*) => {
|
DocumentFragmentNodeTypeId | ElementNodeTypeId(*) => {
|
||||||
|
@ -1088,6 +1100,8 @@ impl Node<ScriptView> {
|
||||||
Node::replace_all(node, abstract_self);
|
Node::replace_all(node, abstract_self);
|
||||||
}
|
}
|
||||||
CommentNodeTypeId | TextNodeTypeId => {
|
CommentNodeTypeId | TextNodeTypeId => {
|
||||||
|
self.wait_until_safe_to_modify_dom();
|
||||||
|
|
||||||
do abstract_self.with_mut_characterdata() |characterdata| {
|
do abstract_self.with_mut_characterdata() |characterdata| {
|
||||||
characterdata.data = value.clone();
|
characterdata.data = value.clone();
|
||||||
|
|
||||||
|
@ -1104,11 +1118,10 @@ impl Node<ScriptView> {
|
||||||
pub fn InsertBefore(&self,
|
pub fn InsertBefore(&self,
|
||||||
node: AbstractNode<ScriptView>,
|
node: AbstractNode<ScriptView>,
|
||||||
child: Option<AbstractNode<ScriptView>>) -> Fallible<AbstractNode<ScriptView>> {
|
child: Option<AbstractNode<ScriptView>>) -> Fallible<AbstractNode<ScriptView>> {
|
||||||
self.wait_until_safe_to_modify_dom();
|
|
||||||
Node::pre_insert(node, node, child)
|
Node::pre_insert(node, node, child)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait_until_safe_to_modify_dom(&self) {
|
pub fn wait_until_safe_to_modify_dom(&self) {
|
||||||
let document = self.owner_doc();
|
let document = self.owner_doc();
|
||||||
document.document().wait_until_safe_to_modify_dom();
|
document.document().wait_until_safe_to_modify_dom();
|
||||||
}
|
}
|
||||||
|
@ -1116,7 +1129,6 @@ impl Node<ScriptView> {
|
||||||
pub fn AppendChild(&self,
|
pub fn AppendChild(&self,
|
||||||
abstract_self: AbstractNode<ScriptView>,
|
abstract_self: AbstractNode<ScriptView>,
|
||||||
node: AbstractNode<ScriptView>) -> Fallible<AbstractNode<ScriptView>> {
|
node: AbstractNode<ScriptView>) -> Fallible<AbstractNode<ScriptView>> {
|
||||||
self.wait_until_safe_to_modify_dom();
|
|
||||||
Node::pre_insert(node, abstract_self, None)
|
Node::pre_insert(node, abstract_self, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,7 +1139,6 @@ impl Node<ScriptView> {
|
||||||
pub fn RemoveChild(&self,
|
pub fn RemoveChild(&self,
|
||||||
abstract_self: AbstractNode<ScriptView>,
|
abstract_self: AbstractNode<ScriptView>,
|
||||||
node: AbstractNode<ScriptView>) -> Fallible<AbstractNode<ScriptView>> {
|
node: AbstractNode<ScriptView>) -> Fallible<AbstractNode<ScriptView>> {
|
||||||
self.wait_until_safe_to_modify_dom();
|
|
||||||
Node::pre_remove(node, abstract_self)
|
Node::pre_remove(node, abstract_self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue