diff options
-rw-r--r-- | components/script/dom/node.rs | 30 | ||||
-rw-r--r-- | tests/wpt/metadata/dom/nodes/ChildNode-replaceWith.html.ini | 11 |
2 files changed, 18 insertions, 23 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 30aa8e78eea..3ef0c9ca5a4 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -666,19 +666,25 @@ impl Node { // https://dom.spec.whatwg.org/#dom-childnode-replacewith pub fn replace_with(&self, nodes: Vec<NodeOrString>) -> ErrorResult { - match self.parent_node.get() { - None => { - // Step 1. - Ok(()) - }, - Some(ref parent_node) => { - // Step 2. - let doc = self.owner_doc(); - let node = try!(doc.node_from_nodes_and_strings(nodes)); - // Step 3. - parent_node.ReplaceChild(node.r(), self).map(|_| ()) - }, + // Step 1. + let parent = if let Some(parent) = self.GetParentNode() { + parent + } else { + // Step 2. + return Ok(()); + }; + // Step 3. + let viable_next_sibling = first_node_not_in(self.following_siblings(), &nodes); + // Step 4. + 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 diff --git a/tests/wpt/metadata/dom/nodes/ChildNode-replaceWith.html.ini b/tests/wpt/metadata/dom/nodes/ChildNode-replaceWith.html.ini deleted file mode 100644 index 5c76bf364ac..00000000000 --- a/tests/wpt/metadata/dom/nodes/ChildNode-replaceWith.html.ini +++ /dev/null @@ -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 - |