Rename toScriptElement -> toScriptElementIfPossible
authorpdr@google.com <pdr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Mar 2013 05:04:38 +0000 (05:04 +0000)
committerpdr@google.com <pdr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Mar 2013 05:04:38 +0000 (05:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=113473

Reviewed by Ryosuke Niwa.

Rename ScriptElement::toScriptElement to ScriptElement::toScriptElementIfPossible to
differentiate this function from other to*Element functions, and to better describe the
function's behavior. Other to*Element functions do not return null if the cast fails,
whereas toScriptElementIfPossible does.

No new tests as this is just a refactoring.

* dom/ScriptElement.cpp:
(WebCore::toScriptElementIfPossible):
* dom/ScriptElement.h:
(WebCore):
* dom/ScriptRunner.cpp:
(WebCore::ScriptRunner::timerFired):

    This is the only unchecked return value but there isn't a security issue here.

* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::collectOptionInnerText):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::attachLater):
(WebCore::HTMLConstructionSite::insertForeignElement):
* html/parser/HTMLScriptRunner.cpp:
(WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent):
(WebCore::HTMLScriptRunner::requestPendingScript):
(WebCore::HTMLScriptRunner::runScript):
* xml/parser/XMLDocumentParser.cpp:
(WebCore::XMLDocumentParser::notifyFinished):
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::startElementNs):
(WebCore::XMLDocumentParser::endElementNs):
* xml/parser/XMLDocumentParserQt.cpp:
(WebCore::XMLDocumentParser::parseStartElement):
(WebCore::XMLDocumentParser::parseEndElement):

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

Source/WebCore/ChangeLog
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/dom/ScriptElement.h
Source/WebCore/dom/ScriptRunner.cpp
Source/WebCore/html/HTMLOptionElement.cpp
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/html/parser/HTMLScriptRunner.cpp
Source/WebCore/xml/parser/XMLDocumentParser.cpp
Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
Source/WebCore/xml/parser/XMLDocumentParserQt.cpp

index 0049e02..1bc4d80 100644 (file)
@@ -1,3 +1,44 @@
+2013-03-27  Philip Rogers  <pdr@google.com>
+
+        Rename toScriptElement -> toScriptElementIfPossible
+        https://bugs.webkit.org/show_bug.cgi?id=113473
+
+        Reviewed by Ryosuke Niwa.
+
+        Rename ScriptElement::toScriptElement to ScriptElement::toScriptElementIfPossible to
+        differentiate this function from other to*Element functions, and to better describe the
+        function's behavior. Other to*Element functions do not return null if the cast fails,
+        whereas toScriptElementIfPossible does.
+
+        No new tests as this is just a refactoring.
+
+        * dom/ScriptElement.cpp:
+        (WebCore::toScriptElementIfPossible):
+        * dom/ScriptElement.h:
+        (WebCore):
+        * dom/ScriptRunner.cpp:
+        (WebCore::ScriptRunner::timerFired):
+
+            This is the only unchecked return value but there isn't a security issue here.
+
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::collectOptionInnerText):
+        * html/parser/HTMLConstructionSite.cpp:
+        (WebCore::HTMLConstructionSite::attachLater):
+        (WebCore::HTMLConstructionSite::insertForeignElement):
+        * html/parser/HTMLScriptRunner.cpp:
+        (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent):
+        (WebCore::HTMLScriptRunner::requestPendingScript):
+        (WebCore::HTMLScriptRunner::runScript):
+        * xml/parser/XMLDocumentParser.cpp:
+        (WebCore::XMLDocumentParser::notifyFinished):
+        * xml/parser/XMLDocumentParserLibxml2.cpp:
+        (WebCore::XMLDocumentParser::startElementNs):
+        (WebCore::XMLDocumentParser::endElementNs):
+        * xml/parser/XMLDocumentParserQt.cpp:
+        (WebCore::XMLDocumentParser::parseStartElement):
+        (WebCore::XMLDocumentParser::parseEndElement):
+
 2013-03-27  Ryosuke Niwa  <rniwa@webkit.org>
 
         Debug test fix after r147018.
index 4b2f6c2..7bd26bc 100644 (file)
@@ -414,7 +414,7 @@ String ScriptElement::scriptContent() const
     return content.toString();
 }
 
-ScriptElement* toScriptElement(Element* element)
+ScriptElement* toScriptElementIfPossible(Element* element)
 {
     if (element->isHTMLElement() && element->hasTagName(HTMLNames::scriptTag))
         return static_cast<HTMLScriptElement*>(element);
index ff42b95..05a418c 100644 (file)
@@ -109,7 +109,7 @@ private:
     String m_fallbackCharacterEncoding;
 };
 
-ScriptElement* toScriptElement(Element*);
+ScriptElement* toScriptElementIfPossible(Element*);
 
 }
 
index e1630e9..4f299eb 100644 (file)
@@ -118,7 +118,7 @@ void ScriptRunner::timerFired(Timer<ScriptRunner>* timer)
     for (size_t i = 0; i < size; ++i) {
         CachedScript* cachedScript = scripts[i].cachedScript();
         RefPtr<Element> element = scripts[i].releaseElementAndClear();
-        toScriptElement(element.get())->execute(cachedScript);
+        toScriptElementIfPossible(element.get())->execute(cachedScript);
         m_document->decrementLoadEventDelayCount();
     }
 }
index dacbdb1..1305a99 100644 (file)
@@ -381,7 +381,7 @@ String HTMLOptionElement::collectOptionInnerText() const
         if (node->isTextNode())
             text.append(node->nodeValue());
         // Text nodes inside script elements are not part of the option text.
-        if (node->isElementNode() && toScriptElement(toElement(node)))
+        if (node->isElementNode() && toScriptElementIfPossible(toElement(node)))
             node = NodeTraversal::nextSkippingChildren(node, this);
         else
             node = NodeTraversal::next(node, this);
index 552b263..78a2e77 100644 (file)
@@ -107,7 +107,7 @@ static inline void executeTask(HTMLConstructionSiteTask& task)
 
 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtr<Node> prpChild, bool selfClosing)
 {
-    ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->isElementNode() || !toScriptElement(toElement(prpChild.get())));
+    ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->isElementNode() || !toScriptElementIfPossible(toElement(prpChild.get())));
     ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !prpChild->isPluginElement());
 
     HTMLConstructionSiteTask task;
@@ -466,7 +466,7 @@ void HTMLConstructionSite::insertForeignElement(AtomicHTMLToken* token, const At
     notImplemented(); // parseError when xmlns or xmlns:xlink are wrong.
 
     RefPtr<Element> element = createElement(token, namespaceURI);
-    if (scriptingContentIsAllowed(m_parserContentPolicy) || !toScriptElement(element.get()))
+    if (scriptingContentIsAllowed(m_parserContentPolicy) || !toScriptElementIfPossible(element.get()))
         attachLater(currentNode(), element, token->selfClosing());
     if (!token->selfClosing())
         m_openElements.push(HTMLStackItem::create(element.release(), token, namespaceURI));
index 53f3d29..1aab3b5 100644 (file)
@@ -138,7 +138,7 @@ void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
 
     // Clear the pending script before possible rentrancy from executeScript()
     RefPtr<Element> element = pendingScript.releaseElementAndClear();
-    if (ScriptElement* scriptElement = toScriptElement(element.get())) {
+    if (ScriptElement* scriptElement = toScriptElementIfPossible(element.get())) {
         NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
         IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(m_document);
         if (errorOccurred)
@@ -267,7 +267,7 @@ bool HTMLScriptRunner::requestPendingScript(PendingScript& pendingScript, Elemen
     ASSERT(!pendingScript.element());
     pendingScript.setElement(script);
     // This should correctly return 0 for empty or invalid srcValues.
-    CachedScript* cachedScript = toScriptElement(script)->cachedScript().get();
+    CachedScript* cachedScript = toScriptElementIfPossible(script)->cachedScript().get();
     if (!cachedScript) {
         notImplemented(); // Dispatch error event.
         return false;
@@ -283,7 +283,7 @@ void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar
     ASSERT(m_document);
     ASSERT(!hasParserBlockingScript());
     {
-        ScriptElement* scriptElement = toScriptElement(script);
+        ScriptElement* scriptElement = toScriptElementIfPossible(script);
 
         // This contains both and ASSERTION and a null check since we should not
         // be getting into the case of a null script element, but seem to be from
index 7f2b17a..59acc34 100644 (file)
@@ -254,7 +254,7 @@ void XMLDocumentParser::notifyFinished(CachedResource* unusedResource)
     RefPtr<Element> e = m_scriptElement;
     m_scriptElement = 0;
 
-    ScriptElement* scriptElement = toScriptElement(e.get());
+    ScriptElement* scriptElement = toScriptElementIfPossible(e.get());
     ASSERT(scriptElement);
 
     // JavaScript can detach this parser, make sure it's kept alive even if detached.
index 5c21abb..d7b4973 100644 (file)
@@ -820,7 +820,7 @@ void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
 
     newElement->beginParsingChildren();
 
-    ScriptElement* scriptElement = toScriptElement(newElement.get());
+    ScriptElement* scriptElement = toScriptElementIfPossible(newElement.get());
     if (scriptElement)
         m_scriptStartPosition = textPosition();
 
@@ -869,7 +869,7 @@ void XMLDocumentParser::endElementNs()
     if (hackAroundLibXMLEntityParsingBug() && context()->depth <= depthTriggeringEntityExpansion())
         setDepthTriggeringEntityExpansion(-1);
 
-    if (!scriptingContentIsAllowed(parserContentPolicy()) && n->isElementNode() && toScriptElement(toElement(n.get()))) {
+    if (!scriptingContentIsAllowed(parserContentPolicy()) && n->isElementNode() && toScriptElementIfPossible(toElement(n.get()))) {
         popCurrentNode();
         n->remove(IGNORE_EXCEPTION);
         return;
@@ -889,7 +889,7 @@ void XMLDocumentParser::endElementNs()
         return;
     }
 
-    ScriptElement* scriptElement = toScriptElement(element);
+    ScriptElement* scriptElement = toScriptElementIfPossible(element);
     if (!scriptElement) {
         popCurrentNode();
         return;
index b15da86..6e42c92 100644 (file)
@@ -491,7 +491,7 @@ void XMLDocumentParser::parseStartElement()
         return;
     }
 
-    ScriptElement* scriptElement = toScriptElement(newElement.get());
+    ScriptElement* scriptElement = toScriptElementIfPossible(newElement.get());
     if (scriptElement)
         m_scriptStartPosition = textPosition();
 
@@ -515,7 +515,7 @@ void XMLDocumentParser::parseEndElement()
     RefPtr<ContainerNode> n = m_currentNode;
     n->finishParsingChildren();
 
-    if (!scriptingContentIsAllowed(parserContentPolicy()) && n->isElementNode() && toScriptElement(toElement(n.get()))) {
+    if (!scriptingContentIsAllowed(parserContentPolicy()) && n->isElementNode() && toScriptElementIfPossible(toElement(n.get()))) {
         popCurrentNode();
         n->remove(IGNORE_EXCEPTION);
         return;
@@ -536,7 +536,7 @@ void XMLDocumentParser::parseEndElement()
         return;
     }
 
-    ScriptElement* scriptElement = toScriptElement(element);
+    ScriptElement* scriptElement = toScriptElementIfPossible(element);
     if (!scriptElement) {
         popCurrentNode();
         return;