script: Fix remaining bugs from Range.deleteContents

This commit is contained in:
Emilio Cobos Álvarez 2016-02-28 18:21:08 +01:00
parent be6940db59
commit 3e36739e38
3 changed files with 42 additions and 43 deletions

View file

@ -1051,21 +1051,18 @@ pub struct FollowingNodeIterator {
root: Root<Node>,
}
impl Iterator for FollowingNodeIterator {
type Item = Root<Node>;
// https://dom.spec.whatwg.org/#concept-tree-following
fn next(&mut self) -> Option<Root<Node>> {
impl FollowingNodeIterator {
/// Skips iterating the children of the current node
pub fn next_skipping_children(&mut self) -> Option<Root<Node>> {
let current = match self.current.take() {
None => return None,
Some(current) => current,
};
if let Some(first_child) = current.GetFirstChild() {
self.current = Some(first_child);
return current.GetFirstChild()
self.next_skipping_children_impl(current)
}
fn next_skipping_children_impl(&mut self, current: Root<Node>) -> Option<Root<Node>> {
if self.root == current {
self.current = None;
return None;
@ -1090,6 +1087,25 @@ impl Iterator for FollowingNodeIterator {
}
}
impl Iterator for FollowingNodeIterator {
type Item = Root<Node>;
// https://dom.spec.whatwg.org/#concept-tree-following
fn next(&mut self) -> Option<Root<Node>> {
let current = match self.current.take() {
None => return None,
Some(current) => current,
};
if let Some(first_child) = current.GetFirstChild() {
self.current = Some(first_child);
return current.GetFirstChild()
}
self.next_skipping_children_impl(current)
}
}
pub struct PrecedingNodeIterator {
current: Option<Root<Node>>,
root: Root<Node>,

View file

@ -750,7 +750,7 @@ impl RangeMethods for Range {
if let Some(text) = start_node.downcast::<CharacterData>() {
return text.ReplaceData(start_offset,
end_offset - start_offset,
DOMString::from(""));
DOMString::new());
}
}
@ -758,10 +758,15 @@ impl RangeMethods for Range {
let mut contained_children: RootedVec<JS<Node>> = RootedVec::new();
let ancestor = self.CommonAncestorContainer();
for child in start_node.following_nodes(ancestor.r()) {
if self.contains(child.r()) &&
!contained_children.contains(&JS::from_ref(child.GetParentNode().unwrap().r())) {
let mut iter = start_node.following_nodes(ancestor.r());
let mut next = iter.next();
while let Some(child) = next {
if self.contains(child.r()) {
contained_children.push(JS::from_ref(child.r()));
next = iter.next_skipping_children();
} else {
next = iter.next();
}
}
@ -778,7 +783,7 @@ impl RangeMethods for Range {
}
reference_node = parent;
}
panic!()
unreachable!()
}
compute_reference(start_node.r(), end_node.r())
@ -786,9 +791,9 @@ impl RangeMethods for Range {
// Step 7.
if let Some(text) = start_node.downcast::<CharacterData>() {
try!(text.ReplaceData(start_offset,
text.ReplaceData(start_offset,
start_node.len() - start_offset,
DOMString::from("")));
DOMString::new()).unwrap();
}
// Step 8.
@ -798,12 +803,13 @@ impl RangeMethods for Range {
// Step 9.
if let Some(text) = end_node.downcast::<CharacterData>() {
try!(text.ReplaceData(0, end_offset, DOMString::from("")));
text.ReplaceData(0, end_offset, DOMString::new()).unwrap();
}
// Step 10.
try!(self.SetStart(new_node.r(), new_offset));
self.SetEnd(new_node.r(), new_offset)
self.SetStart(new_node.r(), new_offset).unwrap();
self.SetEnd(new_node.r(), new_offset).unwrap();
Ok(())
}
// https://dom.spec.whatwg.org/#dom-range-surroundcontents

View file

@ -1,23 +0,0 @@
[Range-deleteContents.html]
type: testharness
[Resulting DOM for range 24 [document, 0, document, 2\]]
expected: FAIL
[Resulting DOM for range 10 [document.documentElement, 0, document.documentElement, 1\]]
expected: FAIL
[Resulting DOM for range 11 [document.documentElement, 0, document.documentElement, 2\]]
expected: FAIL
[Resulting DOM for range 12 [document.documentElement, 1, document.documentElement, 2\]]
expected: FAIL
[Resulting DOM for range 15 [foreignDoc.documentElement, 0, foreignDoc.documentElement, 1\]]
expected: FAIL
[Resulting DOM for range 27 [foreignDoc, 1, foreignComment, 2\]]
expected: FAIL
[Resulting DOM for range 49 [document, 1, document, 2\]]
expected: FAIL