nsLineBox::nsLineBox(nsIFrame* aFrame, int32_t aCount, bool aIsBlock) : mFirstChild(aFrame) // NOTE: memory is already zeroed since we allocate with AllocateByObjectID. { MOZ_COUNT_CTOR(nsLineBox); #ifdef DEBUG ++ctorCount; NS_ASSERTION(!aIsBlock || aCount == 1, "Blocks must have exactly one child"); nsIFrame* f = aFrame; for (int32_t n = aCount; n > 0; f = f->GetNextSibling(), --n) { NS_ASSERTION(aIsBlock == f->IsBlockOutside(), "wrong kind of child frame"); } #endif MOZ_STATIC_ASSERT(NS_STYLE_CLEAR_LAST_VALUE <= 15, "FlagBits needs more bits to store the full range of " "break type ('clear') values"); #if NS_STYLE_CLEAR_NONE > 0 mFlags.mBreakType = NS_STYLE_CLEAR_NONE; #endif mChildCount = aCount; MarkDirty(); mFlags.mBlock = aIsBlock; }
static nsEventStates GetStatesForPseudoClass(const nsAString& aStatePseudo) { // An array of the states that are relevant for various pseudoclasses. // XXXbz this duplicates code in nsCSSRuleProcessor static const nsEventStates sPseudoClassStates[] = { #define CSS_PSEUDO_CLASS(_name, _value) \ nsEventStates(), #define CSS_STATE_PSEUDO_CLASS(_name, _value, _states) \ _states, #include "nsCSSPseudoClassList.h" #undef CSS_STATE_PSEUDO_CLASS #undef CSS_PSEUDO_CLASS // Add more entries for our fake values to make sure we can't // index out of bounds into this array no matter what. nsEventStates(), nsEventStates() }; MOZ_STATIC_ASSERT(NS_ARRAY_LENGTH(sPseudoClassStates) == nsCSSPseudoClasses::ePseudoClass_NotPseudoClass + 1, "Length of PseudoClassStates array is incorrect"); nsCOMPtr<nsIAtom> atom = do_GetAtom(aStatePseudo); // Ignore :moz-any-link so we don't give the element simultaneous // visited and unvisited style state if (nsCSSPseudoClasses::GetPseudoType(atom) == nsCSSPseudoClasses::ePseudoClass_mozAnyLink) { return nsEventStates(); } // Our array above is long enough that indexing into it with // NotPseudoClass is ok. return sPseudoClassStates[nsCSSPseudoClasses::GetPseudoType(atom)]; }
inline size_t nsRuleData::GetPoisonOffset() { // Fill in mValueOffsets such that mValueStorage + mValueOffsets[i] // will yield the frame poison value for all uninitialized value // offsets. MOZ_STATIC_ASSERT(sizeof(uintptr_t) == sizeof(size_t), "expect uintptr_t and size_t to be the same size"); MOZ_STATIC_ASSERT(uintptr_t(-1) > uintptr_t(0), "expect uintptr_t to be unsigned"); MOZ_STATIC_ASSERT(size_t(-1) > size_t(0), "expect size_t to be unsigned"); uintptr_t framePoisonValue = nsPresArena::GetPoisonValue(); return size_t(framePoisonValue - uintptr_t(mValueStorage)) / sizeof(nsCSSValue); }
nsCSSSelector::nsCSSSelector(void) : mLowercaseTag(nullptr), mCasedTag(nullptr), mIDList(nullptr), mClassList(nullptr), mPseudoClassList(nullptr), mAttrList(nullptr), mNegations(nullptr), mNext(nullptr), mNameSpace(kNameSpaceID_Unknown), mOperator(0), mPseudoType(nsCSSPseudoElements::ePseudo_NotPseudoElement) { MOZ_COUNT_CTOR(nsCSSSelector); MOZ_STATIC_ASSERT(nsCSSPseudoElements::ePseudo_MAX < INT16_MAX, "nsCSSPseudoElements::Type values overflow mPseudoType"); }
/* Local implementation of PR_Now, since the executable can't depend on NSPR */ static PRTime _PR_Now() { #ifdef XP_WIN MOZ_STATIC_ASSERT(sizeof(PRTime) == sizeof(FILETIME), "PRTime must have the same size as FILETIME"); FILETIME ft; GetSystemTimeAsFileTime(&ft); PRTime now; CopyMemory(&now, &ft, sizeof(PRTime)); #ifdef __GNUC__ return (now - 116444736000000000LL) / 10LL; #else return (now - 116444736000000000i64) / 10i64; #endif #else struct timeval tm; gettimeofday(&tm, 0); return (((PRTime)tm.tv_sec * 1000000LL) + (PRTime)tm.tv_usec); #endif }
PRIntervalTime DOMStorageDBThread::TimeUntilFlush() { if (mFlushImmediately) { return 0; // Do it now regardless the timeout. } MOZ_STATIC_ASSERT(PR_INTERVAL_NO_TIMEOUT != 0, "PR_INTERVAL_NO_TIMEOUT must be non-zero"); if (!mDirtyEpoch) { return PR_INTERVAL_NO_TIMEOUT; // No pending task... } static const PRIntervalTime kMaxAge = PR_MillisecondsToInterval(FLUSHING_INTERVAL_MS); PRIntervalTime now = PR_IntervalNow() | 1; PRIntervalTime age = now - mDirtyEpoch; if (age > kMaxAge) { return 0; // It is time. } return kMaxAge - age; // Time left, this is used to sleep the monitor }
nsresult Key::EncodeJSValInternal(JSContext* aCx, const jsval aVal, uint8_t aTypeOffset, uint16_t aRecursionDepth) { NS_ENSURE_TRUE(aRecursionDepth < MaxRecursionDepth, NS_ERROR_DOM_INDEXEDDB_DATA_ERR); MOZ_STATIC_ASSERT(eMaxType * MaxArrayCollapse < 256, "Unable to encode jsvals."); if (JSVAL_IS_STRING(aVal)) { nsDependentJSString str; if (!str.init(aCx, aVal)) { return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } EncodeString(str, aTypeOffset); return NS_OK; } if (JSVAL_IS_INT(aVal)) { EncodeNumber((double)JSVAL_TO_INT(aVal), eFloat + aTypeOffset); return NS_OK; } if (JSVAL_IS_DOUBLE(aVal)) { double d = JSVAL_TO_DOUBLE(aVal); if (MOZ_DOUBLE_IS_NaN(d)) { return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; } EncodeNumber(d, eFloat + aTypeOffset); return NS_OK; } if (!JSVAL_IS_PRIMITIVE(aVal)) { JSObject* obj = JSVAL_TO_OBJECT(aVal); if (JS_IsArrayObject(aCx, obj)) { aTypeOffset += eMaxType; if (aTypeOffset == eMaxType * MaxArrayCollapse) { mBuffer.Append(aTypeOffset); aTypeOffset = 0; } NS_ASSERTION((aTypeOffset % eMaxType) == 0 && aTypeOffset < (eMaxType * MaxArrayCollapse), "Wrong typeoffset"); uint32_t length; if (!JS_GetArrayLength(aCx, obj, &length)) { return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } for (uint32_t index = 0; index < length; index++) { jsval val; if (!JS_GetElement(aCx, obj, index, &val)) { return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } nsresult rv = EncodeJSValInternal(aCx, val, aTypeOffset, aRecursionDepth + 1); if (NS_FAILED(rv)) { return rv; } aTypeOffset = 0; } mBuffer.Append(eTerminator + aTypeOffset); return NS_OK; } if (JS_ObjectIsDate(aCx, obj)) { if (!js_DateIsValid(obj)) { return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; } EncodeNumber(js_DateGetMsecSinceEpoch(obj), eDate + aTypeOffset); return NS_OK; } } return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; }