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

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

Issue 2769783002: Centralize more querySelector logic behind QuerySelectorCache. (Closed)
Patch Set: Created 3 years, 9 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: third_party/WebKit/Source/core/dom/SelectorQuery.cpp
diff --git a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
index 5037e303204593b63cee201bc5621043ff77aa99..21e2e6d8f17ea1226166df60599d1e5622ace195 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
@@ -26,6 +26,7 @@
#include "core/dom/SelectorQuery.h"
+#include <memory>
#include "bindings/core/v8/ExceptionState.h"
#include "core/HTMLNames.h"
#include "core/css/SelectorChecker.h"
@@ -34,11 +35,11 @@
#include "core/dom/ElementTraversal.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/Node.h"
+#include "core/dom/NthIndexCache.h"
#include "core/dom/StaticNodeList.h"
#include "core/dom/shadow/ElementShadow.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "wtf/PtrUtil.h"
-#include <memory>
namespace blink {
@@ -146,12 +147,14 @@ Element* SelectorQuery::closest(Element& targetElement) const {
}
StaticElementList* SelectorQuery::queryAll(ContainerNode& rootNode) const {
+ NthIndexCache nthIndexCache(rootNode.document());
HeapVector<Member<Element>> result;
execute<AllElementsSelectorQueryTrait>(rootNode, result);
return StaticElementList::adopt(result);
}
Element* SelectorQuery::queryFirst(ContainerNode& rootNode) const {
+ NthIndexCache nthIndexCache(rootNode.document());
Element* matchedElement = nullptr;
execute<SingleElementSelectorQueryTrait>(rootNode, matchedElement);
return matchedElement;
@@ -597,6 +600,12 @@ SelectorQuery::SelectorQuery(CSSSelectorList selectorList) {
SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors,
const Document& document,
ExceptionState& exceptionState) {
+ if (selectors.isEmpty()) {
+ exceptionState.throwDOMException(SyntaxError,
+ "The provided selector is empty.");
+ return nullptr;
+ }
+
HashMap<AtomicString, std::unique_ptr<SelectorQuery>>::iterator it =
m_entries.find(selectors);
if (it != m_entries.end())
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.cpp ('k') | third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698