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

Unified Diff: Source/core/html/HTMLCollection.cpp

Issue 225023034: Make sure named item cache is always valid HTMLCollection::updateIdNameCache() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move constructor to cpp Created 6 years, 8 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/html/HTMLCollection.h ('k') | Source/core/html/HTMLFormControlsCollection.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLCollection.cpp
diff --git a/Source/core/html/HTMLCollection.cpp b/Source/core/html/HTMLCollection.cpp
index ba1f4c576b97b4c34afbb783a0955da7c1f8e821..8a81afed942ae52b576c675e400d6847f908be28 100644
--- a/Source/core/html/HTMLCollection.cpp
+++ b/Source/core/html/HTMLCollection.cpp
@@ -442,17 +442,19 @@ void HTMLCollection::updateIdNameCache() const
if (hasValidIdNameCache())
return;
- NamedItemCache& cache = createNamedItemCache();
+ OwnPtr<NamedItemCache> cache = NamedItemCache::create();
for (Element* element = traverseToFirstElement(); element; element = traverseNextElement(*element)) {
const AtomicString& idAttrVal = element->getIdAttribute();
if (!idAttrVal.isEmpty())
- cache.addElementWithId(idAttrVal, element);
+ cache->addElementWithId(idAttrVal, element);
if (!element->isHTMLElement())
continue;
const AtomicString& nameAttrVal = element->getNameAttribute();
if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != DocAll || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element))))
- cache.addElementWithName(nameAttrVal, element);
+ cache->addElementWithName(nameAttrVal, element);
}
+ // Set the named item cache last as traversing the tree may cause cache invalidation.
+ setNamedItemCache(cache.release());
}
void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element> >& result) const
@@ -474,4 +476,8 @@ void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element>
result.append(nameResults->at(i));
}
+HTMLCollection::NamedItemCache::NamedItemCache()
+{
+}
+
} // namespace WebCore
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLFormControlsCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698