Bug 1387934 - stylo: inDOMUtils::SelectorMatchesElement should not match with bogus pseudo. r?xidorn draft
authorFernando Jimenez Moreno <ferjmoreno@gmail.com>
Mon, 14 Aug 2017 12:28:58 +0200
changeset 645842 bc7a0da57536fdb1dc4d22d6dc1d529215dfc54d
parent 645674 3bfcbdf5c6c381d5a8febb5c209e27a69fb89f9b
child 726047 3d38c28ab9dcacda4c03c36e35b6f9ee864de77d
push id73908
push userferjmoreno@gmail.com
push dateMon, 14 Aug 2017 10:34:44 +0000
reviewersxidorn
bugs1387934
milestone57.0a1
Bug 1387934 - stylo: inDOMUtils::SelectorMatchesElement should not match with bogus pseudo. r?xidorn MozReview-Commit-ID: 8jG6dWzn8eI
layout/inspector/tests/mochitest.ini
layout/style/ServoStyleRule.cpp
--- a/layout/inspector/tests/mochitest.ini
+++ b/layout/inspector/tests/mochitest.ini
@@ -31,9 +31,8 @@ support-files =
 fail-if = stylo # bug 1387932
 [test_get_all_style_sheets.html]
 [test_is_valid_css_color.html]
 [test_isinheritableproperty.html]
 [test_parseStyleSheet.html]
 [test_parseStyleSheetImport.html]
 fail-if = stylo # bug 1387933
 [test_selectormatcheselement.html]
-fail-if = stylo # bug 1387934
--- a/layout/style/ServoStyleRule.cpp
+++ b/layout/style/ServoStyleRule.cpp
@@ -7,16 +7,17 @@
 /* representation of CSSStyleRule for stylo */
 
 #include "mozilla/ServoStyleRule.h"
 
 #include "mozilla/DeclarationBlockInlines.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/ServoDeclarationBlock.h"
 #include "mozilla/dom/CSSStyleRuleBinding.h"
+#include "nsCSSPseudoClasses.h"
 
 #include "mozAutoDocUpdate.h"
 
 namespace mozilla {
 
 // -- ServoStyleRuleDeclaration ---------------------------------------
 
 ServoStyleRuleDeclaration::ServoStyleRuleDeclaration(
@@ -274,20 +275,27 @@ ServoStyleRule::GetSpecificity(uint32_t 
 }
 
 nsresult
 ServoStyleRule::SelectorMatchesElement(Element* aElement,
                                        uint32_t aSelectorIndex,
                                        const nsAString& aPseudo,
                                        bool* aMatches)
 {
-  nsCOMPtr<nsIAtom> pseudoElt = NS_Atomize(aPseudo);
-  const CSSPseudoElementType pseudoType =
-    nsCSSPseudoElements::GetPseudoType(pseudoElt,
-                                       CSSEnabledState::eIgnoreEnabledState);
-  *aMatches = Servo_StyleRule_SelectorMatchesElement(mRawRule,
-                                                     aElement,
-                                                     aSelectorIndex,
-                                                     pseudoType);
+  CSSPseudoElementType pseudoType = CSSPseudoElementType::NotPseudo;
+  if (!aPseudo.IsEmpty()) {
+    nsCOMPtr<nsIAtom> pseudoElt = NS_Atomize(aPseudo);
+    pseudoType = nsCSSPseudoElements::GetPseudoType(
+        pseudoElt, CSSEnabledState::eIgnoreEnabledState);
+
+    if (pseudoType == CSSPseudoElementType::NotPseudo) {
+      *aMatches = false;
+      return NS_OK;
+    }
+  }
+
+  *aMatches = Servo_StyleRule_SelectorMatchesElement(mRawRule, aElement,
+                                                     aSelectorIndex, pseudoType);
+
   return NS_OK;
 }
 
 } // namespace mozilla