1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsRuleData.h"
8 #include "mozilla/Poison.h"
12 nsRuleData::GetPoisonOffset()
14 // Fill in mValueOffsets such that mValueStorage + mValueOffsets[i]
15 // will yield the frame poison value for all uninitialized value
17 static_assert(sizeof(uintptr_t) == sizeof(size_t),
18 "expect uintptr_t and size_t to be the same size");
19 static_assert(uintptr_t(-1) > uintptr_t(0),
20 "expect uintptr_t to be unsigned");
21 static_assert(size_t(-1) > size_t(0),
22 "expect size_t to be unsigned");
23 uintptr_t framePoisonValue
= mozPoisonValue();
24 return size_t(framePoisonValue
- uintptr_t(mValueStorage
)) /
28 nsRuleData::nsRuleData(uint32_t aSIDs
, nsCSSValue
* aValueStorage
,
29 nsPresContext
* aContext
, nsStyleContext
* aStyleContext
)
31 mCanStoreInRuleTree(true),
32 mPresContext(aContext
),
33 mStyleContext(aStyleContext
),
34 mValueStorage(aValueStorage
)
37 size_t framePoisonOffset
= GetPoisonOffset();
38 for (size_t i
= 0; i
< nsStyleStructID_Length
; ++i
) {
39 mValueOffsets
[i
] = framePoisonOffset
;
45 nsRuleData::~nsRuleData()
48 // assert nothing in mSIDs has poison value
49 size_t framePoisonOffset
= GetPoisonOffset();
50 for (size_t i
= 0; i
< nsStyleStructID_Length
; ++i
) {
51 NS_ABORT_IF_FALSE(!(mSIDs
& (1 << i
)) ||
52 mValueOffsets
[i
] != framePoisonOffset
,
53 "value in SIDs was left with poison offset");