From fa7cd93ca9954184bf0fc3c02bfb9db12bb8d35b Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Sat, 7 Feb 2015 13:25:21 +1100 Subject: [PATCH] Bug 1122781 part 2 - Generate dependencies table of style structs for runtime check. r=dbaron --HG-- extra : source : ed2baad25b34094f5c8abfe42ebe2cd77c1f2bab --- layout/style/nsStyleContext.cpp | 35 +++++++++++++++++++++++++++++++++ layout/style/nsStyleContext.h | 11 +++++++++++ 2 files changed, 46 insertions(+) diff --git a/layout/style/nsStyleContext.cpp b/layout/style/nsStyleContext.cpp index 8801102e431..106f2e0d89f 100644 --- a/layout/style/nsStyleContext.cpp +++ b/layout/style/nsStyleContext.cpp @@ -32,6 +32,35 @@ using namespace mozilla; //---------------------------------------------------------------------- +#ifdef DEBUG + +// Check that the style struct IDs are in the same order as they are +// in nsStyleStructList.h, since when we set up the IDs, we include +// the inherited and reset structs spearately from nsStyleStructList.h +enum DebugStyleStruct { +#define STYLE_STRUCT(name, checkdata_cb) eDebugStyleStruct_##name, +#include "nsStyleStructList.h" +#undef STYLE_STRUCT +}; + +#define STYLE_STRUCT(name, checkdata_cb) \ + static_assert(static_cast(eDebugStyleStruct_##name) == \ + static_cast(eStyleStruct_##name), \ + "Style struct IDs are not declared in order?"); +#include "nsStyleStructList.h" +#undef STYLE_STRUCT + +const uint32_t nsStyleContext::sDependencyTable[] = { +#define STYLE_STRUCT(name, checkdata_cb) +#define STYLE_STRUCT_DEP(dep) NS_STYLE_INHERIT_BIT(dep) | +#define STYLE_STRUCT_END() 0, +#include "nsStyleStructList.h" +#undef STYLE_STRUCT +#undef STYLE_STRUCT_DEP +#undef STYLE_STRUCT_END +}; + +#endif nsStyleContext::nsStyleContext(nsStyleContext* aParent, nsIAtom* aPseudoTag, @@ -54,6 +83,12 @@ nsStyleContext::nsStyleContext(nsStyleContext* aParent, "pseudo element bits no longer fit in a uint64_t"); MOZ_ASSERT(aRuleNode); +#ifdef DEBUG + static_assert(MOZ_ARRAY_LENGTH(nsStyleContext::sDependencyTable) + == nsStyleStructID_Length, + "Number of items in dependency table doesn't match IDs"); +#endif + mNextSibling = this; mPrevSibling = this; if (mParent) { diff --git a/layout/style/nsStyleContext.h b/layout/style/nsStyleContext.h index 91945e93dcd..61738e3d9d4 100644 --- a/layout/style/nsStyleContext.h +++ b/layout/style/nsStyleContext.h @@ -517,6 +517,17 @@ private: uint64_t mBits; // Which structs are inherited from the // parent context or owned by mRuleNode. uint32_t mRefCnt; + +#ifdef DEBUG + static bool DependencyAllowed(nsStyleStructID aOuterSID, + nsStyleStructID aInnerSID) + { + return !!(sDependencyTable[aOuterSID] & + nsCachedStyleData::GetBitForSID(aInnerSID)); + } + + static const uint32_t sDependencyTable[]; +#endif }; already_AddRefed