|
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/. */ |
|
5 |
|
6 #include "nsRuleData.h" |
|
7 |
|
8 #include "mozilla/Poison.h" |
|
9 #include <stdint.h> |
|
10 |
|
11 inline size_t |
|
12 nsRuleData::GetPoisonOffset() |
|
13 { |
|
14 // Fill in mValueOffsets such that mValueStorage + mValueOffsets[i] |
|
15 // will yield the frame poison value for all uninitialized value |
|
16 // offsets. |
|
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)) / |
|
25 sizeof(nsCSSValue); |
|
26 } |
|
27 |
|
28 nsRuleData::nsRuleData(uint32_t aSIDs, nsCSSValue* aValueStorage, |
|
29 nsPresContext* aContext, nsStyleContext* aStyleContext) |
|
30 : mSIDs(aSIDs), |
|
31 mCanStoreInRuleTree(true), |
|
32 mPresContext(aContext), |
|
33 mStyleContext(aStyleContext), |
|
34 mValueStorage(aValueStorage) |
|
35 { |
|
36 #ifndef MOZ_VALGRIND |
|
37 size_t framePoisonOffset = GetPoisonOffset(); |
|
38 for (size_t i = 0; i < nsStyleStructID_Length; ++i) { |
|
39 mValueOffsets[i] = framePoisonOffset; |
|
40 } |
|
41 #endif |
|
42 } |
|
43 |
|
44 #ifdef DEBUG |
|
45 nsRuleData::~nsRuleData() |
|
46 { |
|
47 #ifndef MOZ_VALGRIND |
|
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"); |
|
54 } |
|
55 #endif |
|
56 } |
|
57 #endif |