Bug 550593: Make nsISMILType::Init infallible, and return |void| instead of |nsresult|. r=roc

This commit is contained in:
Daniel Holbert 2010-03-22 11:57:36 -07:00
Родитель 8e0a7988a3
Коммит 8205353382
20 изменённых файлов: 34 добавлений и 58 удалений

Просмотреть файл

@ -43,14 +43,12 @@ namespace mozilla {
/*static*/ SMILBoolType SMILBoolType::sSingleton;
nsresult
void
SMILBoolType::Init(nsSMILValue& aValue) const
{
NS_PRECONDITION(aValue.mType == this || aValue.IsNull(),
"Unexpected value type");
NS_PRECONDITION(aValue.IsNull(), "Unexpected value type");
aValue.mU.mBool = PR_FALSE;
aValue.mType = this;
return NS_OK;
}
void

Просмотреть файл

@ -50,7 +50,7 @@ public:
protected:
// nsISMILType Methods
// -------------------
virtual nsresult Init(nsSMILValue& aValue) const;
virtual void Init(nsSMILValue& aValue) const;
virtual void Destroy(nsSMILValue&) const;
virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,

Просмотреть файл

@ -43,14 +43,12 @@ namespace mozilla {
/*static*/ SMILEnumType SMILEnumType::sSingleton;
nsresult
void
SMILEnumType::Init(nsSMILValue& aValue) const
{
NS_PRECONDITION(aValue.mType == this || aValue.IsNull(),
"Unexpected value type");
NS_PRECONDITION(aValue.IsNull(), "Unexpected value type");
aValue.mU.mUint = 0;
aValue.mType = this;
return NS_OK;
}
void

Просмотреть файл

@ -50,7 +50,7 @@ public:
protected:
// nsISMILType Methods
// -------------------
virtual nsresult Init(nsSMILValue& aValue) const;
virtual void Init(nsSMILValue& aValue) const;
virtual void Destroy(nsSMILValue&) const;
virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
virtual PRBool IsEqual(const nsSMILValue& aLeft,

Просмотреть файл

@ -43,13 +43,12 @@ namespace mozilla {
/*static*/ SMILIntegerType SMILIntegerType::sSingleton;
nsresult
void
SMILIntegerType::Init(nsSMILValue& aValue) const
{
NS_ABORT_IF_FALSE(aValue.IsNull(), "Unexpected value type");
aValue.mU.mInt = 0;
aValue.mType = this;
return NS_OK;
}
void

Просмотреть файл

@ -44,7 +44,7 @@ namespace mozilla {
class SMILIntegerType : public nsISMILType
{
public:
virtual nsresult Init(nsSMILValue& aValue) const;
virtual void Init(nsSMILValue& aValue) const;
virtual void Destroy(nsSMILValue&) const;
virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
virtual PRBool IsEqual(const nsSMILValue& aLeft,

Просмотреть файл

@ -85,11 +85,10 @@ protected:
* Initialises aValue and sets it to some identity value such that adding
* aValue to another value of the same type has no effect.
*
* @pre (aValue.mType == this && aValue.mU is valid)
* || aValue.mType == null-type
* @post aValue.mType == this || NS_FAILED(rv)
* @pre aValue.IsNull()
* @post aValue.mType == this
*/
virtual nsresult Init(nsSMILValue& aValue) const = 0;
virtual void Init(nsSMILValue& aValue) const = 0;
/**
* Destroys any data associated with a value of this type.

Просмотреть файл

@ -126,14 +126,13 @@ ExtractValueWrapper(const nsSMILValue& aValue)
// Class methods
// -------------
nsresult
void
nsSMILCSSValueType::Init(nsSMILValue& aValue) const
{
NS_ABORT_IF_FALSE(aValue.IsNull(), "Unexpected SMIL value type");
aValue.mU.mPtr = nsnull;
aValue.mType = this;
return NS_OK;
}
void

Просмотреть файл

@ -60,7 +60,7 @@ public:
protected:
// nsISMILType Methods
// -------------------
NS_OVERRIDE virtual nsresult Init(nsSMILValue& aValue) const;
NS_OVERRIDE virtual void Init(nsSMILValue& aValue) const;
NS_OVERRIDE virtual void Destroy(nsSMILValue&) const;
NS_OVERRIDE virtual nsresult Assign(nsSMILValue& aDest,
const nsSMILValue& aSrc) const;

Просмотреть файл

@ -43,14 +43,12 @@
/*static*/ nsSMILFloatType nsSMILFloatType::sSingleton;
nsresult
void
nsSMILFloatType::Init(nsSMILValue& aValue) const
{
NS_PRECONDITION(aValue.mType == this || aValue.IsNull(),
"Unexpected value type");
NS_PRECONDITION(aValue.IsNull(), "Unexpected value type");
aValue.mU.mDouble = 0.0;
aValue.mType = this;
return NS_OK;
}
void

Просмотреть файл

@ -50,7 +50,7 @@ public:
protected:
// nsISMILType Methods
// -------------------
virtual nsresult Init(nsSMILValue& aValue) const;
virtual void Init(nsSMILValue& aValue) const;
virtual void Destroy(nsSMILValue&) const;
virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
virtual PRBool IsEqual(const nsSMILValue& aLeft,

Просмотреть файл

@ -50,7 +50,7 @@ public:
protected:
// nsISMILType Methods
// -------------------
virtual nsresult Init(nsSMILValue& aValue) const { return NS_OK; }
virtual void Init(nsSMILValue& aValue) const {}
virtual void Destroy(nsSMILValue& aValue) const {}
virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;

Просмотреть файл

@ -56,10 +56,7 @@ nsSMILValue::nsSMILValue(const nsISMILType* aType)
nsSMILValue::nsSMILValue(const nsSMILValue& aVal)
: mType(&nsSMILNullType::sSingleton)
{
nsresult rv = InitAndCheckPostcondition(aVal.mType);
if (NS_FAILED(rv))
return;
InitAndCheckPostcondition(aVal.mType);
mType->Assign(*this, aVal);
}
@ -70,9 +67,7 @@ nsSMILValue::operator=(const nsSMILValue& aVal)
return *this;
if (mType != aVal.mType) {
nsresult rv = DestroyAndReinit(aVal.mType);
if (NS_FAILED(rv))
return *this; // Initialization failed; return early
DestroyAndReinit(aVal.mType);
}
mType->Assign(*this, aVal);
@ -134,9 +129,7 @@ nsSMILValue::Interpolate(const nsSMILValue& aEndVal,
if (aResult.mType != mType) {
// Outparam has wrong type
nsresult rv = aResult.DestroyAndReinit(mType);
if (NS_FAILED(rv))
return rv;
aResult.DestroyAndReinit(mType);
}
return mType->Interpolate(*this, aEndVal, aUnitDistance, aResult);
@ -146,13 +139,12 @@ nsSMILValue::Interpolate(const nsSMILValue& aEndVal,
// Helper methods
// Wrappers for nsISMILType::Init & ::Destroy that verify their postconditions
nsresult
void
nsSMILValue::InitAndCheckPostcondition(const nsISMILType* aNewType)
{
nsresult rv = aNewType->Init(*this);
NS_ABORT_IF_FALSE(mType == aNewType || (NS_FAILED(rv) && IsNull()),
aNewType->Init(*this);
NS_ABORT_IF_FALSE(mType == aNewType,
"Post-condition of Init failed. nsSMILValue is invalid");
return rv;
}
void
@ -163,9 +155,9 @@ nsSMILValue::DestroyAndCheckPostcondition()
"nsSMILValue not null after destroying");
}
nsresult
void
nsSMILValue::DestroyAndReinit(const nsISMILType* aNewType)
{
DestroyAndCheckPostcondition();
return InitAndCheckPostcondition(aNewType);
InitAndCheckPostcondition(aNewType);
}

Просмотреть файл

@ -90,9 +90,9 @@ public:
const nsISMILType* mType;
protected:
nsresult InitAndCheckPostcondition(const nsISMILType* aNewType);
void DestroyAndCheckPostcondition();
nsresult DestroyAndReinit(const nsISMILType* aNewType);
void InitAndCheckPostcondition(const nsISMILType* aNewType);
void DestroyAndCheckPostcondition();
void DestroyAndReinit(const nsISMILType* aNewType);
};
#endif // NS_SMILVALUE_H_

Просмотреть файл

@ -46,7 +46,7 @@ namespace mozilla {
/*static*/ SVGOrientSMILType SVGOrientSMILType::sSingleton;
nsresult
void
SVGOrientSMILType::Init(nsSMILValue& aValue) const
{
NS_ABORT_IF_FALSE(aValue.IsNull(), "Unexpected value type");
@ -55,7 +55,6 @@ SVGOrientSMILType::Init(nsSMILValue& aValue) const
aValue.mU.mOrient.mUnit = nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED;
aValue.mU.mOrient.mOrientType = nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE;
aValue.mType = this;
return NS_OK;
}
void

Просмотреть файл

@ -64,7 +64,7 @@ public:
protected:
// nsISMILType Methods
// -------------------
virtual nsresult Init(nsSMILValue& aValue) const;
virtual void Init(nsSMILValue& aValue) const;
virtual void Destroy(nsSMILValue&) const;
virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
virtual PRBool IsEqual(const nsSMILValue& aLeft,

Просмотреть файл

@ -44,17 +44,14 @@ namespace mozilla {
/*static*/ SVGViewBoxSMILType SVGViewBoxSMILType::sSingleton;
nsresult
void
SVGViewBoxSMILType::Init(nsSMILValue& aValue) const
{
NS_ABORT_IF_FALSE(aValue.IsNull(), "Unexpected value type");
nsSVGViewBoxRect* viewBox = new nsSVGViewBoxRect();
NS_ENSURE_TRUE(viewBox, NS_ERROR_OUT_OF_MEMORY);
aValue.mU.mPtr = viewBox;
aValue.mType = this;
return NS_OK;
}
void

Просмотреть файл

@ -50,7 +50,7 @@ public:
protected:
// nsISMILType Methods
// -------------------
virtual nsresult Init(nsSMILValue& aValue) const;
virtual void Init(nsSMILValue& aValue) const;
virtual void Destroy(nsSMILValue&) const;
virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
virtual PRBool IsEqual(const nsSMILValue& aLeft,

Просмотреть файл

@ -47,17 +47,14 @@ typedef nsTArray<nsSVGSMILTransform> TransformArray;
//----------------------------------------------------------------------
// nsISMILType implementation
nsresult
void
nsSVGTransformSMILType::Init(nsSMILValue &aValue) const
{
NS_PRECONDITION(aValue.IsNull(), "Unexpected value type");
TransformArray* transforms = new TransformArray(1);
NS_ENSURE_TRUE(transforms, NS_ERROR_OUT_OF_MEMORY);
aValue.mU.mPtr = transforms;
aValue.mType = this;
return NS_OK;
}
void

Просмотреть файл

@ -112,7 +112,7 @@ public:
protected:
// nsISMILType Methods
// -------------------
virtual nsresult Init(nsSMILValue& aValue) const;
virtual void Init(nsSMILValue& aValue) const;
virtual void Destroy(nsSMILValue& aValue) const;
virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
virtual PRBool IsEqual(const nsSMILValue& aLeft,