Bug 1410624: style: Hook QuerySelector into stylo. r=heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 21 Oct 2017 14:54:43 +0200
changeset 690476 f893dff589cbc67625109afce0a3b39ccc0be836
parent 690475 7917c3ad070820bf7bac54fab17ba7c0424143b7
child 690477 6b97923790f04e48b9c4e7d6eb2fa7229328c96f
push id87308
push userbmo:emilio@crisal.io
push dateThu, 02 Nov 2017 01:16:37 +0000
reviewersheycam
bugs1410624
milestone58.0a1
Bug 1410624: style: Hook QuerySelector into stylo. r=heycam MozReview-Commit-ID: 4uKWN9uqi3r Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
dom/base/nsINode.cpp
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -2924,25 +2924,36 @@ struct ElementHolder {
   Element* ElementAt(uint32_t aIndex) { return nullptr; }
 
   Element* mElement;
 };
 
 Element*
 nsINode::QuerySelector(const nsAString& aSelector, ErrorResult& aResult)
 {
-  nsCSSSelectorList* selectorList = ParseSelectorList(aSelector, aResult);
-  if (!selectorList) {
-    // Either we failed (and aResult already has the exception), or this
-    // is a pseudo-element-only selector that matches nothing.
-    return nullptr;
-  }
-  ElementHolder holder;
-  FindMatchingElements<true, ElementHolder>(this, selectorList, holder, aResult);
-  return holder.mElement;
+  return WithSelectorList<Element*>(
+    aSelector,
+    aResult,
+    [&](const RawServoSelectorList* aList) -> Element* {
+      if (!aList) {
+        return nullptr;
+      }
+      return const_cast<Element*>(Servo_SelectorList_QueryFirst(this, aList));
+    },
+    [&](nsCSSSelectorList* aList) -> Element* {
+      if (!aList) {
+        // Either we failed (and aResult already has the exception), or this
+        // is a pseudo-element-only selector that matches nothing.
+        return nullptr;
+      }
+      ElementHolder holder;
+      FindMatchingElements<true, ElementHolder>(this, aList, holder, aResult);
+      return holder.mElement;
+    }
+  );
 }
 
 already_AddRefed<nsINodeList>
 nsINode::QuerySelectorAll(const nsAString& aSelector, ErrorResult& aResult)
 {
   RefPtr<nsSimpleContentList> contentList = new nsSimpleContentList(this);
 
   WithSelectorList<void>(