Title: [175791] trunk/Source/WebCore
Revision
175791
Author
[email protected]
Date
2014-11-09 09:21:51 -0800 (Sun, 09 Nov 2014)

Log Message

Use is<>() / downcast<>() for HTMLCollection subclasses
https://bugs.webkit.org/show_bug.cgi?id=138541

Reviewed by Sam Weinig.

Use is<>() / downcast<>() for HTMLCollection subclasses for
safety and consistency with the rest of the code base.

No new tests, no behavior change.

* bindings/gobject/WebKitDOMPrivate.cpp:
(WebKit::wrap):
* html/HTMLAllCollection.h:
* html/HTMLCollection.cpp:
(WebCore::isMatchingHTMLElement):
(WebCore::isMatchingElement):
* html/HTMLCollection.h:
* html/HTMLFormControlsCollection.h:
* html/HTMLNameCollection.h:
* html/HTMLOptionsCollection.h:
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::options):
* html/HTMLTableRowsCollection.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (175790 => 175791)


--- trunk/Source/WebCore/ChangeLog	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/ChangeLog	2014-11-09 17:21:51 UTC (rev 175791)
@@ -1,3 +1,29 @@
+2014-11-09  Chris Dumez  <[email protected]>
+
+        Use is<>() / downcast<>() for HTMLCollection subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=138541
+
+        Reviewed by Sam Weinig.
+
+        Use is<>() / downcast<>() for HTMLCollection subclasses for
+        safety and consistency with the rest of the code base.
+
+        No new tests, no behavior change.
+
+        * bindings/gobject/WebKitDOMPrivate.cpp:
+        (WebKit::wrap):
+        * html/HTMLAllCollection.h:
+        * html/HTMLCollection.cpp:
+        (WebCore::isMatchingHTMLElement):
+        (WebCore::isMatchingElement):
+        * html/HTMLCollection.h:
+        * html/HTMLFormControlsCollection.h:
+        * html/HTMLNameCollection.h:
+        * html/HTMLOptionsCollection.h:
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::options):
+        * html/HTMLTableRowsCollection.h:
+
 2014-11-08  Chris Dumez  <[email protected]>
 
         Call faster HTMLElement::hasTagName() in HTMLCollection

Modified: trunk/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp (175790 => 175791)


--- trunk/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp	2014-11-09 17:21:51 UTC (rev 175791)
@@ -149,8 +149,8 @@
 {
     ASSERT(collection);
 
-    if (collection->type() == WebCore::SelectOptions)
-        return WEBKIT_DOM_HTML_COLLECTION(wrapHTMLOptionsCollection(static_cast<HTMLOptionsCollection*>(collection)));
+    if (is<HTMLOptionsCollection>(*collection))
+        return WEBKIT_DOM_HTML_COLLECTION(wrapHTMLOptionsCollection(downcast<HTMLOptionsCollection>(collection)));
     return wrapHTMLCollection(collection);
 }
 

Modified: trunk/Source/WebCore/html/HTMLAllCollection.h (175790 => 175791)


--- trunk/Source/WebCore/html/HTMLAllCollection.h	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/html/HTMLAllCollection.h	2014-11-09 17:21:51 UTC (rev 175791)
@@ -43,4 +43,6 @@
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLAllCollection, DocAll)
+
 #endif // HTMLAllCollection_h

Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (175790 => 175791)


--- trunk/Source/WebCore/html/HTMLCollection.cpp	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp	2014-11-09 17:21:51 UTC (rev 175791)
@@ -206,7 +206,7 @@
     case DocAnchors:
         return element.hasTagName(aTag) && element.fastHasAttribute(nameAttr);
     case DocumentNamedItems:
-        return static_cast<const DocumentNameCollection&>(collection).elementMatches(element);
+        return downcast<DocumentNameCollection>(collection).elementMatches(element);
     case DocAll:
     case NodeChildren:
     case WindowNamedItems:
@@ -226,7 +226,7 @@
     case NodeChildren:
         return true;
     case WindowNamedItems:
-        return static_cast<const WindowNameCollection&>(collection).elementMatches(element);
+        return downcast<WindowNameCollection>(collection).elementMatches(element);
     default:
         // Collection types that only deal with HTMLElements.
         return is<HTMLElement>(element) && isMatchingHTMLElement(collection, downcast<HTMLElement>(element));

Modified: trunk/Source/WebCore/html/HTMLCollection.h (175790 => 175791)


--- trunk/Source/WebCore/html/HTMLCollection.h	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/html/HTMLCollection.h	2014-11-09 17:21:51 UTC (rev 175791)
@@ -33,6 +33,7 @@
 #include <memory>
 #include <wtf/Forward.h>
 #include <wtf/HashMap.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -175,6 +176,11 @@
     const unsigned m_usesCustomForwardOnlyTraversal : 1;
 };
 
-} // namespace
+} // namespace WebCore
 
-#endif
+#define SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(ClassName, Type) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ClassName) \
+    static bool isType(const WebCore::HTMLCollection& collection) { return collection.type() == WebCore::Type; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
+#endif // HTMLCollection_h

Modified: trunk/Source/WebCore/html/HTMLFormControlsCollection.h (175790 => 175791)


--- trunk/Source/WebCore/html/HTMLFormControlsCollection.h	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/html/HTMLFormControlsCollection.h	2014-11-09 17:21:51 UTC (rev 175791)
@@ -57,6 +57,8 @@
     mutable unsigned m_cachedElementOffsetInArray;
 };
 
-} // namespace
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLFormControlsCollection, FormControls)
+
+#endif // HTMLFormControlsCollection_h

Modified: trunk/Source/WebCore/html/HTMLNameCollection.h (175790 => 175791)


--- trunk/Source/WebCore/html/HTMLNameCollection.h	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/html/HTMLNameCollection.h	2014-11-09 17:21:51 UTC (rev 175791)
@@ -85,6 +85,9 @@
     }
 };
 
-}
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(WindowNameCollection, WindowNamedItems)
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(DocumentNameCollection, DocumentNamedItems)
+
+#endif // HTMLNameCollection_h

Modified: trunk/Source/WebCore/html/HTMLOptionsCollection.h (175790 => 175791)


--- trunk/Source/WebCore/html/HTMLOptionsCollection.h	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/html/HTMLOptionsCollection.h	2014-11-09 17:21:51 UTC (rev 175791)
@@ -54,6 +54,8 @@
     explicit HTMLOptionsCollection(HTMLSelectElement&);
 };
 
-} //namespace
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLOptionsCollection, SelectOptions)
+
+#endif // HTMLOptionsCollection_h

Modified: trunk/Source/WebCore/html/HTMLSelectElement.cpp (175790 => 175791)


--- trunk/Source/WebCore/html/HTMLSelectElement.cpp	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/html/HTMLSelectElement.cpp	2014-11-09 17:21:51 UTC (rev 175791)
@@ -375,7 +375,7 @@
 
 PassRefPtr<HTMLOptionsCollection> HTMLSelectElement::options()
 {
-    return static_cast<HTMLOptionsCollection*>(ensureCachedHTMLCollection(SelectOptions).get());
+    return downcast<HTMLOptionsCollection>(ensureCachedHTMLCollection(SelectOptions).get());
 }
 
 void HTMLSelectElement::updateListItemSelectedStates()

Modified: trunk/Source/WebCore/html/HTMLTableRowsCollection.h (175790 => 175791)


--- trunk/Source/WebCore/html/HTMLTableRowsCollection.h	2014-11-09 10:12:14 UTC (rev 175790)
+++ trunk/Source/WebCore/html/HTMLTableRowsCollection.h	2014-11-09 17:21:51 UTC (rev 175791)
@@ -52,6 +52,8 @@
     virtual Element* customElementAfter(Element*) const override;
 };
 
-} // namespace
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLTableRowsCollection, TableRows)
+
+#endif // HTMLTableRowsCollection_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to