Use is<>() / downcast<>() for HTMLCollection subclasses
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Nov 2014 17:21:51 +0000 (17:21 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Nov 2014 17:21:51 +0000 (17:21 +0000)
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175791 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
Source/WebCore/html/HTMLAllCollection.h
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLCollection.h
Source/WebCore/html/HTMLFormControlsCollection.h
Source/WebCore/html/HTMLNameCollection.h
Source/WebCore/html/HTMLOptionsCollection.h
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLTableRowsCollection.h

index 08ed0a4..1d08551 100644 (file)
@@ -1,3 +1,29 @@
+2014-11-09  Chris Dumez  <cdumez@apple.com>
+
+        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  <cdumez@apple.com>
 
         Call faster HTMLElement::hasTagName() in HTMLCollection
index 374c29f..425098b 100644 (file)
@@ -149,8 +149,8 @@ WebKitDOMHTMLCollection* wrap(HTMLCollection* collection)
 {
     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);
 }
 
index 6c93aea..24bbf3d 100644 (file)
@@ -43,4 +43,6 @@ private:
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLAllCollection, DocAll)
+
 #endif // HTMLAllCollection_h
index 1214c8e..a290054 100644 (file)
@@ -206,7 +206,7 @@ inline bool isMatchingHTMLElement(const HTMLCollection& collection, HTMLElement&
     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 @@ inline bool isMatchingElement(const HTMLCollection& collection, Element& element
     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));
index 32bdbed..f40417e 100644 (file)
@@ -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 @@ private:
     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
index e56aa4d..caa6a0d 100644 (file)
@@ -57,6 +57,8 @@ private:
     mutable unsigned m_cachedElementOffsetInArray;
 };
 
-} // namespace
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLFormControlsCollection, FormControls)
+
+#endif // HTMLFormControlsCollection_h
index 29f647f..022ea30 100644 (file)
@@ -85,6 +85,9 @@ private:
     }
 };
 
-}
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(WindowNameCollection, WindowNamedItems)
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(DocumentNameCollection, DocumentNamedItems)
+
+#endif // HTMLNameCollection_h
index 9c79256..15834ab 100644 (file)
@@ -54,6 +54,8 @@ private:
     explicit HTMLOptionsCollection(HTMLSelectElement&);
 };
 
-} //namespace
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLOptionsCollection, SelectOptions)
+
+#endif // HTMLOptionsCollection_h
index c24fee2..ea3043e 100644 (file)
@@ -375,7 +375,7 @@ PassRefPtr<HTMLCollection> HTMLSelectElement::selectedOptions()
 
 PassRefPtr<HTMLOptionsCollection> HTMLSelectElement::options()
 {
-    return static_cast<HTMLOptionsCollection*>(ensureCachedHTMLCollection(SelectOptions).get());
+    return downcast<HTMLOptionsCollection>(ensureCachedHTMLCollection(SelectOptions).get());
 }
 
 void HTMLSelectElement::updateListItemSelectedStates()
index f7ca604..0f5cdd7 100644 (file)
@@ -52,6 +52,8 @@ private:
     virtual Element* customElementAfter(Element*) const override;
 };
 
-} // namespace
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLTableRowsCollection, TableRows)
+
+#endif // HTMLTableRowsCollection_h