From 33f2cd29fd8e0b21d046da76fddfa6aadc68171a Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 7 Apr 2015 18:41:27 +0200 Subject: [PATCH] Implement ParentNode attributes --- components/script/dom/document.rs | 15 +++ components/script/dom/documentfragment.rs | 18 ++- components/script/dom/element.rs | 15 +++ .../script/dom/webidls/ParentNode.webidl | 3 +- tests/wpt/metadata/dom/interfaces.html.ini | 54 -------- .../nodes/Element-childElement-null.html.ini | 5 - ...ent-childElementCount-dynamic-add.html.ini | 5 - ...-childElementCount-dynamic-remove.html.ini | 5 - ...Element-childElementCount-nochild.html.ini | 5 - .../nodes/Element-childElementCount.html.ini | 5 - ...ement-firstElementChild-namespace.html.ini | 5 - .../nodes/Element-firstElementChild.html.ini | 5 - .../nodes/Element-lastElementChild.html.ini | 5 - .../dom/nodes/Node-properties.html.ini | 118 ------------------ .../wpt/metadata/html/dom/interfaces.html.ini | 18 --- 15 files changed, 48 insertions(+), 233 deletions(-) delete mode 100644 tests/wpt/metadata/dom/nodes/Element-childElement-null.html.ini delete mode 100644 tests/wpt/metadata/dom/nodes/Element-childElementCount-dynamic-add.html.ini delete mode 100644 tests/wpt/metadata/dom/nodes/Element-childElementCount-dynamic-remove.html.ini delete mode 100644 tests/wpt/metadata/dom/nodes/Element-childElementCount-nochild.html.ini delete mode 100644 tests/wpt/metadata/dom/nodes/Element-childElementCount.html.ini delete mode 100644 tests/wpt/metadata/dom/nodes/Element-firstElementChild-namespace.html.ini delete mode 100644 tests/wpt/metadata/dom/nodes/Element-firstElementChild.html.ini delete mode 100644 tests/wpt/metadata/dom/nodes/Element-lastElementChild.html.ini diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 62fdfbeb109..dad3cf7c96a 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -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> { + NodeCast::from_ref(self).child_elements().next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild + fn GetLastElementChild(self) -> Option> { + 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>> { let root: JSRef = NodeCast::from_ref(self); diff --git a/components/script/dom/documentfragment.rs b/components/script/dom/documentfragment.rs index f8e76103d7d..2a61aa98460 100644 --- a/components/script/dom/documentfragment.rs +++ b/components/script/dom/documentfragment.rs @@ -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> { + NodeCast::from_ref(self).child_elements().next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild + fn GetLastElementChild(self) -> Option> { + 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>> { let root: JSRef = NodeCast::from_ref(self); diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index c3bf678a48d..e0e5534c79e 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -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> { + NodeCast::from_ref(self).child_elements().next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild + fn GetLastElementChild(self) -> Option> { + 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>> { let root: JSRef = NodeCast::from_ref(self); diff --git a/components/script/dom/webidls/ParentNode.webidl b/components/script/dom/webidls/ParentNode.webidl index daa4339611f..9df1143f625 100644 --- a/components/script/dom/webidls/ParentNode.webidl +++ b/components/script/dom/webidls/ParentNode.webidl @@ -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); diff --git a/tests/wpt/metadata/dom/interfaces.html.ini b/tests/wpt/metadata/dom/interfaces.html.ini index c3913ed9046..271ee13a1c6 100644 --- a/tests/wpt/metadata/dom/interfaces.html.ini +++ b/tests/wpt/metadata/dom/interfaces.html.ini @@ -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 diff --git a/tests/wpt/metadata/dom/nodes/Element-childElement-null.html.ini b/tests/wpt/metadata/dom/nodes/Element-childElement-null.html.ini deleted file mode 100644 index 818ba86101a..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-childElement-null.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-childElement-null.html] - type: testharness - [Null test] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-childElementCount-dynamic-add.html.ini b/tests/wpt/metadata/dom/nodes/Element-childElementCount-dynamic-add.html.ini deleted file mode 100644 index a4a5567bce9..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-childElementCount-dynamic-add.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-childElementCount-dynamic-add.html] - type: testharness - [Dynamic Adding of Elements] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-childElementCount-dynamic-remove.html.ini b/tests/wpt/metadata/dom/nodes/Element-childElementCount-dynamic-remove.html.ini deleted file mode 100644 index b6e76d17946..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-childElementCount-dynamic-remove.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-childElementCount-dynamic-remove.html] - type: testharness - [Dynamic Removal of Elements] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-childElementCount-nochild.html.ini b/tests/wpt/metadata/dom/nodes/Element-childElementCount-nochild.html.ini deleted file mode 100644 index 0428d706422..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-childElementCount-nochild.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-childElementCount-nochild.html] - type: testharness - [childElementCount without Child Element Nodes] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-childElementCount.html.ini b/tests/wpt/metadata/dom/nodes/Element-childElementCount.html.ini deleted file mode 100644 index d31cb1aacae..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-childElementCount.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-childElementCount.html] - type: testharness - [childElementCount] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-firstElementChild-namespace.html.ini b/tests/wpt/metadata/dom/nodes/Element-firstElementChild-namespace.html.ini deleted file mode 100644 index 668880f53dc..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-firstElementChild-namespace.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-firstElementChild-namespace.html] - type: testharness - [firstElementChild with namespaces] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-firstElementChild.html.ini b/tests/wpt/metadata/dom/nodes/Element-firstElementChild.html.ini deleted file mode 100644 index 1c1a15cc8aa..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-firstElementChild.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-firstElementChild.html] - type: testharness - [firstElementChild] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-lastElementChild.html.ini b/tests/wpt/metadata/dom/nodes/Element-lastElementChild.html.ini deleted file mode 100644 index fc91e280383..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-lastElementChild.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-lastElementChild.html] - type: testharness - [lastElementChild] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Node-properties.html.ini b/tests/wpt/metadata/dom/nodes/Node-properties.html.ini index 94e5d7b9725..41bd3f2f43f 100644 --- a/tests/wpt/metadata/dom/nodes/Node-properties.html.ini +++ b/tests/wpt/metadata/dom/nodes/Node-properties.html.ini @@ -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 - diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 6bb217f0051..3650080b4a2 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -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