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

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

Issue 2588643004: Allow positional selectors to match elements without a parent. (Closed)
Patch Set: Changed the expectation instead of the crashtest, since it felt a bit saner. Created 4 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/NthIndexCache.cpp
diff --git a/third_party/WebKit/Source/core/dom/NthIndexCache.cpp b/third_party/WebKit/Source/core/dom/NthIndexCache.cpp
index 723f0c477dfe0716f5df084de45ad6efb692c7ad..570c92ca802105c42cc385b5839f8f4d7211a26f 100644
--- a/third_party/WebKit/Source/core/dom/NthIndexCache.cpp
+++ b/third_party/WebKit/Source/core/dom/NthIndexCache.cpp
@@ -81,15 +81,14 @@ unsigned uncachedNthLastOfTypeIndex(Element& element, unsigned& siblingCount) {
unsigned NthIndexCache::nthChildIndex(Element& element) {
if (element.isPseudoElement())
return 1;
- DCHECK(element.parentNode());
NthIndexCache* nthIndexCache = element.document().nthIndexCache();
NthIndexData* nthIndexData = nullptr;
- if (nthIndexCache && nthIndexCache->m_parentMap)
+ if (element.parentNode() && nthIndexCache && nthIndexCache->m_parentMap)
rune 2016/12/20 09:18:47 If you don't have a parent node, won't N always be
nthIndexData = nthIndexCache->m_parentMap->get(element.parentNode());
if (nthIndexData)
return nthIndexData->nthIndex(element);
unsigned index = uncachedNthChildIndex(element);
- if (nthIndexCache && index > kCachedSiblingCountLimit)
+ if (element.parentNode() && nthIndexCache && index > kCachedSiblingCountLimit)
nthIndexCache->cacheNthIndexDataForParent(element);
return index;
}
@@ -97,22 +96,20 @@ unsigned NthIndexCache::nthChildIndex(Element& element) {
unsigned NthIndexCache::nthLastChildIndex(Element& element) {
if (element.isPseudoElement())
return 1;
- DCHECK(element.parentNode());
NthIndexCache* nthIndexCache = element.document().nthIndexCache();
NthIndexData* nthIndexData = nullptr;
- if (nthIndexCache && nthIndexCache->m_parentMap)
+ if (element.parentNode() && nthIndexCache && nthIndexCache->m_parentMap)
nthIndexData = nthIndexCache->m_parentMap->get(element.parentNode());
if (nthIndexData)
return nthIndexData->nthLastIndex(element);
unsigned index = uncachedNthLastChildIndex(element);
- if (nthIndexCache && index > kCachedSiblingCountLimit)
+ if (element.parentNode() && nthIndexCache && index > kCachedSiblingCountLimit)
nthIndexCache->cacheNthIndexDataForParent(element);
return index;
}
NthIndexData* NthIndexCache::nthTypeIndexDataForParent(Element& element) const {
- DCHECK(element.parentNode());
- if (!m_parentMapForType)
+ if (!m_parentMapForType || !element.parentNode())
return nullptr;
if (const IndexByType* map = m_parentMapForType->get(element.parentNode()))
return map->get(element.tagName());

Powered by Google App Engine
This is Rietveld 408576698