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

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

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
Index: Source/core/html/HTMLCollection.h
diff --git a/Source/core/html/HTMLCollection.h b/Source/core/html/HTMLCollection.h
index 0b1601da4db92e05041f1c58827c0c1201decc90..60b3674f848c4725294ce554e195fa9289ac9450 100644
--- a/Source/core/html/HTMLCollection.h
+++ b/Source/core/html/HTMLCollection.h
@@ -67,12 +67,18 @@ protected:
class NamedItemCache {
public:
+ static PassOwnPtr<NamedItemCache> create()
+ {
+ return adoptPtr(new NamedItemCache);
+ }
+
Vector<Element*>* getElementsById(const AtomicString& id) const { return m_idCache.get(id.impl()); }
Vector<Element*>* getElementsByName(const AtomicString& name) const { return m_nameCache.get(name.impl()); }
void addElementWithId(const AtomicString& id, Element* element) { addElementToMap(m_idCache, id, element); }
void addElementWithName(const AtomicString& name, Element* element) { addElementToMap(m_nameCache, name, element); }
private:
+ NamedItemCache();
typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > StringToElementsMap;
static void addElementToMap(StringToElementsMap& map, const AtomicString& key, Element* element)
{
@@ -94,13 +100,13 @@ protected:
virtual void updateIdNameCache() const;
bool hasValidIdNameCache() const { return m_namedItemCache; }
- NamedItemCache& createNamedItemCache() const
+ void setNamedItemCache(PassOwnPtr<NamedItemCache> cache) const
{
ASSERT(!m_namedItemCache);
document().incrementNodeListWithIdNameCacheCount();
- m_namedItemCache = adoptPtr(new NamedItemCache);
- return *m_namedItemCache;
+ m_namedItemCache = cache;
}
+
NamedItemCache& namedItemCache() const
{
ASSERT(m_namedItemCache);
« no previous file with comments | « LayoutTests/fast/dom/htmlcollection-selectedOptions-namedItem-crash-expected.txt ('k') | Source/core/html/HTMLCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698