Bug 1315874 - Use UniquePtr for handling heap-allocated nsISMILAttr objects; r?dholbert draft
authorBrian Birtles <birtles@gmail.com>
Thu, 30 Mar 2017 13:10:07 +0900
changeset 554900 6a610e3024a55523bcf953004534bb949886f516
parent 554899 7ad25b4491c871e97b87ba78628cc750f51fa1b9
child 554901 f0a83d31b4b56e9ea4d29a31a4c8f4580b61b35a
push id52084
push userbbirtles@mozilla.com
push dateMon, 03 Apr 2017 07:50:01 +0000
reviewersdholbert
bugs1315874
milestone55.0a1
Bug 1315874 - Use UniquePtr for handling heap-allocated nsISMILAttr objects; r?dholbert Later in this patch series we will add another call site for CreateSMILAttr so this seems like a good opportunity to convert this to UniquePtr which should be safer than passing back raw pointers the caller needs to free. I've also replaced a few uses of () with {} to make these lines unambiguous (i.e. avoid "C++'s most vexing parse"). MozReview-Commit-ID: 10lA0ZaXChj
dom/base/Element.h
dom/smil/nsSMILCompositor.cpp
dom/smil/nsSMILCompositor.h
dom/svg/SVGAnimatedLengthList.cpp
dom/svg/SVGAnimatedLengthList.h
dom/svg/SVGAnimatedNumberList.cpp
dom/svg/SVGAnimatedNumberList.h
dom/svg/SVGAnimatedPathSegList.cpp
dom/svg/SVGAnimatedPathSegList.h
dom/svg/SVGAnimatedPointList.cpp
dom/svg/SVGAnimatedPointList.h
dom/svg/SVGAnimatedPreserveAspectRatio.cpp
dom/svg/SVGAnimatedPreserveAspectRatio.h
dom/svg/nsSVGAngle.cpp
dom/svg/nsSVGAngle.h
dom/svg/nsSVGAnimatedTransformList.cpp
dom/svg/nsSVGAnimatedTransformList.h
dom/svg/nsSVGBoolean.cpp
dom/svg/nsSVGBoolean.h
dom/svg/nsSVGClass.cpp
dom/svg/nsSVGClass.h
dom/svg/nsSVGElement.cpp
dom/svg/nsSVGElement.h
dom/svg/nsSVGEnum.cpp
dom/svg/nsSVGEnum.h
dom/svg/nsSVGInteger.cpp
dom/svg/nsSVGInteger.h
dom/svg/nsSVGIntegerPair.cpp
dom/svg/nsSVGIntegerPair.h
dom/svg/nsSVGLength2.cpp
dom/svg/nsSVGLength2.h
dom/svg/nsSVGNumber2.cpp
dom/svg/nsSVGNumber2.h
dom/svg/nsSVGNumberPair.cpp
dom/svg/nsSVGNumberPair.h
dom/svg/nsSVGString.cpp
dom/svg/nsSVGString.h
dom/svg/nsSVGViewBox.cpp
dom/svg/nsSVGViewBox.h
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -34,16 +34,17 @@
 #include "mozilla/dom/DOMRect.h"
 #include "nsAttrValue.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/DOMTokenListSupportedTokens.h"
 #include "mozilla/dom/WindowBinding.h"
 #include "mozilla/dom/ElementBinding.h"
 #include "mozilla/dom/Nullable.h"
+#include "mozilla/UniquePtr.h"
 #include "Units.h"
 #include "DOMIntersectionObserver.h"
 
 class mozAutoDocUpdate;
 class nsIFrame;
 class nsIDOMMozNamedAttrMap;
 class nsIMozBrowserFrame;
 class nsIURI;
@@ -312,20 +313,19 @@ public:
    * context, so that the style changes will be noticed.
    */
   virtual nsresult SetSMILOverrideStyleDeclaration(
     DeclarationBlock* aDeclaration, bool aNotify);
 
   /**
    * Returns a new nsISMILAttr that allows the caller to animate the given
    * attribute on this element.
-   *
-   * The CALLER OWNS the result and is responsible for deleting it.
    */
-  virtual nsISMILAttr* GetAnimatedAttr(int32_t aNamespaceID, nsIAtom* aName)
+  virtual UniquePtr<nsISMILAttr> GetAnimatedAttr(int32_t aNamespaceID,
+                                                 nsIAtom* aName)
   {
     return nullptr;
   }
 
   /**
    * Get the SMIL override style for this element. This is a style declaration
    * that is applied *after* the inline style, and it can be used e.g. to store
    * animated style values.
--- a/dom/smil/nsSMILCompositor.cpp
+++ b/dom/smil/nsSMILCompositor.cpp
@@ -51,17 +51,17 @@ nsSMILCompositor::AddAnimationFunction(n
 void
 nsSMILCompositor::ComposeAttribute(bool& aMightHavePendingStyleUpdates)
 {
   if (!mKey.mElement)
     return;
 
   // FIRST: Get the nsISMILAttr (to grab base value from, and to eventually
   // give animated value to)
-  nsAutoPtr<nsISMILAttr> smilAttr(CreateSMILAttr());
+  UniquePtr<nsISMILAttr> smilAttr{CreateSMILAttr()};
   if (!smilAttr) {
     // Target attribute not found (or, out of memory)
     return;
   }
   if (mAnimationFunctions.IsEmpty()) {
     // No active animation functions. (We can still have a nsSMILCompositor in
     // that case if an animation function has *just* become inactive)
     smilAttr->ClearAnimValue();
@@ -108,44 +108,44 @@ nsSMILCompositor::ComposeAttribute(bool&
 }
 
 void
 nsSMILCompositor::ClearAnimationEffects()
 {
   if (!mKey.mElement || !mKey.mAttributeName)
     return;
 
-  nsAutoPtr<nsISMILAttr> smilAttr(CreateSMILAttr());
+  UniquePtr<nsISMILAttr> smilAttr{CreateSMILAttr()};
   if (!smilAttr) {
     // Target attribute not found (or, out of memory)
     return;
   }
   smilAttr->ClearAnimValue();
 }
 
 // Protected Helper Functions
 // --------------------------
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSMILCompositor::CreateSMILAttr()
 {
   nsCSSPropertyID propID =
     nsCSSProps::LookupProperty(nsDependentAtomString(mKey.mAttributeName),
                                CSSEnabledState::eForAllContent);
   if (nsSMILCSSProperty::IsPropertyAnimatable(propID)) {
     // If we are animating the 'width' or 'height' of an outer SVG
     // element we should animate it as a CSS property, but for other elements
     // (e.g. <rect>) we should animate it as a length attribute.
     // The easiest way to test for an outer SVG element, is to see if it is an
     // SVG-namespace element mapping its width/height attribute to style.
     bool animateAsAttr = (mKey.mAttributeName == nsGkAtoms::width ||
                           mKey.mAttributeName == nsGkAtoms::height) &&
                          mKey.mElement->GetNameSpaceID() == kNameSpaceID_SVG &&
                          !mKey.mElement->IsAttributeMapped(mKey.mAttributeName);
     if (!animateAsAttr) {
-      return new nsSMILCSSProperty(propID, mKey.mElement.get());
+      return MakeUnique<nsSMILCSSProperty>(propID, mKey.mElement.get());
     }
   }
 
   return mKey.mElement->GetAnimatedAttr(mKey.mAttributeNamespaceID,
                                         mKey.mAttributeName);
 }
 
 uint32_t
--- a/dom/smil/nsSMILCompositor.h
+++ b/dom/smil/nsSMILCompositor.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NS_SMILCOMPOSITOR_H_
 #define NS_SMILCOMPOSITOR_H_
 
 #include "mozilla/Move.h"
+#include "mozilla/UniquePtr.h"
 #include "nsAutoPtr.h"
 #include "nsTHashtable.h"
 #include "nsString.h"
 #include "nsSMILAnimationFunction.h"
 #include "nsSMILTargetIdentifier.h"
 #include "nsSMILCompositorTable.h"
 #include "PLDHashTable.h"
 
@@ -68,19 +69,18 @@ public:
   void ToggleForceCompositing() { mForceCompositing = true; }
 
   // Transfers |aOther|'s mCachedBaseValue to |this|
   void StealCachedBaseValue(nsSMILCompositor* aOther) {
     mCachedBaseValue = mozilla::Move(aOther->mCachedBaseValue);
   }
 
  private:
-  // Create a nsISMILAttr for my target, on the heap.  Caller is responsible
-  // for deallocating the returned object.
-  nsISMILAttr* CreateSMILAttr();
+  // Create a nsISMILAttr for my target, on the heap.
+  UniquePtr<nsISMILAttr> CreateSMILAttr();
 
   // Finds the index of the first function that will affect our animation
   // sandwich. Also toggles the 'mForceCompositing' flag if it finds that any
   // (used) functions have changed.
   uint32_t GetFirstFuncToAffectSandwich();
 
   // If the passed-in base value differs from our cached base value, this
   // method updates the cached value (and toggles the 'mForceCompositing' flag)
--- a/dom/svg/SVGAnimatedLengthList.cpp
+++ b/dom/svg/SVGAnimatedLengthList.cpp
@@ -114,23 +114,24 @@ SVGAnimatedLengthList::ClearAnimValue(ns
     // must do that before touching mAnimVal. See comments above.
     //
     domWrapper->InternalAnimValListWillChangeTo(mBaseVal);
   }
   mAnimVal = nullptr;
   aElement->DidAnimateLengthList(aAttrEnum);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 SVGAnimatedLengthList::ToSMILAttr(nsSVGElement *aSVGElement,
                                   uint8_t aAttrEnum,
                                   uint8_t aAxis,
                                   bool aCanZeroPadList)
 {
-  return new SMILAnimatedLengthList(this, aSVGElement, aAttrEnum, aAxis, aCanZeroPadList);
+  return MakeUnique<SMILAnimatedLengthList>(this, aSVGElement, aAttrEnum,
+                                            aAxis, aCanZeroPadList);
 }
 
 nsresult
 SVGAnimatedLengthList::
   SMILAnimatedLengthList::ValueFromString(const nsAString& aStr,
                                const dom::SVGAnimationElement* /*aSrcElement*/,
                                nsSMILValue& aValue,
                                bool& aPreventCachingOfSandwich) const
--- a/dom/svg/SVGAnimatedLengthList.h
+++ b/dom/svg/SVGAnimatedLengthList.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_SVGANIMATEDLENGTHLIST_H__
 #define MOZILLA_SVGANIMATEDLENGTHLIST_H__
 
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "nsAutoPtr.h"
 #include "nsISMILAttr.h"
 #include "SVGLengthList.h"
 
 class nsSMILValue;
 class nsSVGElement;
 
 namespace mozilla {
@@ -69,19 +70,19 @@ public:
 
   void ClearAnimValue(nsSVGElement *aElement,
                       uint32_t aAttrEnum);
 
   bool IsAnimating() const {
     return !!mAnimVal;
   }
 
-  /// Callers own the returned nsISMILAttr
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement, uint8_t aAttrEnum,
-                          uint8_t aAxis, bool aCanZeroPadList);
+  UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement,
+                                    uint8_t aAttrEnum, uint8_t aAxis,
+                                    bool aCanZeroPadList);
 
 private:
 
   // mAnimVal is a pointer to allow us to determine if we're being animated or
   // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
   // if we're animating is not an option, since that would break animation *to*
   // the empty string (<set to="">).
 
--- a/dom/svg/SVGAnimatedNumberList.cpp
+++ b/dom/svg/SVGAnimatedNumberList.cpp
@@ -116,21 +116,21 @@ SVGAnimatedNumberList::ClearAnimValue(ns
     // must do that before touching mAnimVal. See comments above.
     //
     domWrapper->InternalAnimValListWillChangeTo(mBaseVal);
   }
   mAnimVal = nullptr;
   aElement->DidAnimateNumberList(aAttrEnum);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 SVGAnimatedNumberList::ToSMILAttr(nsSVGElement *aSVGElement,
                                   uint8_t aAttrEnum)
 {
-  return new SMILAnimatedNumberList(this, aSVGElement, aAttrEnum);
+  return MakeUnique<SMILAnimatedNumberList>(this, aSVGElement, aAttrEnum);
 }
 
 nsresult
 SVGAnimatedNumberList::
   SMILAnimatedNumberList::ValueFromString(const nsAString& aStr,
                                const dom::SVGAnimationElement* /*aSrcElement*/,
                                nsSMILValue& aValue,
                                bool& aPreventCachingOfSandwich) const
--- a/dom/svg/SVGAnimatedNumberList.h
+++ b/dom/svg/SVGAnimatedNumberList.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_SVGANIMATEDNUMBERLIST_H__
 #define MOZILLA_SVGANIMATEDNUMBERLIST_H__
 
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "nsAutoPtr.h"
 #include "nsISMILAttr.h"
 #include "SVGNumberList.h"
 
 class nsSMILValue;
 class nsSVGElement;
 
 namespace mozilla {
@@ -77,18 +78,18 @@ public:
   // useable, and represents the default base value of the attribute.
   bool IsExplicitlySet() const
     { return !!mAnimVal || mIsBaseSet; }
   
   bool IsAnimating() const {
     return !!mAnimVal;
   }
 
-  /// Callers own the returned nsISMILAttr
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement, uint8_t aAttrEnum);
+  UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement,
+                                    uint8_t aAttrEnum);
 
 private:
 
   // mAnimVal is a pointer to allow us to determine if we're being animated or
   // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
   // if we're animating is not an option, since that would break animation *to*
   // the empty string (<set to="">).
 
--- a/dom/svg/SVGAnimatedPathSegList.cpp
+++ b/dom/svg/SVGAnimatedPathSegList.cpp
@@ -139,20 +139,20 @@ SVGAnimatedPathSegList::ClearAnimValue(n
     // a different number of items to the last active animated value.
     //
     domWrapper->InternalListWillChangeTo(mBaseVal);
   }
   mAnimVal = nullptr;
   aElement->DidAnimatePathSegList();
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 SVGAnimatedPathSegList::ToSMILAttr(nsSVGElement *aElement)
 {
-  return new SMILAnimatedPathSegList(this, aElement);
+  return MakeUnique<SMILAnimatedPathSegList>(this, aElement);
 }
 
 nsresult
 SVGAnimatedPathSegList::
   SMILAnimatedPathSegList::ValueFromString(const nsAString& aStr,
                                const dom::SVGAnimationElement* /*aSrcElement*/,
                                nsSMILValue& aValue,
                                bool& aPreventCachingOfSandwich) const
--- a/dom/svg/SVGAnimatedPathSegList.h
+++ b/dom/svg/SVGAnimatedPathSegList.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_SVGANIMATEDPATHSEGLIST_H__
 #define MOZILLA_SVGANIMATEDPATHSEGLIST_H__
 
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/UniquePtr.h"
 #include "nsAutoPtr.h"
 #include "nsISMILAttr.h"
 #include "SVGPathData.h"
 
 class nsSMILValue;
 class nsSVGElement;
 
 namespace mozilla {
@@ -82,18 +83,17 @@ public:
   void *GetAnimValKey() const {
     return (void*)&mAnimVal;
   }
   
   bool IsAnimating() const {
     return !!mAnimVal;
   }
 
-  /// Callers own the returned nsISMILAttr
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aElement);
+  UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aElement);
 
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
 
 private:
 
   // mAnimVal is a pointer to allow us to determine if we're being animated or
   // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
   // if we're animating is not an option, since that would break animation *to*
--- a/dom/svg/SVGAnimatedPointList.cpp
+++ b/dom/svg/SVGAnimatedPointList.cpp
@@ -142,20 +142,20 @@ SVGAnimatedPointList::ClearAnimValue(nsS
     // a different number of items to the last active animated value.
     //
     domWrapper->InternalListWillChangeTo(mBaseVal);
   }
   mAnimVal = nullptr;
   aElement->DidAnimatePointList();
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 SVGAnimatedPointList::ToSMILAttr(nsSVGElement *aElement)
 {
-  return new SMILAnimatedPointList(this, aElement);
+  return MakeUnique<SMILAnimatedPointList>(this, aElement);
 }
 
 nsresult
 SVGAnimatedPointList::
   SMILAnimatedPointList::ValueFromString(const nsAString& aStr,
                                const dom::SVGAnimationElement* /*aSrcElement*/,
                                nsSMILValue& aValue,
                                bool& aPreventCachingOfSandwich) const
--- a/dom/svg/SVGAnimatedPointList.h
+++ b/dom/svg/SVGAnimatedPointList.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_SVGANIMATEDPOINTLIST_H__
 #define MOZILLA_SVGANIMATEDPOINTLIST_H__
 
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "nsAutoPtr.h"
 #include "nsISMILAttr.h"
 #include "SVGPointList.h"
 
 class nsSMILValue;
 class nsSVGElement;
 
 namespace mozilla {
@@ -81,18 +82,17 @@ public:
   void *GetAnimValKey() const {
     return (void*)&mAnimVal;
   }
 
   bool IsAnimating() const {
     return !!mAnimVal;
   }
 
-  /// Callers own the returned nsISMILAttr
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aElement);
+  UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aElement);
 
 private:
 
   // mAnimVal is a pointer to allow us to determine if we're being animated or
   // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
   // if we're animating is not an option, since that would break animation *to*
   // the empty string (<set to="">).
 
--- a/dom/svg/SVGAnimatedPreserveAspectRatio.cpp
+++ b/dom/svg/SVGAnimatedPreserveAspectRatio.cpp
@@ -276,20 +276,20 @@ SVGAnimatedPreserveAspectRatio::ToDOMAni
   return domAnimatedPAspectRatio.forget();
 }
 
 DOMSVGAnimatedPreserveAspectRatio::~DOMSVGAnimatedPreserveAspectRatio()
 {
   sSVGAnimatedPAspectRatioTearoffTable.RemoveTearoff(mVal);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 SVGAnimatedPreserveAspectRatio::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILPreserveAspectRatio(this, aSVGElement);
+  return MakeUnique<SMILPreserveAspectRatio>(this, aSVGElement);
 }
 
 // typedef for inner class, to make function signatures shorter below:
 typedef SVGAnimatedPreserveAspectRatio::SMILPreserveAspectRatio
   SMILPreserveAspectRatio;
 
 nsresult
 SMILPreserveAspectRatio::ValueFromString(const nsAString& aStr,
--- a/dom/svg/SVGAnimatedPreserveAspectRatio.h
+++ b/dom/svg/SVGAnimatedPreserveAspectRatio.h
@@ -8,16 +8,17 @@
 #define MOZILLA_SVGANIMATEDPRESERVEASPECTRATIO_H__
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "nsISMILAttr.h"
 #include "nsSVGElement.h"
 #include "SVGPreserveAspectRatio.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 
 class nsSMILValue;
 
 namespace mozilla {
 namespace dom {
 class DOMSVGAnimatedPreserveAspectRatio;
 class SVGAnimationElement;
 } // namespace dom
@@ -67,18 +68,17 @@ public:
     { return mAnimVal; }
   bool IsAnimated() const
     { return mIsAnimated; }
   bool IsExplicitlySet() const
     { return mIsAnimated || mIsBaseSet; }
 
   already_AddRefed<mozilla::dom::DOMSVGAnimatedPreserveAspectRatio>
   ToDOMAnimatedPreserveAspectRatio(nsSVGElement* aSVGElement);
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
 
   SVGPreserveAspectRatio mAnimVal;
   SVGPreserveAspectRatio mBaseVal;
   bool mIsAnimated;
   bool mIsBaseSet;
 
--- a/dom/svg/nsSVGAngle.cpp
+++ b/dom/svg/nsSVGAngle.cpp
@@ -345,22 +345,22 @@ nsSVGAngle::ToDOMAnimatedAngle(nsSVGElem
   return domAnimatedAngle.forget();
 }
 
 SVGAnimatedAngle::~SVGAnimatedAngle()
 {
   sSVGAnimatedAngleTearoffTable.RemoveTearoff(mVal);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGAngle::ToSMILAttr(nsSVGElement *aSVGElement)
 {
   if (aSVGElement->NodeInfo()->Equals(nsGkAtoms::marker, kNameSpaceID_SVG)) {
     SVGMarkerElement *marker = static_cast<SVGMarkerElement*>(aSVGElement);
-    return new SMILOrient(marker->GetOrientType(), this, aSVGElement);
+    return MakeUnique<SMILOrient>(marker->GetOrientType(), this, aSVGElement);
   }
   // SMILOrient would not be useful for general angle attributes (also,
   // "orient" is the only animatable <angle>-valued attribute in SVG 1.1).
   NS_NOTREACHED("Trying to animate unknown angle attribute.");
   return nullptr;
 }
 
 nsresult
--- a/dom/svg/nsSVGAngle.h
+++ b/dom/svg/nsSVGAngle.h
@@ -6,16 +6,17 @@
 
 #ifndef __NS_SVGANGLE_H__
 #define __NS_SVGANGLE_H__
 
 #include "nsCOMPtr.h"
 #include "nsError.h"
 #include "nsISMILAttr.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 
 class nsISupports;
 class nsSMILValue;
 class nsSVGElement;
 
 namespace mozilla {
 
 // Angle Unit Types
@@ -65,18 +66,17 @@ public:
   uint8_t GetBaseValueUnit() const { return mBaseValUnit; }
   uint8_t GetAnimValueUnit() const { return mAnimValUnit; }
   float GetBaseValInSpecifiedUnits() const { return mBaseVal; }
   float GetAnimValInSpecifiedUnits() const { return mAnimVal; }
 
   static nsresult ToDOMSVGAngle(nsISupports **aResult);
   already_AddRefed<mozilla::dom::SVGAnimatedAngle>
     ToDOMAnimatedAngle(nsSVGElement* aSVGElement);
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
   static float GetDegreesPerUnit(uint8_t aUnit);
 
 private:
 
   float mAnimVal;
   float mBaseVal;
   uint8_t mAnimValUnit;
--- a/dom/svg/nsSVGAnimatedTransformList.cpp
+++ b/dom/svg/nsSVGAnimatedTransformList.cpp
@@ -162,20 +162,20 @@ nsSVGAnimatedTransformList::IsExplicitly
   //    nsSVGElement::UnsetAttr or a failed nsSVGElement::ParseAttribute)
   // 2) DOM call -- simply fetching the baseVal doesn't mean the transform value
   //    has been set. It is set if that baseVal has one or more transforms in
   //    the list.
   // 3) Animation -- which will cause the mAnimVal member to be allocated
   return mIsAttrSet || !mBaseVal.IsEmpty() || mAnimVal;
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGAnimatedTransformList::ToSMILAttr(nsSVGElement* aSVGElement)
 {
-  return new SMILAnimatedTransformList(this, aSVGElement);
+  return MakeUnique<SMILAnimatedTransformList>(this, aSVGElement);
 }
 
 nsresult
 nsSVGAnimatedTransformList::SMILAnimatedTransformList::ValueFromString(
   const nsAString& aStr,
   const dom::SVGAnimationElement* aSrcElement,
   nsSMILValue& aValue,
   bool& aPreventCachingOfSandwich) const
--- a/dom/svg/nsSVGAnimatedTransformList.h
+++ b/dom/svg/nsSVGAnimatedTransformList.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_SVGANIMATEDTRANSFORMLIST_H__
 #define MOZILLA_SVGANIMATEDTRANSFORMLIST_H__
 
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "nsAutoPtr.h"
 #include "nsISMILAttr.h"
 #include "SVGTransformList.h"
 
 class nsIAtom;
 class nsSMILValue;
 class nsSVGElement;
 
@@ -104,18 +105,17 @@ public:
    * accessor lets it detect cases where the "modification" is actually adding
    * a transform where we previously had none. These cases require a more
    * thorough nsChangeHint.)
    */
   bool HadTransformBeforeLastBaseValChange() const {
     return mHadTransformBeforeLastBaseValChange;
   }
 
-  /// Callers own the returned nsISMILAttr
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
 
   // mAnimVal is a pointer to allow us to determine if we're being animated or
   // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
   // if we're animating is not an option, since that would break animation *to*
   // the empty string (<set to="">).
 
--- a/dom/svg/nsSVGBoolean.cpp
+++ b/dom/svg/nsSVGBoolean.cpp
@@ -124,20 +124,20 @@ nsSVGBoolean::ToDOMAnimatedBoolean(nsSVG
   return domAnimatedBoolean.forget();
 }
 
 SVGAnimatedBoolean::~SVGAnimatedBoolean()
 {
   SVGAnimatedBooleanTearoffTable().RemoveTearoff(mVal);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGBoolean::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILBool(this, aSVGElement);
+  return MakeUnique<SMILBool>(this, aSVGElement);
 }
 
 nsresult
 nsSVGBoolean::SMILBool::ValueFromString(const nsAString& aStr,
                                         const SVGAnimationElement* /*aSrcElement*/,
                                         nsSMILValue& aValue,
                                         bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGBoolean.h
+++ b/dom/svg/nsSVGBoolean.h
@@ -6,16 +6,17 @@
 
 #ifndef __NS_SVGBOOLEAN_H__
 #define __NS_SVGBOOLEAN_H__
 
 #include "nsCOMPtr.h"
 #include "nsError.h"
 #include "nsISMILAttr.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 
 class nsIAtom;
 class nsSMILValue;
 class nsSVGElement;
 
 namespace mozilla {
 namespace dom {
 class SVGAnimationElement;
@@ -41,18 +42,17 @@ public:
     { return mBaseVal; }
 
   void SetAnimValue(bool aValue, nsSVGElement *aSVGElement);
   bool GetAnimValue() const
     { return mAnimVal; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedBoolean>
     ToDOMAnimatedBoolean(nsSVGElement* aSVGElement);
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
 
   bool mAnimVal;
   bool mBaseVal;
   bool mIsAnimated;
   uint8_t mAttrEnum; // element specified tracking for attribute
 
--- a/dom/svg/nsSVGClass.cpp
+++ b/dom/svg/nsSVGClass.cpp
@@ -112,20 +112,20 @@ nsSVGClass::SetAnimValue(const nsAString
 
 void
 DOMAnimatedString::GetAnimVal(nsAString& aResult)
 {
   mSVGElement->FlushAnimations();
   mVal->GetAnimValue(aResult, mSVGElement);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGClass::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILString(this, aSVGElement);
+  return MakeUnique<SMILString>(this, aSVGElement);
 }
 
 nsresult
 nsSVGClass::SMILString::ValueFromString(const nsAString& aStr,
                                         const dom::SVGAnimationElement* /*aSrcElement*/,
                                         nsSMILValue& aValue,
                                         bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGClass.h
+++ b/dom/svg/nsSVGClass.h
@@ -8,16 +8,17 @@
 #define __NS_SVGCLASS_H__
 
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "nsISMILAttr.h"
 #include "nsString.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 
 class nsSVGElement;
 
 namespace mozilla {
 namespace dom {
 class SVGAnimatedString;
 } // namespace dom
 } // namespace mozilla
@@ -38,18 +39,17 @@ public:
   void SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement);
   void GetAnimValue(nsAString& aValue, const nsSVGElement *aSVGElement) const;
   bool IsAnimated() const
     { return !!mAnimVal; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedString>
   ToDOMAnimatedString(nsSVGElement* aSVGElement);
 
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement *aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement *aSVGElement);
 
 private:
 
   nsAutoPtr<nsString> mAnimVal;
 
 public:
   struct SMILString : public nsISMILAttr
   {
--- a/dom/svg/nsSVGElement.cpp
+++ b/dom/svg/nsSVGElement.cpp
@@ -2512,30 +2512,30 @@ nsSVGElement::RecompileScriptEventListen
     }
 
     nsAutoString value;
     GetAttr(kNameSpaceID_None, attr, value);
     SetEventHandler(GetEventNameForAttr(attr), value, true);
   }
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGElement::GetAnimatedAttr(int32_t aNamespaceID, nsIAtom* aName)
 {
   if (aNamespaceID == kNameSpaceID_None) {
     // Transforms:
     if (GetTransformListAttrName() == aName) {
       // The transform attribute is being animated, so we must ensure that the
       // SVGAnimatedTransformList is/has been allocated:
       return GetAnimatedTransformList(DO_ALLOCATE)->ToSMILAttr(this);
     }
 
     // Motion (fake 'attribute' for animateMotion)
     if (aName == nsGkAtoms::mozAnimateMotionDummyAttr) {
-      return new SVGMotionSMILAttr(this);
+      return MakeUnique<SVGMotionSMILAttr>(this);
     }
 
     // Lengths:
     LengthAttributesInfo info = GetLengthInfo();
     for (uint32_t i = 0; i < info.mLengthCount; i++) {
       if (aName == *info.mLengthInfo[i].mName) {
         return info.mLengths[i].ToSMILAttr(this);
       }
--- a/dom/svg/nsSVGElement.h
+++ b/dom/svg/nsSVGElement.h
@@ -287,17 +287,18 @@ public:
    * require the nsSVGAnimatedTransformList to be allocated and for this method
    * to return non-null must pass the DO_ALLOCATE flag.
    */
   virtual nsSVGAnimatedTransformList* GetAnimatedTransformList(
                                                         uint32_t aFlags = 0) {
     return nullptr;
   }
 
-  virtual nsISMILAttr* GetAnimatedAttr(int32_t aNamespaceID, nsIAtom* aName) override;
+  mozilla::UniquePtr<nsISMILAttr> GetAnimatedAttr(int32_t aNamespaceID,
+                                                  nsIAtom* aName) override;
   void AnimationNeedsResample();
   void FlushAnimations();
 
   virtual void RecompileScriptEventListeners() override;
 
   void GetStringBaseValue(uint8_t aAttrEnum, nsAString& aResult) const;
   void SetStringBaseValue(uint8_t aAttrEnum, const nsAString& aValue);
 
--- a/dom/svg/nsSVGEnum.cpp
+++ b/dom/svg/nsSVGEnum.cpp
@@ -124,20 +124,20 @@ nsSVGEnum::ToDOMAnimatedEnum(nsSVGElemen
   return domAnimatedEnum.forget();
 }
 
 nsSVGEnum::DOMAnimatedEnum::~DOMAnimatedEnum()
 {
   sSVGAnimatedEnumTearoffTable.RemoveTearoff(mVal);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGEnum::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILEnum(this, aSVGElement);
+  return MakeUnique<SMILEnum>(this, aSVGElement);
 }
 
 nsresult
 nsSVGEnum::SMILEnum::ValueFromString(const nsAString& aStr,
                                      const dom::SVGAnimationElement* /*aSrcElement*/,
                                      nsSMILValue& aValue,
                                      bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGEnum.h
+++ b/dom/svg/nsSVGEnum.h
@@ -8,16 +8,17 @@
 #define __NS_SVGENUM_H__
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "nsISMILAttr.h"
 #include "nsSVGElement.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimatedEnumeration.h"
+#include "mozilla/UniquePtr.h"
 
 class nsIAtom;
 class nsSMILValue;
 
 namespace mozilla {
 namespace dom {
 class SVGAnimationElement;
 } // namespace dom
@@ -51,18 +52,17 @@ public:
   uint16_t GetAnimValue() const
     { return mAnimVal; }
   bool IsExplicitlySet() const
     { return mIsAnimated || mIsBaseSet; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedEnumeration>
   ToDOMAnimatedEnum(nsSVGElement* aSVGElement);
 
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
   nsSVGEnumValue mAnimVal;
   nsSVGEnumValue mBaseVal;
   uint8_t mAttrEnum; // element specified tracking for attribute
   bool mIsAnimated;
   bool mIsBaseSet;
 
--- a/dom/svg/nsSVGInteger.cpp
+++ b/dom/svg/nsSVGInteger.cpp
@@ -93,20 +93,20 @@ nsSVGInteger::ToDOMAnimatedInteger(nsSVG
   return domAnimatedInteger.forget();
 }
 
 nsSVGInteger::DOMAnimatedInteger::~DOMAnimatedInteger()
 {
   sSVGAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGInteger::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILInteger(this, aSVGElement);
+  return MakeUnique<SMILInteger>(this, aSVGElement);
 }
 
 nsresult
 nsSVGInteger::SMILInteger::ValueFromString(const nsAString& aStr,
                                            const dom::SVGAnimationElement* /*aSrcElement*/,
                                            nsSMILValue& aValue,
                                            bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGInteger.h
+++ b/dom/svg/nsSVGInteger.h
@@ -8,16 +8,17 @@
 #define __NS_SVGINTEGER_H__
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "SVGAnimatedInteger.h"
 #include "nsISMILAttr.h"
 #include "nsSVGElement.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 
 class nsSMILValue;
 
 namespace mozilla {
 namespace dom {
 class SVGAnimationElement;
 } // namespace dom
 } // namespace mozilla
@@ -50,19 +51,18 @@ public:
   // explicitly set by markup or a DOM call), false otherwise.
   // If this returns false, the animated value is still valid, that is,
   // useable, and represents the default base value of the attribute.
   bool IsExplicitlySet() const
     { return mIsAnimated || mIsBaseSet; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedInteger>
     ToDOMAnimatedInteger(nsSVGElement* aSVGElement);
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
-  
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
+
 private:
 
   int32_t mAnimVal;
   int32_t mBaseVal;
   uint8_t mAttrEnum; // element specified tracking for attribute
   bool mIsAnimated;
   bool mIsBaseSet;
 
--- a/dom/svg/nsSVGIntegerPair.cpp
+++ b/dom/svg/nsSVGIntegerPair.cpp
@@ -172,20 +172,20 @@ nsSVGIntegerPair::DOMAnimatedInteger::~D
 {
   if (mIndex == eFirst) {
     sSVGFirstAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
   } else {
     sSVGSecondAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
   }
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGIntegerPair::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILIntegerPair(this, aSVGElement);
+  return MakeUnique<SMILIntegerPair>(this, aSVGElement);
 }
 
 nsresult
 nsSVGIntegerPair::SMILIntegerPair::ValueFromString(const nsAString& aStr,
                                                    const dom::SVGAnimationElement* /*aSrcElement*/,
                                                    nsSMILValue& aValue,
                                                    bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGIntegerPair.h
+++ b/dom/svg/nsSVGIntegerPair.h
@@ -8,16 +8,17 @@
 #define __NS_SVGINTEGERPAIR_H__
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "nsISMILAttr.h"
 #include "nsSVGElement.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimatedInteger.h"
+#include "mozilla/UniquePtr.h"
 
 class nsSMILValue;
 
 namespace mozilla {
 namespace dom {
 class SVGAnimationElement;
 } // namespace dom
 } // namespace mozilla
@@ -57,18 +58,17 @@ public:
   // If this returns false, the animated value is still valid, that is,
   // useable, and represents the default base value of the attribute.
   bool IsExplicitlySet() const
     { return mIsAnimated || mIsBaseSet; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedInteger>
     ToDOMAnimatedInteger(PairIndex aIndex,
                          nsSVGElement* aSVGElement);
-   // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
 
   int32_t mAnimVal[2];
   int32_t mBaseVal[2];
   uint8_t mAttrEnum; // element specified tracking for attribute
   bool mIsAnimated;
   bool mIsBaseSet;
--- a/dom/svg/nsSVGLength2.cpp
+++ b/dom/svg/nsSVGLength2.cpp
@@ -464,20 +464,20 @@ nsSVGLength2::ToDOMAnimatedLength(nsSVGE
   return svgAnimatedLength.forget();
 }
 
 SVGAnimatedLength::~SVGAnimatedLength()
 {
   sSVGAnimatedLengthTearoffTable.RemoveTearoff(mVal);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGLength2::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILLength(this, aSVGElement);
+  return MakeUnique<SMILLength>(this, aSVGElement);
 }
 
 nsresult
 nsSVGLength2::SMILLength::ValueFromString(const nsAString& aStr,
                                  const SVGAnimationElement* /*aSrcElement*/,
                                  nsSMILValue& aValue,
                                  bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGLength2.h
+++ b/dom/svg/nsSVGLength2.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __NS_SVGLENGTH2_H__
 #define __NS_SVGLENGTH2_H__
 
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "nsCoord.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "nsIDOMSVGLength.h"
 #include "nsISMILAttr.h"
 #include "nsMathUtils.h"
 #include "nsSVGElement.h"
 #include "SVGContentUtils.h"
@@ -147,21 +148,19 @@ public:
   // If this returns false, the animated value is still valid, that is,
   // useable, and represents the default base value of the attribute.
   bool IsExplicitlySet() const
     { return mIsAnimated || mIsBaseSet; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedLength>
   ToDOMAnimatedLength(nsSVGElement* aSVGElement);
 
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
-  
   float mAnimVal;
   float mBaseVal;
   uint8_t mSpecifiedUnitType;
   uint8_t mAttrEnum; // element specified tracking for attribute
   uint8_t mCtxType; // X, Y or Unspecified
   bool mIsAnimated:1;
   bool mIsBaseSet:1;
 
--- a/dom/svg/nsSVGNumber2.cpp
+++ b/dom/svg/nsSVGNumber2.cpp
@@ -121,20 +121,20 @@ nsSVGNumber2::ToDOMAnimatedNumber(nsSVGE
   return domAnimatedNumber.forget();
 }
 
 nsSVGNumber2::DOMAnimatedNumber::~DOMAnimatedNumber()
 {
   sSVGAnimatedNumberTearoffTable.RemoveTearoff(mVal);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGNumber2::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILNumber(this, aSVGElement);
+  return MakeUnique<SMILNumber>(this, aSVGElement);
 }
 
 nsresult
 nsSVGNumber2::SMILNumber::ValueFromString(const nsAString& aStr,
                                           const mozilla::dom::SVGAnimationElement* /*aSrcElement*/,
                                           nsSMILValue& aValue,
                                           bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGNumber2.h
+++ b/dom/svg/nsSVGNumber2.h
@@ -10,16 +10,17 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "nsISMILAttr.h"
 #include "nsMathUtils.h"
 #include "nsSVGElement.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/dom/SVGAnimatedNumber.h"
+#include "mozilla/UniquePtr.h"
 
 class nsSMILValue;
 
 namespace mozilla {
 namespace dom {
 class SVGAnimationElement;
 } // namespace dom
 } // namespace mozilla
@@ -51,21 +52,19 @@ public:
   // explicitly set by markup or a DOM call), false otherwise.
   // If this returns false, the animated value is still valid, that is,
   // useable, and represents the default base value of the attribute.
   bool IsExplicitlySet() const
     { return mIsAnimated || mIsBaseSet; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedNumber>
   ToDOMAnimatedNumber(nsSVGElement* aSVGElement);
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
-
   float mAnimVal;
   float mBaseVal;
   uint8_t mAttrEnum; // element specified tracking for attribute
   bool mIsAnimated;
   bool mIsBaseSet;
 
 public:
   struct DOMAnimatedNumber final : public mozilla::dom::SVGAnimatedNumber
--- a/dom/svg/nsSVGNumberPair.cpp
+++ b/dom/svg/nsSVGNumberPair.cpp
@@ -165,20 +165,20 @@ nsSVGNumberPair::DOMAnimatedNumber::~DOM
 {
   if (mIndex == eFirst) {
     sSVGFirstAnimatedNumberTearoffTable.RemoveTearoff(mVal);
   } else {
     sSVGSecondAnimatedNumberTearoffTable.RemoveTearoff(mVal);
   }
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGNumberPair::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILNumberPair(this, aSVGElement);
+  return MakeUnique<SMILNumberPair>(this, aSVGElement);
 }
 
 nsresult
 nsSVGNumberPair::SMILNumberPair::ValueFromString(const nsAString& aStr,
                                                  const dom::SVGAnimationElement* /*aSrcElement*/,
                                                  nsSMILValue& aValue,
                                                  bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGNumberPair.h
+++ b/dom/svg/nsSVGNumberPair.h
@@ -10,16 +10,17 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "nsISMILAttr.h"
 #include "nsMathUtils.h"
 #include "nsSVGElement.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimatedNumber.h"
 #include "mozilla/FloatingPoint.h"
+#include "mozilla/UniquePtr.h"
 
 
 class nsSMILValue;
 
 namespace mozilla {
 namespace dom {
 class SVGAnimationElement;
 } // namespace dom
@@ -60,21 +61,19 @@ public:
   // If this returns false, the animated value is still valid, that is,
   // useable, and represents the default base value of the attribute.
   bool IsExplicitlySet() const
     { return mIsAnimated || mIsBaseSet; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedNumber>
     ToDOMAnimatedNumber(PairIndex aIndex,
                         nsSVGElement* aSVGElement);
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
-
   float mAnimVal[2];
   float mBaseVal[2];
   uint8_t mAttrEnum; // element specified tracking for attribute
   bool mIsAnimated;
   bool mIsBaseSet;
 
 public:
   struct DOMAnimatedNumber final : public mozilla::dom::SVGAnimatedNumber
--- a/dom/svg/nsSVGString.cpp
+++ b/dom/svg/nsSVGString.cpp
@@ -92,20 +92,20 @@ nsSVGString::ToDOMAnimatedString(nsSVGEl
   return domAnimatedString.forget();
 }
 
 nsSVGString::DOMAnimatedString::~DOMAnimatedString()
 {
   SVGAnimatedStringTearoffTable().RemoveTearoff(mVal);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGString::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILString(this, aSVGElement);
+  return MakeUnique<SMILString>(this, aSVGElement);
 }
 
 nsresult
 nsSVGString::SMILString::ValueFromString(const nsAString& aStr,
                                          const dom::SVGAnimationElement* /*aSrcElement*/,
                                          nsSMILValue& aValue,
                                          bool& aPreventCachingOfSandwich) const
 {
--- a/dom/svg/nsSVGString.h
+++ b/dom/svg/nsSVGString.h
@@ -7,16 +7,17 @@
 #ifndef __NS_SVGSTRING_H__
 #define __NS_SVGSTRING_H__
 
 #include "nsAutoPtr.h"
 #include "nsError.h"
 #include "nsSVGElement.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/SVGAnimatedString.h"
+#include "mozilla/UniquePtr.h"
 
 class nsSVGString
 {
 
 public:
   void Init(uint8_t aAttrEnum) {
     mAnimVal = nullptr;
     mAttrEnum = aAttrEnum;
@@ -38,21 +39,19 @@ public:
   // If this returns false, the animated value is still valid, that is,
   // useable, and represents the default base value of the attribute.
   bool IsExplicitlySet() const
     { return !!mAnimVal || mIsBaseSet; }
 
   already_AddRefed<mozilla::dom::SVGAnimatedString>
   ToDOMAnimatedString(nsSVGElement* aSVGElement);
 
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement *aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement *aSVGElement);
 
 private:
-
   nsAutoPtr<nsString> mAnimVal;
   uint8_t mAttrEnum; // element specified tracking for attribute
   bool mIsBaseSet;
 
 public:
   struct DOMAnimatedString final : public mozilla::dom::SVGAnimatedString
   {
     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
--- a/dom/svg/nsSVGViewBox.cpp
+++ b/dom/svg/nsSVGViewBox.cpp
@@ -299,20 +299,20 @@ nsSVGViewBox::DOMBaseVal::SetWidth(float
 void
 nsSVGViewBox::DOMBaseVal::SetHeight(float aHeight, ErrorResult& aRv)
 {
   nsSVGViewBoxRect rect = mVal->GetBaseValue();
   rect.height = aHeight;
   mVal->SetBaseValue(rect, mSVGElement);
 }
 
-nsISMILAttr*
+UniquePtr<nsISMILAttr>
 nsSVGViewBox::ToSMILAttr(nsSVGElement *aSVGElement)
 {
-  return new SMILViewBox(this, aSVGElement);
+  return MakeUnique<SMILViewBox>(this, aSVGElement);
 }
 
 nsresult
 nsSVGViewBox::SMILViewBox
             ::ValueFromString(const nsAString& aStr,
                               const dom::SVGAnimationElement* /*aSrcElement*/,
                               nsSMILValue& aValue,
                               bool& aPreventCachingOfSandwich) const
--- a/dom/svg/nsSVGViewBox.h
+++ b/dom/svg/nsSVGViewBox.h
@@ -10,16 +10,17 @@
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsError.h"
 #include "mozilla/dom/SVGAnimatedRect.h"
 #include "mozilla/dom/SVGIRect.h"
 #include "nsISMILAttr.h"
 #include "nsSVGElement.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "nsSVGAttrTearoffTable.h"
 
 class nsSMILValue;
 
 namespace mozilla {
 namespace dom {
 class SVGAnimationElement;
 } // namespace dom
@@ -85,21 +86,19 @@ public:
   ToSVGAnimatedRect(nsSVGElement *aSVGElement);
 
   already_AddRefed<mozilla::dom::SVGIRect>
   ToDOMBaseVal(nsSVGElement* aSVGElement);
 
   already_AddRefed<mozilla::dom::SVGIRect>
   ToDOMAnimVal(nsSVGElement* aSVGElement);
 
-  // Returns a new nsISMILAttr object that the caller must delete
-  nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
+  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
 
 private:
-
   nsSVGViewBoxRect mBaseVal;
   nsAutoPtr<nsSVGViewBoxRect> mAnimVal;
   bool mHasBaseVal;
 
 public:
   struct DOMBaseVal final : public mozilla::dom::SVGIRect
   {
     NS_DECL_CYCLE_COLLECTING_ISUPPORTS