From 2721f313e577a9b189dece2a8fb2f53d34f38247 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Thu, 30 May 2013 18:34:53 -0400 Subject: [PATCH] bug 877886 - get rid of a number of static constructors in content/ and dom/ r=smaug --- .../canvas/src/CanvasRenderingContext2D.cpp | 8 ++-- content/smil/SMILBoolType.cpp | 4 +- content/smil/SMILBoolType.h | 6 ++- content/smil/SMILEnumType.cpp | 4 +- content/smil/SMILEnumType.h | 7 ++- content/smil/SMILIntegerType.cpp | 4 +- content/smil/SMILIntegerType.h | 7 ++- content/smil/SMILStringType.cpp | 4 +- content/smil/SMILStringType.h | 7 ++- content/smil/nsSMILCSSValueType.cpp | 2 +- content/smil/nsSMILFloatType.cpp | 4 +- content/smil/nsSMILFloatType.h | 7 ++- content/smil/nsSMILNullType.cpp | 4 +- content/smil/nsSMILNullType.h | 7 ++- content/smil/nsSMILValue.cpp | 6 +-- content/smil/nsSMILValue.h | 4 +- .../content/src/DOMSVGAnimatedLengthList.cpp | 18 ++++--- .../content/src/DOMSVGAnimatedNumberList.cpp | 18 ++++--- content/svg/content/src/DOMSVGPathSegList.cpp | 18 ++++--- content/svg/content/src/DOMSVGPointList.cpp | 18 ++++--- content/svg/content/src/DOMSVGStringList.cpp | 16 +++++-- .../content/src/SVGAnimatedPathSegList.cpp | 8 ++-- .../src/SVGAnimatedPreserveAspectRatio.cpp | 8 ++-- .../content/src/SVGIntegerPairSMILType.cpp | 4 +- .../svg/content/src/SVGIntegerPairSMILType.h | 7 ++- .../svg/content/src/SVGLengthListSMILType.cpp | 2 +- content/svg/content/src/SVGMotionSMILType.cpp | 2 +- .../svg/content/src/SVGNumberListSMILType.cpp | 2 +- .../svg/content/src/SVGNumberPairSMILType.cpp | 2 +- content/svg/content/src/SVGOrientSMILType.cpp | 2 +- .../content/src/SVGPathSegListSMILType.cpp | 4 +- .../svg/content/src/SVGPathSegListSMILType.h | 6 ++- .../svg/content/src/SVGPointListSMILType.cpp | 2 +- content/svg/content/src/SVGTransform.cpp | 17 ++++--- .../content/src/SVGTransformListSMILType.cpp | 10 ++-- .../content/src/SVGTransformListSMILType.h | 7 ++- .../svg/content/src/SVGViewBoxSMILType.cpp | 2 +- .../src/nsSVGAnimatedTransformList.cpp | 6 +-- content/svg/content/src/nsSVGBoolean.cpp | 24 ++++++---- content/svg/content/src/nsSVGClass.cpp | 8 ++-- content/svg/content/src/nsSVGEnum.cpp | 8 ++-- content/svg/content/src/nsSVGInteger.cpp | 8 ++-- content/svg/content/src/nsSVGIntegerPair.cpp | 8 ++-- content/svg/content/src/nsSVGLength2.cpp | 8 ++-- content/svg/content/src/nsSVGNumber2.cpp | 8 ++-- content/svg/content/src/nsSVGString.cpp | 24 ++++++---- dom/base/nsDOMException.cpp | 48 +++++++++---------- dom/indexedDB/IDBTransaction.cpp | 5 +- dom/src/geolocation/nsGeolocation.cpp | 2 +- dom/src/geolocation/nsGeolocation.h | 3 +- 50 files changed, 243 insertions(+), 175 deletions(-) diff --git a/content/canvas/src/CanvasRenderingContext2D.cpp b/content/canvas/src/CanvasRenderingContext2D.cpp index c0d4403c9ec0..e077551351e1 100644 --- a/content/canvas/src/CanvasRenderingContext2D.cpp +++ b/content/canvas/src/CanvasRenderingContext2D.cpp @@ -122,10 +122,6 @@ namespace mgfx = mozilla::gfx; namespace mozilla { namespace dom { -static float kDefaultFontSize = 10.0; -static NS_NAMED_LITERAL_STRING(kDefaultFontName, "sans-serif"); -static NS_NAMED_LITERAL_STRING(kDefaultFontStyle, "10px sans-serif"); - // Cap sigma to avoid overly large temp surfaces. const Float SIGMA_MAX = 100; @@ -2708,12 +2704,14 @@ gfxFontGroup *CanvasRenderingContext2D::GetCurrentFontStyle() // use lazy initilization for the font group since it's rather expensive if (!CurrentState().fontGroup) { ErrorResult err; + NS_NAMED_LITERAL_STRING(kDefaultFontStyle, "10px sans-serif"); + static float kDefaultFontSize = 10.0; SetFont(kDefaultFontStyle, err); if (err.Failed()) { gfxFontStyle style; style.size = kDefaultFontSize; CurrentState().fontGroup = - gfxPlatform::GetPlatform()->CreateFontGroup(kDefaultFontName, + gfxPlatform::GetPlatform()->CreateFontGroup(NS_LITERAL_STRING("sans-serif"), &style, nullptr); if (CurrentState().fontGroup) { diff --git a/content/smil/SMILBoolType.cpp b/content/smil/SMILBoolType.cpp index c79486190384..88127cb308be 100644 --- a/content/smil/SMILBoolType.cpp +++ b/content/smil/SMILBoolType.cpp @@ -10,8 +10,6 @@ namespace mozilla { -/*static*/ SMILBoolType SMILBoolType::sSingleton; - void SMILBoolType::Init(nsSMILValue& aValue) const { @@ -25,7 +23,7 @@ SMILBoolType::Destroy(nsSMILValue& aValue) const { NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); aValue.mU.mBool = false; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/smil/SMILBoolType.h b/content/smil/SMILBoolType.h index d67d45561070..f90456bb9a83 100644 --- a/content/smil/SMILBoolType.h +++ b/content/smil/SMILBoolType.h @@ -15,7 +15,11 @@ class SMILBoolType : public nsISMILType { public: // Singleton for nsSMILValue objects to hold onto. - static SMILBoolType sSingleton; + static SMILBoolType* Singleton() + { + static SMILBoolType sSingleton; + return &sSingleton; + } protected: // nsISMILType Methods diff --git a/content/smil/SMILEnumType.cpp b/content/smil/SMILEnumType.cpp index efbb4c91096b..f283b16e40d2 100644 --- a/content/smil/SMILEnumType.cpp +++ b/content/smil/SMILEnumType.cpp @@ -10,8 +10,6 @@ namespace mozilla { -/*static*/ SMILEnumType SMILEnumType::sSingleton; - void SMILEnumType::Init(nsSMILValue& aValue) const { @@ -25,7 +23,7 @@ SMILEnumType::Destroy(nsSMILValue& aValue) const { NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); aValue.mU.mUint = 0; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/smil/SMILEnumType.h b/content/smil/SMILEnumType.h index 384646406bbb..24438cdd68fc 100644 --- a/content/smil/SMILEnumType.h +++ b/content/smil/SMILEnumType.h @@ -15,7 +15,12 @@ class SMILEnumType : public nsISMILType { public: // Singleton for nsSMILValue objects to hold onto. - static SMILEnumType sSingleton; + static SMILEnumType* + Singleton() + { + static SMILEnumType sSingleton; + return &sSingleton; + } protected: // nsISMILType Methods diff --git a/content/smil/SMILIntegerType.cpp b/content/smil/SMILIntegerType.cpp index 84084684acb8..f6fd69088591 100644 --- a/content/smil/SMILIntegerType.cpp +++ b/content/smil/SMILIntegerType.cpp @@ -10,8 +10,6 @@ namespace mozilla { -/*static*/ SMILIntegerType SMILIntegerType::sSingleton; - void SMILIntegerType::Init(nsSMILValue& aValue) const { @@ -25,7 +23,7 @@ SMILIntegerType::Destroy(nsSMILValue& aValue) const { NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); aValue.mU.mInt = 0; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/smil/SMILIntegerType.h b/content/smil/SMILIntegerType.h index 4d342f5ef755..b3593896cfdb 100644 --- a/content/smil/SMILIntegerType.h +++ b/content/smil/SMILIntegerType.h @@ -29,7 +29,12 @@ public: double aUnitDistance, nsSMILValue& aResult) const MOZ_OVERRIDE; - static SMILIntegerType sSingleton; + static SMILIntegerType* + Singleton() + { + static SMILIntegerType sSingleton; + return &sSingleton; + } private: SMILIntegerType() {} diff --git a/content/smil/SMILStringType.cpp b/content/smil/SMILStringType.cpp index ba0a539fe9af..6b549939d4ef 100644 --- a/content/smil/SMILStringType.cpp +++ b/content/smil/SMILStringType.cpp @@ -10,8 +10,6 @@ namespace mozilla { -/*static*/ SMILStringType SMILStringType::sSingleton; - void SMILStringType::Init(nsSMILValue& aValue) const { @@ -26,7 +24,7 @@ SMILStringType::Destroy(nsSMILValue& aValue) const NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); delete static_cast(aValue.mU.mPtr); aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/smil/SMILStringType.h b/content/smil/SMILStringType.h index ebcbce09fd08..c2709509f2db 100644 --- a/content/smil/SMILStringType.h +++ b/content/smil/SMILStringType.h @@ -15,7 +15,12 @@ class SMILStringType : public nsISMILType { public: // Singleton for nsSMILValue objects to hold onto. - static SMILStringType sSingleton; + static SMILStringType* + Singleton() + { + static SMILStringType sSingleton; + return &sSingleton; + } protected: // nsISMILType Methods diff --git a/content/smil/nsSMILCSSValueType.cpp b/content/smil/nsSMILCSSValueType.cpp index 9c13b942f776..edad560b23ab 100644 --- a/content/smil/nsSMILCSSValueType.cpp +++ b/content/smil/nsSMILCSSValueType.cpp @@ -151,7 +151,7 @@ nsSMILCSSValueType::Destroy(nsSMILValue& aValue) const { NS_ABORT_IF_FALSE(aValue.mType == this, "Unexpected SMIL value type"); delete static_cast(aValue.mU.mPtr); - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/smil/nsSMILFloatType.cpp b/content/smil/nsSMILFloatType.cpp index 26af7a71b558..9e3bc7243096 100644 --- a/content/smil/nsSMILFloatType.cpp +++ b/content/smil/nsSMILFloatType.cpp @@ -8,8 +8,6 @@ #include "nsDebug.h" #include -/*static*/ nsSMILFloatType nsSMILFloatType::sSingleton; - void nsSMILFloatType::Init(nsSMILValue& aValue) const { @@ -23,7 +21,7 @@ nsSMILFloatType::Destroy(nsSMILValue& aValue) const { NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); aValue.mU.mDouble = 0.0; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/smil/nsSMILFloatType.h b/content/smil/nsSMILFloatType.h index 0f21f2e6857e..0e4579130dea 100644 --- a/content/smil/nsSMILFloatType.h +++ b/content/smil/nsSMILFloatType.h @@ -13,7 +13,12 @@ class nsSMILFloatType : public nsISMILType { public: // Singleton for nsSMILValue objects to hold onto. - static nsSMILFloatType sSingleton; + static nsSMILFloatType* + Singleton() + { + static nsSMILFloatType sSingleton; + return &sSingleton; + } protected: // nsISMILType Methods diff --git a/content/smil/nsSMILNullType.cpp b/content/smil/nsSMILNullType.cpp index 01674567bc63..7f1fc3b018e9 100644 --- a/content/smil/nsSMILNullType.cpp +++ b/content/smil/nsSMILNullType.cpp @@ -7,15 +7,13 @@ #include "nsSMILValue.h" #include "nsDebug.h" -/*static*/ nsSMILNullType nsSMILNullType::sSingleton; - nsresult nsSMILNullType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const { NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types"); NS_PRECONDITION(aSrc.mType == this, "Unexpected source type"); aDest.mU = aSrc.mU; - aDest.mType = &sSingleton; + aDest.mType = Singleton(); return NS_OK; } diff --git a/content/smil/nsSMILNullType.h b/content/smil/nsSMILNullType.h index 8e4ca7e055ba..3c9172e6da32 100644 --- a/content/smil/nsSMILNullType.h +++ b/content/smil/nsSMILNullType.h @@ -13,7 +13,12 @@ class nsSMILNullType : public nsISMILType { public: // Singleton for nsSMILValue objects to hold onto. - static nsSMILNullType sSingleton; + static nsSMILNullType* + Singleton() + { + static nsSMILNullType sSingleton; + return &sSingleton; + } protected: // nsISMILType Methods diff --git a/content/smil/nsSMILValue.cpp b/content/smil/nsSMILValue.cpp index e4853dce7912..319fa4e2eed2 100644 --- a/content/smil/nsSMILValue.cpp +++ b/content/smil/nsSMILValue.cpp @@ -11,7 +11,7 @@ // Public methods nsSMILValue::nsSMILValue(const nsISMILType* aType) - : mType(&nsSMILNullType::sSingleton) + : mType(nsSMILNullType::Singleton()) { if (!aType) { NS_ERROR("Trying to construct nsSMILValue with null mType pointer"); @@ -22,7 +22,7 @@ nsSMILValue::nsSMILValue(const nsISMILType* aType) } nsSMILValue::nsSMILValue(const nsSMILValue& aVal) - : mType(&nsSMILNullType::sSingleton) + : mType(nsSMILNullType::Singleton()) { InitAndCheckPostcondition(aVal.mType); mType->Assign(*this, aVal); @@ -62,7 +62,7 @@ nsSMILValue::Swap(nsSMILValue& aOther) // |tmp| is about to die -- we need to clear its mType, so that its // destructor doesn't muck with the data we just transferred out of it. - tmp.mType = &nsSMILNullType::sSingleton; + tmp.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/smil/nsSMILValue.h b/content/smil/nsSMILValue.h index 18d66164c7e8..6eb8e5454ad2 100644 --- a/content/smil/nsSMILValue.h +++ b/content/smil/nsSMILValue.h @@ -21,7 +21,7 @@ class nsSMILValue { public: - nsSMILValue() : mU(), mType(&nsSMILNullType::sSingleton) { } + nsSMILValue() : mU(), mType(nsSMILNullType::Singleton()) { } explicit nsSMILValue(const nsISMILType* aType); nsSMILValue(const nsSMILValue& aVal); @@ -41,7 +41,7 @@ public: bool IsNull() const { - return (mType == &nsSMILNullType::sSingleton); + return (mType == nsSMILNullType::Singleton()); } // Swaps the member data (mU & mPtr) of |this| with |aOther| diff --git a/content/svg/content/src/DOMSVGAnimatedLengthList.cpp b/content/svg/content/src/DOMSVGAnimatedLengthList.cpp index e607a73a4e65..844e913fc618 100644 --- a/content/svg/content/src/DOMSVGAnimatedLengthList.cpp +++ b/content/svg/content/src/DOMSVGAnimatedLengthList.cpp @@ -16,8 +16,14 @@ namespace mozilla { -static nsSVGAttrTearoffTable - sSVGAnimatedLengthListTearoffTable; +static inline +nsSVGAttrTearoffTable& +SVGAnimatedLengthListTearoffTable() +{ + static nsSVGAttrTearoffTable + sSVGAnimatedLengthListTearoffTable; + return sSVGAnimatedLengthListTearoffTable; +} NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGAnimatedLengthList, mElement) @@ -62,10 +68,10 @@ DOMSVGAnimatedLengthList::GetDOMWrapper(SVGAnimatedLengthList *aList, uint8_t aAxis) { nsRefPtr wrapper = - sSVGAnimatedLengthListTearoffTable.GetTearoff(aList); + SVGAnimatedLengthListTearoffTable().GetTearoff(aList); if (!wrapper) { wrapper = new DOMSVGAnimatedLengthList(aElement, aAttrEnum, aAxis); - sSVGAnimatedLengthListTearoffTable.AddTearoff(aList, wrapper); + SVGAnimatedLengthListTearoffTable().AddTearoff(aList, wrapper); } return wrapper.forget(); } @@ -73,14 +79,14 @@ DOMSVGAnimatedLengthList::GetDOMWrapper(SVGAnimatedLengthList *aList, /* static */ DOMSVGAnimatedLengthList* DOMSVGAnimatedLengthList::GetDOMWrapperIfExists(SVGAnimatedLengthList *aList) { - return sSVGAnimatedLengthListTearoffTable.GetTearoff(aList); + return SVGAnimatedLengthListTearoffTable().GetTearoff(aList); } DOMSVGAnimatedLengthList::~DOMSVGAnimatedLengthList() { // Script no longer has any references to us, to our base/animVal objects, or // to any of their list items. - sSVGAnimatedLengthListTearoffTable.RemoveTearoff(&InternalAList()); + SVGAnimatedLengthListTearoffTable().RemoveTearoff(&InternalAList()); } void diff --git a/content/svg/content/src/DOMSVGAnimatedNumberList.cpp b/content/svg/content/src/DOMSVGAnimatedNumberList.cpp index 46cf2c8c8a72..df5be14bd7bd 100644 --- a/content/svg/content/src/DOMSVGAnimatedNumberList.cpp +++ b/content/svg/content/src/DOMSVGAnimatedNumberList.cpp @@ -16,8 +16,14 @@ namespace mozilla { -static nsSVGAttrTearoffTable - sSVGAnimatedNumberListTearoffTable; + static inline +nsSVGAttrTearoffTable& +SVGAnimatedNumberListTearoffTable() +{ + static nsSVGAttrTearoffTable + sSVGAnimatedNumberListTearoffTable; + return sSVGAnimatedNumberListTearoffTable; +} NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGAnimatedNumberList, mElement) @@ -61,10 +67,10 @@ DOMSVGAnimatedNumberList::GetDOMWrapper(SVGAnimatedNumberList *aList, uint8_t aAttrEnum) { nsRefPtr wrapper = - sSVGAnimatedNumberListTearoffTable.GetTearoff(aList); + SVGAnimatedNumberListTearoffTable().GetTearoff(aList); if (!wrapper) { wrapper = new DOMSVGAnimatedNumberList(aElement, aAttrEnum); - sSVGAnimatedNumberListTearoffTable.AddTearoff(aList, wrapper); + SVGAnimatedNumberListTearoffTable().AddTearoff(aList, wrapper); } return wrapper.forget(); } @@ -72,14 +78,14 @@ DOMSVGAnimatedNumberList::GetDOMWrapper(SVGAnimatedNumberList *aList, /* static */ DOMSVGAnimatedNumberList* DOMSVGAnimatedNumberList::GetDOMWrapperIfExists(SVGAnimatedNumberList *aList) { - return sSVGAnimatedNumberListTearoffTable.GetTearoff(aList); + return SVGAnimatedNumberListTearoffTable().GetTearoff(aList); } DOMSVGAnimatedNumberList::~DOMSVGAnimatedNumberList() { // Script no longer has any references to us, to our base/animVal objects, or // to any of their list items. - sSVGAnimatedNumberListTearoffTable.RemoveTearoff(&InternalAList()); + SVGAnimatedNumberListTearoffTable().RemoveTearoff(&InternalAList()); } void diff --git a/content/svg/content/src/DOMSVGPathSegList.cpp b/content/svg/content/src/DOMSVGPathSegList.cpp index 8ef7ef13f90f..77d20760601d 100644 --- a/content/svg/content/src/DOMSVGPathSegList.cpp +++ b/content/svg/content/src/DOMSVGPathSegList.cpp @@ -18,8 +18,14 @@ namespace mozilla { -static nsSVGAttrTearoffTable - sSVGPathSegListTearoffTable; + static inline +nsSVGAttrTearoffTable& +SVGPathSegListTearoffTable() +{ + static nsSVGAttrTearoffTable + sSVGPathSegListTearoffTable; + return sSVGPathSegListTearoffTable; +} NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGPathSegList) // No unlinking of mElement, we'd need to null out the value pointer (the @@ -49,10 +55,10 @@ DOMSVGPathSegList::GetDOMWrapper(void *aList, bool aIsAnimValList) { nsRefPtr wrapper = - sSVGPathSegListTearoffTable.GetTearoff(aList); + SVGPathSegListTearoffTable().GetTearoff(aList); if (!wrapper) { wrapper = new DOMSVGPathSegList(aElement, aIsAnimValList); - sSVGPathSegListTearoffTable.AddTearoff(aList, wrapper); + SVGPathSegListTearoffTable().AddTearoff(aList, wrapper); } return wrapper.forget(); } @@ -60,7 +66,7 @@ DOMSVGPathSegList::GetDOMWrapper(void *aList, /* static */ DOMSVGPathSegList* DOMSVGPathSegList::GetDOMWrapperIfExists(void *aList) { - return sSVGPathSegListTearoffTable.GetTearoff(aList); + return SVGPathSegListTearoffTable().GetTearoff(aList); } DOMSVGPathSegList::~DOMSVGPathSegList() @@ -70,7 +76,7 @@ DOMSVGPathSegList::~DOMSVGPathSegList() void *key = mIsAnimValList ? InternalAList().GetAnimValKey() : InternalAList().GetBaseValKey(); - sSVGPathSegListTearoffTable.RemoveTearoff(key); + SVGPathSegListTearoffTable().RemoveTearoff(key); } JSObject* diff --git a/content/svg/content/src/DOMSVGPointList.cpp b/content/svg/content/src/DOMSVGPointList.cpp index 96f4596d7b40..a567f645b352 100644 --- a/content/svg/content/src/DOMSVGPointList.cpp +++ b/content/svg/content/src/DOMSVGPointList.cpp @@ -36,8 +36,14 @@ UpdateListIndicesFromIndex(FallibleTArray& aItemsArray, namespace mozilla { -static nsSVGAttrTearoffTable - sSVGPointListTearoffTable; + static inline +nsSVGAttrTearoffTable& +SVGPointListTearoffTable() +{ + static nsSVGAttrTearoffTable + sSVGPointListTearoffTable; + return sSVGPointListTearoffTable; +} NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGPointList) // No unlinking of mElement, we'd need to null out the value pointer (the @@ -67,10 +73,10 @@ DOMSVGPointList::GetDOMWrapper(void *aList, bool aIsAnimValList) { nsRefPtr wrapper = - sSVGPointListTearoffTable.GetTearoff(aList); + SVGPointListTearoffTable().GetTearoff(aList); if (!wrapper) { wrapper = new DOMSVGPointList(aElement, aIsAnimValList); - sSVGPointListTearoffTable.AddTearoff(aList, wrapper); + SVGPointListTearoffTable().AddTearoff(aList, wrapper); } return wrapper.forget(); } @@ -78,7 +84,7 @@ DOMSVGPointList::GetDOMWrapper(void *aList, /* static */ DOMSVGPointList* DOMSVGPointList::GetDOMWrapperIfExists(void *aList) { - return sSVGPointListTearoffTable.GetTearoff(aList); + return SVGPointListTearoffTable().GetTearoff(aList); } DOMSVGPointList::~DOMSVGPointList() @@ -88,7 +94,7 @@ DOMSVGPointList::~DOMSVGPointList() void *key = mIsAnimValList ? InternalAList().GetAnimValKey() : InternalAList().GetBaseValKey(); - sSVGPointListTearoffTable.RemoveTearoff(key); + SVGPointListTearoffTable().RemoveTearoff(key); } JSObject* diff --git a/content/svg/content/src/DOMSVGStringList.cpp b/content/svg/content/src/DOMSVGStringList.cpp index 0670d7559c38..b180b65559e5 100644 --- a/content/svg/content/src/DOMSVGStringList.cpp +++ b/content/svg/content/src/DOMSVGStringList.cpp @@ -18,8 +18,14 @@ namespace mozilla { using namespace dom; -static nsSVGAttrTearoffTable - sSVGStringListTearoffTable; +static inline +nsSVGAttrTearoffTable& +SVGStringListTearoffTable() +{ + static nsSVGAttrTearoffTable + sSVGStringListTearoffTable; + return sSVGStringListTearoffTable; +} NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGStringList, mElement) @@ -38,12 +44,12 @@ DOMSVGStringList::GetDOMWrapper(SVGStringList *aList, uint8_t aAttrEnum) { nsRefPtr wrapper = - sSVGStringListTearoffTable.GetTearoff(aList); + SVGStringListTearoffTable().GetTearoff(aList); if (!wrapper) { wrapper = new DOMSVGStringList(aElement, aIsConditionalProcessingAttribute, aAttrEnum); - sSVGStringListTearoffTable.AddTearoff(aList, wrapper); + SVGStringListTearoffTable().AddTearoff(aList, wrapper); } return wrapper.forget(); } @@ -51,7 +57,7 @@ DOMSVGStringList::GetDOMWrapper(SVGStringList *aList, DOMSVGStringList::~DOMSVGStringList() { // Script no longer has any references to us. - sSVGStringListTearoffTable.RemoveTearoff(&InternalList()); + SVGStringListTearoffTable().RemoveTearoff(&InternalList()); } /* virtual */ JSObject* diff --git a/content/svg/content/src/SVGAnimatedPathSegList.cpp b/content/svg/content/src/SVGAnimatedPathSegList.cpp index 0f37bfe9bc8d..54eccf027ab7 100644 --- a/content/svg/content/src/SVGAnimatedPathSegList.cpp +++ b/content/svg/content/src/SVGAnimatedPathSegList.cpp @@ -154,7 +154,7 @@ SVGAnimatedPathSegList:: nsSMILValue& aValue, bool& aPreventCachingOfSandwich) const { - nsSMILValue val(&SVGPathSegListSMILType::sSingleton); + nsSMILValue val(SVGPathSegListSMILType::Singleton()); SVGPathDataAndOwner *list = static_cast(val.mU.mPtr); nsresult rv = list->SetValueFromString(aStr); if (NS_SUCCEEDED(rv)) { @@ -173,7 +173,7 @@ SVGAnimatedPathSegList::SMILAnimatedPathSegList::GetBaseValue() const // from ALL return points. This function must only return THIS variable: nsSMILValue val; - nsSMILValue tmp(&SVGPathSegListSMILType::sSingleton); + nsSMILValue tmp(SVGPathSegListSMILType::Singleton()); SVGPathDataAndOwner *list = static_cast(tmp.mU.mPtr); nsresult rv = list->CopyFrom(mVal->mBaseVal); if (NS_SUCCEEDED(rv)) { @@ -186,9 +186,9 @@ SVGAnimatedPathSegList::SMILAnimatedPathSegList::GetBaseValue() const nsresult SVGAnimatedPathSegList::SMILAnimatedPathSegList::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &SVGPathSegListSMILType::sSingleton, + NS_ASSERTION(aValue.mType == SVGPathSegListSMILType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &SVGPathSegListSMILType::sSingleton) { + if (aValue.mType == SVGPathSegListSMILType::Singleton()) { mVal->SetAnimValue(*static_cast(aValue.mU.mPtr), mElement); } diff --git a/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp b/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp index 342570d75bcc..8b02eebe6b91 100644 --- a/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp +++ b/content/svg/content/src/SVGAnimatedPreserveAspectRatio.cpp @@ -321,7 +321,7 @@ SMILPreserveAspectRatio::ValueFromString(const nsAString& aStr, nsresult res = ToPreserveAspectRatio(aStr, &par); NS_ENSURE_SUCCESS(res, res); - nsSMILValue val(&SMILEnumType::sSingleton); + nsSMILValue val(SMILEnumType::Singleton()); val.mU.mUint = PackPreserveAspectRatio(par); aValue = val; aPreventCachingOfSandwich = false; @@ -331,7 +331,7 @@ SMILPreserveAspectRatio::ValueFromString(const nsAString& aStr, nsSMILValue SMILPreserveAspectRatio::GetBaseValue() const { - nsSMILValue val(&SMILEnumType::sSingleton); + nsSMILValue val(SMILEnumType::Singleton()); val.mU.mUint = PackPreserveAspectRatio(mVal->GetBaseValue()); return val; } @@ -349,9 +349,9 @@ SMILPreserveAspectRatio::ClearAnimValue() nsresult SMILPreserveAspectRatio::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &SMILEnumType::sSingleton, + NS_ASSERTION(aValue.mType == SMILEnumType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &SMILEnumType::sSingleton) { + if (aValue.mType == SMILEnumType::Singleton()) { mVal->SetAnimValue(aValue.mU.mUint, mSVGElement); } return NS_OK; diff --git a/content/svg/content/src/SVGIntegerPairSMILType.cpp b/content/svg/content/src/SVGIntegerPairSMILType.cpp index e91e5f872e27..41779327ba22 100644 --- a/content/svg/content/src/SVGIntegerPairSMILType.cpp +++ b/content/svg/content/src/SVGIntegerPairSMILType.cpp @@ -10,8 +10,6 @@ namespace mozilla { -/*static*/ SVGIntegerPairSMILType SVGIntegerPairSMILType::sSingleton; - void SVGIntegerPairSMILType::Init(nsSMILValue& aValue) const { @@ -28,7 +26,7 @@ SVGIntegerPairSMILType::Destroy(nsSMILValue& aValue) const NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); aValue.mU.mIntPair[0] = 0; aValue.mU.mIntPair[1] = 0; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/SVGIntegerPairSMILType.h b/content/svg/content/src/SVGIntegerPairSMILType.h index 21591dbef032..50ecc4e7e6cd 100644 --- a/content/svg/content/src/SVGIntegerPairSMILType.h +++ b/content/svg/content/src/SVGIntegerPairSMILType.h @@ -17,7 +17,12 @@ class SVGIntegerPairSMILType : public nsISMILType { public: // Singleton for nsSMILValue objects to hold onto. - static SVGIntegerPairSMILType sSingleton; + static SVGIntegerPairSMILType* + Singleton() + { + static SVGIntegerPairSMILType sSingleton; + return &sSingleton; + } protected: // nsISMILType Methods diff --git a/content/svg/content/src/SVGLengthListSMILType.cpp b/content/svg/content/src/SVGLengthListSMILType.cpp index 57c30418d140..91a00231a44e 100644 --- a/content/svg/content/src/SVGLengthListSMILType.cpp +++ b/content/svg/content/src/SVGLengthListSMILType.cpp @@ -37,7 +37,7 @@ SVGLengthListSMILType::Destroy(nsSMILValue& aValue) const NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value type"); delete static_cast(aValue.mU.mPtr); aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/SVGMotionSMILType.cpp b/content/svg/content/src/SVGMotionSMILType.cpp index aa7bf617e598..88168cb7545f 100644 --- a/content/svg/content/src/SVGMotionSMILType.cpp +++ b/content/svg/content/src/SVGMotionSMILType.cpp @@ -179,7 +179,7 @@ SVGMotionSMILType::Destroy(nsSMILValue& aValue) const delete arr; aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/SVGNumberListSMILType.cpp b/content/svg/content/src/SVGNumberListSMILType.cpp index a4cac0863e4c..17b1bdc4b0e4 100644 --- a/content/svg/content/src/SVGNumberListSMILType.cpp +++ b/content/svg/content/src/SVGNumberListSMILType.cpp @@ -50,7 +50,7 @@ SVGNumberListSMILType::Destroy(nsSMILValue& aValue) const NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value type"); delete static_cast(aValue.mU.mPtr); aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/SVGNumberPairSMILType.cpp b/content/svg/content/src/SVGNumberPairSMILType.cpp index 0aea3465d4ce..8ebff061141b 100644 --- a/content/svg/content/src/SVGNumberPairSMILType.cpp +++ b/content/svg/content/src/SVGNumberPairSMILType.cpp @@ -28,7 +28,7 @@ SVGNumberPairSMILType::Destroy(nsSMILValue& aValue) const NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); aValue.mU.mNumberPair[0] = 0; aValue.mU.mNumberPair[1] = 0; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/SVGOrientSMILType.cpp b/content/svg/content/src/SVGOrientSMILType.cpp index 631e92004afc..e8355f8ac758 100644 --- a/content/svg/content/src/SVGOrientSMILType.cpp +++ b/content/svg/content/src/SVGOrientSMILType.cpp @@ -30,7 +30,7 @@ SVGOrientSMILType::Destroy(nsSMILValue& aValue) const { NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value."); aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/SVGPathSegListSMILType.cpp b/content/svg/content/src/SVGPathSegListSMILType.cpp index 225638d7cc3c..d242bf3a0595 100644 --- a/content/svg/content/src/SVGPathSegListSMILType.cpp +++ b/content/svg/content/src/SVGPathSegListSMILType.cpp @@ -17,8 +17,6 @@ namespace mozilla { -/*static*/ SVGPathSegListSMILType SVGPathSegListSMILType::sSingleton; - //---------------------------------------------------------------------- // nsISMILType implementation @@ -36,7 +34,7 @@ SVGPathSegListSMILType::Destroy(nsSMILValue& aValue) const NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value type"); delete static_cast(aValue.mU.mPtr); aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/SVGPathSegListSMILType.h b/content/svg/content/src/SVGPathSegListSMILType.h index 0085c0d2d11b..e1b6a0d189e6 100644 --- a/content/svg/content/src/SVGPathSegListSMILType.h +++ b/content/svg/content/src/SVGPathSegListSMILType.h @@ -22,7 +22,11 @@ class SVGPathSegListSMILType : public nsISMILType { public: // Singleton for nsSMILValue objects to hold onto. - static SVGPathSegListSMILType sSingleton; + static SVGPathSegListSMILType* Singleton() + { + static SVGPathSegListSMILType sSingleton; + return &sSingleton; + } protected: // nsISMILType Methods diff --git a/content/svg/content/src/SVGPointListSMILType.cpp b/content/svg/content/src/SVGPointListSMILType.cpp index a05a337d98db..5be79a42c064 100644 --- a/content/svg/content/src/SVGPointListSMILType.cpp +++ b/content/svg/content/src/SVGPointListSMILType.cpp @@ -33,7 +33,7 @@ SVGPointListSMILType::Destroy(nsSMILValue& aValue) const NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value type"); delete static_cast(aValue.mU.mPtr); aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/SVGTransform.cpp b/content/svg/content/src/SVGTransform.cpp index 975e76ff6c41..d9e62ab3d53a 100644 --- a/content/svg/content/src/SVGTransform.cpp +++ b/content/svg/content/src/SVGTransform.cpp @@ -16,7 +16,12 @@ namespace mozilla { namespace dom { -static nsSVGAttrTearoffTable sSVGMatrixTearoffTable; +static nsSVGAttrTearoffTable& +SVGMatrixTearoffTable() +{ + static nsSVGAttrTearoffTable sSVGMatrixTearoffTable; + return sSVGMatrixTearoffTable; +} //---------------------------------------------------------------------- @@ -36,7 +41,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(SVGTransform) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mList) SVGMatrix* matrix = - sSVGMatrixTearoffTable.GetTearoff(tmp); + SVGMatrixTearoffTable().GetTearoff(tmp); CycleCollectionNoteChild(cb, matrix, "matrix"); NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -104,9 +109,9 @@ SVGTransform::SVGTransform(const nsSVGTransform &aTransform) SVGTransform::~SVGTransform() { - SVGMatrix* matrix = sSVGMatrixTearoffTable.GetTearoff(this); + SVGMatrix* matrix = SVGMatrixTearoffTable().GetTearoff(this); if (matrix) { - sSVGMatrixTearoffTable.RemoveTearoff(this); + SVGMatrixTearoffTable().RemoveTearoff(this); NS_RELEASE(matrix); } // Our mList's weak ref to us must be nulled out when we die. If GC has @@ -127,10 +132,10 @@ SVGMatrix* SVGTransform::Matrix() { SVGMatrix* wrapper = - sSVGMatrixTearoffTable.GetTearoff(this); + SVGMatrixTearoffTable().GetTearoff(this); if (!wrapper) { NS_ADDREF(wrapper = new SVGMatrix(*this)); - sSVGMatrixTearoffTable.AddTearoff(this, wrapper); + SVGMatrixTearoffTable().AddTearoff(this, wrapper); } return wrapper; } diff --git a/content/svg/content/src/SVGTransformListSMILType.cpp b/content/svg/content/src/SVGTransformListSMILType.cpp index 1f191098a04d..6c3b6812af93 100644 --- a/content/svg/content/src/SVGTransformListSMILType.cpp +++ b/content/svg/content/src/SVGTransformListSMILType.cpp @@ -12,8 +12,6 @@ using namespace mozilla; -/*static*/ SVGTransformListSMILType SVGTransformListSMILType::sSingleton; - typedef FallibleTArray TransformArray; //---------------------------------------------------------------------- @@ -36,7 +34,7 @@ SVGTransformListSMILType::Destroy(nsSMILValue& aValue) const TransformArray* params = static_cast(aValue.mU.mPtr); delete params; aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult @@ -321,7 +319,7 @@ SVGTransformListSMILType::AppendTransform( const SVGTransformSMILData& aTransform, nsSMILValue& aValue) { - NS_PRECONDITION(aValue.mType == &sSingleton, "Unexpected SMIL value type"); + NS_PRECONDITION(aValue.mType == &Singleton(), "Unexpected SMIL value type"); TransformArray& transforms = *static_cast(aValue.mU.mPtr); return transforms.AppendElement(aTransform) ? @@ -333,7 +331,7 @@ bool SVGTransformListSMILType::AppendTransforms(const SVGTransformList& aList, nsSMILValue& aValue) { - NS_PRECONDITION(aValue.mType == &sSingleton, "Unexpected SMIL value type"); + NS_PRECONDITION(aValue.mType == &Singleton(), "Unexpected SMIL value type"); TransformArray& transforms = *static_cast(aValue.mU.mPtr); @@ -353,7 +351,7 @@ bool SVGTransformListSMILType::GetTransforms(const nsSMILValue& aValue, FallibleTArray& aTransforms) { - NS_PRECONDITION(aValue.mType == &sSingleton, "Unexpected SMIL value type"); + NS_PRECONDITION(aValue.mType == &Singleton(), "Unexpected SMIL value type"); const TransformArray& smilTransforms = *static_cast(aValue.mU.mPtr); diff --git a/content/svg/content/src/SVGTransformListSMILType.h b/content/svg/content/src/SVGTransformListSMILType.h index 280db7c2be97..2f3e58c0daf9 100644 --- a/content/svg/content/src/SVGTransformListSMILType.h +++ b/content/svg/content/src/SVGTransformListSMILType.h @@ -81,7 +81,12 @@ class SVGTransformListSMILType : public nsISMILType { public: // Singleton for nsSMILValue objects to hold onto. - static SVGTransformListSMILType sSingleton; + static SVGTransformListSMILType* + Singleton() + { + static SVGTransformListSMILType sSingleton; + return &sSingleton; + } protected: // nsISMILType Methods diff --git a/content/svg/content/src/SVGViewBoxSMILType.cpp b/content/svg/content/src/SVGViewBoxSMILType.cpp index 20c1503e3593..3725c235a03c 100644 --- a/content/svg/content/src/SVGViewBoxSMILType.cpp +++ b/content/svg/content/src/SVGViewBoxSMILType.cpp @@ -28,7 +28,7 @@ SVGViewBoxSMILType::Destroy(nsSMILValue& aValue) const NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); delete static_cast(aValue.mU.mPtr); aValue.mU.mPtr = nullptr; - aValue.mType = &nsSMILNullType::sSingleton; + aValue.mType = nsSMILNullType::Singleton(); } nsresult diff --git a/content/svg/content/src/nsSVGAnimatedTransformList.cpp b/content/svg/content/src/nsSVGAnimatedTransformList.cpp index 6d358eb0c1f8..b109f4453ef8 100644 --- a/content/svg/content/src/nsSVGAnimatedTransformList.cpp +++ b/content/svg/content/src/nsSVGAnimatedTransformList.cpp @@ -225,7 +225,7 @@ nsSVGAnimatedTransformList::SMILAnimatedTransformList::ParseValue( return; } - nsSMILValue val(&SVGTransformListSMILType::sSingleton); + nsSMILValue val(SVGTransformListSMILType::Singleton()); SVGTransformSMILData transform(transformType, params); if (NS_FAILED(SVGTransformListSMILType::AppendTransform(transform, val))) { return; // OOM @@ -292,7 +292,7 @@ nsSVGAnimatedTransformList::SMILAnimatedTransformList::GetBaseValue() const // To benefit from Return Value Optimization and avoid copy constructor calls // due to our use of return-by-value, we must return the exact same object // from ALL return points. This function must only return THIS variable: - nsSMILValue val(&SVGTransformListSMILType::sSingleton); + nsSMILValue val(SVGTransformListSMILType::Singleton()); if (!SVGTransformListSMILType::AppendTransforms(mVal->mBaseVal, val)) { val = nsSMILValue(); } @@ -305,7 +305,7 @@ nsSVGAnimatedTransformList::SMILAnimatedTransformList::SetAnimValue( const nsSMILValue& aNewAnimValue) { NS_ABORT_IF_FALSE( - aNewAnimValue.mType == &SVGTransformListSMILType::sSingleton, + aNewAnimValue.mType == SVGTransformListSMILType::Singleton(), "Unexpected type to assign animated value"); SVGTransformList animVal; if (!SVGTransformListSMILType::GetTransforms(aNewAnimValue, diff --git a/content/svg/content/src/nsSVGBoolean.cpp b/content/svg/content/src/nsSVGBoolean.cpp index b0d325793bc7..98f53c0f6826 100644 --- a/content/svg/content/src/nsSVGBoolean.cpp +++ b/content/svg/content/src/nsSVGBoolean.cpp @@ -15,8 +15,14 @@ using namespace mozilla::dom; /* Implementation */ -static nsSVGAttrTearoffTable - sSVGAnimatedBooleanTearoffTable; +static inline +nsSVGAttrTearoffTable& +SVGAnimatedBooleanTearoffTable() +{ + static nsSVGAttrTearoffTable + sSVGAnimatedBooleanTearoffTable; + return sSVGAnimatedBooleanTearoffTable; +} static nsresult GetValueFromString(const nsAString &aValueAsString, @@ -108,10 +114,10 @@ already_AddRefed nsSVGBoolean::ToDOMAnimatedBoolean(nsSVGElement* aSVGElement) { nsRefPtr domAnimatedBoolean = - sSVGAnimatedBooleanTearoffTable.GetTearoff(this); + SVGAnimatedBooleanTearoffTable().GetTearoff(this); if (!domAnimatedBoolean) { domAnimatedBoolean = new SVGAnimatedBoolean(this, aSVGElement); - sSVGAnimatedBooleanTearoffTable.AddTearoff(this, domAnimatedBoolean); + SVGAnimatedBooleanTearoffTable().AddTearoff(this, domAnimatedBoolean); } return domAnimatedBoolean.forget(); @@ -119,7 +125,7 @@ nsSVGBoolean::ToDOMAnimatedBoolean(nsSVGElement* aSVGElement) SVGAnimatedBoolean::~SVGAnimatedBoolean() { - sSVGAnimatedBooleanTearoffTable.RemoveTearoff(mVal); + SVGAnimatedBooleanTearoffTable().RemoveTearoff(mVal); } nsISMILAttr* @@ -140,7 +146,7 @@ nsSVGBoolean::SMILBool::ValueFromString(const nsAString& aStr, return rv; } - nsSMILValue val(&SMILBoolType::sSingleton); + nsSMILValue val(SMILBoolType::Singleton()); val.mU.mBool = value; aValue = val; aPreventCachingOfSandwich = false; @@ -151,7 +157,7 @@ nsSVGBoolean::SMILBool::ValueFromString(const nsAString& aStr, nsSMILValue nsSVGBoolean::SMILBool::GetBaseValue() const { - nsSMILValue val(&SMILBoolType::sSingleton); + nsSMILValue val(SMILBoolType::Singleton()); val.mU.mBool = mVal->mBaseVal; return val; } @@ -169,9 +175,9 @@ nsSVGBoolean::SMILBool::ClearAnimValue() nsresult nsSVGBoolean::SMILBool::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &SMILBoolType::sSingleton, + NS_ASSERTION(aValue.mType == SMILBoolType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &SMILBoolType::sSingleton) { + if (aValue.mType == SMILBoolType::Singleton()) { mVal->SetAnimValue(uint16_t(aValue.mU.mBool), mSVGElement); } return NS_OK; diff --git a/content/svg/content/src/nsSVGClass.cpp b/content/svg/content/src/nsSVGClass.cpp index 0de605606ce5..b231ce0e7c52 100644 --- a/content/svg/content/src/nsSVGClass.cpp +++ b/content/svg/content/src/nsSVGClass.cpp @@ -92,7 +92,7 @@ nsSVGClass::SMILString::ValueFromString(const nsAString& aStr, nsSMILValue& aValue, bool& aPreventCachingOfSandwich) const { - nsSMILValue val(&SMILStringType::sSingleton); + nsSMILValue val(SMILStringType::Singleton()); *static_cast(val.mU.mPtr) = aStr; aValue.Swap(val); @@ -103,7 +103,7 @@ nsSVGClass::SMILString::ValueFromString(const nsAString& aStr, nsSMILValue nsSVGClass::SMILString::GetBaseValue() const { - nsSMILValue val(&SMILStringType::sSingleton); + nsSMILValue val(SMILStringType::Singleton()); mSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, *static_cast(val.mU.mPtr)); return val; @@ -121,9 +121,9 @@ nsSVGClass::SMILString::ClearAnimValue() nsresult nsSVGClass::SMILString::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &SMILStringType::sSingleton, + NS_ASSERTION(aValue.mType == SMILStringType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &SMILStringType::sSingleton) { + if (aValue.mType == SMILStringType::Singleton()) { mVal->SetAnimValue(*static_cast(aValue.mU.mPtr), mSVGElement); } return NS_OK; diff --git a/content/svg/content/src/nsSVGEnum.cpp b/content/svg/content/src/nsSVGEnum.cpp index 02284a417066..d09b09f23fc5 100644 --- a/content/svg/content/src/nsSVGEnum.cpp +++ b/content/svg/content/src/nsSVGEnum.cpp @@ -166,7 +166,7 @@ nsSVGEnum::SMILEnum::ValueFromString(const nsAString& aStr, while (mapping && mapping->mKey) { if (valAtom == *(mapping->mKey)) { - nsSMILValue val(&SMILEnumType::sSingleton); + nsSMILValue val(SMILEnumType::Singleton()); val.mU.mUint = mapping->mVal; aValue = val; aPreventCachingOfSandwich = false; @@ -184,7 +184,7 @@ nsSVGEnum::SMILEnum::ValueFromString(const nsAString& aStr, nsSMILValue nsSVGEnum::SMILEnum::GetBaseValue() const { - nsSMILValue val(&SMILEnumType::sSingleton); + nsSMILValue val(SMILEnumType::Singleton()); val.mU.mUint = mVal->mBaseVal; return val; } @@ -202,9 +202,9 @@ nsSVGEnum::SMILEnum::ClearAnimValue() nsresult nsSVGEnum::SMILEnum::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &SMILEnumType::sSingleton, + NS_ASSERTION(aValue.mType == SMILEnumType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &SMILEnumType::sSingleton) { + if (aValue.mType == SMILEnumType::Singleton()) { NS_ABORT_IF_FALSE(aValue.mU.mUint <= USHRT_MAX, "Very large enumerated value - too big for uint16_t"); mVal->SetAnimValue(uint16_t(aValue.mU.mUint), mSVGElement); diff --git a/content/svg/content/src/nsSVGInteger.cpp b/content/svg/content/src/nsSVGInteger.cpp index a2bb8f2d2c34..d227b4efdf54 100644 --- a/content/svg/content/src/nsSVGInteger.cpp +++ b/content/svg/content/src/nsSVGInteger.cpp @@ -157,7 +157,7 @@ nsSVGInteger::SMILInteger::ValueFromString(const nsAString& aStr, return rv; } - nsSMILValue smilVal(&SMILIntegerType::sSingleton); + nsSMILValue smilVal(SMILIntegerType::Singleton()); smilVal.mU.mInt = val; aValue = smilVal; aPreventCachingOfSandwich = false; @@ -167,7 +167,7 @@ nsSVGInteger::SMILInteger::ValueFromString(const nsAString& aStr, nsSMILValue nsSVGInteger::SMILInteger::GetBaseValue() const { - nsSMILValue val(&SMILIntegerType::sSingleton); + nsSMILValue val(SMILIntegerType::Singleton()); val.mU.mInt = mVal->mBaseVal; return val; } @@ -185,9 +185,9 @@ nsSVGInteger::SMILInteger::ClearAnimValue() nsresult nsSVGInteger::SMILInteger::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &SMILIntegerType::sSingleton, + NS_ASSERTION(aValue.mType == SMILIntegerType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &SMILIntegerType::sSingleton) { + if (aValue.mType == SMILIntegerType::Singleton()) { mVal->SetAnimValue(int(aValue.mU.mInt), mSVGElement); } return NS_OK; diff --git a/content/svg/content/src/nsSVGIntegerPair.cpp b/content/svg/content/src/nsSVGIntegerPair.cpp index 08cf34ed120a..6f78db9ba032 100644 --- a/content/svg/content/src/nsSVGIntegerPair.cpp +++ b/content/svg/content/src/nsSVGIntegerPair.cpp @@ -224,7 +224,7 @@ nsSVGIntegerPair::SMILIntegerPair::ValueFromString(const nsAString& aStr, return rv; } - nsSMILValue val(&SVGIntegerPairSMILType::sSingleton); + nsSMILValue val(SVGIntegerPairSMILType::Singleton()); val.mU.mIntPair[0] = values[0]; val.mU.mIntPair[1] = values[1]; aValue = val; @@ -236,7 +236,7 @@ nsSVGIntegerPair::SMILIntegerPair::ValueFromString(const nsAString& aStr, nsSMILValue nsSVGIntegerPair::SMILIntegerPair::GetBaseValue() const { - nsSMILValue val(&SVGIntegerPairSMILType::sSingleton); + nsSMILValue val(SVGIntegerPairSMILType::Singleton()); val.mU.mIntPair[0] = mVal->mBaseVal[0]; val.mU.mIntPair[1] = mVal->mBaseVal[1]; return val; @@ -256,9 +256,9 @@ nsSVGIntegerPair::SMILIntegerPair::ClearAnimValue() nsresult nsSVGIntegerPair::SMILIntegerPair::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &SVGIntegerPairSMILType::sSingleton, + NS_ASSERTION(aValue.mType == SVGIntegerPairSMILType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &SVGIntegerPairSMILType::sSingleton) { + if (aValue.mType == SVGIntegerPairSMILType::Singleton()) { mVal->SetAnimValue(aValue.mU.mIntPair, mSVGElement); } return NS_OK; diff --git a/content/svg/content/src/nsSVGLength2.cpp b/content/svg/content/src/nsSVGLength2.cpp index b2a3b48d2fe7..6e5b3322e830 100644 --- a/content/svg/content/src/nsSVGLength2.cpp +++ b/content/svg/content/src/nsSVGLength2.cpp @@ -517,7 +517,7 @@ nsSVGLength2::SMILLength::ValueFromString(const nsAString& aStr, return rv; } - nsSMILValue val(&nsSMILFloatType::sSingleton); + nsSMILValue val(nsSMILFloatType::Singleton()); val.mU.mDouble = value / mVal->GetUnitScaleFactor(mSVGElement, unitType); aValue = val; aPreventCachingOfSandwich = @@ -531,7 +531,7 @@ nsSVGLength2::SMILLength::ValueFromString(const nsAString& aStr, nsSMILValue nsSVGLength2::SMILLength::GetBaseValue() const { - nsSMILValue val(&nsSMILFloatType::sSingleton); + nsSMILValue val(nsSMILFloatType::Singleton()); val.mU.mDouble = mVal->GetBaseValue(mSVGElement); return val; } @@ -549,9 +549,9 @@ nsSVGLength2::SMILLength::ClearAnimValue() nsresult nsSVGLength2::SMILLength::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &nsSMILFloatType::sSingleton, + NS_ASSERTION(aValue.mType == nsSMILFloatType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &nsSMILFloatType::sSingleton) { + if (aValue.mType == nsSMILFloatType::Singleton()) { mVal->SetAnimValue(float(aValue.mU.mDouble), mSVGElement); } return NS_OK; diff --git a/content/svg/content/src/nsSVGNumber2.cpp b/content/svg/content/src/nsSVGNumber2.cpp index 713be8510a14..17ad2fb87f6d 100644 --- a/content/svg/content/src/nsSVGNumber2.cpp +++ b/content/svg/content/src/nsSVGNumber2.cpp @@ -197,7 +197,7 @@ nsSVGNumber2::SMILNumber::ValueFromString(const nsAString& aStr, return rv; } - nsSMILValue val(&nsSMILFloatType::sSingleton); + nsSMILValue val(nsSMILFloatType::Singleton()); val.mU.mDouble = value; aValue = val; aPreventCachingOfSandwich = false; @@ -208,7 +208,7 @@ nsSVGNumber2::SMILNumber::ValueFromString(const nsAString& aStr, nsSMILValue nsSVGNumber2::SMILNumber::GetBaseValue() const { - nsSMILValue val(&nsSMILFloatType::sSingleton); + nsSMILValue val(nsSMILFloatType::Singleton()); val.mU.mDouble = mVal->mBaseVal; return val; } @@ -226,9 +226,9 @@ nsSVGNumber2::SMILNumber::ClearAnimValue() nsresult nsSVGNumber2::SMILNumber::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &nsSMILFloatType::sSingleton, + NS_ASSERTION(aValue.mType == nsSMILFloatType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &nsSMILFloatType::sSingleton) { + if (aValue.mType == nsSMILFloatType::Singleton()) { mVal->SetAnimValue(float(aValue.mU.mDouble), mSVGElement); } return NS_OK; diff --git a/content/svg/content/src/nsSVGString.cpp b/content/svg/content/src/nsSVGString.cpp index 6dea24c105e9..b017b729c0a2 100644 --- a/content/svg/content/src/nsSVGString.cpp +++ b/content/svg/content/src/nsSVGString.cpp @@ -23,8 +23,14 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGString::DOMAnimatedString) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedString) NS_INTERFACE_MAP_END -static nsSVGAttrTearoffTable - sSVGAnimatedStringTearoffTable; +static inline +nsSVGAttrTearoffTable& +SVGAnimatedStringTearoffTable() +{ + static nsSVGAttrTearoffTable + sSVGAnimatedStringTearoffTable; + return sSVGAnimatedStringTearoffTable; +} /* Implementation */ @@ -84,10 +90,10 @@ already_AddRefed nsSVGString::ToDOMAnimatedString(nsSVGElement* aSVGElement) { nsRefPtr domAnimatedString = - sSVGAnimatedStringTearoffTable.GetTearoff(this); + SVGAnimatedStringTearoffTable().GetTearoff(this); if (!domAnimatedString) { domAnimatedString = new DOMAnimatedString(this, aSVGElement); - sSVGAnimatedStringTearoffTable.AddTearoff(this, domAnimatedString); + SVGAnimatedStringTearoffTable().AddTearoff(this, domAnimatedString); } return domAnimatedString.forget(); @@ -95,7 +101,7 @@ nsSVGString::ToDOMAnimatedString(nsSVGElement* aSVGElement) nsSVGString::DOMAnimatedString::~DOMAnimatedString() { - sSVGAnimatedStringTearoffTable.RemoveTearoff(mVal); + SVGAnimatedStringTearoffTable().RemoveTearoff(mVal); } nsISMILAttr* @@ -110,7 +116,7 @@ nsSVGString::SMILString::ValueFromString(const nsAString& aStr, nsSMILValue& aValue, bool& aPreventCachingOfSandwich) const { - nsSMILValue val(&SMILStringType::sSingleton); + nsSMILValue val(SMILStringType::Singleton()); *static_cast(val.mU.mPtr) = aStr; aValue.Swap(val); @@ -121,7 +127,7 @@ nsSVGString::SMILString::ValueFromString(const nsAString& aStr, nsSMILValue nsSVGString::SMILString::GetBaseValue() const { - nsSMILValue val(&SMILStringType::sSingleton); + nsSMILValue val(SMILStringType::Singleton()); mSVGElement->GetStringBaseValue(mVal->mAttrEnum, *static_cast(val.mU.mPtr)); return val; } @@ -138,9 +144,9 @@ nsSVGString::SMILString::ClearAnimValue() nsresult nsSVGString::SMILString::SetAnimValue(const nsSMILValue& aValue) { - NS_ASSERTION(aValue.mType == &SMILStringType::sSingleton, + NS_ASSERTION(aValue.mType == SMILStringType::Singleton(), "Unexpected type to assign animated value"); - if (aValue.mType == &SMILStringType::sSingleton) { + if (aValue.mType == SMILStringType::Singleton()) { mVal->SetAnimValue(*static_cast(aValue.mU.mPtr), mSVGElement); } return NS_OK; diff --git a/dom/base/nsDOMException.cpp b/dom/base/nsDOMException.cpp index 3f9f710cb5a6..9736ac9d0512 100644 --- a/dom/base/nsDOMException.cpp +++ b/dom/base/nsDOMException.cpp @@ -14,6 +14,8 @@ #include "nsString.h" #include "prprf.h" +using namespace mozilla; + enum DOM4ErrorTypeCodeMap { /* DOM4 errors from http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#domexception */ IndexSizeError = nsIDOMDOMException::INDEX_SIZE_ERR, @@ -60,23 +62,6 @@ enum DOM4ErrorTypeCodeMap { LockedFileInactiveError = 0, }; -#define DOM4_MSG_DEF(name, message, nsresult) {(nsresult), name, #name, message}, -#define DOM_MSG_DEF(val, message) {(val), NS_ERROR_GET_CODE(val), #val, message}, - -static struct ResultStruct -{ - nsresult mNSResult; - uint16_t mCode; - const char* mName; - const char* mMessage; -} gDOMErrorMsgMap[] = { -#include "domerr.msg" - {NS_OK, 0, nullptr, nullptr} // sentinel to mark end of array -}; - -#undef DOM4_MSG_DEF -#undef DOM_MSG_DEF - static void NSResultToNameAndMessage(nsresult aNSResult, const char** aName, @@ -86,17 +71,30 @@ NSResultToNameAndMessage(nsresult aNSResult, *aName = nullptr; *aMessage = nullptr; *aCode = 0; - ResultStruct* result_struct = gDOMErrorMsgMap; - while (result_struct->mName) { - if (aNSResult == result_struct->mNSResult) { - *aName = result_struct->mName; - *aMessage = result_struct->mMessage; - *aCode = result_struct->mCode; +#define DOM4_MSG_DEF(name, message, nsresult) {(nsresult), name, #name, message}, +#define DOM_MSG_DEF(val, message) {(val), NS_ERROR_GET_CODE(val), #val, message}, + + static const struct ResultStruct + { + nsresult mNSResult; + uint16_t mCode; + const char* mName; + const char* mMessage; + } sDOMErrorMsgMap[] = { +#include "domerr.msg" + }; + +#undef DOM4_MSG_DEF +#undef DOM_MSG_DEF + + for (uint32_t idx = 0; idx < ArrayLength(sDOMErrorMsgMap); idx++) { + if (aNSResult == sDOMErrorMsgMap[idx].mNSResult) { + *aName = sDOMErrorMsgMap[idx].mName; + *aMessage = sDOMErrorMsgMap[idx].mMessage; + *aCode = sDOMErrorMsgMap[idx].mCode; return; } - - ++result_struct; } NS_WARNING("Huh, someone is throwing non-DOM errors using the DOM module!"); diff --git a/dom/indexedDB/IDBTransaction.cpp b/dom/indexedDB/IDBTransaction.cpp index f665ddd87fa0..62f11902fe36 100644 --- a/dom/indexedDB/IDBTransaction.cpp +++ b/dom/indexedDB/IDBTransaction.cpp @@ -85,8 +85,6 @@ NS_IMETHODIMP_(nsrefcnt) StartTransactionRunnable::Release() NS_IMPL_QUERY_INTERFACE1(StartTransactionRunnable, nsIRunnable) -StartTransactionRunnable gStartTransactionRunnable; - } // anonymous namespace @@ -128,7 +126,8 @@ IDBTransaction::CreateInternal(IDBDatabase* aDatabase, TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate(); NS_ENSURE_TRUE(pool, nullptr); - pool->Dispatch(transaction, &gStartTransactionRunnable, false, nullptr); + static StartTransactionRunnable sStartTransactionRunnable; + pool->Dispatch(transaction, &sStartTransactionRunnable, false, nullptr); } } else if (!aIsVersionChangeTransactionChild) { diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index 2c761bc98b6e..d5e8c0e48612 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -938,7 +938,7 @@ nsGeolocationService::StopDevice() NS_LITERAL_STRING("shutdown").get()); } -nsRefPtr nsGeolocationService::sService; +StaticRefPtr nsGeolocationService::sService; already_AddRefed nsGeolocationService::GetGeolocationService() diff --git a/dom/src/geolocation/nsGeolocation.h b/dom/src/geolocation/nsGeolocation.h index 0e0601b4f0b7..b1e64b3861d7 100644 --- a/dom/src/geolocation/nsGeolocation.h +++ b/dom/src/geolocation/nsGeolocation.h @@ -9,6 +9,7 @@ // Microsoft's API Name hackery sucks #undef CreateEvent +#include "mozilla/StaticPtr.h" #include "nsCOMPtr.h" #include "nsAutoPtr.h" #include "nsCOMArray.h" @@ -112,7 +113,7 @@ class nsGeolocationService MOZ_FINAL : public nsIGeolocationUpdate, public nsIOb public: static already_AddRefed GetGeolocationService(); - static nsRefPtr sService; + static mozilla::StaticRefPtr sService; NS_DECL_ISUPPORTS NS_DECL_NSIGEOLOCATIONUPDATE