mirror of
https://github.com/servo/servo.git
synced 2025-07-27 01:00:41 +01:00
Fix Node::replace_with
This commit is contained in:
parent
8bab1cd7a4
commit
748dfdf575
2 changed files with 18 additions and 23 deletions
|
@ -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() {
|
|
||||||
None => {
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
Ok(())
|
let parent = if let Some(parent) = self.GetParentNode() {
|
||||||
},
|
parent
|
||||||
Some(ref parent_node) => {
|
} else {
|
||||||
// Step 2.
|
// Step 2.
|
||||||
let doc = self.owner_doc();
|
return Ok(());
|
||||||
let node = try!(doc.node_from_nodes_and_strings(nodes));
|
};
|
||||||
// Step 3.
|
// Step 3.
|
||||||
parent_node.ReplaceChild(node.r(), self).map(|_| ())
|
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
|
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue