Commit b38b6ff0 authored by pdr@google.com's avatar 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):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147057 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent be2db29e
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.
......@@ -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);
......
......@@ -109,7 +109,7 @@ private:
String m_fallbackCharacterEncoding;
};
ScriptElement* toScriptElement(Element*);
ScriptElement* toScriptElementIfPossible(Element*);
}
......
......@@ -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();
}
}
......
......@@ -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);
......
......@@ -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));
......
......@@ -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
......
......@@ -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.
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment