Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: Source/core/xml/parser/XMLDocumentParser.cpp

Issue 1267283002: Gracefully handle XMLDocumentParser being detached by mutation events. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add clarifying comment Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/xml/parser/XMLDocumentParser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/xml/parser/XMLDocumentParser.cpp
diff --git a/Source/core/xml/parser/XMLDocumentParser.cpp b/Source/core/xml/parser/XMLDocumentParser.cpp
index a7f927f952982a8fab2eab6a32929d1ab068de1f..816d9d396522efeb1f903498ca499d4103c1a624 100644
--- a/Source/core/xml/parser/XMLDocumentParser.cpp
+++ b/Source/core/xml/parser/XMLDocumentParser.cpp
@@ -380,25 +380,30 @@ void XMLDocumentParser::handleError(XMLErrors::ErrorType type, const char* forma
stopParsing();
}
-void XMLDocumentParser::enterText()
+void XMLDocumentParser::createLeafTextNodeIfNeeded()
{
+ if (m_leafTextNode)
+ return;
+
ASSERT(m_bufferedText.size() == 0);
- ASSERT(!m_leafTextNode);
m_leafTextNode = Text::create(m_currentNode->document(), "");
m_currentNode->parserAppendChild(m_leafTextNode.get());
}
-void XMLDocumentParser::exitText()
+bool XMLDocumentParser::updateLeafTextNode()
{
if (isStopped())
- return;
+ return false;
if (!m_leafTextNode)
- return;
+ return true;
m_leafTextNode->appendData(toString(m_bufferedText.data(), m_bufferedText.size()));
m_bufferedText.clear();
m_leafTextNode = nullptr;
+
+ // Mutation event handlers executed by appendData() might detach this parser.
+ return !isStopped();
}
void XMLDocumentParser::detach()
@@ -428,7 +433,9 @@ void XMLDocumentParser::end()
if (m_sawError) {
insertErrorMessageBlock();
} else {
- exitText();
+ updateLeafTextNode();
+ // Do not bail out if in a stopped state, but notify document that
+ // parsing has finished.
document()->styleResolverChanged();
}
@@ -992,7 +999,8 @@ void XMLDocumentParser::startElementNs(const AtomicString& localName, const Atom
return;
}
- exitText();
+ if (!updateLeafTextNode())
+ return;
AtomicString adjustedURI = uri;
if (m_parsingFragment && adjustedURI.isNull()) {
@@ -1069,7 +1077,8 @@ void XMLDocumentParser::endElementNs()
// the end of this method.
RefPtrWillBeRawPtr<XMLDocumentParser> protect(this);
- exitText();
+ if (!updateLeafTextNode())
+ return;
RefPtrWillBeRawPtr<ContainerNode> n = m_currentNode;
if (m_currentNode->isElementNode())
@@ -1145,8 +1154,7 @@ void XMLDocumentParser::characters(const xmlChar* chars, int length)
return;
}
- if (!m_leafTextNode)
- enterText();
+ createLeafTextNodeIfNeeded();
m_bufferedText.append(chars, length);
}
@@ -1176,7 +1184,8 @@ void XMLDocumentParser::processingInstruction(const String& target, const String
return;
}
- exitText();
+ if (!updateLeafTextNode())
+ return;
// ### handle exceptions
TrackExceptionState exceptionState;
@@ -1218,7 +1227,8 @@ void XMLDocumentParser::cdataBlock(const String& text)
return;
}
- exitText();
+ if (!updateLeafTextNode())
+ return;
m_currentNode->parserAppendChild(CDATASection::create(m_currentNode->document(), text));
}
@@ -1233,7 +1243,8 @@ void XMLDocumentParser::comment(const String& text)
return;
}
- exitText();
+ if (!updateLeafTextNode())
+ return;
m_currentNode->parserAppendChild(Comment::create(m_currentNode->document(), text));
}
@@ -1264,7 +1275,7 @@ void XMLDocumentParser::startDocument(const String& version, const String& encod
void XMLDocumentParser::endDocument()
{
- exitText();
+ updateLeafTextNode();
}
void XMLDocumentParser::internalSubset(const String& name, const String& externalID, const String& systemID)
« no previous file with comments | « Source/core/xml/parser/XMLDocumentParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698