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

Unified Diff: third_party/WebKit/Source/wtf/LinkedHashSet.h

Issue 1892533003: Catch illegal hash table modifications when they happen. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add reqd copy ctor Created 4 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 | « third_party/WebKit/Source/wtf/HashTable.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/LinkedHashSet.h
diff --git a/third_party/WebKit/Source/wtf/LinkedHashSet.h b/third_party/WebKit/Source/wtf/LinkedHashSet.h
index d4bb0fbf02cdee762844acae5c7963d1475dbfc7..ba05506ad9001697cc84fe13f7fa6e5f9d5a3000 100644
--- a/third_party/WebKit/Source/wtf/LinkedHashSet.h
+++ b/third_party/WebKit/Source/wtf/LinkedHashSet.h
@@ -279,8 +279,10 @@ public:
template<typename VisitorDispatcher>
void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); }
- int64_t modifications() const { return m_impl.modifications(); }
- void checkModifications(int64_t mods) const { m_impl.checkModifications(mods); }
+#if ENABLE(ASSERT)
+ void enterModificationForbiddenScope() { m_impl.enterModificationForbiddenScope(); }
+ void leaveModificationForbiddenScope() { m_impl.leaveModificationForbiddenScope(); }
+#endif
private:
Node* anchor() { return reinterpret_cast<Node*>(&m_anchor); }
@@ -416,8 +418,7 @@ protected:
LinkedHashSetConstIterator(const LinkedHashSetNodeBase* position, const LinkedHashSetType* container)
: m_position(position)
#if ENABLE(ASSERT)
- , m_container(container)
- , m_containerModifications(container->modifications())
+ , m_modificationForbiddenScope(position ? container : nullptr)
#endif
{
}
@@ -425,7 +426,6 @@ protected:
public:
PointerType get() const
{
- checkModifications();
return &static_cast<const Node*>(m_position)->m_value;
}
ReferenceType operator*() const { return *get(); }
@@ -434,16 +434,28 @@ public:
LinkedHashSetConstIterator& operator++()
{
ASSERT(m_position);
- checkModifications();
m_position = m_position->m_next;
+#if ENABLE(ASSERT)
+ // If now at the end, leave the forbidden scope. Waiting until
+ // the iterator goes out of (stack) scope disallows perfectly valid
+ // code idioms.
+ if (!m_position)
+ m_modificationForbiddenScope.leaveScope();
+#endif
return *this;
}
LinkedHashSetConstIterator& operator--()
{
ASSERT(m_position);
- checkModifications();
m_position = m_position->m_prev;
+#if ENABLE(ASSERT)
+ // If now at the end, leave the forbidden scope. Waiting until
+ // the iterator goes out of (stack) scope disallows perfectly valid
+ // code idioms.
+ if (!m_position)
+ m_modificationForbiddenScope.leaveScope();
+#endif
return *this;
}
@@ -460,16 +472,13 @@ public:
}
private:
+ template<typename T, typename U, typename V, typename W> friend class LinkedHashSet;
+ friend class LinkedHashSetIterator<LinkedHashSetType>;
+
const LinkedHashSetNodeBase* m_position;
#if ENABLE(ASSERT)
- void checkModifications() const { m_container->checkModifications(m_containerModifications); }
- const LinkedHashSetType* m_container;
- int64_t m_containerModifications;
-#else
- void checkModifications() const { }
+ HashTableModificationForbiddenScope<LinkedHashSetType> m_modificationForbiddenScope;
#endif
- template<typename T, typename U, typename V, typename W> friend class LinkedHashSet;
- friend class LinkedHashSetIterator<LinkedHashSetType>;
};
template<typename LinkedHashSetType>
« no previous file with comments | « third_party/WebKit/Source/wtf/HashTable.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698