Bug 550593: Make nsISMILType::Init infallible, and return |void| instead of |nsresult|. r=roc
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 22 Mar 2010 11:57:36 -0700
changeset 39715 de234fec8da7ec980f38a755dfde520ba0d101d6
parent 39714 4bb83011e8902dd89a18b55f44065773400cf02f
child 39716 5dc1c7e48631d14fd0f543ee0d17c56862af24b5
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs550593
milestone1.9.3a4pre
Bug 550593: Make nsISMILType::Init infallible, and return |void| instead of |nsresult|. r=roc
content/smil/SMILBoolType.cpp
content/smil/SMILBoolType.h
content/smil/SMILEnumType.cpp
content/smil/SMILEnumType.h
content/smil/SMILIntegerType.cpp
content/smil/SMILIntegerType.h
content/smil/nsISMILType.h
content/smil/nsSMILCSSValueType.cpp
content/smil/nsSMILCSSValueType.h
content/smil/nsSMILFloatType.cpp
content/smil/nsSMILFloatType.h
content/smil/nsSMILNullType.h
content/smil/nsSMILValue.cpp
content/smil/nsSMILValue.h
content/svg/content/src/SVGOrientSMILType.cpp
content/svg/content/src/SVGOrientSMILType.h
content/svg/content/src/SVGViewBoxSMILType.cpp
content/svg/content/src/SVGViewBoxSMILType.h
content/svg/content/src/nsSVGTransformSMILType.cpp
content/svg/content/src/nsSVGTransformSMILType.h
--- a/content/smil/SMILBoolType.cpp
+++ b/content/smil/SMILBoolType.cpp
@@ -38,24 +38,22 @@
 #include "nsSMILValue.h"
 #include "nsDebug.h"
 #include <math.h>
 
 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
 SMILBoolType::Destroy(nsSMILValue& aValue) const
 {
   NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
   aValue.mU.mBool = PR_FALSE;
   aValue.mType = &nsSMILNullType::sSingleton;
--- a/content/smil/SMILBoolType.h
+++ b/content/smil/SMILBoolType.h
@@ -45,17 +45,17 @@ class SMILBoolType : public nsISMILType
 {
 public:
   // Singleton for nsSMILValue objects to hold onto.
   static SMILBoolType sSingleton;
 
 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,
                        PRUint32 aCount) const;
   virtual PRBool IsEqual(const nsSMILValue& aLeft,
                          const nsSMILValue& aRight) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
--- a/content/smil/SMILEnumType.cpp
+++ b/content/smil/SMILEnumType.cpp
@@ -38,24 +38,22 @@
 #include "nsSMILValue.h"
 #include "nsDebug.h"
 #include <math.h>
 
 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
 SMILEnumType::Destroy(nsSMILValue& aValue) const
 {
   NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
   aValue.mU.mUint = 0;
   aValue.mType = &nsSMILNullType::sSingleton;
--- a/content/smil/SMILEnumType.h
+++ b/content/smil/SMILEnumType.h
@@ -45,17 +45,17 @@ class SMILEnumType : public nsISMILType
 {
 public:
   // Singleton for nsSMILValue objects to hold onto.
   static SMILEnumType sSingleton;
 
 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,
                            const nsSMILValue& aRight) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
--- a/content/smil/SMILIntegerType.cpp
+++ b/content/smil/SMILIntegerType.cpp
@@ -38,23 +38,22 @@
 #include "nsSMILValue.h"
 #include "nsDebug.h"
 #include <math.h>
 
 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
 SMILIntegerType::Destroy(nsSMILValue& aValue) const
 {
   NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
   aValue.mU.mInt = 0;
   aValue.mType = &nsSMILNullType::sSingleton;
--- a/content/smil/SMILIntegerType.h
+++ b/content/smil/SMILIntegerType.h
@@ -39,17 +39,17 @@
 
 #include "nsISMILType.h"
 
 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,
                            const nsSMILValue& aRight) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
--- a/content/smil/nsISMILType.h
+++ b/content/smil/nsISMILType.h
@@ -80,21 +80,20 @@ class nsISMILType
    */
   friend class nsSMILValue;
 
 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.
    *
    * @pre  aValue.mType == this
    * @post aValue.IsNull()
    */
   virtual void Destroy(nsSMILValue& aValue) const = 0;
--- a/content/smil/nsSMILCSSValueType.cpp
+++ b/content/smil/nsSMILCSSValueType.cpp
@@ -121,24 +121,23 @@ ExtractValueWrapper(nsSMILValue& aValue)
 static const ValueWrapper*
 ExtractValueWrapper(const nsSMILValue& aValue)
 {
   return static_cast<const ValueWrapper*>(aValue.mU.mPtr);
 }
 
 // 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
 nsSMILCSSValueType::Destroy(nsSMILValue& aValue) const
 {
   NS_ABORT_IF_FALSE(aValue.mType == this, "Unexpected SMIL value type");
   delete static_cast<ValueWrapper*>(aValue.mU.mPtr);
   aValue.mType = &nsSMILNullType::sSingleton;
--- a/content/smil/nsSMILCSSValueType.h
+++ b/content/smil/nsSMILCSSValueType.h
@@ -55,17 +55,17 @@ class nsSMILCSSValueType : public nsISMI
 {
 public:
   // Singleton for nsSMILValue objects to hold onto.
   static nsSMILCSSValueType sSingleton;
 
 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;
   NS_OVERRIDE virtual PRBool   IsEqual(const nsSMILValue& aLeft,
                                        const nsSMILValue& aRight) const;
   NS_OVERRIDE virtual nsresult Add(nsSMILValue& aDest,
                                    const nsSMILValue& aValueToAdd,
                                    PRUint32 aCount) const;
--- a/content/smil/nsSMILFloatType.cpp
+++ b/content/smil/nsSMILFloatType.cpp
@@ -38,24 +38,22 @@
 
 #include "nsSMILFloatType.h"
 #include "nsSMILValue.h"
 #include "nsDebug.h"
 #include <math.h>
 
 /*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
 nsSMILFloatType::Destroy(nsSMILValue& aValue) const
 {
   NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
   aValue.mU.mDouble = 0.0;
   aValue.mType      = &nsSMILNullType::sSingleton;
--- a/content/smil/nsSMILFloatType.h
+++ b/content/smil/nsSMILFloatType.h
@@ -45,17 +45,17 @@ class nsSMILFloatType : public nsISMILTy
 {
 public:
   // Singleton for nsSMILValue objects to hold onto.
   static nsSMILFloatType sSingleton;
 
 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,
                            const nsSMILValue& aRight) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
--- a/content/smil/nsSMILNullType.h
+++ b/content/smil/nsSMILNullType.h
@@ -45,17 +45,17 @@ class nsSMILNullType : public nsISMILTyp
 {
 public:
   // Singleton for nsSMILValue objects to hold onto.
   static nsSMILNullType sSingleton;
 
 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;
 
   // The remaining methods should never be called, so although they're very
   // simple they don't need to be inline.
   virtual PRBool   IsEqual(const nsSMILValue& aLeft,
                            const nsSMILValue& aRight) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
--- a/content/smil/nsSMILValue.cpp
+++ b/content/smil/nsSMILValue.cpp
@@ -51,33 +51,28 @@ nsSMILValue::nsSMILValue(const nsISMILTy
   }
 
   InitAndCheckPostcondition(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);
 }
 
 const nsSMILValue&
 nsSMILValue::operator=(const nsSMILValue& aVal)
 {
   if (&aVal == this)
     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);
 
   return *this;
 }
 
 PRBool
@@ -129,43 +124,40 @@ nsSMILValue::Interpolate(const nsSMILVal
 {
   if (aEndVal.mType != mType) {
     NS_ERROR("Trying to interpolate between incompatible types");
     return NS_ERROR_FAILURE;
   }
 
   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);
 }
 
 //----------------------------------------------------------------------
 // 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
 nsSMILValue::DestroyAndCheckPostcondition()
 {
   mType->Destroy(*this);
   NS_ABORT_IF_FALSE(IsNull(), "Post-condition of Destroy failed. "
                     "nsSMILValue not null after destroying");
 }
 
-nsresult
+void
 nsSMILValue::DestroyAndReinit(const nsISMILType* aNewType)
 {
   DestroyAndCheckPostcondition();
-  return InitAndCheckPostcondition(aNewType);
+  InitAndCheckPostcondition(aNewType);
 }
--- a/content/smil/nsSMILValue.h
+++ b/content/smil/nsSMILValue.h
@@ -85,14 +85,14 @@ public:
       PRUint16 mUnit;
       PRUint16 mOrientType;
     } mOrient;
     void* mPtr;
   } mU;
   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_
--- a/content/svg/content/src/SVGOrientSMILType.cpp
+++ b/content/svg/content/src/SVGOrientSMILType.cpp
@@ -41,26 +41,25 @@
 #include "nsIDOMSVGMarkerElement.h"
 #include "nsDebug.h"
 #include <math.h>
 
 namespace mozilla {
 
 /*static*/ SVGOrientSMILType SVGOrientSMILType::sSingleton;
 
-nsresult
+void
 SVGOrientSMILType::Init(nsSMILValue& aValue) const
 {
   NS_ABORT_IF_FALSE(aValue.IsNull(), "Unexpected value type");
 
   aValue.mU.mOrient.mAngle = 0.0f;
   aValue.mU.mOrient.mUnit = nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED;
   aValue.mU.mOrient.mOrientType = nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE;
   aValue.mType = this;
-  return NS_OK;
 }
 
 void
 SVGOrientSMILType::Destroy(nsSMILValue& aValue) const
 {
   NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value.");
   aValue.mU.mPtr = nsnull;
   aValue.mType = &nsSMILNullType::sSingleton;
--- a/content/svg/content/src/SVGOrientSMILType.h
+++ b/content/svg/content/src/SVGOrientSMILType.h
@@ -59,17 +59,17 @@ class SVGOrientSMILType : public nsISMIL
 {
 public:
   // Singleton for nsSMILValue objects to hold onto.
   static SVGOrientSMILType sSingleton;
 
 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,
                            const nsSMILValue& aRight) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
--- a/content/svg/content/src/SVGViewBoxSMILType.cpp
+++ b/content/svg/content/src/SVGViewBoxSMILType.cpp
@@ -39,27 +39,24 @@
 #include "nsSVGViewBox.h"
 #include "nsDebug.h"
 #include <math.h>
 
 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
 SVGViewBoxSMILType::Destroy(nsSMILValue& aValue) const
 {
   NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
   delete static_cast<nsSVGViewBoxRect*>(aValue.mU.mPtr);
   aValue.mU.mPtr = nsnull;
--- a/content/svg/content/src/SVGViewBoxSMILType.h
+++ b/content/svg/content/src/SVGViewBoxSMILType.h
@@ -45,17 +45,17 @@ class SVGViewBoxSMILType : public nsISMI
 {
 public:
   // Singleton for nsSMILValue objects to hold onto.
   static SVGViewBoxSMILType sSingleton;
 
 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,
                            const nsSMILValue& aRight) const;
   virtual nsresult Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
                                    const nsSMILValue& aTo,
--- a/content/svg/content/src/nsSVGTransformSMILType.cpp
+++ b/content/svg/content/src/nsSVGTransformSMILType.cpp
@@ -42,27 +42,24 @@
 
 /*static*/ nsSVGTransformSMILType nsSVGTransformSMILType::sSingleton;
 
 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
 nsSVGTransformSMILType::Destroy(nsSMILValue& aValue) const
 {
   NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value type");
   TransformArray* params = static_cast<TransformArray*>(aValue.mU.mPtr);
   delete params;
--- a/content/svg/content/src/nsSVGTransformSMILType.h
+++ b/content/svg/content/src/nsSVGTransformSMILType.h
@@ -107,17 +107,17 @@ class nsSVGTransformSMILType : public ns
 {
 public:
   // Singleton for nsSMILValue objects to hold onto.
   static nsSVGTransformSMILType sSingleton;
 
 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,
                            const nsSMILValue& aRight) const;
   virtual nsresult Add(nsSMILValue& aDest,
                        const nsSMILValue& aValueToAdd,
                        PRUint32 aCount) const;
   virtual nsresult SandwichAdd(nsSMILValue& aDest,