Bug 1387934 - stylo: inDOMUtils::SelectorMatchesElement should not match with bogus pseudo. r?xidorn
MozReview-Commit-ID: 8jG6dWzn8eI
--- 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