Implement ParentNode attributes

This commit is contained in:
Anthony Ramine 2015-04-07 18:41:27 +02:00
parent e57630711f
commit 33f2cd29fd
15 changed files with 48 additions and 233 deletions

View file

@ -1378,6 +1378,21 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
}
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
fn GetFirstElementChild(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).child_elements().next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
fn GetLastElementChild(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_temporary).next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
fn ChildElementCount(self) -> u32 {
NodeCast::from_ref(self).child_elements().count() as u32
}
// http://dom.spec.whatwg.org/#dom-parentnode-queryselector
fn QuerySelector(self, selectors: DOMString) -> Fallible<Option<Temporary<Element>>> {
let root: JSRef<Node> = NodeCast::from_ref(self);

View file

@ -5,7 +5,8 @@
use dom::bindings::codegen::Bindings::DocumentFragmentBinding;
use dom::bindings::codegen::Bindings::DocumentFragmentBinding::DocumentFragmentMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast};
use dom::bindings::codegen::InheritTypes::DocumentFragmentDerived;
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
@ -56,6 +57,21 @@ impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> {
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
}
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
fn GetFirstElementChild(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).child_elements().next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
fn GetLastElementChild(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_temporary).next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
fn ChildElementCount(self) -> u32 {
NodeCast::from_ref(self).child_elements().count() as u32
}
// http://dom.spec.whatwg.org/#dom-parentnode-queryselector
fn QuerySelector(self, selectors: DOMString) -> Fallible<Option<Temporary<Element>>> {
let root: JSRef<Node> = NodeCast::from_ref(self);

View file

@ -1223,6 +1223,21 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
}
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
fn GetFirstElementChild(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).child_elements().next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
fn GetLastElementChild(self) -> Option<Temporary<Element>> {
NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_temporary).next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
fn ChildElementCount(self) -> u32 {
NodeCast::from_ref(self).child_elements().count() as u32
}
// http://dom.spec.whatwg.org/#dom-parentnode-queryselector
fn QuerySelector(self, selectors: DOMString) -> Fallible<Option<Temporary<Element>>> {
let root: JSRef<Node> = NodeCast::from_ref(self);

View file

@ -11,14 +11,13 @@
interface ParentNode {
[Constant]
readonly attribute HTMLCollection children;
/*
[Pure]
readonly attribute Element? firstElementChild;
[Pure]
readonly attribute Element? lastElementChild;
[Pure]
readonly attribute unsigned long childElementCount;
*/
// Not implemented yet
// void prepend((Node or DOMString)... nodes);
// void append((Node or DOMString)... nodes);

View file

@ -99,15 +99,6 @@
[Document interface: operation createTreeWalker(Node,unsigned long,NodeFilter)]
expected: FAIL
[Document interface: attribute firstElementChild]
expected: FAIL
[Document interface: attribute lastElementChild]
expected: FAIL
[Document interface: attribute childElementCount]
expected: FAIL
[Document interface: operation prepend([object Object\],[object Object\])]
expected: FAIL
@ -171,15 +162,6 @@
[DocumentFragment interface: operation getElementById(DOMString)]
expected: FAIL
[DocumentFragment interface: attribute firstElementChild]
expected: FAIL
[DocumentFragment interface: attribute lastElementChild]
expected: FAIL
[DocumentFragment interface: attribute childElementCount]
expected: FAIL
[DocumentFragment interface: operation prepend([object Object\],[object Object\])]
expected: FAIL
@ -198,15 +180,6 @@
[DocumentFragment interface: calling getElementById(DOMString) on document.createDocumentFragment() with too few arguments must throw TypeError]
expected: FAIL
[DocumentFragment interface: document.createDocumentFragment() must inherit property "firstElementChild" with the proper type (2)]
expected: FAIL
[DocumentFragment interface: document.createDocumentFragment() must inherit property "lastElementChild" with the proper type (3)]
expected: FAIL
[DocumentFragment interface: document.createDocumentFragment() must inherit property "childElementCount" with the proper type (4)]
expected: FAIL
[DocumentFragment interface: document.createDocumentFragment() must inherit property "prepend" with the proper type (5)]
expected: FAIL
@ -267,15 +240,6 @@
[Element interface: operation removeAttributeNode(Attr)]
expected: FAIL
[Element interface: attribute firstElementChild]
expected: FAIL
[Element interface: attribute lastElementChild]
expected: FAIL
[Element interface: attribute childElementCount]
expected: FAIL
[Element interface: operation prepend([object Object\],[object Object\])]
expected: FAIL
@ -333,15 +297,6 @@
[Element interface: calling removeAttributeNode(Attr) on element with too few arguments must throw TypeError]
expected: FAIL
[Element interface: element must inherit property "firstElementChild" with the proper type (28)]
expected: FAIL
[Element interface: element must inherit property "lastElementChild" with the proper type (29)]
expected: FAIL
[Element interface: element must inherit property "childElementCount" with the proper type (30)]
expected: FAIL
[Element interface: element must inherit property "prepend" with the proper type (31)]
expected: FAIL
@ -1026,15 +981,6 @@
[Document interface: xmlDoc must inherit property "createNodeIterator" with the proper type (25)]
expected: FAIL
[Document interface: xmlDoc must inherit property "firstElementChild" with the proper type (29)]
expected: FAIL
[Document interface: xmlDoc must inherit property "lastElementChild" with the proper type (30)]
expected: FAIL
[Document interface: xmlDoc must inherit property "childElementCount" with the proper type (31)]
expected: FAIL
[Document interface: xmlDoc must inherit property "prepend" with the proper type (32)]
expected: FAIL

View file

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

View file

@ -1,5 +0,0 @@
[Element-childElementCount-dynamic-add.html]
type: testharness
[Dynamic Adding of Elements]
expected: FAIL

View file

@ -1,5 +0,0 @@
[Element-childElementCount-dynamic-remove.html]
type: testharness
[Dynamic Removal of Elements]
expected: FAIL

View file

@ -1,5 +0,0 @@
[Element-childElementCount-nochild.html]
type: testharness
[childElementCount without Child Element Nodes]
expected: FAIL

View file

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

View file

@ -1,5 +0,0 @@
[Element-firstElementChild-namespace.html]
type: testharness
[firstElementChild with namespaces]
expected: FAIL

View file

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

View file

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

View file

@ -3,120 +3,48 @@
[testDiv.previousElementSibling]
expected: FAIL
[testDiv.childElementCount]
expected: FAIL
[testDiv.firstElementChild]
expected: FAIL
[testDiv.lastElementChild]
expected: FAIL
[detachedDiv.previousElementSibling]
expected: FAIL
[detachedDiv.nextElementSibling]
expected: FAIL
[detachedDiv.childElementCount]
expected: FAIL
[detachedDiv.firstElementChild]
expected: FAIL
[detachedDiv.lastElementChild]
expected: FAIL
[detachedPara1.previousElementSibling]
expected: FAIL
[detachedPara1.nextElementSibling]
expected: FAIL
[detachedPara1.childElementCount]
expected: FAIL
[detachedPara1.lastElementChild]
expected: FAIL
[detachedPara1.firstElementChild]
expected: FAIL
[detachedPara2.previousElementSibling]
expected: FAIL
[detachedPara2.nextElementSibling]
expected: FAIL
[detachedPara2.childElementCount]
expected: FAIL
[detachedPara2.lastElementChild]
expected: FAIL
[detachedPara2.firstElementChild]
expected: FAIL
[foreignPara1.previousElementSibling]
expected: FAIL
[foreignPara1.nextElementSibling]
expected: FAIL
[foreignPara1.childElementCount]
expected: FAIL
[foreignPara1.lastElementChild]
expected: FAIL
[foreignPara1.firstElementChild]
expected: FAIL
[foreignPara2.previousElementSibling]
expected: FAIL
[foreignPara2.nextElementSibling]
expected: FAIL
[foreignPara2.childElementCount]
expected: FAIL
[foreignPara2.lastElementChild]
expected: FAIL
[foreignPara2.firstElementChild]
expected: FAIL
[xmlElement.previousElementSibling]
expected: FAIL
[xmlElement.nextElementSibling]
expected: FAIL
[xmlElement.childElementCount]
expected: FAIL
[xmlElement.lastElementChild]
expected: FAIL
[xmlElement.firstElementChild]
expected: FAIL
[detachedXmlElement.previousElementSibling]
expected: FAIL
[detachedXmlElement.nextElementSibling]
expected: FAIL
[detachedXmlElement.childElementCount]
expected: FAIL
[detachedXmlElement.lastElementChild]
expected: FAIL
[detachedXmlElement.firstElementChild]
expected: FAIL
[detachedTextNode.wholeText]
expected: FAIL
@ -138,72 +66,26 @@
[paras[0\].nextElementSibling]
expected: FAIL
[paras[0\].childElementCount]
expected: FAIL
[paras[0\].lastElementChild]
expected: FAIL
[paras[0\].firstElementChild]
expected: FAIL
[paras[1\].previousElementSibling]
expected: FAIL
[paras[1\].nextElementSibling]
expected: FAIL
[paras[1\].childElementCount]
expected: FAIL
[paras[1\].lastElementChild]
expected: FAIL
[paras[1\].firstElementChild]
expected: FAIL
[paras[2\].previousElementSibling]
expected: FAIL
[paras[2\].nextElementSibling]
expected: FAIL
[paras[2\].childElementCount]
expected: FAIL
[paras[2\].lastElementChild]
expected: FAIL
[paras[2\].firstElementChild]
expected: FAIL
[paras[3\].previousElementSibling]
expected: FAIL
[paras[3\].nextElementSibling]
expected: FAIL
[paras[3\].childElementCount]
expected: FAIL
[paras[3\].lastElementChild]
expected: FAIL
[paras[3\].firstElementChild]
expected: FAIL
[paras[4\].previousElementSibling]
expected: FAIL
[paras[4\].nextElementSibling]
expected: FAIL
[paras[4\].childElementCount]
expected: FAIL
[paras[4\].lastElementChild]
expected: FAIL
[paras[4\].firstElementChild]
expected: FAIL

View file

@ -1191,15 +1191,6 @@
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "all" with the proper type (81)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "firstElementChild" with the proper type (84)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "lastElementChild" with the proper type (85)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "childElementCount" with the proper type (86)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "prepend" with the proper type (87)]
expected: FAIL
@ -2205,15 +2196,6 @@
[Element interface: calling removeAttributeNode(Attr) on document.createElement("noscript") with too few arguments must throw TypeError]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "firstElementChild" with the proper type (28)]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "lastElementChild" with the proper type (29)]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "childElementCount" with the proper type (30)]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "prepend" with the proper type (31)]
expected: FAIL