Auto merge of #5609 - nox:nondocumenttypechildnode, r=jdm

This commit is contained in:
bors-servo 2015-04-09 09:06:57 -05:00
commit bbe1403b27
12 changed files with 44 additions and 141 deletions

View file

@ -6,11 +6,13 @@
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
use dom::bindings::codegen::InheritTypes::{CharacterDataDerived, NodeCast};
use dom::bindings::codegen::InheritTypes::{CharacterDataDerived, ElementCast};
use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::error::{Fallible, ErrorResult};
use dom::bindings::error::Error::IndexSize;
use dom::bindings::js::JSRef;
use dom::bindings::js::{JSRef, Temporary};
use dom::document::Document;
use dom::element::Element;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId};
@ -127,5 +129,17 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
let node: JSRef<Node> = NodeCast::from_ref(self);
node.remove_self();
}
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
fn GetPreviousElementSibling(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).preceding_siblings()
.filter_map(ElementCast::to_temporary).next()
}
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
fn GetNextElementSibling(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).following_siblings()
.filter_map(ElementCast::to_temporary).next()
}
}

View file

@ -1178,6 +1178,18 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
Ok(())
}
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
fn GetPreviousElementSibling(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).preceding_siblings()
.filter_map(ElementCast::to_temporary).next()
}
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
fn GetNextElementSibling(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).following_siblings()
.filter_map(ElementCast::to_temporary).next()
}
// http://dom.spec.whatwg.org/#dom-parentnode-children
fn Children(self) -> Temporary<HTMLCollection> {
let window = window_from_node(self).root();

View file

@ -415,6 +415,7 @@ pub trait NodeHelpers<'a> {
fn rev_children(self) -> ReverseChildrenIterator;
fn child_elements(self) -> ChildElementIterator;
fn following_siblings(self) -> NodeChildrenIterator;
fn preceding_siblings(self) -> ReverseChildrenIterator;
fn is_in_doc(self) -> bool;
fn is_inclusive_ancestor_of(self, parent: JSRef<Node>) -> bool;
fn is_parent_of(self, child: JSRef<Node>) -> bool;
@ -764,6 +765,12 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
}
}
fn preceding_siblings(self) -> ReverseChildrenIterator {
ReverseChildrenIterator {
current: self.prev_sibling(),
}
}
fn is_parent_of(self, child: JSRef<Node>) -> bool {
match child.parent_node() {
Some(ref parent) if parent == &Temporary::from_rooted(self) => true,

View file

@ -26,3 +26,4 @@ interface CharacterData : Node {
};
CharacterData implements ChildNode;
CharacterData implements NonDocumentTypeChildNode;

View file

@ -16,10 +16,10 @@ interface ChildNode {
void remove();
};
// [NoInterfaceObject]
// interface NonDocumentTypeChildNode {
// [Pure]
// readonly attribute Element? previousElementSibling;
// [Pure]
// readonly attribute Element? nextElementSibling;
// };
[NoInterfaceObject]
interface NonDocumentTypeChildNode {
[Pure]
readonly attribute Element? previousElementSibling;
[Pure]
readonly attribute Element? nextElementSibling;
};

View file

@ -70,4 +70,5 @@ partial interface Element {
};
Element implements ChildNode;
Element implements NonDocumentTypeChildNode;
Element implements ParentNode;

View file

@ -246,12 +246,6 @@
[Element interface: operation queryAll(DOMString)]
expected: FAIL
[Element interface: attribute previousElementSibling]
expected: FAIL
[Element interface: attribute nextElementSibling]
expected: FAIL
[Element interface: operation before([object Object\],[object Object\])]
expected: FAIL
@ -315,12 +309,6 @@
[Element interface: calling queryAll(DOMString) on element with too few arguments must throw TypeError]
expected: FAIL
[Element interface: element must inherit property "previousElementSibling" with the proper type (37)]
expected: FAIL
[Element interface: element must inherit property "nextElementSibling" with the proper type (38)]
expected: FAIL
[Element interface: element must inherit property "before" with the proper type (39)]
expected: FAIL
@ -339,12 +327,6 @@
[NamedNodeMap interface: operation setNamedItemNS(Attr)]
expected: FAIL
[CharacterData interface: attribute previousElementSibling]
expected: FAIL
[CharacterData interface: attribute nextElementSibling]
expected: FAIL
[CharacterData interface: operation before([object Object\],[object Object\])]
expected: FAIL
@ -369,12 +351,6 @@
[Text interface: document.createTextNode("abc") must inherit property "wholeText" with the proper type (1)]
expected: FAIL
[CharacterData interface: document.createTextNode("abc") must inherit property "previousElementSibling" with the proper type (7)]
expected: FAIL
[CharacterData interface: document.createTextNode("abc") must inherit property "nextElementSibling" with the proper type (8)]
expected: FAIL
[CharacterData interface: document.createTextNode("abc") must inherit property "before" with the proper type (9)]
expected: FAIL
@ -387,12 +363,6 @@
[CharacterData interface: calling after([object Object\],[object Object\]) on document.createTextNode("abc") with too few arguments must throw TypeError]
expected: FAIL
[CharacterData interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "previousElementSibling" with the proper type (7)]
expected: FAIL
[CharacterData interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "nextElementSibling" with the proper type (8)]
expected: FAIL
[CharacterData interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "before" with the proper type (9)]
expected: FAIL
@ -408,12 +378,6 @@
[Comment interface object length]
expected: FAIL
[CharacterData interface: document.createComment("abc") must inherit property "previousElementSibling" with the proper type (7)]
expected: FAIL
[CharacterData interface: document.createComment("abc") must inherit property "nextElementSibling" with the proper type (8)]
expected: FAIL
[CharacterData interface: document.createComment("abc") must inherit property "before" with the proper type (9)]
expected: FAIL

View file

@ -1,5 +0,0 @@
[Element-nextElementSibling.html]
type: testharness
[nextElementSibling]
expected: FAIL

View file

@ -1,5 +0,0 @@
[Element-previousElementSibling.html]
type: testharness
[previousElementSibling]
expected: FAIL

View file

@ -1,5 +0,0 @@
[Element-siblingElement-null.html]
type: testharness
[Null test]
expected: FAIL

View file

@ -1,50 +1,5 @@
[Node-properties.html]
type: testharness
[testDiv.previousElementSibling]
expected: FAIL
[detachedDiv.previousElementSibling]
expected: FAIL
[detachedDiv.nextElementSibling]
expected: FAIL
[detachedPara1.previousElementSibling]
expected: FAIL
[detachedPara1.nextElementSibling]
expected: FAIL
[detachedPara2.previousElementSibling]
expected: FAIL
[detachedPara2.nextElementSibling]
expected: FAIL
[foreignPara1.previousElementSibling]
expected: FAIL
[foreignPara1.nextElementSibling]
expected: FAIL
[foreignPara2.previousElementSibling]
expected: FAIL
[foreignPara2.nextElementSibling]
expected: FAIL
[xmlElement.previousElementSibling]
expected: FAIL
[xmlElement.nextElementSibling]
expected: FAIL
[detachedXmlElement.previousElementSibling]
expected: FAIL
[detachedXmlElement.nextElementSibling]
expected: FAIL
[detachedTextNode.wholeText]
expected: FAIL
@ -60,33 +15,3 @@
[detachedXmlTextNode.wholeText]
expected: FAIL
[paras[0\].previousElementSibling]
expected: FAIL
[paras[0\].nextElementSibling]
expected: FAIL
[paras[1\].previousElementSibling]
expected: FAIL
[paras[1\].nextElementSibling]
expected: FAIL
[paras[2\].previousElementSibling]
expected: FAIL
[paras[2\].nextElementSibling]
expected: FAIL
[paras[3\].previousElementSibling]
expected: FAIL
[paras[3\].nextElementSibling]
expected: FAIL
[paras[4\].previousElementSibling]
expected: FAIL
[paras[4\].nextElementSibling]
expected: FAIL

View file

@ -2214,12 +2214,6 @@
[Element interface: calling queryAll(DOMString) on document.createElement("noscript") with too few arguments must throw TypeError]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "previousElementSibling" with the proper type (37)]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "nextElementSibling" with the proper type (38)]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "before" with the proper type (39)]
expected: FAIL