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

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

Issue 1532103002: Better handling of DocumentOrderedMap same-ID lookups during tree removals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review updates, part2 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp ('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/core/dom/TreeScope.cpp
diff --git a/third_party/WebKit/Source/core/dom/TreeScope.cpp b/third_party/WebKit/Source/core/dom/TreeScope.cpp
index fe8f2ff9f4158bc2e2c17573f1389aacf4d19d1b..b1ef5db78976946ad332ccee02eac84547b269e1 100644
--- a/third_party/WebKit/Source/core/dom/TreeScope.cpp
+++ b/third_party/WebKit/Source/core/dom/TreeScope.cpp
@@ -186,11 +186,44 @@ void TreeScope::addElementById(const AtomicString& elementId, Element* element)
m_idTargetObserverRegistry->notifyObservers(elementId);
}
+
+#if ENABLE(ASSERT)
+namespace {
+
+class RemovingElementIdScope {
+ STACK_ALLOCATED();
+public:
+ RemovingElementIdScope(DocumentOrderedMap& elementsById, const AtomicString& id)
+ : m_elementsById(&elementsById)
+ {
+ m_elementsById->willRemoveId(id);
+ }
+ ~RemovingElementIdScope()
+ {
+ m_elementsById->willRemoveId(nullAtom);
+ }
+
+private:
+ RawPtrWillBeMember<DocumentOrderedMap> m_elementsById;
+};
+
+}
+#endif
+
void TreeScope::removeElementById(const AtomicString& elementId, Element* element)
{
if (!m_elementsById)
return;
m_elementsById->remove(elementId, element);
+#if ENABLE(ASSERT)
+ // Register 'elementId' as being removed. This is done should observers
+ // attempt to also look it up, something that the underlying DocumentOrderedMap
+ // is incapable of answering precisely while an element (and its
+ // children) are being removed from the tree. This is _only_ done to avoid
+ // an assert in DocumentOrderedMap::get() from falsely triggering for such
+ // unusual and unexpected lookups.
+ RemovingElementIdScope removalScope(*m_elementsById, elementId);
+#endif
m_idTargetObserverRegistry->notifyObservers(elementId);
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/DocumentOrderedMap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698