Title: [184420] trunk
Revision
184420
Author
[email protected]
Date
2015-05-15 15:55:53 -0700 (Fri, 15 May 2015)

Log Message

Move HTMLElement's children property to ParentNode
https://bugs.webkit.org/show_bug.cgi?id=145072

Reviewed by Chris Dumez.

Source/WebCore:

Match the latest DOM standard and other browsers by moving the children property
to ParentNode, thus exposing it on Element, Document and DocumentFragment.

Test: fast/dom/ParentNode-children.html

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::children):
Moved implementation from HTMLElement to here.

(WebCore::ContainerNode::ensureCachedHTMLCollection):
(WebCore::ContainerNode::cachedHTMLCollection):
Moved implementation from Element to here so that ContainerNode::children
can use it.

(WebCore::ContainerNode::firstElementChild):
(WebCore::ContainerNode::lastElementChild):
(WebCore::ContainerNode::childElementCount):
Remove unnecessary assertions.

* dom/ContainerNode.h:
Moved declarations from HTMLElement and Element to here.

* dom/Element.cpp:
(WebCore::Element::ensureCachedHTMLCollection): Deleted.
(WebCore::Element::cachedHTMLCollection): Deleted.
* dom/Element.h:
Moved to ContainerNode.

* dom/Node.cpp:
(WebCore::Node::previousElementSibling):
(WebCore::Node::nextElementSibling):
Remove unnecessary assertions.

* dom/ParentNode.idl:
Moved the children property here from HTMLElement.

* html/HTMLElement.cpp:
(WebCore::HTMLElement::children): Deleted.
* html/HTMLElement.h:
Moved to ContainerNode.

* html/HTMLElement.idl:
Get rid of the children property for all bindings except Objective-C which needs
to keep it to avoid changing the public API.

LayoutTests:

* fast/dom/ParentNode-children-expected.txt: Added.
* fast/dom/ParentNode-children.html: Added.
Test children on Element, Document and DocumentFragment.

* fast/dom/xmlserializer-serialize-to-string-exception-expected.txt:
Update results since document.children is no longer undefined.

* js/dom/dom-static-property-for-in-iteration-expected.txt:
Update results.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (184419 => 184420)


--- trunk/LayoutTests/ChangeLog	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/LayoutTests/ChangeLog	2015-05-15 22:55:53 UTC (rev 184420)
@@ -1,3 +1,20 @@
+2015-05-15  Sam Weinig  <[email protected]>
+
+        Move HTMLElement's children property to ParentNode
+        https://bugs.webkit.org/show_bug.cgi?id=145072
+
+        Reviewed by Chris Dumez.
+
+        * fast/dom/ParentNode-children-expected.txt: Added.
+        * fast/dom/ParentNode-children.html: Added.
+        Test children on Element, Document and DocumentFragment.
+
+        * fast/dom/xmlserializer-serialize-to-string-exception-expected.txt:
+        Update results since document.children is no longer undefined.
+
+        * js/dom/dom-static-property-for-in-iteration-expected.txt:
+        Update results.
+
 2015-05-15  Zalan Bujtas  <[email protected]>
 
         White edge on animating panel on http://rokkosunnyvale.com

Added: trunk/LayoutTests/fast/dom/ParentNode-children-expected.txt (0 => 184420)


--- trunk/LayoutTests/fast/dom/ParentNode-children-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/ParentNode-children-expected.txt	2015-05-15 22:55:53 UTC (rev 184420)
@@ -0,0 +1,20 @@
+Tests the basic functionality of the `children` property on ParentNode.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.children is an instance of HTMLCollection
+PASS document.documentElement.children is an instance of HTMLCollection
+PASS document.createDocumentFragment().children is an instance of HTMLCollection
+PASS document.children.length is 1
+PASS document.children[0] is document.documentElement
+PASS document.documentElement.children.length is 2
+PASS document.documentElement.children[0] is document.head
+PASS document.documentElement.children[1] is document.body
+PASS documentFragment.children.length is 2
+PASS documentFragment.children[0] is child1
+PASS documentFragment.children[1] is child2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/ParentNode-children.html (0 => 184420)


--- trunk/LayoutTests/fast/dom/ParentNode-children.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/ParentNode-children.html	2015-05-15 22:55:53 UTC (rev 184420)
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<script>
+
+description("Tests the basic functionality of the `children` property on ParentNode.");
+
+shouldBeType("document.children", "HTMLCollection");
+shouldBeType("document.documentElement.children", "HTMLCollection");
+shouldBeType("document.createDocumentFragment().children", "HTMLCollection");
+
+shouldBe("document.children.length", "1");
+shouldBe("document.children[0]", "document.documentElement");
+
+shouldBe("document.documentElement.children.length", "2");
+shouldBe("document.documentElement.children[0]", "document.head");
+shouldBe("document.documentElement.children[1]", "document.body");
+
+var documentFragment = document.createDocumentFragment();
+var child1 = document.createElement("div");
+var child2 = document.createElement("div");
+documentFragment.appendChild(child1);
+documentFragment.appendChild(child2);
+
+shouldBe("documentFragment.children.length", "2");
+shouldBe("documentFragment.children[0]", "child1");
+shouldBe("documentFragment.children[1]", "child2");
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/fast/dom/xmlserializer-serialize-to-string-exception-expected.txt (184419 => 184420)


--- trunk/LayoutTests/fast/dom/xmlserializer-serialize-to-string-exception-expected.txt	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/LayoutTests/fast/dom/xmlserializer-serialize-to-string-exception-expected.txt	2015-05-15 22:55:53 UTC (rev 184420)
@@ -12,7 +12,7 @@
 Exception thrown = [TypeError: Type error]
 PASS
 
-4. Verifying XMLSerializer.serializeToString() should THROW exception with node value = undefined
+4. Verifying XMLSerializer.serializeToString() should THROW exception with node value = [object HTMLCollection]
 Exception thrown = [TypeError: Type error]
 PASS
 

Modified: trunk/LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt (184419 => 184420)


--- trunk/LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt	2015-05-15 22:55:53 UTC (rev 184420)
@@ -39,7 +39,6 @@
 PASS a["accessKey"] is 
 PASS a["innerText"] is nerget
 PASS a["outerText"] is nerget
-PASS a["children"] is [object HTMLCollection]
 PASS a["contentEditable"] is inherit
 PASS a["isContentEditable"] is false
 PASS a["spellcheck"] is true
@@ -48,7 +47,7 @@
 PASS a["style"] is [object CSSStyleDeclaration]
 PASS a["id"] is foo
 PASS a["offsetLeft"] is 8
-PASS a["offsetTop"] is 759
+PASS a["offsetTop"] is 744
 PASS a["offsetWidth"] is 40
 PASS a["offsetHeight"] is 18
 PASS a["clientLeft"] is 0
@@ -69,6 +68,7 @@
 PASS a["webkitRegionOverset"] is undefined
 PASS a["previousElementSibling"] is [object HTMLDivElement]
 PASS a["nextElementSibling"] is [object HTMLScriptElement]
+PASS a["children"] is [object HTMLCollection]
 PASS a["firstElementChild"] is null
 PASS a["lastElementChild"] is null
 PASS a["childElementCount"] is 0

Modified: trunk/Source/WebCore/ChangeLog (184419 => 184420)


--- trunk/Source/WebCore/ChangeLog	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/ChangeLog	2015-05-15 22:55:53 UTC (rev 184420)
@@ -1,3 +1,55 @@
+2015-05-15  Sam Weinig  <[email protected]>
+
+        Move HTMLElement's children property to ParentNode
+        https://bugs.webkit.org/show_bug.cgi?id=145072
+
+        Reviewed by Chris Dumez.
+
+        Match the latest DOM standard and other browsers by moving the children property
+        to ParentNode, thus exposing it on Element, Document and DocumentFragment.
+
+        Test: fast/dom/ParentNode-children.html
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::children):
+        Moved implementation from HTMLElement to here.
+
+        (WebCore::ContainerNode::ensureCachedHTMLCollection):
+        (WebCore::ContainerNode::cachedHTMLCollection):
+        Moved implementation from Element to here so that ContainerNode::children
+        can use it.
+
+        (WebCore::ContainerNode::firstElementChild):
+        (WebCore::ContainerNode::lastElementChild):
+        (WebCore::ContainerNode::childElementCount):
+        Remove unnecessary assertions.
+
+        * dom/ContainerNode.h:
+        Moved declarations from HTMLElement and Element to here.
+
+        * dom/Element.cpp:
+        (WebCore::Element::ensureCachedHTMLCollection): Deleted.
+        (WebCore::Element::cachedHTMLCollection): Deleted.
+        * dom/Element.h:
+        Moved to ContainerNode.
+
+        * dom/Node.cpp:
+        (WebCore::Node::previousElementSibling):
+        (WebCore::Node::nextElementSibling):
+        Remove unnecessary assertions.
+
+        * dom/ParentNode.idl:
+        Moved the children property here from HTMLElement.
+
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::children): Deleted.
+        * html/HTMLElement.h:
+        Moved to ContainerNode.
+
+        * html/HTMLElement.idl:
+        Get rid of the children property for all bindings except Objective-C which needs
+        to keep it to avoid changing the public API.
+
 2015-05-15  Zalan Bujtas  <[email protected]>
 
         WebCore ASan debug build fails. ERROR: WebCore has a weak external symbol in it.

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (184419 => 184420)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2015-05-15 22:55:53 UTC (rev 184420)
@@ -32,6 +32,9 @@
 #include "Editor.h"
 #include "FloatRect.h"
 #include "FrameView.h"
+#include "HTMLFormControlsCollection.h"
+#include "HTMLOptionsCollection.h"
+#include "HTMLTableRowsCollection.h"
 #include "InlineTextBox.h"
 #include "InsertionPoint.h"
 #include "JSLazyEventListener.h"
@@ -912,26 +915,46 @@
     return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeList>(*this, name);
 }
 
+Ref<HTMLCollection> ContainerNode::children()
+{
+    return ensureCachedHTMLCollection(NodeChildren);
+}
+
 Element* ContainerNode::firstElementChild() const
 {
-    ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
-
     return ElementTraversal::firstChild(*this);
 }
 
 Element* ContainerNode::lastElementChild() const
 {
-    ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
-
     return ElementTraversal::lastChild(*this);
 }
 
 unsigned ContainerNode::childElementCount() const
 {
-    ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
-
     auto children = childrenOfType<Element>(*this);
     return std::distance(children.begin(), children.end());
 }
 
+Ref<HTMLCollection> ContainerNode::ensureCachedHTMLCollection(CollectionType type)
+{
+    if (HTMLCollection* collection = cachedHTMLCollection(type))
+        return *collection;
+
+    if (type == TableRows)
+        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLTableRowsCollection>(downcast<HTMLTableElement>(*this), type);
+    else if (type == SelectOptions)
+        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLOptionsCollection>(downcast<HTMLSelectElement>(*this), type);
+    else if (type == FormControls) {
+        ASSERT(hasTagName(HTMLNames::formTag) || hasTagName(HTMLNames::fieldsetTag));
+        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLFormControlsCollection>(*this, type);
+    }
+    return ensureRareData().ensureNodeLists().addCachedCollection<HTMLCollection>(*this, type);
+}
+
+HTMLCollection* ContainerNode::cachedHTMLCollection(CollectionType type)
+{
+    return hasRareData() && rareData()->nodeLists() ? rareData()->nodeLists()->cachedCollection<HTMLCollection>(type) : nullptr;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/ContainerNode.h (184419 => 184420)


--- trunk/Source/WebCore/dom/ContainerNode.h	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/dom/ContainerNode.h	2015-05-15 22:55:53 UTC (rev 184420)
@@ -24,11 +24,13 @@
 #ifndef ContainerNode_h
 #define ContainerNode_h
 
+#include "CollectionType.h"
 #include "ExceptionCodePlaceholder.h"
 #include "Node.h"
 
 namespace WebCore {
 
+class HTMLCollection;
 class QualifiedName;
 class RenderElement;
 
@@ -146,6 +148,7 @@
     RefPtr<RadioNodeList> radioNodeList(const AtomicString&);
 
     // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
+    Ref<HTMLCollection> children();
     Element* firstElementChild() const;
     Element* lastElementChild() const;
     unsigned childElementCount() const;
@@ -163,6 +166,9 @@
     void setFirstChild(Node* child) { m_firstChild = child; }
     void setLastChild(Node* child) { m_lastChild = child; }
 
+    Ref<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
+    HTMLCollection* cachedHTMLCollection(CollectionType);
+
 private:
     void removeBetween(Node* previousChild, Node* nextChild, Node& oldChild);
     void insertBeforeCommon(Node& nextChild, Node& oldChild);

Modified: trunk/Source/WebCore/dom/Element.cpp (184419 => 184420)


--- trunk/Source/WebCore/dom/Element.cpp	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/dom/Element.cpp	2015-05-15 22:55:53 UTC (rev 184420)
@@ -48,13 +48,10 @@
 #include "HTMLCanvasElement.h"
 #include "HTMLCollection.h"
 #include "HTMLDocument.h"
-#include "HTMLFormControlsCollection.h"
 #include "HTMLLabelElement.h"
 #include "HTMLNameCollection.h"
-#include "HTMLOptionsCollection.h"
 #include "HTMLParserIdioms.h"
 #include "HTMLSelectElement.h"
-#include "HTMLTableRowsCollection.h"
 #include "HTMLTemplateElement.h"
 #include "IdTargetObserverRegistry.h"
 #include "InsertionPoint.h"
@@ -3056,27 +3053,6 @@
     dispatchSubtreeModifiedEvent();
 }
 
-Ref<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType type)
-{
-    if (HTMLCollection* collection = cachedHTMLCollection(type))
-        return *collection;
-
-    if (type == TableRows) {
-        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLTableRowsCollection>(downcast<HTMLTableElement>(*this), type);
-    } else if (type == SelectOptions) {
-        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLOptionsCollection>(downcast<HTMLSelectElement>(*this), type);
-    } else if (type == FormControls) {
-        ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag));
-        return ensureRareData().ensureNodeLists().addCachedCollection<HTMLFormControlsCollection>(*this, type);
-    }
-    return ensureRareData().ensureNodeLists().addCachedCollection<HTMLCollection>(*this, type);
-}
-
-HTMLCollection* Element::cachedHTMLCollection(CollectionType type)
-{
-    return hasRareData() && rareData()->nodeLists() ? rareData()->nodeLists()->cachedCollection<HTMLCollection>(type) : 0;
-}
-
 IntSize Element::savedLayerScrollOffset() const
 {
     return hasRareData() ? elementRareData()->savedLayerScrollOffset() : IntSize();

Modified: trunk/Source/WebCore/dom/Element.h (184419 => 184420)


--- trunk/Source/WebCore/dom/Element.h	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/dom/Element.h	2015-05-15 22:55:53 UTC (rev 184420)
@@ -25,7 +25,6 @@
 #ifndef Element_h
 #define Element_h
 
-#include "CollectionType.h"
 #include "Document.h"
 #include "ElementData.h"
 #include "HTMLNames.h"
@@ -498,9 +497,6 @@
     void clearTabIndexExplicitlyIfNeeded();
     void setTabIndexExplicitly(short);
 
-    Ref<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
-    HTMLCollection* cachedHTMLCollection(CollectionType);
-
     // classAttributeChanged() exists to share code between
     // parseAttribute (called via setAttribute()) and
     // svgAttributeChanged (called when element.className.baseValue is set)

Modified: trunk/Source/WebCore/dom/Node.cpp (184419 => 184420)


--- trunk/Source/WebCore/dom/Node.cpp	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/dom/Node.cpp	2015-05-15 22:55:53 UTC (rev 184420)
@@ -432,15 +432,11 @@
 
 Element* Node::previousElementSibling() const
 {
-    ASSERT(is<CharacterData>(*this) || is<Element>(*this));
-
     return ElementTraversal::previousSibling(*this);
 }
 
 Element* Node::nextElementSibling() const
 {
-    ASSERT(is<CharacterData>(*this) || is<Element>(*this));
-
     return ElementTraversal::nextSibling(*this);
 }
 

Modified: trunk/Source/WebCore/dom/ParentNode.idl (184419 => 184420)


--- trunk/Source/WebCore/dom/ParentNode.idl	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/dom/ParentNode.idl	2015-05-15 22:55:53 UTC (rev 184420)
@@ -28,6 +28,7 @@
 [
     NoInterfaceObject,
 ] interface ParentNode {
+    readonly attribute HTMLCollection children;
     readonly attribute Element firstElementChild;
     readonly attribute Element lastElementChild;
     readonly attribute unsigned long childElementCount;

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (184419 => 184420)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2015-05-15 22:55:53 UTC (rev 184420)
@@ -861,11 +861,6 @@
     setAttribute(translateAttr, enable ? "yes" : "no");
 }
 
-Ref<HTMLCollection> HTMLElement::children()
-{
-    return ensureCachedHTMLCollection(NodeChildren);
-}
-
 bool HTMLElement::rendererIsNeeded(const RenderStyle& style)
 {
     if (hasTagName(noscriptTag)) {

Modified: trunk/Source/WebCore/html/HTMLElement.h (184419 => 184420)


--- trunk/Source/WebCore/html/HTMLElement.h	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/html/HTMLElement.h	2015-05-15 22:55:53 UTC (rev 184420)
@@ -42,8 +42,6 @@
 public:
     static Ref<HTMLElement> create(const QualifiedName& tagName, Document&);
 
-    Ref<HTMLCollection> children();
-
     WEBCORE_EXPORT virtual String title() const override final;
 
     virtual short tabIndex() const override;

Modified: trunk/Source/WebCore/html/HTMLElement.idl (184419 => 184420)


--- trunk/Source/WebCore/html/HTMLElement.idl	2015-05-15 21:59:50 UTC (rev 184419)
+++ trunk/Source/WebCore/html/HTMLElement.idl	2015-05-15 22:55:53 UTC (rev 184420)
@@ -48,7 +48,9 @@
     [RaisesException] void insertAdjacentText([Default=Undefined] optional DOMString where,
                             [Default=Undefined] optional DOMString text);
 
+#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
     readonly attribute HTMLCollection children;
+#endif
 
              [TreatNullAs=NullString, SetterRaisesException] attribute DOMString contentEditable;
     readonly attribute boolean isContentEditable;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to