layout/style/nsRuleData.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsRuleData.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsRuleData.h"
    1.10 +
    1.11 +#include "mozilla/Poison.h"
    1.12 +#include <stdint.h>
    1.13 +
    1.14 +inline size_t
    1.15 +nsRuleData::GetPoisonOffset()
    1.16 +{
    1.17 +  // Fill in mValueOffsets such that mValueStorage + mValueOffsets[i]
    1.18 +  // will yield the frame poison value for all uninitialized value
    1.19 +  // offsets.
    1.20 +  static_assert(sizeof(uintptr_t) == sizeof(size_t),
    1.21 +                "expect uintptr_t and size_t to be the same size");
    1.22 +  static_assert(uintptr_t(-1) > uintptr_t(0),
    1.23 +                "expect uintptr_t to be unsigned");
    1.24 +  static_assert(size_t(-1) > size_t(0),
    1.25 +                "expect size_t to be unsigned");
    1.26 +  uintptr_t framePoisonValue = mozPoisonValue();
    1.27 +  return size_t(framePoisonValue - uintptr_t(mValueStorage)) /
    1.28 +         sizeof(nsCSSValue);
    1.29 +}
    1.30 +
    1.31 +nsRuleData::nsRuleData(uint32_t aSIDs, nsCSSValue* aValueStorage,
    1.32 +                       nsPresContext* aContext, nsStyleContext* aStyleContext)
    1.33 +  : mSIDs(aSIDs),
    1.34 +    mCanStoreInRuleTree(true),
    1.35 +    mPresContext(aContext),
    1.36 +    mStyleContext(aStyleContext),
    1.37 +    mValueStorage(aValueStorage)
    1.38 +{
    1.39 +#ifndef MOZ_VALGRIND
    1.40 +  size_t framePoisonOffset = GetPoisonOffset();
    1.41 +  for (size_t i = 0; i < nsStyleStructID_Length; ++i) {
    1.42 +    mValueOffsets[i] = framePoisonOffset;
    1.43 +  }
    1.44 +#endif
    1.45 +}
    1.46 +
    1.47 +#ifdef DEBUG
    1.48 +nsRuleData::~nsRuleData()
    1.49 +{
    1.50 +#ifndef MOZ_VALGRIND
    1.51 +  // assert nothing in mSIDs has poison value
    1.52 +  size_t framePoisonOffset = GetPoisonOffset();
    1.53 +  for (size_t i = 0; i < nsStyleStructID_Length; ++i) {
    1.54 +    NS_ABORT_IF_FALSE(!(mSIDs & (1 << i)) ||
    1.55 +                      mValueOffsets[i] != framePoisonOffset,
    1.56 +                      "value in SIDs was left with poison offset");
    1.57 +  }
    1.58 +#endif
    1.59 +}
    1.60 +#endif

mercurial