Bug 1356305 - stylo: Initialize system metrics before traversing; r=bholley

MozReview-Commit-ID: IOeT4qSHTy5

--HG--
extra : rebase_source : 3a3f87d8564bd47620b0658aef97522f3583dfbe
This commit is contained in:
Manish Goregaokar 2017-04-14 09:28:25 +08:00
Родитель 023a635e1c
Коммит 1042765b58
5 изменённых файлов: 25 добавлений и 28 удалений

Просмотреть файл

@ -650,7 +650,7 @@ Gecko_MatchStringArgPseudo(RawGeckoElementBorrowed aElement,
EventStates dummyMask; // mask is never read because we pass aDependence=nullptr
return nsCSSRuleProcessor::StringPseudoMatches(aElement, aType, aIdent,
aElement->OwnerDoc(), true,
dummyMask, false, aSetSlowSelectorFlag, nullptr);
dummyMask, aSetSlowSelectorFlag, nullptr);
}
nsIAtom*

Просмотреть файл

@ -16,6 +16,7 @@
#include "mozilla/dom/KeyframeEffectReadOnly.h"
#include "nsCSSAnonBoxes.h"
#include "nsCSSPseudoElements.h"
#include "nsCSSRuleProcessor.h"
#include "nsDeviceContext.h"
#include "nsHTMLStyleSheet.h"
#include "nsIDocumentInlines.h"
@ -245,6 +246,8 @@ ServoStyleSet::PreTraverseSync()
{
ResolveMappedAttrDeclarationBlocks();
nsCSSRuleProcessor::InitSystemMetrics();
// This is lazily computed and pseudo matching needs to access
// it so force computation early.
mPresContext->Document()->GetDocumentState();

Просмотреть файл

@ -47,6 +47,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/EventStates.h"
#include "mozilla/Preferences.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/Likely.h"
#include "mozilla/OperatorNewExtensions.h"
@ -1061,13 +1062,15 @@ nsCSSRuleProcessor::Startup()
true);
}
static bool
InitSystemMetrics()
/* static */ void
nsCSSRuleProcessor::InitSystemMetrics()
{
NS_ASSERTION(!sSystemMetrics, "already initialized");
if (sSystemMetrics)
return;
MOZ_ASSERT(NS_IsMainThread());
sSystemMetrics = new nsTArray< nsCOMPtr<nsIAtom> >;
NS_ENSURE_TRUE(sSystemMetrics, false);
/***************************************************************************
* ANY METRICS ADDED HERE SHOULD ALSO BE ADDED AS MEDIA QUERIES IN *
@ -1193,8 +1196,6 @@ InitSystemMetrics()
}
}
#endif
return true;
}
/* static */ void
@ -1213,9 +1214,7 @@ nsCSSRuleProcessor::Shutdown()
/* static */ bool
nsCSSRuleProcessor::HasSystemMetric(nsIAtom* aMetric)
{
if (!sSystemMetrics && !InitSystemMetrics()) {
return false;
}
nsCSSRuleProcessor::InitSystemMetrics();
return sSystemMetrics->IndexOf(aMetric) != sSystemMetrics->NoIndex;
}
@ -1223,8 +1222,7 @@ nsCSSRuleProcessor::HasSystemMetric(nsIAtom* aMetric)
/* static */ uint8_t
nsCSSRuleProcessor::GetWindowsThemeIdentifier()
{
if (!sSystemMetrics)
InitSystemMetrics();
nsCSSRuleProcessor::InitSystemMetrics();
return sWinThemeId;
}
#endif
@ -1639,17 +1637,16 @@ StateSelectorMatches(Element* aElement,
static inline bool
IsSignificantChildMaybeThreadSafe(const nsIContent* aContent,
bool aTextIsSignificant,
bool aWhitespaceIsSignificant,
bool aIsGecko)
bool aWhitespaceIsSignificant)
{
if (aIsGecko) {
auto content = const_cast<nsIContent*>(aContent);
return IsSignificantChild(content, aTextIsSignificant, aWhitespaceIsSignificant);
} else {
if (ServoStyleSet::IsInServoTraversal()) {
// See bug 1349100 for optimizing this
return nsStyleUtil::ThreadSafeIsSignificantChild(aContent,
aTextIsSignificant,
aWhitespaceIsSignificant);
} else {
auto content = const_cast<nsIContent*>(aContent);
return IsSignificantChild(content, aTextIsSignificant, aWhitespaceIsSignificant);
}
}
@ -1660,7 +1657,6 @@ nsCSSRuleProcessor::StringPseudoMatches(const mozilla::dom::Element* aElement,
const nsIDocument* aDocument,
bool aForStyling,
EventStates aStateMask,
bool aIsGecko,
bool* aSetSlowSelectorFlag,
bool* const aDependence)
{
@ -1670,13 +1666,13 @@ nsCSSRuleProcessor::StringPseudoMatches(const mozilla::dom::Element* aElement,
case CSSPseudoClassType::mozLocaleDir:
{
bool docIsRTL;
if (aIsGecko) {
if (ServoStyleSet::IsInServoTraversal()) {
docIsRTL = aDocument->ThreadSafeGetDocumentState()
.HasState(NS_DOCUMENT_STATE_RTL_LOCALE);
} else {
auto doc = const_cast<nsIDocument*>(aDocument);
docIsRTL = doc->GetDocumentState()
.HasState(NS_DOCUMENT_STATE_RTL_LOCALE);
} else {
docIsRTL = aDocument->ThreadSafeGetDocumentState()
.HasState(NS_DOCUMENT_STATE_RTL_LOCALE);
}
nsDependentString dirString(aString);
@ -1722,7 +1718,7 @@ nsCSSRuleProcessor::StringPseudoMatches(const mozilla::dom::Element* aElement,
do {
child = aElement->GetChildAt(++index);
} while (child &&
(!IsSignificantChildMaybeThreadSafe(child, true, false, aIsGecko) ||
(!IsSignificantChildMaybeThreadSafe(child, true, false) ||
(child->GetNameSpaceID() == aElement->GetNameSpaceID() &&
child->NodeInfo()->NameAtom()->Equals(nsDependentString(aString)))));
if (child) {
@ -2168,7 +2164,6 @@ static bool SelectorMatches(Element* aElement,
aTreeMatchContext.mDocument,
aTreeMatchContext.mForStyling,
aNodeMatchContext.mStateMask,
true,
&setSlowSelectorFlag,
aDependence);
if (setSlowSelectorFlag) {

Просмотреть файл

@ -82,6 +82,7 @@ public:
nsresult ClearRuleCascades();
static void Startup();
static void InitSystemMetrics();
static void Shutdown();
static void FreeSystemMetrics();
static bool HasSystemMetric(nsIAtom* aMetric);
@ -152,7 +153,6 @@ public:
* (For setting the slow selector flag)
* @param aStateMask Mask containing states which we should exclude.
* Ignored if aDependence is null
* @param aIsGecko Set if Gecko.
* @param aSetSlowSelectorFlag Outparam, set if the caller is
* supposed to set the slow selector flag.
* @param aDependence Pointer to be set to true if we ignored a state due to
@ -164,7 +164,6 @@ public:
const nsIDocument* aDocument,
bool aForStyling,
mozilla::EventStates aStateMask,
bool aIsGecko,
bool* aSetSlowSelectorFlag,
bool* const aDependence = nullptr);

Просмотреть файл

@ -151,7 +151,7 @@ function check_hazards () {
exit 1
fi
NUM_ALLOWED_WRITE_HAZARDS=9
NUM_ALLOWED_WRITE_HAZARDS=8
if [ $NUM_WRITE_HAZARDS -gt $NUM_ALLOWED_WRITE_HAZARDS ]; then
echo "TEST-UNEXPECTED-FAIL $NUM_WRITE_HAZARDS heap write hazards detected out of $NUM_ALLOWED_WRITE_HAZARDS allowed" >&2
echo "TinderboxPrint: documentation<br/><a href='https://wiki.mozilla.org/Javascript:Hazard_Builds#Diagnosing_a_heap_write_hazard_failure'>heap write hazard analysis failures</a>, visit \"Inspect Task\" link for hazard details"