Title: [97551] trunk/Source/WebCore
Revision
97551
Author
[email protected]
Date
2011-10-15 00:59:24 -0700 (Sat, 15 Oct 2011)

Log Message

Make toHTMLElement fail to compile if you try to use it on an HTMLElement*
https://bugs.webkit.org/show_bug.cgi?id=70164

Reviewed by Adam Barth.

Refactoring covered by existing tests.

* bindings/js/JSHTMLFrameSetElementCustom.cpp:
(WebCore::JSHTMLFrameSetElement::nameGetter): Removed unneeded casts and
some unneeded local variables as well. Changed the name of the local variable
for the HTMLFrameElement to frameElement to avoid confusion with the Frame.
* dom/Document.cpp:
(WebCore::Document::openSearchDescriptionURL): Removed unneeded HTMLElement
check; we can call hasTagName directly on a Node and that takes care of
checking both that it's an HTMLElement and checking the tag name.
* dom/MicroDataItemList.cpp:
(WebCore::MicroDataItemList::nodeMatches): Use toHTMLElement instead of
a cast. Also changed hasAttribute calls to fastHasAttribute and getAttribute
calls to fastGetAttribute since these are neither style attributes nor SVG
animatables.
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyInlineStyleToPushDown): Use toHTMLElement.
(WebCore::ApplyStyleCommand::addInlineStyleIfNeeded): Ditto.
* editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::show): Removed unneeded toHTMLElement call.
* html/HTMLElement.cpp:
(WebCore::HTMLElement::setOuterHTML): Use toHTMLElement.
* html/HTMLElement.h: Added toHTMLElement overload to catch calls when the
pointer is already HTMLElement* or a pointer to a class derived from it.
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::recalcListItems): Use toHTMLElement.
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::innerTextElement): Use toHTMLElement.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (97550 => 97551)


--- trunk/Source/WebCore/ChangeLog	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/ChangeLog	2011-10-15 07:59:24 UTC (rev 97551)
@@ -1,3 +1,39 @@
+2011-10-15  Darin Adler  <[email protected]>
+
+        Make toHTMLElement fail to compile if you try to use it on an HTMLElement*
+        https://bugs.webkit.org/show_bug.cgi?id=70164
+
+        Reviewed by Adam Barth.
+
+        Refactoring covered by existing tests.
+
+        * bindings/js/JSHTMLFrameSetElementCustom.cpp:
+        (WebCore::JSHTMLFrameSetElement::nameGetter): Removed unneeded casts and
+        some unneeded local variables as well. Changed the name of the local variable
+        for the HTMLFrameElement to frameElement to avoid confusion with the Frame.
+        * dom/Document.cpp:
+        (WebCore::Document::openSearchDescriptionURL): Removed unneeded HTMLElement
+        check; we can call hasTagName directly on a Node and that takes care of
+        checking both that it's an HTMLElement and checking the tag name.
+        * dom/MicroDataItemList.cpp:
+        (WebCore::MicroDataItemList::nodeMatches): Use toHTMLElement instead of
+        a cast. Also changed hasAttribute calls to fastHasAttribute and getAttribute
+        calls to fastGetAttribute since these are neither style attributes nor SVG
+        animatables.
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::applyInlineStyleToPushDown): Use toHTMLElement.
+        (WebCore::ApplyStyleCommand::addInlineStyleIfNeeded): Ditto.
+        * editing/DeleteButtonController.cpp:
+        (WebCore::DeleteButtonController::show): Removed unneeded toHTMLElement call.
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::setOuterHTML): Use toHTMLElement.
+        * html/HTMLElement.h: Added toHTMLElement overload to catch calls when the
+        pointer is already HTMLElement* or a pointer to a class derived from it.
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::recalcListItems): Use toHTMLElement.
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::innerTextElement): Use toHTMLElement.
+
 2011-10-15  Antoine Labour  <[email protected]>
 
         Add WebAcceleratedContentLayer backed by a texture to support accelerated content hosting

Modified: trunk/Source/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp (97550 => 97551)


--- trunk/Source/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp	2011-10-15 07:59:24 UTC (rev 97551)
@@ -49,15 +49,12 @@
 
 JSValue JSHTMLFrameSetElement::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
 {
-    JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(asObject(slotBase));
-    HTMLElement* element = toHTMLElement(thisObj->impl());
-
-    Node* frame = element->children()->namedItem(identifierToAtomicString(propertyName));
-    if (Document* doc = static_cast<HTMLFrameElement*>(frame)->contentDocument()) {
-        if (JSDOMWindowShell* window = toJSDOMWindowShell(doc->frame(), currentWorld(exec)))
+    HTMLElement* element = static_cast<JSHTMLElement*>(asObject(slotBase))->impl();
+    Node* frameElement = element->children()->namedItem(identifierToAtomicString(propertyName));
+    if (Document* document = static_cast<HTMLFrameElement*>(frameElement)->contentDocument()) {
+        if (JSDOMWindowShell* window = toJSDOMWindowShell(document->frame(), currentWorld(exec)))
             return window;
     }
-
     return jsUndefined();
 }
 

Modified: trunk/Source/WebCore/dom/Document.cpp (97550 => 97551)


--- trunk/Source/WebCore/dom/Document.cpp	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/dom/Document.cpp	2011-10-15 07:59:24 UTC (rev 97551)
@@ -4073,7 +4073,7 @@
 
     RefPtr<HTMLCollection> children = head()->children();
     for (Node* child = children->firstItem(); child; child = children->nextItem()) {
-        if (!child->isHTMLElement() || !static_cast<HTMLElement*>(child)->hasTagName(linkTag))
+        if (!child->hasTagName(linkTag))
             continue;
         HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(child);
         if (!equalIgnoringCase(linkElement->type(), openSearchMIMEType) || !equalIgnoringCase(linkElement->rel(), openSearchRelation))

Modified: trunk/Source/WebCore/dom/MicroDataItemList.cpp (97550 => 97551)


--- trunk/Source/WebCore/dom/MicroDataItemList.cpp	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/dom/MicroDataItemList.cpp	2011-10-15 07:59:24 UTC (rev 97551)
@@ -32,6 +32,8 @@
 #include "HTMLElement.h"
 #include "HTMLNames.h"
 
+using namespace HTMLNames;
+
 namespace WebCore {
 
 MicroDataItemList::MicroDataItemList(PassRefPtr<Node> rootNode, const String& typeNames)
@@ -51,14 +53,14 @@
     if (!testNode->isHTMLElement())
         return false;
 
-    HTMLElement* testElement = static_cast<HTMLElement*>(testNode);
-    if (!testElement->hasAttribute(HTMLNames::itemscopeAttr) || testElement->hasAttribute(HTMLNames::itempropAttr))
+    HTMLElement* testElement = toHTMLElement(testNode);
+    if (!testElement->fastHasAttribute(itemscopeAttr) || testElement->fastHasAttribute(itempropAttr))
         return false;
 
     if (!m_typeNames.size())
         return true;
 
-    return m_typeNames.contains(testElement->getAttribute(HTMLNames::itemtypeAttr));
+    return m_typeNames.contains(testElement->fastGetAttribute(itemtypeAttr));
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (97550 => 97551)


--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp	2011-10-15 07:59:24 UTC (rev 97551)
@@ -935,9 +935,9 @@
         return;
 
     RefPtr<EditingStyle> newInlineStyle = style;
-    if (node->isHTMLElement() && static_cast<HTMLElement*>(node)->inlineStyleDecl()) {
+    if (node->isHTMLElement() && toHTMLElement(node)->inlineStyleDecl()) {
         newInlineStyle = style->copy();
-        newInlineStyle->mergeInlineStyleOfElement(static_cast<HTMLElement*>(node), EditingStyle::OverrideValues);
+        newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingStyle::OverrideValues);
     }
 
     // Since addInlineStyleIfNeeded can't add styles to block-flow render objects, add style attribute instead.
@@ -1414,7 +1414,7 @@
 
     if (styleChange.cssStyle().length()) {
         if (styleContainer) {
-            CSSMutableStyleDeclaration* existingStyle = toHTMLElement(styleContainer)->inlineStyleDecl();
+            CSSMutableStyleDeclaration* existingStyle = styleContainer->inlineStyleDecl();
             if (existingStyle)
                 setNodeAttribute(styleContainer, styleAttr, existingStyle->cssText() + styleChange.cssStyle());
             else

Modified: trunk/Source/WebCore/editing/DeleteButtonController.cpp (97550 => 97551)


--- trunk/Source/WebCore/editing/DeleteButtonController.cpp	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/editing/DeleteButtonController.cpp	2011-10-15 07:59:24 UTC (rev 97551)
@@ -284,7 +284,7 @@
     if (!enabled() || !element || !element->inDocument() || !isDeletableElement(element))
         return;
 
-    if (!m_frame->editor()->shouldShowDeleteInterface(toHTMLElement(element)))
+    if (!m_frame->editor()->shouldShowDeleteInterface(element))
         return;
 
     // we rely on the renderer having current information, so we should update the layout if needed

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (97550 => 97551)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2011-10-15 07:59:24 UTC (rev 97551)
@@ -404,7 +404,7 @@
         ec = NO_MODIFICATION_ALLOWED_ERR;
         return;
     }
-    RefPtr<HTMLElement> parent = static_cast<HTMLElement*>(p);
+    RefPtr<HTMLElement> parent = toHTMLElement(p);
     RefPtr<Node> prev = previousSibling();
     RefPtr<Node> next = nextSibling();
 

Modified: trunk/Source/WebCore/html/HTMLElement.h (97550 => 97551)


--- trunk/Source/WebCore/html/HTMLElement.h	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/html/HTMLElement.h	2011-10-15 07:59:24 UTC (rev 97551)
@@ -121,6 +121,9 @@
     return static_cast<const HTMLElement*>(node);
 }
 
+// This will catch anyone doing an unnecessary cast.
+void toHTMLElement(const HTMLElement*);
+
 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document* document)
     : StyledElement(tagName, document, CreateHTMLElement)
 {

Modified: trunk/Source/WebCore/html/HTMLSelectElement.cpp (97550 => 97551)


--- trunk/Source/WebCore/html/HTMLSelectElement.cpp	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/html/HTMLSelectElement.cpp	2011-10-15 07:59:24 UTC (rev 97551)
@@ -674,7 +674,7 @@
             continue;
         }
 
-        HTMLElement* current = static_cast<HTMLElement*>(currentNode);
+        HTMLElement* current = toHTMLElement(currentNode);
 
         // optgroup tags may not nest. However, both FireFox and IE will
         // flatten the tree automatically, so we follow suit.

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (97550 => 97551)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-10-15 07:44:39 UTC (rev 97550)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-10-15 07:59:24 UTC (rev 97551)
@@ -272,7 +272,7 @@
 {
     Node* node = shadowRoot()->firstChild();
     ASSERT(!node || node->hasTagName(divTag));
-    return static_cast<HTMLElement*>(node);
+    return toHTMLElement(node);
 }
 
 void HTMLTextAreaElement::rendererWillBeDestroyed()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to