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