Fix Node::replace_with

This commit is contained in:
Anthony Ramine 2015-12-14 00:13:56 +01:00
parent 8bab1cd7a4
commit 748dfdf575
2 changed files with 18 additions and 23 deletions

View file

@ -666,19 +666,25 @@ impl Node {
// https://dom.spec.whatwg.org/#dom-childnode-replacewith // https://dom.spec.whatwg.org/#dom-childnode-replacewith
pub fn replace_with(&self, nodes: Vec<NodeOrString>) -> ErrorResult { pub fn replace_with(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
match self.parent_node.get() { // Step 1.
None => { let parent = if let Some(parent) = self.GetParentNode() {
// Step 1. parent
Ok(()) } else {
}, // Step 2.
Some(ref parent_node) => { return Ok(());
// Step 2. };
let doc = self.owner_doc(); // Step 3.
let node = try!(doc.node_from_nodes_and_strings(nodes)); let viable_next_sibling = first_node_not_in(self.following_siblings(), &nodes);
// Step 3. // Step 4.
parent_node.ReplaceChild(node.r(), self).map(|_| ()) let node = try!(self.owner_doc().node_from_nodes_and_strings(nodes));
}, if self.parent_node == Some(&*parent) {
// Step 5.
try!(parent.ReplaceChild(&node, self));
} else {
// Step 6.
try!(Node::pre_insert(&node, &parent, viable_next_sibling.r()));
} }
Ok(())
} }
// https://dom.spec.whatwg.org/#dom-parentnode-prepend // https://dom.spec.whatwg.org/#dom-parentnode-prepend

View file

@ -1,11 +0,0 @@
[ChildNode-replaceWith.html]
type: testharness
[Comment.replaceWith() with one sibling of child and child itself as arguments.]
expected: FAIL
[Element.replaceWith() with one sibling of child and child itself as arguments.]
expected: FAIL
[Text.replaceWith() with one sibling of child and child itself as arguments.]
expected: FAIL