This commit is contained in:
Daniel Holbert 2010-04-01 09:38:11 -07:00
commit 9eec42a4ac
4 changed files with 120 additions and 14 deletions

View File

@ -506,7 +506,8 @@ nsCSSValue::URL::URL(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
: mURI(aURI),
mString(aString),
mReferrer(aReferrer),
mOriginPrincipal(aOriginPrincipal)
mOriginPrincipal(aOriginPrincipal),
mRefCnt(0)
{
NS_PRECONDITION(aOriginPrincipal, "Must have an origin principal");
mString->AddRef();
@ -592,6 +593,7 @@ nsCSSValueGradient::nsCSSValueGradient(PRBool aIsRadial,
mBgPosY(eCSSUnit_None),
mAngle(eCSSUnit_None),
mRadialShape(eCSSUnit_None),
mRadialSize(eCSSUnit_None)
mRadialSize(eCSSUnit_None),
mRefCnt(0)
{
}

View File

@ -51,7 +51,6 @@
#include "nsCRTGlue.h"
#include "nsStringBuffer.h"
#include "nsTArray.h"
#include "nsISupportsImpl.h"
class imgIRequest;
class nsIDocument;
@ -380,9 +379,26 @@ public:
nsCOMPtr<nsIURI> mReferrer;
nsCOMPtr<nsIPrincipal> mOriginPrincipal;
NS_INLINE_DECL_REFCOUNTING(URL)
void AddRef() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking nsCSSValue::URL");
return;
}
++mRefCnt;
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::URL", sizeof(*this));
}
void Release() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking nsCSSValue::URL");
return;
}
--mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::URL");
if (mRefCnt == 0)
delete this;
}
protected:
nsrefcnt mRefCnt;
// not to be implemented
URL(const URL& aOther);
@ -404,7 +420,25 @@ public:
// Override AddRef and Release to not only log ourselves correctly, but
// also so that we delete correctly without a virtual destructor
NS_INLINE_DECL_REFCOUNTING(Image)
void AddRef() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking nsCSSValue::Image");
return;
}
++mRefCnt;
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Image", sizeof(*this));
}
void Release() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking nsCSSValue::Image");
return;
}
--mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Image");
if (mRefCnt == 0)
delete this;
}
};
private:
@ -495,9 +529,28 @@ struct nsCSSValueGradient {
return !(*this == aOther);
}
NS_INLINE_DECL_REFCOUNTING(nsCSSValueGradient)
void AddRef() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking nsCSSValue::Gradient");
return;
}
++mRefCnt;
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Gradient", sizeof(*this));
}
void Release() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking nsCSSValue::Gradient");
return;
}
--mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Gradient");
if (mRefCnt == 0)
delete this;
}
private:
nsrefcnt mRefCnt;
// not to be implemented
nsCSSValueGradient(const nsCSSValueGradient& aOther);
nsCSSValueGradient& operator=(const nsCSSValueGradient& aOther);
@ -535,8 +588,6 @@ struct nsCSSValue::Array {
return PR_TRUE;
}
// XXXdholbert This uses a 16-bit ref count to save space. Should we use
// a variant of NS_INLINE_DECL_REFCOUNTING that takes a type as an argument?
void AddRef() {
if (mRefCnt == PR_UINT16_MAX) {
NS_WARNING("refcount overflow, leaking nsCSSValue::Array");

View File

@ -1317,6 +1317,7 @@ nsStyleGradient::nsStyleGradient(void)
: mShape(NS_STYLE_GRADIENT_SHAPE_LINEAR)
, mSize(NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER)
, mRepeating(PR_FALSE)
, mRefCnt(0)
{
}
@ -2317,6 +2318,26 @@ nsChangeHint nsStyleTextReset::MaxDifference()
}
#endif
// --------------------
// nsCSSShadowArray
// nsCSSShadowItem
//
nsrefcnt
nsCSSShadowArray::Release()
{
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking object");
return mRefCnt;
}
mRefCnt--;
if (mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
// Allowed to return one of NS_STYLE_HINT_NONE, NS_STYLE_HINT_REFLOW
// or NS_STYLE_HINT_VISUAL. Currently we just return NONE or REFLOW, though.
// XXXbz can this not return a more specific hint? If that's ever

View File

@ -163,14 +163,38 @@ public:
// stops are in the order specified in the stylesheet
nsTArray<nsStyleGradientStop> mStops;
nsrefcnt AddRef() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking nsStyleGradient");
return mRefCnt;
}
++mRefCnt;
NS_LOG_ADDREF(this, mRefCnt, "nsStyleGradient", sizeof(*this));
return mRefCnt;
}
nsrefcnt Release() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking nsStyleGradient");
return mRefCnt;
}
--mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "nsStyleGradient");
if (mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
PRBool operator==(const nsStyleGradient& aOther) const;
PRBool operator!=(const nsStyleGradient& aOther) const {
return !(*this == aOther);
};
NS_INLINE_DECL_REFCOUNTING(nsStyleGradient)
private:
nsrefcnt mRefCnt;
~nsStyleGradient() {}
// Not to be implemented
@ -647,7 +671,7 @@ class nsCSSShadowArray {
}
nsCSSShadowArray(PRUint32 aArrayLen) :
mLength(aArrayLen)
mLength(aArrayLen), mRefCnt(0)
{
MOZ_COUNT_CTOR(nsCSSShadowArray);
for (PRUint32 i = 1; i < mLength; ++i) {
@ -663,6 +687,15 @@ class nsCSSShadowArray {
}
}
nsrefcnt AddRef() {
if (mRefCnt == PR_UINT32_MAX) {
NS_WARNING("refcount overflow, leaking object");
return mRefCnt;
}
return ++mRefCnt;
}
nsrefcnt Release();
PRUint32 Length() const { return mLength; }
nsCSSShadowItem* ShadowAt(PRUint32 i) {
NS_ABORT_IF_FALSE(i < mLength, "Accessing too high an index in the text shadow array!");
@ -673,10 +706,9 @@ class nsCSSShadowArray {
return &mArray[i];
}
NS_INLINE_DECL_REFCOUNTING(nsCSSShadowArray)
private:
PRUint32 mLength;
PRUint32 mRefCnt;
nsCSSShadowItem mArray[1]; // This MUST be the last item
};