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

Unified Diff: third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp

Issue 1555653002: Handle some failing DocumentOrderedMap ID lookups across tree removals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 5 years 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: third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp
diff --git a/third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp b/third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp
index 85495bec18bf499bb57041f8f20c9c76053cd278..1cfba8681409fcf30a5d0d4d967b7d18e26fc905 100644
--- a/third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp
+++ b/third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp
@@ -50,9 +50,20 @@ DocumentOrderedMap::DocumentOrderedMap()
{
}
-DocumentOrderedMap::~DocumentOrderedMap()
+DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DocumentOrderedMap);
+
+#if ENABLE(ASSERT)
+void DocumentOrderedMap::enterTreeRemoveScope()
esprehn 2016/01/05 07:48:33 no need for the methods, put the class in Document
sof 2016/01/05 07:53:37 That's what ps#1 did, but then I got worried about
+{
+ m_treeRemovalScopeLevel++;
+}
+
+void DocumentOrderedMap::leaveTreeRemoveScope()
{
+ ASSERT(m_treeRemovalScopeLevel);
+ m_treeRemovalScopeLevel--;
}
+#endif
inline bool keyMatchesId(const AtomicString& key, const Element& element)
{
@@ -114,14 +125,6 @@ void DocumentOrderedMap::remove(const AtomicString& key, Element* element)
}
}
-#if ENABLE(ASSERT)
-void DocumentOrderedMap::willRemoveId(const AtomicString& key)
-{
- ASSERT(m_removingId.isNull() || key.isNull());
- m_removingId = key;
-}
-#endif
-
template<bool keyMatches(const AtomicString&, const Element&)>
inline Element* DocumentOrderedMap::get(const AtomicString& key, const TreeScope* scope) const
{
@@ -138,20 +141,17 @@ inline Element* DocumentOrderedMap::get(const AtomicString& key, const TreeScope
// Iterate to find the node that matches. Nothing will match iff an element
// with children having duplicate IDs is being removed -- the tree traversal
- // will be over an updated tree not having that element. In all other cases,
+ // will be over an updated tree not having that subtree. In all other cases,
// a match is expected.
- //
- // Such calls to get()/getElementById() while handling element removals will
- // legitimately happen when e.g., adjusting form ID associations. Quietly
- // allow those lookups to (expectedly) fail by having the tree scope removal
- // register the element ID it is in the process of removing.
for (Element& element : ElementTraversal::startsAfter(scope->rootNode())) {
if (!keyMatches(key, element))
continue;
entry->element = &element;
return &element;
}
- ASSERT(key == m_removingId);
+ // As get()/getElementById() can legitimately be called while handling element
+ // removals, allow failure iff we're in the scope of node removals.
+ ASSERT(m_treeRemovalScopeLevel);
return 0;
}

Powered by Google App Engine
This is Rietveld 408576698