Bug 1265452 - Remove use of nsAutoPtr from gfx/thebes. r=jrmuizel
authorJonathan Kew <jkew@mozilla.com>
Fri, 15 Apr 2016 20:45:37 +0100
changeset 317690 9d396d690080bef8191a1e8525cca2593051b338
parent 317689 d5ed5fe137737f370d89aff9afb3d8eb2c749b48
child 317691 1d5416c99477d004ade3de1bc4a7171b613acd0f
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1265452
milestone48.0a1
Bug 1265452 - Remove use of nsAutoPtr from gfx/thebes. r=jrmuizel
gfx/thebes/gfxBlur.h
gfx/thebes/gfxContext.h
gfx/thebes/gfxDWriteCommon.h
gfx/thebes/gfxDWriteFonts.cpp
gfx/thebes/gfxDWriteFonts.h
gfx/thebes/gfxDrawable.h
gfx/thebes/gfxFT2FontList.cpp
gfx/thebes/gfxFcPlatformFontList.h
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
gfx/thebes/gfxFontEntry.cpp
gfx/thebes/gfxFontEntry.h
gfx/thebes/gfxFontInfoLoader.h
gfx/thebes/gfxFontUtils.cpp
gfx/thebes/gfxFontUtils.h
gfx/thebes/gfxGDIFont.cpp
gfx/thebes/gfxGDIFont.h
gfx/thebes/gfxGDIFontList.cpp
gfx/thebes/gfxImageSurface.h
gfx/thebes/gfxMacFont.cpp
gfx/thebes/gfxMacFont.h
gfx/thebes/gfxMacPlatformFontList.mm
gfx/thebes/gfxPattern.h
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformFontList.cpp
gfx/thebes/gfxPlatformFontList.h
gfx/thebes/gfxReusableSurfaceWrapper.h
gfx/thebes/gfxSVGGlyphs.h
gfx/thebes/gfxTeeSurface.cpp
gfx/thebes/gfxTextRun.cpp
gfx/thebes/gfxTextRun.h
gfx/thebes/gfxUserFontSet.cpp
gfx/thebes/gfxUserFontSet.h
gfx/thebes/gfxXlibSurface.cpp
layout/inspector/nsFontFace.cpp
--- a/gfx/thebes/gfxBlur.h
+++ b/gfx/thebes/gfxBlur.h
@@ -3,17 +3,16 @@
  * 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 GFX_BLUR_H
 #define GFX_BLUR_H
 
 #include "gfxTypes.h"
 #include "nsSize.h"
-#include "nsAutoPtr.h"
 #include "gfxPoint.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtr.h"
 
 class gfxContext;
 struct gfxRect;
 
 namespace mozilla {
--- a/gfx/thebes/gfxContext.h
+++ b/gfx/thebes/gfxContext.h
@@ -9,17 +9,16 @@
 #include "gfxTypes.h"
 
 #include "gfxASurface.h"
 #include "gfxPoint.h"
 #include "gfxRect.h"
 #include "gfxMatrix.h"
 #include "gfxPattern.h"
 #include "nsTArray.h"
-#include "nsAutoPtr.h"
 
 #include "mozilla/gfx/2D.h"
 
 typedef struct _cairo cairo_t;
 class GlyphBufferAzure;
 template <typename T> class FallibleTArray;
 
 namespace mozilla {
--- a/gfx/thebes/gfxDWriteCommon.h
+++ b/gfx/thebes/gfxDWriteCommon.h
@@ -5,17 +5,16 @@
 
 #ifndef GFX_DWRITECOMMON_H
 #define GFX_DWRITECOMMON_H
 
 // Mozilla includes
 #include "nscore.h"
 #include "nsIServiceManager.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "cairo-features.h"
 #include "gfxFontConstants.h"
 #include "nsTArray.h"
 #include "gfxWindowsPlatform.h"
 #include "nsIUUIDGenerator.h"
 
 #include <windows.h>
 #include <dwrite.h>
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -592,17 +592,17 @@ gfxDWriteFont::ProvidesGlyphWidths() con
     return !mUseSubpixelPositions ||
            (mFontFace->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD);
 }
 
 int32_t
 gfxDWriteFont::GetGlyphWidth(DrawTarget& aDrawTarget, uint16_t aGID)
 {
     if (!mGlyphWidths) {
-        mGlyphWidths = new nsDataHashtable<nsUint32HashKey,int32_t>(128);
+        mGlyphWidths = MakeUnique<nsDataHashtable<nsUint32HashKey,int32_t>>(128);
     }
 
     int32_t width = -1;
     if (mGlyphWidths->Get(aGID, &width)) {
         return width;
     }
 
     width = NS_lround(MeasureGlyphWidth(aGID) * 65536.0);
--- a/gfx/thebes/gfxDWriteFonts.h
+++ b/gfx/thebes/gfxDWriteFonts.h
@@ -2,16 +2,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 GFX_WINDOWSDWRITEFONTS_H
 #define GFX_WINDOWSDWRITEFONTS_H
 
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/UniquePtr.h"
 #include <dwrite.h>
 
 #include "gfxFont.h"
 #include "gfxUserFontSet.h"
 #include "cairo-win32.h"
 
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
@@ -93,17 +94,17 @@ protected:
     RefPtr<IDWriteFontFace> mFontFace;
     RefPtr<IDWriteFont> mFont;
     RefPtr<IDWriteFontFamily> mFontFamily;
     cairo_font_face_t *mCairoFontFace;
 
     Metrics *mMetrics;
 
     // cache of glyph widths in 16.16 fixed-point pixels
-    nsAutoPtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths;
+    mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,int32_t>> mGlyphWidths;
 
     uint32_t mSpaceGlyph;
 
     bool mNeedsOblique;
     bool mNeedsBold;
     bool mUseSubpixelPositions;
     bool mAllowManualShowGlyphs;
     bool mAzureScaledFontIsCairo;
--- a/gfx/thebes/gfxDrawable.h
+++ b/gfx/thebes/gfxDrawable.h
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * 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 GFX_DRAWABLE_H
 #define GFX_DRAWABLE_H
 
-#include "nsAutoPtr.h"
 #include "gfxRect.h"
 #include "gfxMatrix.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Types.h"
 
 class gfxContext;
 class gfxPattern;
 
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -1400,17 +1400,17 @@ PreloadAsUserFontFaces(nsStringHashKey::
 
 #if 0
         ALOG("\n**** Preloading family [%s] face [%s] CRC32 [0x%08x]",
              NS_ConvertUTF16toUTF8(family->Name()).get(),
              fe->mFilename.get(),
              crc);
 #endif
 
-        fe->mUserFontData = new gfxUserFontData;
+        fe->mUserFontData = MakeUnique<gfxUserFontData>();
         fe->mUserFontData->mRealName = fe->Name();
         fe->mUserFontData->mCRC32 = crc;
         fe->mUserFontData->mLength = buf.st_size;
 
         // Stash it persistently in the user-font cache.
         gfxUserFontSet::UserFontCache::CacheFont(
             fe, gfxUserFontSet::UserFontCache::kPersistent);
     }
--- a/gfx/thebes/gfxFcPlatformFontList.h
+++ b/gfx/thebes/gfxFcPlatformFontList.h
@@ -6,16 +6,17 @@
 #ifndef GFXFCPLATFORMFONTLIST_H_
 #define GFXFCPLATFORMFONTLIST_H_
 
 #include "gfxFont.h"
 #include "gfxFontEntry.h"
 #include "gfxFT2FontBase.h"
 #include "gfxPlatformFontList.h"
 #include "mozilla/mozalloc.h"
+#include "nsClassHashtable.h"
 
 #include <fontconfig/fontconfig.h>
 #include "ft2build.h"
 #include FT_FREETYPE_H
 #include FT_TRUETYPE_TABLES_H
 #include <cairo.h>
 #include <cairo-ft.h>
 
@@ -272,19 +273,18 @@ protected:
 
     // to avoid enumerating all fonts, maintain a mapping of local font
     // names to family
     nsBaseHashtable<nsStringHashKey,
                     nsCountedRef<FcPattern>,
                     FcPattern*> mLocalNames;
 
     // caching generic/lang ==> font family list
-    nsBaseHashtable<nsCStringHashKey,
-                    nsAutoPtr<PrefFontList>,
-                    PrefFontList*> mGenericMappings;
+    nsClassHashtable<nsCStringHashKey,
+                     PrefFontList> mGenericMappings;
 
     // Caching family lookups as found by FindAndAddFamilies after resolving
     // substitutions. The gfxFontFamily objects cached here are owned by the
     // gfxFcPlatformFontList via its mFamilies table; note that if the main
     // font list is rebuilt (e.g. due to a fontconfig configuration change),
     // these pointers will be invalidated. InitFontList() flushes the cache
     // in this case.
     nsDataHashtable<nsCStringHashKey,
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -695,17 +695,17 @@ gfxShapedText::SetupClusterBoundaries(ui
 }
 
 gfxShapedText::DetailedGlyph *
 gfxShapedText::AllocateDetailedGlyphs(uint32_t aIndex, uint32_t aCount)
 {
     NS_ASSERTION(aIndex < GetLength(), "Index out of range");
 
     if (!mDetailedGlyphs) {
-        mDetailedGlyphs = new DetailedGlyphStore();
+        mDetailedGlyphs = MakeUnique<DetailedGlyphStore>();
     }
 
     return mDetailedGlyphs->Allocate(aIndex, aCount);
 }
 
 void
 gfxShapedText::SetGlyphs(uint32_t aIndex, CompressedGlyph aGlyph,
                          const DetailedGlyph *aGlyphs)
@@ -853,17 +853,17 @@ gfxFont::gfxFont(gfxFontEntry *aFontEntr
 #endif
     mKerningSet = HasFeatureSet(HB_TAG('k','e','r','n'), mKerningEnabled);
 }
 
 gfxFont::~gfxFont()
 {
     uint32_t i, count = mGlyphExtentsArray.Length();
     // We destroy the contents of mGlyphExtentsArray explicitly instead of
-    // using nsAutoPtr because VC++ can't deal with nsTArrays of nsAutoPtrs
+    // using UniquePtr because VC++ can't deal with nsTArrays of UniquePtrs
     // of classes that lack a proper copy constructor
     for (i = 0; i < count; ++i) {
         delete mGlyphExtentsArray[i];
     }
 
     mFontEntry->NotifyFontDestroyed(this);
 
     if (mGlyphChangeObservers) {
@@ -883,17 +883,17 @@ gfxFont::GetGlyphHAdvance(DrawTarget* aD
         return GetGlyphWidth(*aDrawTarget, aGID) / 65536.0;
     }
     if (mFUnitsConvFactor < 0.0f) {
         GetMetrics(eHorizontal);
     }
     NS_ASSERTION(mFUnitsConvFactor >= 0.0f,
                  "missing font unit conversion factor");
     if (!mHarfBuzzShaper) {
-        mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
+        mHarfBuzzShaper = MakeUnique<gfxHarfBuzzShaper>(this);
     }
     gfxHarfBuzzShaper* shaper =
         static_cast<gfxHarfBuzzShaper*>(mHarfBuzzShaper.get());
     if (!shaper->Initialize()) {
         return 0;
     }
     return shaper->GetGlyphHAdvance(aGID) / 65536.0;
 }
@@ -1457,17 +1457,17 @@ gfxFont::SupportsSubSuperscript(uint32_t
     }
 
     // xxx - for graphite, don't really know how to sniff lookups so bail
     if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
         return true;
     }
 
     if (!mHarfBuzzShaper) {
-        mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
+        mHarfBuzzShaper = MakeUnique<gfxHarfBuzzShaper>(this);
     }
     gfxHarfBuzzShaper* shaper =
         static_cast<gfxHarfBuzzShaper*>(mHarfBuzzShaper.get());
     if (!shaper->Initialize()) {
         return false;
     }
 
     // get the hbset containing input glyphs for the feature
@@ -2045,26 +2045,26 @@ gfxFont::Draw(gfxTextRun *aTextRun, uint
         if (aTextRun->UseCenterBaseline()) {
             gfxPoint baseAdj(0, (metrics.emAscent - metrics.emDescent) / 2);
             mat.Translate(baseAdj);
         }
 
         aRunParams.context->SetMatrix(mat);
     }
 
-    nsAutoPtr<gfxTextContextPaint> contextPaint;
+    UniquePtr<gfxTextContextPaint> contextPaint;
     if (fontParams.haveSVGGlyphs && !fontParams.contextPaint) {
         // If no pattern is specified for fill, use the current pattern
         NS_ASSERTION((int(aRunParams.drawMode) & int(DrawMode::GLYPH_STROKE)) == 0,
                      "no pattern supplied for stroking text");
         RefPtr<gfxPattern> fillPattern = aRunParams.context->GetPattern();
-        contextPaint =
+        contextPaint.reset(
             new SimpleTextContextPaint(fillPattern, nullptr,
-                                       aRunParams.context->CurrentMatrix());
-        fontParams.contextPaint = contextPaint;
+                                       aRunParams.context->CurrentMatrix()));
+        fontParams.contextPaint = contextPaint.get();
     }
 
     // Synthetic-bold strikes are each offset one device pixel in run direction.
     // (these values are only needed if IsSyntheticBold() is true)
     if (IsSyntheticBold()) {
         double xscale = CalcXScale(aRunParams.context->GetDrawTarget());
         fontParams.synBoldOnePixelOffset = aRunParams.direction * xscale;
         if (xscale != 0.0) {
@@ -2269,17 +2269,17 @@ gfxFont::Measure(gfxTextRun *aTextRun,
 {
     // If aBoundingBoxType is TIGHT_HINTED_OUTLINE_EXTENTS
     // and the underlying cairo font may be antialiased,
     // we need to create a copy in order to avoid getting cached extents.
     // This is only used by MathML layout at present.
     if (aBoundingBoxType == TIGHT_HINTED_OUTLINE_EXTENTS &&
         mAntialiasOption != kAntialiasNone) {
         if (!mNonAAFont) {
-            mNonAAFont = CopyWithAntialiasOption(kAntialiasNone);
+            mNonAAFont.reset(CopyWithAntialiasOption(kAntialiasNone));
         }
         // if font subclass doesn't implement CopyWithAntialiasOption(),
         // it will return null and we'll proceed to use the existing font
         if (mNonAAFont) {
             return mNonAAFont->Measure(aTextRun, aStart, aEnd,
                                        TIGHT_HINTED_OUTLINE_EXTENTS,
                                        aRefDrawTarget, aSpacing, aOrientation);
         }
@@ -2535,17 +2535,17 @@ gfxFont::GetShapedWord(DrawTarget *aDraw
                      aAppUnitsPerDevUnit,
                      aFlags);
 
     CacheHashEntry *entry = mWordCache->PutEntry(key);
     if (!entry) {
         NS_WARNING("failed to create word cache entry - expect missing text");
         return nullptr;
     }
-    gfxShapedWord *sw = entry->mShapedWord;
+    gfxShapedWord* sw = entry->mShapedWord.get();
 
     bool isContent = !mStyle.systemFont;
 
     if (sw) {
         sw->ResetAge();
         Telemetry::Accumulate((isContent ? Telemetry::WORD_CACHE_HITS_CONTENT :
                                    Telemetry::WORD_CACHE_HITS_CHROME),
                               aLength);
@@ -2561,37 +2561,36 @@ gfxFont::GetShapedWord(DrawTarget *aDraw
                                Telemetry::WORD_CACHE_MISSES_CHROME),
                           aLength);
 #ifndef RELEASE_BUILD
     if (aTextPerf) {
         aTextPerf->current.wordCacheMiss++;
     }
 #endif
 
-    sw = entry->mShapedWord = gfxShapedWord::Create(aText, aLength,
-                                                    aRunScript,
-                                                    aAppUnitsPerDevUnit,
-                                                    aFlags);
+    sw = gfxShapedWord::Create(aText, aLength, aRunScript, aAppUnitsPerDevUnit,
+                               aFlags);
+    entry->mShapedWord.reset(sw);
     if (!sw) {
         NS_WARNING("failed to create gfxShapedWord - expect missing text");
         return nullptr;
     }
 
     DebugOnly<bool> ok =
         ShapeText(aDrawTarget, aText, 0, aLength, aRunScript, aVertical, sw);
 
     NS_WARN_IF_FALSE(ok, "failed to shape word - expect garbled text");
 
     return sw;
 }
 
 bool
 gfxFont::CacheHashEntry::KeyEquals(const KeyTypePointer aKey) const
 {
-    const gfxShapedWord *sw = mShapedWord;
+    const gfxShapedWord* sw = mShapedWord.get();
     if (!sw) {
         return false;
     }
     if (sw->GetLength() != aKey->mLength ||
         sw->GetFlags() != aKey->mFlags ||
         sw->GetAppUnitsPerDevUnit() != aKey->mAppUnitsPerDevUnit ||
         sw->Script() != aKey->mScript) {
         return false;
@@ -2650,26 +2649,26 @@ gfxFont::ShapeText(DrawTarget      *aDra
 {
     bool ok = false;
 
     // XXX Currently, we do all vertical shaping through harfbuzz.
     // Vertical graphite support may be wanted as a future enhancement.
     if (FontCanSupportGraphite() && !aVertical) {
         if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
             if (!mGraphiteShaper) {
-                mGraphiteShaper = new gfxGraphiteShaper(this);
+                mGraphiteShaper = MakeUnique<gfxGraphiteShaper>(this);
             }
             ok = mGraphiteShaper->ShapeText(aDrawTarget, aText, aOffset, aLength,
                                             aScript, aVertical, aShapedText);
         }
     }
 
     if (!ok) {
         if (!mHarfBuzzShaper) {
-            mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
+            mHarfBuzzShaper = MakeUnique<gfxHarfBuzzShaper>(this);
         }
         ok = mHarfBuzzShaper->ShapeText(aDrawTarget, aText, aOffset, aLength,
                                         aScript, aVertical, aShapedText);
     }
 
     NS_WARN_IF_FALSE(ok, "shaper failed, expect scrambled or missing text");
 
     PostShapingFixup(aDrawTarget, aText, aOffset, aLength,
@@ -3175,36 +3174,34 @@ gfxFont::InitFakeSmallCapsRun(DrawTarget
                     // This is the hard case: the transformation caused chars
                     // to be inserted or deleted, so we can't shape directly
                     // into the destination textrun but have to handle the
                     // mismatch of character positions.
                     gfxTextRunFactory::Parameters params = {
                         aDrawTarget, nullptr, nullptr, nullptr, 0,
                         aTextRun->GetAppUnitsPerDevUnit()
                     };
-                    nsAutoPtr<gfxTextRun> tempRun;
-                    tempRun =
+                    UniquePtr<gfxTextRun> tempRun(
                         gfxTextRun::Create(&params, convertedString.Length(),
-                                           aTextRun->GetFontGroup(), 0);
+                                           aTextRun->GetFontGroup(), 0));
                     tempRun->AddGlyphRun(f, aMatchType, 0, true, aOrientation);
-                    if (!f->SplitAndInitTextRun(aDrawTarget, tempRun,
+                    if (!f->SplitAndInitTextRun(aDrawTarget, tempRun.get(),
                                                 convertedString.BeginReading(),
                                                 0, convertedString.Length(),
                                                 aScript, vertical)) {
                         ok = false;
                     } else {
-                        nsAutoPtr<gfxTextRun> mergedRun;
-                        mergedRun =
+                        UniquePtr<gfxTextRun> mergedRun(
                             gfxTextRun::Create(&params, runLength,
-                                               aTextRun->GetFontGroup(), 0);
-                        MergeCharactersInTextRun(mergedRun, tempRun,
+                                               aTextRun->GetFontGroup(), 0));
+                        MergeCharactersInTextRun(mergedRun.get(), tempRun.get(),
                                                  charsToMergeArray.Elements(),
                                                  deletedCharsArray.Elements());
                         gfxTextRun::Range runRange(0, runLength);
-                        aTextRun->CopyGlyphDataFrom(mergedRun, runRange,
+                        aTextRun->CopyGlyphDataFrom(mergedRun.get(), runRange,
                                                     aOffset + runStart);
                     }
                 } else {
                     aTextRun->AddGlyphRun(f, aMatchType, aOffset + runStart,
                                           true, aOrientation);
                     if (!f->SplitAndInitTextRun(aDrawTarget, aTextRun,
                                                 convertedString.BeginReading(),
                                                 aOffset + runStart, runLength,
@@ -3796,17 +3793,18 @@ gfxFont::AddSizeOfIncludingThis(MallocSi
     aSizes->mFontInstances += aMallocSizeOf(this);
     AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
 }
 
 void
 gfxFont::AddGlyphChangeObserver(GlyphChangeObserver *aObserver)
 {
     if (!mGlyphChangeObservers) {
-        mGlyphChangeObservers = new nsTHashtable<nsPtrHashKey<GlyphChangeObserver> >;
+        mGlyphChangeObservers.reset(
+            new nsTHashtable<nsPtrHashKey<GlyphChangeObserver>>);
     }
     mGlyphChangeObservers->PutEntry(aObserver);
 }
 
 void
 gfxFont::RemoveGlyphChangeObserver(GlyphChangeObserver *aObserver)
 {
     NS_ASSERTION(mGlyphChangeObservers, "No observers registered");
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -648,17 +648,17 @@ public:
                                              uint32_t&, void*),
                       void* aHandleFeatureData);
 
 protected:
     // Work out whether cairo will snap inter-glyph spacing to pixels.
     static void GetRoundOffsetsToPixels(DrawTarget* aDrawTarget,
                                         bool* aRoundX, bool* aRoundY);
 
-    // the font this shaper is working with. The font owns a nsAutoPtr reference
+    // the font this shaper is working with. The font owns a UniquePtr reference
     // to this object, and will destroy it before it dies. Thus, mFont will always
     // be valid.
     gfxFont* MOZ_NON_OWNING_REF mFont;
 };
 
 
 /*
  * gfxShapedText is an abstract superclass for gfxShapedWord and gfxTextRun.
@@ -1140,17 +1140,17 @@ protected:
         nsTArray<DGRec>             mOffsetToIndex;
 
         // Records the most recently used index into mOffsetToIndex, so that
         // we can support sequential access more quickly than just doing
         // a binary search each time.
         nsTArray<DGRec>::index_type mLastUsed;
     };
 
-    nsAutoPtr<DetailedGlyphStore>   mDetailedGlyphs;
+    mozilla::UniquePtr<DetailedGlyphStore>   mDetailedGlyphs;
 
     // Number of char16_t characters and CompressedGlyph glyph records
     uint32_t                        mLength;
 
     // Shaping flags (direction, ligature-suppression)
     uint32_t                        mFlags;
 
     int32_t                         mAppUnitsPerDevUnit;
@@ -1529,17 +1529,17 @@ public:
     };
 
     const Metrics& GetMetrics(Orientation aOrientation)
     {
         if (aOrientation == eHorizontal) {
             return GetHorizontalMetrics();
         }
         if (!mVerticalMetrics) {
-            mVerticalMetrics = CreateVerticalMetrics();
+            mVerticalMetrics.reset(CreateVerticalMetrics());
         }
         return *mVerticalMetrics;
     }
 
     /**
      * We let layout specify spacing on either side of any
      * character. We need to specify both before and after
      * spacing so that substring measurement can do the right things.
@@ -1746,17 +1746,17 @@ public:
                                  int32_t aAppUnitsPerDevUnit,
                                  uint32_t aFlags,
                                  gfxTextPerfMetrics *aTextPerf);
 
     // Ensure the ShapedWord cache is initialized. This MUST be called before
     // any attempt to use GetShapedWord().
     void InitWordCache() {
         if (!mWordCache) {
-            mWordCache = new nsTHashtable<CacheHashEntry>;
+            mWordCache = mozilla::MakeUnique<nsTHashtable<CacheHashEntry>>();
         }
     }
 
     // Called by the gfxFontCache timer to increment the age of all the words,
     // so that they'll expire after a sufficient period of non-use
     void AgeCachedWords();
 
     // Discard all cached word records; called on memory-pressure notification.
@@ -2060,65 +2060,66 @@ protected:
 
         size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
         {
             return aMallocSizeOf(mShapedWord.get());
         }
 
         enum { ALLOW_MEMMOVE = true };
 
-        nsAutoPtr<gfxShapedWord> mShapedWord;
+        mozilla::UniquePtr<gfxShapedWord> mShapedWord;
     };
 
-    nsAutoPtr<nsTHashtable<CacheHashEntry> > mWordCache;
+    mozilla::UniquePtr<nsTHashtable<CacheHashEntry> > mWordCache;
 
     static const uint32_t  kShapedWordCacheMaxAge = 3;
 
     bool                       mIsValid;
 
     // use synthetic bolding for environments where this is not supported
     // by the platform
     bool                       mApplySyntheticBold;
 
     bool                       mKerningSet;     // kerning explicitly set?
     bool                       mKerningEnabled; // if set, on or off?
 
     nsExpirationState          mExpirationState;
     gfxFontStyle               mStyle;
     AutoTArray<gfxGlyphExtents*,1> mGlyphExtentsArray;
-    nsAutoPtr<nsTHashtable<nsPtrHashKey<GlyphChangeObserver> > > mGlyphChangeObservers;
+    mozilla::UniquePtr<nsTHashtable<nsPtrHashKey<GlyphChangeObserver>>>
+                               mGlyphChangeObservers;
 
     gfxFloat                   mAdjustedSize;
 
     // Conversion factor from font units to dev units; note that this may be
     // zero (in the degenerate case where mAdjustedSize has become zero).
     // This is OK because we only multiply by this factor, never divide.
     float                      mFUnitsConvFactor;
 
     // the AA setting requested for this font - may affect glyph bounds
     AntialiasOption            mAntialiasOption;
 
     // a copy of the font without antialiasing, if needed for separate
     // measurement by mathml code
-    nsAutoPtr<gfxFont>         mNonAAFont;
+    mozilla::UniquePtr<gfxFont>         mNonAAFont;
 
     // we create either or both of these shapers when needed, depending
     // whether the font has graphite tables, and whether graphite shaping
     // is actually enabled
-    nsAutoPtr<gfxFontShaper>   mHarfBuzzShaper;
-    nsAutoPtr<gfxFontShaper>   mGraphiteShaper;
+    mozilla::UniquePtr<gfxFontShaper>   mHarfBuzzShaper;
+    mozilla::UniquePtr<gfxFontShaper>   mGraphiteShaper;
 
     // if a userfont with unicode-range specified, contains map of *possible*
     // ranges supported by font
     RefPtr<gfxCharacterMap> mUnicodeRangeMap;
 
     RefPtr<mozilla::gfx::ScaledFont> mAzureScaledFont;
 
     // For vertical metrics, created on demand.
-    nsAutoPtr<const Metrics> mVerticalMetrics;
+    mozilla::UniquePtr<const Metrics> mVerticalMetrics;
 
     // Helper for subclasses that want to initialize standard metrics from the
     // tables of sfnt (TrueType/OpenType) fonts.
     // This will use mFUnitsConvFactor if it is already set, else compute it
     // from mAdjustedSize and the unitsPerEm in the font's 'head' table.
     // Returns TRUE and sets mIsValid=TRUE if successful;
     // Returns TRUE but leaves mIsValid=FALSE if the font seems to be broken.
     // Returns FALSE if the font does not appear to be an sfnt at all,
--- a/gfx/thebes/gfxFontEntry.cpp
+++ b/gfx/thebes/gfxFontEntry.cpp
@@ -380,17 +380,17 @@ gfxFontEntry::TryGetSVGData(gfxFont* aFo
         // blob to the gfxSVGGlyphs, once we've confirmed the table exists
         hb_blob_t *svgTable = GetFontTable(TRUETYPE_TAG('S','V','G',' '));
         if (!svgTable) {
             return false;
         }
 
         // gfxSVGGlyphs will hb_blob_destroy() the table when it is finished
         // with it.
-        mSVGGlyphs = new gfxSVGGlyphs(svgTable, this);
+        mSVGGlyphs = MakeUnique<gfxSVGGlyphs>(svgTable, this);
     }
 
     if (!mFontsUsingSVGGlyphs.Contains(aFont)) {
         mFontsUsingSVGGlyphs.AppendElement(aFont);
     }
 
     return !!mSVGGlyphs;
 }
@@ -425,19 +425,19 @@ gfxFontEntry::TryGetMathTable()
         // blob to the gfxMathTable, once we've confirmed the table exists
         hb_blob_t *mathTable = GetFontTable(TRUETYPE_TAG('M','A','T','H'));
         if (!mathTable) {
             return false;
         }
 
         // gfxMathTable will hb_blob_destroy() the table when it is finished
         // with it.
-        mMathTable = new gfxMathTable(mathTable);
+        mMathTable = MakeUnique<gfxMathTable>(mathTable);
         if (!mMathTable->HasValidHeaders()) {
-            mMathTable = nullptr;
+            mMathTable.reset(nullptr);
             return false;
         }
     }
 
     return !!mMathTable;
 }
 
 gfxFloat
@@ -638,17 +638,17 @@ gfxFontEntry::FontTableHashEntry::GetBlo
 }
 
 bool
 gfxFontEntry::GetExistingFontTable(uint32_t aTag, hb_blob_t **aBlob)
 {
     if (!mFontTableCache) {
         // we do this here rather than on fontEntry construction
         // because not all shapers will access the table cache at all
-        mFontTableCache = new nsTHashtable<FontTableHashEntry>(8);
+        mFontTableCache = MakeUnique<nsTHashtable<FontTableHashEntry>>(8);
     }
 
     FontTableHashEntry *entry = mFontTableCache->GetEntry(aTag);
     if (!entry) {
         return false;
     }
 
     *aBlob = entry->GetBlob();
@@ -657,31 +657,31 @@ gfxFontEntry::GetExistingFontTable(uint3
 
 hb_blob_t *
 gfxFontEntry::ShareFontTableAndGetBlob(uint32_t aTag,
                                        nsTArray<uint8_t>* aBuffer)
 {
     if (MOZ_UNLIKELY(!mFontTableCache)) {
         // we do this here rather than on fontEntry construction
         // because not all shapers will access the table cache at all
-      mFontTableCache = new nsTHashtable<FontTableHashEntry>(8);
+      mFontTableCache = MakeUnique<nsTHashtable<FontTableHashEntry>>(8);
     }
 
     FontTableHashEntry *entry = mFontTableCache->PutEntry(aTag);
     if (MOZ_UNLIKELY(!entry)) { // OOM
         return nullptr;
     }
 
     if (!aBuffer) {
         // ensure the entry is null
         entry->Clear();
         return nullptr;
     }
 
-    return entry->ShareTableAndGetBlob(Move(*aBuffer), mFontTableCache);
+    return entry->ShareTableAndGetBlob(Move(*aBuffer), mFontTableCache.get());
 }
 
 static int
 DirEntryCmp(const void* aKey, const void* aItem)
 {
     int32_t tag = *static_cast<const int32_t*>(aKey);
     const TableDirEntry* entry = static_cast<const TableDirEntry*>(aItem);
     return tag - int32_t(entry->tag);
@@ -888,17 +888,17 @@ PR_STATIC_ASSERT(MOZ_NUM_SCRIPT_CODES <=
 // high-order three bytes of tag with script in low-order byte
 #define SCRIPT_FEATURE(s,tag) (((~FEATURE_SCRIPT_MASK) & (tag)) | \
                                ((FEATURE_SCRIPT_MASK) & (s)))
 
 bool
 gfxFontEntry::SupportsOpenTypeFeature(int32_t aScript, uint32_t aFeatureTag)
 {
     if (!mSupportedFeatures) {
-        mSupportedFeatures = new nsDataHashtable<nsUint32HashKey,bool>();
+        mSupportedFeatures = MakeUnique<nsDataHashtable<nsUint32HashKey,bool>>();
     }
 
     // note: high-order three bytes *must* be unique for each feature
     // listed below (see SCRIPT_FEATURE macro def'n)
     NS_ASSERTION(aFeatureTag == HB_TAG('s','m','c','p') ||
                  aFeatureTag == HB_TAG('c','2','s','c') ||
                  aFeatureTag == HB_TAG('p','c','a','p') ||
                  aFeatureTag == HB_TAG('c','2','p','c') ||
@@ -966,17 +966,17 @@ gfxFontEntry::SupportsOpenTypeFeature(in
 
     return result;
 }
 
 const hb_set_t*
 gfxFontEntry::InputsForOpenTypeFeature(int32_t aScript, uint32_t aFeatureTag)
 {
     if (!mFeatureInputs) {
-        mFeatureInputs = new nsDataHashtable<nsUint32HashKey,hb_set_t*>();
+        mFeatureInputs = MakeUnique<nsDataHashtable<nsUint32HashKey,hb_set_t*>>();
     }
 
     NS_ASSERTION(aFeatureTag == HB_TAG('s','u','p','s') ||
                  aFeatureTag == HB_TAG('s','u','b','s'),
                  "use of unknown feature tag");
 
     uint32_t scriptFeature = SCRIPT_FEATURE(aScript, aFeatureTag);
     hb_set_t *inputGlyphs;
@@ -1027,17 +1027,17 @@ gfxFontEntry::InputsForOpenTypeFeature(i
     mFeatureInputs->Put(scriptFeature, inputGlyphs);
     return inputGlyphs;
 }
 
 bool
 gfxFontEntry::SupportsGraphiteFeature(uint32_t aFeatureTag)
 {
     if (!mSupportedFeatures) {
-        mSupportedFeatures = new nsDataHashtable<nsUint32HashKey,bool>();
+        mSupportedFeatures = MakeUnique<nsDataHashtable<nsUint32HashKey,bool>>();
     }
 
     // note: high-order three bytes *must* be unique for each feature
     // listed below (see SCRIPT_FEATURE macro def'n)
     NS_ASSERTION(aFeatureTag == HB_TAG('s','m','c','p') ||
                  aFeatureTag == HB_TAG('c','2','s','c') ||
                  aFeatureTag == HB_TAG('p','c','a','p') ||
                  aFeatureTag == HB_TAG('c','2','p','c') ||
--- a/gfx/thebes/gfxFontEntry.h
+++ b/gfx/thebes/gfxFontEntry.h
@@ -428,24 +428,24 @@ public:
     uint32_t         mNonDefaultSubSpaceFeatures[(MOZ_NUM_SCRIPT_CODES + 31) / 32];
 
     uint16_t         mWeight;
     int16_t          mStretch;
 
     RefPtr<gfxCharacterMap> mCharacterMap;
     uint32_t         mUVSOffset;
     mozilla::UniquePtr<uint8_t[]> mUVSData;
-    nsAutoPtr<gfxUserFontData> mUserFontData;
-    nsAutoPtr<gfxSVGGlyphs> mSVGGlyphs;
+    mozilla::UniquePtr<gfxUserFontData> mUserFontData;
+    mozilla::UniquePtr<gfxSVGGlyphs> mSVGGlyphs;
     // list of gfxFonts that are using SVG glyphs
     nsTArray<gfxFont*> mFontsUsingSVGGlyphs;
-    nsAutoPtr<gfxMathTable> mMathTable;
+    mozilla::UniquePtr<gfxMathTable> mMathTable;
     nsTArray<gfxFontFeature> mFeatureSettings;
-    nsAutoPtr<nsDataHashtable<nsUint32HashKey,bool>> mSupportedFeatures;
-    nsAutoPtr<nsDataHashtable<nsUint32HashKey,hb_set_t*>> mFeatureInputs;
+    mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,bool>> mSupportedFeatures;
+    mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,hb_set_t*>> mFeatureInputs;
     uint32_t         mLanguageOverride;
 
     // Color Layer font support
     hb_blob_t*       mCOLR;
     hb_blob_t*       mCPAL;
 
 protected:
     friend class gfxPlatformFontList;
@@ -620,17 +620,17 @@ private:
         static void DeleteFontTableBlobData(void *aBlobData);
         // not implemented
         FontTableHashEntry& operator=(FontTableHashEntry& toCopy);
 
         FontTableBlobData *mSharedBlobData;
         hb_blob_t *mBlob;
     };
 
-    nsAutoPtr<nsTHashtable<FontTableHashEntry> > mFontTableCache;
+    mozilla::UniquePtr<nsTHashtable<FontTableHashEntry> > mFontTableCache;
 
     gfxFontEntry(const gfxFontEntry&);
     gfxFontEntry& operator=(const gfxFontEntry&);
 };
 
 
 // used when iterating over all fonts looking for a match for a given character
 struct GlobalFontMatch {
--- a/gfx/thebes/gfxFontInfoLoader.h
+++ b/gfx/thebes/gfxFontInfoLoader.h
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * 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 GFX_FONT_INFO_LOADER_H
 #define GFX_FONT_INFO_LOADER_H
 
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsIObserver.h"
 #include "nsITimer.h"
 #include "nsIThread.h"
 #include "nsRefPtrHashtable.h"
 #include "nsString.h"
 #include "gfxFont.h"
 #include "nsIRunnable.h"
--- a/gfx/thebes/gfxFontUtils.cpp
+++ b/gfx/thebes/gfxFontUtils.cpp
@@ -61,18 +61,20 @@ typedef struct {
 
 void
 gfxSparseBitSet::Dump(const char* aPrefix, eGfxLog aWhichLog) const
 {
     NS_ASSERTION(mBlocks.DebugGetHeader(), "mHdr is null, this is bad");
     uint32_t b, numBlocks = mBlocks.Length();
 
     for (b = 0; b < numBlocks; b++) {
-        Block *block = mBlocks[b];
-        if (!block) continue;
+        Block *block = mBlocks[b].get();
+        if (!block) {
+            continue;
+        }
         const int BUFSIZE = 256;
         char outStr[BUFSIZE];
         int index = 0;
         index += snprintf(&outStr[index], BUFSIZE - index, "%s u+%6.6x [", aPrefix, (b << BLOCK_INDEX_SHIFT));
         for (int i = 0; i < 32; i += 4) {
             for (int j = i; j < i + 4; j++) {
                 uint8_t bits = block->mBits[j];
                 uint8_t flip1 = ((bits & 0xaa) >> 1) | ((bits & 0x55) << 1);
--- a/gfx/thebes/gfxFontUtils.h
+++ b/gfx/thebes/gfxFontUtils.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_FONT_UTILS_H
 #define GFX_FONT_UTILS_H
 
 #include "gfxPlatform.h"
 #include "nsComponentManagerUtils.h"
 #include "nsTArray.h"
-#include "nsAutoPtr.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Endian.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/UniquePtr.h"
 
 #include "zlib.h"
 #include <algorithm>
 
@@ -39,51 +38,54 @@ private:
     };
 
 public:
     gfxSparseBitSet() { }
     gfxSparseBitSet(const gfxSparseBitSet& aBitset) {
         uint32_t len = aBitset.mBlocks.Length();
         mBlocks.AppendElements(len);
         for (uint32_t i = 0; i < len; ++i) {
-            Block *block = aBitset.mBlocks[i];
-            if (block)
-                mBlocks[i] = new Block(*block);
+            Block *block = aBitset.mBlocks[i].get();
+            if (block) {
+                mBlocks[i] = mozilla::MakeUnique<Block>(*block);
+            }
         }
     }
 
     bool Equals(const gfxSparseBitSet *aOther) const {
         if (mBlocks.Length() != aOther->mBlocks.Length()) {
             return false;
         }
         size_t n = mBlocks.Length();
         for (size_t i = 0; i < n; ++i) {
-            const Block *b1 = mBlocks[i];
-            const Block *b2 = aOther->mBlocks[i];
+            const Block *b1 = mBlocks[i].get();
+            const Block *b2 = aOther->mBlocks[i].get();
             if (!b1 != !b2) {
                 return false;
             }
             if (!b1) {
                 continue;
             }
             if (memcmp(&b1->mBits, &b2->mBits, BLOCK_SIZE) != 0) {
                 return false;
             }
         }
         return true;
     }
 
     bool test(uint32_t aIndex) const {
         NS_ASSERTION(mBlocks.DebugGetHeader(), "mHdr is null, this is bad");
         uint32_t blockIndex = aIndex/BLOCK_SIZE_BITS;
-        if (blockIndex >= mBlocks.Length())
+        if (blockIndex >= mBlocks.Length()) {
             return false;
-        Block *block = mBlocks[blockIndex];
-        if (!block)
+        }
+        const Block *block = mBlocks[blockIndex].get();
+        if (!block) {
             return false;
+        }
         return ((block->mBits[(aIndex>>3) & (BLOCK_SIZE - 1)]) & (1 << (aIndex & 0x7))) != 0;
     }
 
     // dump out contents of bitmap
     void Dump(const char* aPrefix, eGfxLog aWhichLog) const;
 
     bool TestRange(uint32_t aStart, uint32_t aEnd) {
         uint32_t startBlock, endBlock, blockLen;
@@ -94,70 +96,79 @@ public:
         if (startBlock >= blockLen) return false;
         
         // check for blocks in range, if none, return false
         uint32_t blockIndex;
         bool hasBlocksInRange = false;
 
         endBlock = aEnd >> BLOCK_INDEX_SHIFT;
         for (blockIndex = startBlock; blockIndex <= endBlock; blockIndex++) {
-            if (blockIndex < blockLen && mBlocks[blockIndex])
+            if (blockIndex < blockLen && mBlocks[blockIndex]) {
                 hasBlocksInRange = true;
+            }
         }
-        if (!hasBlocksInRange) return false;
+        if (!hasBlocksInRange) {
+            return false;
+        }
 
         Block *block;
         uint32_t i, start, end;
         
         // first block, check bits
-        if ((block = mBlocks[startBlock])) {
+        if ((block = mBlocks[startBlock].get())) {
             start = aStart;
             end = std::min(aEnd, ((startBlock+1) << BLOCK_INDEX_SHIFT) - 1);
             for (i = start; i <= end; i++) {
-                if ((block->mBits[(i>>3) & (BLOCK_SIZE - 1)]) & (1 << (i & 0x7)))
+                if ((block->mBits[(i>>3) & (BLOCK_SIZE - 1)]) & (1 << (i & 0x7))) {
                     return true;
+                }
             }
         }
-        if (endBlock == startBlock) return false;
+        if (endBlock == startBlock) {
+            return false;
+        }
 
         // [2..n-1] blocks check bytes
         for (blockIndex = startBlock + 1; blockIndex < endBlock; blockIndex++) {
             uint32_t index;
             
-            if (blockIndex >= blockLen || !(block = mBlocks[blockIndex])) continue;
+            if (blockIndex >= blockLen ||
+                !(block = mBlocks[blockIndex].get())) {
+                continue;
+            }
             for (index = 0; index < BLOCK_SIZE; index++) {
-                if (block->mBits[index]) 
+                if (block->mBits[index]) {
                     return true;
+                }
             }
         }
         
         // last block, check bits
-        if (endBlock < blockLen && (block = mBlocks[endBlock])) {
+        if (endBlock < blockLen && (block = mBlocks[endBlock].get())) {
             start = endBlock << BLOCK_INDEX_SHIFT;
             end = aEnd;
             for (i = start; i <= end; i++) {
-                if ((block->mBits[(i>>3) & (BLOCK_SIZE - 1)]) & (1 << (i & 0x7)))
+                if ((block->mBits[(i>>3) & (BLOCK_SIZE - 1)]) & (1 << (i & 0x7))) {
                     return true;
+                }
             }
         }
         
         return false;
     }
     
     void set(uint32_t aIndex) {
         uint32_t blockIndex = aIndex/BLOCK_SIZE_BITS;
         if (blockIndex >= mBlocks.Length()) {
-            nsAutoPtr<Block> *blocks = mBlocks.AppendElements(blockIndex + 1 - mBlocks.Length());
-            if (MOZ_UNLIKELY(!blocks)) // OOM
-                return;
+            mBlocks.AppendElements(blockIndex + 1 - mBlocks.Length());
         }
-        Block *block = mBlocks[blockIndex];
+        Block *block = mBlocks[blockIndex].get();
         if (!block) {
             block = new Block;
-            mBlocks[blockIndex] = block;
+            mBlocks[blockIndex].reset(block);
         }
         block->mBits[(aIndex>>3) & (BLOCK_SIZE - 1)] |= 1 << (aIndex & 0x7);
     }
 
     void set(uint32_t aIndex, bool aValue) {
         if (aValue)
             set(aIndex);
         else
@@ -165,76 +176,70 @@ public:
     }
 
     void SetRange(uint32_t aStart, uint32_t aEnd) {
         const uint32_t startIndex = aStart/BLOCK_SIZE_BITS;
         const uint32_t endIndex = aEnd/BLOCK_SIZE_BITS;
 
         if (endIndex >= mBlocks.Length()) {
             uint32_t numNewBlocks = endIndex + 1 - mBlocks.Length();
-            nsAutoPtr<Block> *blocks = mBlocks.AppendElements(numNewBlocks);
-            if (MOZ_UNLIKELY(!blocks)) // OOM
-                return;
+            mBlocks.AppendElements(numNewBlocks);
         }
 
         for (uint32_t i = startIndex; i <= endIndex; ++i) {
             const uint32_t blockFirstBit = i * BLOCK_SIZE_BITS;
             const uint32_t blockLastBit = blockFirstBit + BLOCK_SIZE_BITS - 1;
 
-            Block *block = mBlocks[i];
+            Block *block = mBlocks[i].get();
             if (!block) {
-                bool fullBlock = false;
-                if (aStart <= blockFirstBit && aEnd >= blockLastBit)
-                    fullBlock = true;
+                bool fullBlock =
+                    (aStart <= blockFirstBit && aEnd >= blockLastBit);
 
                 block = new Block(fullBlock ? 0xFF : 0);
-                mBlocks[i] = block;
+                mBlocks[i].reset(block);
 
-                if (fullBlock)
+                if (fullBlock) {
                     continue;
+                }
             }
 
             const uint32_t start = aStart > blockFirstBit ? aStart - blockFirstBit : 0;
             const uint32_t end = std::min<uint32_t>(aEnd - blockFirstBit, BLOCK_SIZE_BITS - 1);
 
             for (uint32_t bit = start; bit <= end; ++bit) {
                 block->mBits[bit>>3] |= 1 << (bit & 0x7);
             }
         }
     }
 
     void clear(uint32_t aIndex) {
         uint32_t blockIndex = aIndex/BLOCK_SIZE_BITS;
         if (blockIndex >= mBlocks.Length()) {
-            nsAutoPtr<Block> *blocks = mBlocks.AppendElements(blockIndex + 1 - mBlocks.Length());
-            if (MOZ_UNLIKELY(!blocks)) // OOM
-                return;
+            mBlocks.AppendElements(blockIndex + 1 - mBlocks.Length());
         }
-        Block *block = mBlocks[blockIndex];
+        Block *block = mBlocks[blockIndex].get();
         if (!block) {
             return;
         }
         block->mBits[(aIndex>>3) & (BLOCK_SIZE - 1)] &= ~(1 << (aIndex & 0x7));
     }
 
     void ClearRange(uint32_t aStart, uint32_t aEnd) {
         const uint32_t startIndex = aStart/BLOCK_SIZE_BITS;
         const uint32_t endIndex = aEnd/BLOCK_SIZE_BITS;
 
         if (endIndex >= mBlocks.Length()) {
             uint32_t numNewBlocks = endIndex + 1 - mBlocks.Length();
-            nsAutoPtr<Block> *blocks = mBlocks.AppendElements(numNewBlocks);
-            if (MOZ_UNLIKELY(!blocks)) // OOM
-                return;
+            mBlocks.AppendElements(numNewBlocks);
         }
 
         for (uint32_t i = startIndex; i <= endIndex; ++i) {
             const uint32_t blockFirstBit = i * BLOCK_SIZE_BITS;
 
-            Block *block = mBlocks[i];
+            Block *block = mBlocks[i].get();
             if (!block) {
                 // any nonexistent block is implicitly all clear,
                 // so there's no need to even create it
                 continue;
             }
 
             const uint32_t start = aStart > blockFirstBit ? aStart - blockFirstBit : 0;
             const uint32_t end = std::min<uint32_t>(aEnd - blockFirstBit, BLOCK_SIZE_BITS - 1);
@@ -244,53 +249,51 @@ public:
             }
         }
     }
 
     size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
         size_t total = mBlocks.ShallowSizeOfExcludingThis(aMallocSizeOf);
         for (uint32_t i = 0; i < mBlocks.Length(); i++) {
             if (mBlocks[i]) {
-                total += aMallocSizeOf(mBlocks[i]);
+                total += aMallocSizeOf(mBlocks[i].get());
             }
         }
         return total;
     }
 
     size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
         return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
     }
 
     // clear out all blocks in the array
     void reset() {
         uint32_t i;
-        for (i = 0; i < mBlocks.Length(); i++)
-            mBlocks[i] = nullptr;    
+        for (i = 0; i < mBlocks.Length(); i++) {
+            mBlocks[i] = nullptr;
+        }
     }
 
     // set this bitset to the union of its current contents and another
     void Union(const gfxSparseBitSet& aBitset) {
         // ensure mBlocks is large enough
         uint32_t blockCount = aBitset.mBlocks.Length();
         if (blockCount > mBlocks.Length()) {
             uint32_t needed = blockCount - mBlocks.Length();
-            nsAutoPtr<Block> *blocks = mBlocks.AppendElements(needed);
-            if (MOZ_UNLIKELY(!blocks)) { // OOM
-                return;
-            }
+            mBlocks.AppendElements(needed);
         }
         // for each block that may be present in aBitset...
         for (uint32_t i = 0; i < blockCount; ++i) {
             // if it is missing (implicitly empty), just skip
             if (!aBitset.mBlocks[i]) {
                 continue;
             }
             // if the block is missing in this set, just copy the other
             if (!mBlocks[i]) {
-                mBlocks[i] = new Block(*aBitset.mBlocks[i]);
+                mBlocks[i] = mozilla::MakeUnique<Block>(*aBitset.mBlocks[i]);
                 continue;
             }
             // else set existing block to the union of both
             uint32_t *dst = reinterpret_cast<uint32_t*>(mBlocks[i]->mBits);
             const uint32_t *src =
                 reinterpret_cast<const uint32_t*>(aBitset.mBlocks[i]->mBits);
             for (uint32_t j = 0; j < BLOCK_SIZE / 4; ++j) {
                 dst[j] |= src[j];
@@ -301,26 +304,26 @@ public:
     void Compact() {
         mBlocks.Compact();
     }
 
     uint32_t GetChecksum() const {
         uint32_t check = adler32(0, Z_NULL, 0);
         for (uint32_t i = 0; i < mBlocks.Length(); i++) {
             if (mBlocks[i]) {
-                const Block *block = mBlocks[i];
+                const Block *block = mBlocks[i].get();
                 check = adler32(check, (uint8_t*) (&i), 4);
                 check = adler32(check, (uint8_t*) block, sizeof(Block));
             }
         }
         return check;
     }
 
 private:
-    nsTArray< nsAutoPtr<Block> > mBlocks;
+    nsTArray<mozilla::UniquePtr<Block>> mBlocks;
 };
 
 #define TRUETYPE_TAG(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
 
 namespace mozilla {
 
 // Byte-swapping types and name table structure definitions moved from
 // gfxFontUtils.cpp to .h file so that gfxFont.cpp can also refer to them
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -464,17 +464,17 @@ gfxGDIFont::GetGlyph(uint32_t aUnicode, 
     // We don't support variation selector sequences or non-BMP characters
     // in the legacy bitmap, vector or postscript fonts that might use
     // this code path.
     if (aUnicode > 0xffff || aVarSelector) {
         return 0;
     }
 
     if (!mGlyphIDs) {
-        mGlyphIDs = new nsDataHashtable<nsUint32HashKey,uint32_t>(64);
+        mGlyphIDs = MakeUnique<nsDataHashtable<nsUint32HashKey,uint32_t>>(64);
     }
 
     uint32_t gid;
     if (mGlyphIDs->Get(aUnicode, &gid)) {
         return gid;
     }
 
     wchar_t ch = aUnicode;
@@ -501,17 +501,17 @@ gfxGDIFont::GetGlyph(uint32_t aUnicode, 
     mGlyphIDs->Put(aUnicode, glyph);
     return glyph;
 }
 
 int32_t
 gfxGDIFont::GetGlyphWidth(DrawTarget& aDrawTarget, uint16_t aGID)
 {
     if (!mGlyphWidths) {
-        mGlyphWidths = new nsDataHashtable<nsUint32HashKey,int32_t>(128);
+        mGlyphWidths = MakeUnique<nsDataHashtable<nsUint32HashKey,int32_t>>(128);
     }
 
     int32_t width;
     if (mGlyphWidths->Get(aGID, &width)) {
         return width;
     }
 
     DCFromDrawTarget dc(aDrawTarget);
--- a/gfx/thebes/gfxGDIFont.h
+++ b/gfx/thebes/gfxGDIFont.h
@@ -101,16 +101,16 @@ protected:
     cairo_font_face_t    *mFontFace;
 
     Metrics              *mMetrics;
     uint32_t              mSpaceGlyph;
 
     bool                  mNeedsBold;
 
     // cache of glyph IDs (used for non-sfnt fonts only)
-    nsAutoPtr<nsDataHashtable<nsUint32HashKey,uint32_t> > mGlyphIDs;
+    mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,uint32_t> > mGlyphIDs;
     SCRIPT_CACHE          mScriptCache;
 
     // cache of glyph widths in 16.16 fixed-point pixels
-    nsAutoPtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths;
+    mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths;
 };
 
 #endif /* GFX_GDIFONT_H */
--- a/gfx/thebes/gfxGDIFontList.cpp
+++ b/gfx/thebes/gfxGDIFontList.cpp
@@ -125,17 +125,17 @@ GDIFontEntry::GDIFontEntry(const nsAStri
                            bool aFamilyHasItalicFace)
     : gfxFontEntry(aFaceName),
       mWindowsFamily(0), mWindowsPitch(0),
       mFontType(aFontType),
       mForceGDI(false),
       mFamilyHasItalicFace(aFamilyHasItalicFace),
       mCharset(), mUnicodeRanges()
 {
-    mUserFontData = aUserFontData;
+    mUserFontData.reset(aUserFontData);
     mStyle = aStyle;
     mWeight = aWeight;
     mStretch = aStretch;
     if (IsType1())
         mForceGDI = true;
     mIsDataUserFont = aUserFontData != nullptr;
 
     InitLogFont(aFaceName, aFontType);
--- a/gfx/thebes/gfxImageSurface.h
+++ b/gfx/thebes/gfxImageSurface.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_IMAGESURFACE_H
 #define GFX_IMAGESURFACE_H
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/RefPtr.h"
 #include "gfxASurface.h"
-#include "nsAutoPtr.h"
 #include "nsSize.h"
 
 // ARGB -- raw buffer.. wont be changed.. good for storing data.
 
 class gfxSubimageSurface;
 
 namespace mozilla {
 namespace gfx {
--- a/gfx/thebes/gfxMacFont.cpp
+++ b/gfx/thebes/gfxMacFont.cpp
@@ -133,17 +133,17 @@ gfxMacFont::ShapeText(DrawTarget     *aD
         return false;
     }
 
     // Currently, we don't support vertical shaping via CoreText,
     // so we ignore RequiresAATLayout if vertical is requested.
     if (static_cast<MacOSFontEntry*>(GetFontEntry())->RequiresAATLayout() &&
         !aVertical) {
         if (!mCoreTextShaper) {
-            mCoreTextShaper = new gfxCoreTextShaper(this);
+            mCoreTextShaper = MakeUnique<gfxCoreTextShaper>(this);
         }
         if (mCoreTextShaper->ShapeText(aDrawTarget, aText, aOffset, aLength,
                                        aScript, aVertical, aShapedText)) {
             PostShapingFixup(aDrawTarget, aText, aOffset,
                              aLength, aVertical, aShapedText);
             return true;
         }
     }
--- a/gfx/thebes/gfxMacFont.h
+++ b/gfx/thebes/gfxMacFont.h
@@ -88,15 +88,15 @@ protected:
     CGFontRef             mCGFont;
 
     // a Core Text font reference, created only if we're using CT to measure
     // glyph widths; otherwise null.
     CTFontRef             mCTFont;
 
     cairo_font_face_t    *mFontFace;
 
-    nsAutoPtr<gfxFontShaper> mCoreTextShaper;
+    mozilla::UniquePtr<gfxFontShaper> mCoreTextShaper;
 
     Metrics               mMetrics;
     uint32_t              mSpaceGlyph;
 };
 
 #endif /* GFX_MACFONT_H */
--- a/gfx/thebes/gfxMacPlatformFontList.mm
+++ b/gfx/thebes/gfxMacPlatformFontList.mm
@@ -1063,24 +1063,24 @@ gfxMacPlatformFontList::MakePlatformFont
                                        &ReleaseData);
     CGFontRef fontRef = ::CGFontCreateWithDataProvider(provider);
     ::CGDataProviderRelease(provider);
 
     if (!fontRef) {
         return nullptr;
     }
 
-    nsAutoPtr<MacOSFontEntry>
-        newFontEntry(new MacOSFontEntry(uniqueName, fontRef, aWeight,
-                                        aStretch, aStyle, true, false));
+    auto newFontEntry =
+        MakeUnique<MacOSFontEntry>(uniqueName, fontRef, aWeight, aStretch,
+                                   aStyle, true, false);
     ::CFRelease(fontRef);
 
     // if succeeded and font cmap is good, return the new font
     if (newFontEntry->mIsValid && NS_SUCCEEDED(newFontEntry->ReadCMAP())) {
-        return newFontEntry.forget();
+        return newFontEntry.release();
     }
 
     // if something is funky about this font, delete immediately
 
 #if DEBUG
     NS_WARNING("downloaded font not loaded properly");
 #endif
 
--- a/gfx/thebes/gfxPattern.h
+++ b/gfx/thebes/gfxPattern.h
@@ -8,17 +8,16 @@
 
 #include "gfxTypes.h"
 
 #include "gfxMatrix.h"
 #include "mozilla/Alignment.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PatternHelpers.h"
 #include "nsISupportsImpl.h"
-#include "nsAutoPtr.h"
 #include "nsTArray.h"
 
 typedef struct _cairo_pattern cairo_pattern_t;
 
 
 class gfxPattern final{
     NS_INLINE_DECL_REFCOUNTING(gfxPattern)
 
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -6,17 +6,16 @@
 #ifndef GFX_PLATFORM_H
 #define GFX_PLATFORM_H
 
 #include "mozilla/Logging.h"
 #include "mozilla/gfx/Types.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 
 #include "gfxTypes.h"
 #include "gfxFontFamilyList.h"
 #include "gfxBlur.h"
 #include "nsRect.h"
 
 #include "qcms.h"
 
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -179,17 +179,17 @@ gfxPlatformFontList::MemoryReporter::Col
 gfxPlatformFontList::gfxPlatformFontList(bool aNeedFullnamePostscriptNames)
     : mFontFamilies(64), mOtherFamilyNames(16),
       mBadUnderlineFamilyNames(8), mSharedCmaps(8),
       mStartIndex(0), mIncrement(1), mNumFamilies(0), mFontlistInitCount(0)
 {
     mOtherFamilyNamesInitialized = false;
 
     if (aNeedFullnamePostscriptNames) {
-        mExtraNames = new ExtraNames();
+        mExtraNames = MakeUnique<ExtraNames>();
     }
     mFaceNameListsInitialized = false;
 
     LoadBadUnderlineList();
 
     // pref changes notification setup
     NS_ASSERTION(!gFontListPrefObserver,
                  "There has been font list pref observer already");
@@ -376,17 +376,17 @@ gfxPlatformFontList::LookupInFaceNameLis
         }
     }
 
     // lookup in name lookup tables, return null if not found
     if (!(lookup = FindFaceName(aFaceName))) {
         // names not completely initialized, so keep track of lookup misses
         if (!mFaceNameListsInitialized) {
             if (!mFaceNamesMissed) {
-                mFaceNamesMissed = new nsTHashtable<nsStringHashKey>(2);
+                mFaceNamesMissed = MakeUnique<nsTHashtable<nsStringHashKey>>(2);
             }
             mFaceNamesMissed->PutEntry(aFaceName);
         }
     }
 
     return lookup;
 }
 
@@ -668,17 +668,17 @@ gfxPlatformFontList::FindAndAddFamilies(
     // in practice so avoid pulling in names at startup
     if (!familyEntry && !mOtherFamilyNamesInitialized && !IsASCII(aFamily)) {
         InitOtherFamilyNames();
         familyEntry = mOtherFamilyNames.GetWeak(key);
         if (!familyEntry && !mOtherFamilyNamesInitialized) {
             // localized family names load timed out, add name to list of
             // names to check after localized names are loaded
             if (!mOtherNamesMissed) {
-                mOtherNamesMissed = new nsTHashtable<nsStringHashKey>(2);
+                mOtherNamesMissed = MakeUnique<nsTHashtable<nsStringHashKey>>(2);
             }
             mOtherNamesMissed->PutEntry(key);
         }
     }
 
     familyEntry = CheckFamily(familyEntry);
     if (familyEntry) {
         aOutput->AppendElement(familyEntry);
@@ -847,21 +847,22 @@ nsTArray<RefPtr<gfxFontFamily>>*
 gfxPlatformFontList::GetPrefFontsLangGroup(mozilla::FontFamilyType aGenericType,
                                            eFontPrefLang aPrefLang)
 {
     // treat -moz-fixed as monospace
     if (aGenericType == eFamily_moz_fixed) {
         aGenericType = eFamily_monospace;
     }
 
-    PrefFontList* prefFonts = mLangGroupPrefFonts[aPrefLang][aGenericType];
+    PrefFontList* prefFonts =
+        mLangGroupPrefFonts[aPrefLang][aGenericType].get();
     if (MOZ_UNLIKELY(!prefFonts)) {
         prefFonts = new PrefFontList;
         ResolveGenericFontNames(aGenericType, aPrefLang, prefFonts);
-        mLangGroupPrefFonts[aPrefLang][aGenericType] = prefFonts;
+        mLangGroupPrefFonts[aPrefLang][aGenericType].reset(prefFonts);
     }
     return prefFonts;
 }
 
 void
 gfxPlatformFontList::AddGenericFonts(mozilla::FontFamilyType aGenericType,
                                      nsIAtom* aLanguage,
                                      nsTArray<gfxFontFamily*>& aFamilyList)
@@ -1565,17 +1566,17 @@ gfxPlatformFontList::AddSizeOfExcludingT
                                               aMallocSizeOf);
     }
 
     for (uint32_t i = eFontPrefLang_First;
          i < eFontPrefLang_First + eFontPrefLang_Count; i++) {
         auto& prefFontsLangGroup = mLangGroupPrefFonts[i];
         for (uint32_t j = eFamily_generic_first;
              j < eFamily_generic_first + eFamily_generic_count; j++) {
-            PrefFontList* pf = prefFontsLangGroup[j];
+            PrefFontList* pf = prefFontsLangGroup[j].get();
             if (pf) {
                 aSizes->mFontListSize +=
                     pf->ShallowSizeOfExcludingThis(aMallocSizeOf);
             }
         }
     }
 
     aSizes->mFontListSize +=
--- a/gfx/thebes/gfxPlatformFontList.h
+++ b/gfx/thebes/gfxPlatformFontList.h
@@ -386,26 +386,26 @@ protected:
     struct ExtraNames {
       ExtraNames() : mFullnames(64), mPostscriptNames(64) {}
 
       // fullname ==> font entry (unique, one name per font entry)
       FontEntryTable mFullnames;
       // Postscript name ==> font entry (unique, one name per font entry)
       FontEntryTable mPostscriptNames;
     };
-    nsAutoPtr<ExtraNames> mExtraNames;
+    mozilla::UniquePtr<ExtraNames> mExtraNames;
 
     // face names missed when face name loading takes a long time
-    nsAutoPtr<nsTHashtable<nsStringHashKey> > mFaceNamesMissed;
+    mozilla::UniquePtr<nsTHashtable<nsStringHashKey> > mFaceNamesMissed;
 
     // localized family names missed when face name loading takes a long time
-    nsAutoPtr<nsTHashtable<nsStringHashKey> > mOtherNamesMissed;
+    mozilla::UniquePtr<nsTHashtable<nsStringHashKey> > mOtherNamesMissed;
 
     typedef nsTArray<RefPtr<gfxFontFamily>> PrefFontList;
-    typedef mozilla::RangedArray<nsAutoPtr<PrefFontList>,
+    typedef mozilla::RangedArray<mozilla::UniquePtr<PrefFontList>,
                                  mozilla::eFamily_generic_first,
                                  mozilla::eFamily_generic_count> PrefFontsForLangGroup;
     mozilla::RangedArray<PrefFontsForLangGroup,
                          eFontPrefLang_First,
                          eFontPrefLang_Count> mLangGroupPrefFonts;
 
     // when system-wide font lookup fails for a character, cache it to skip future searches
     gfxSparseBitSet mCodepointsWithNoFonts;
--- a/gfx/thebes/gfxReusableSurfaceWrapper.h
+++ b/gfx/thebes/gfxReusableSurfaceWrapper.h
@@ -2,17 +2,16 @@
  * 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 GFXCOWSURFACEWRAPPER
 #define GFXCOWSURFACEWRAPPER
 
 #include "gfxImageSurface.h"
 #include "nsISupportsImpl.h"
-#include "nsAutoPtr.h"
 
 
 /**
  * Provides an interface to implement a cross thread/process wrapper for a
  * gfxImageSurface that has copy-on-write semantics.
  *
  * Only the owner thread can write to the surface and acquire
  * read locks. Destroying a gfxReusableSurfaceWrapper releases
--- a/gfx/thebes/gfxSVGGlyphs.h
+++ b/gfx/thebes/gfxSVGGlyphs.h
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_SVG_GLYPHS_WRAPPER_H
 #define GFX_SVG_GLYPHS_WRAPPER_H
 
 #include "gfxFontUtils.h"
 #include "mozilla/gfx/2D.h"
 #include "nsString.h"
-#include "nsAutoPtr.h"
 #include "nsClassHashtable.h"
 #include "nsBaseHashtable.h"
 #include "nsHashKeys.h"
 #include "gfxPattern.h"
 #include "mozilla/gfx/UserData.h"
 #include "nsRefreshDriver.h"
 #include "DrawMode.h"
 
--- a/gfx/thebes/gfxTeeSurface.cpp
+++ b/gfx/thebes/gfxTeeSurface.cpp
@@ -1,15 +1,14 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * 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/. */
 
 #include "gfxTeeSurface.h"
-#include "nsAutoPtr.h"
 #include "nsTArray.h"
 
 #include "cairo-tee.h"
 
 gfxTeeSurface::gfxTeeSurface(cairo_surface_t *csurf)
 {
     Init(csurf, true);
 }
--- a/gfx/thebes/gfxTextRun.cpp
+++ b/gfx/thebes/gfxTextRun.cpp
@@ -2056,17 +2056,17 @@ gfxFontGroup::MakeHyphenTextRun(DrawTarg
 }
 
 gfxFloat
 gfxFontGroup::GetHyphenWidth(gfxTextRun::PropertyProvider *aProvider)
 {
     if (mHyphenWidth < 0) {
         RefPtr<DrawTarget> dt(aProvider->GetDrawTarget());
         if (dt) {
-            nsAutoPtr<gfxTextRun>
+            UniquePtr<gfxTextRun>
                 hyphRun(MakeHyphenTextRun(dt,
                                           aProvider->GetAppUnitsPerDevUnit()));
             mHyphenWidth = hyphRun.get() ? hyphRun->GetAdvanceWidth() : 0;
         }
     }
     return mHyphenWidth;
 }
 
@@ -2543,17 +2543,17 @@ gfxTextRun *
 gfxFontGroup::GetEllipsisTextRun(int32_t aAppUnitsPerDevPixel, uint32_t aFlags,
                                  LazyReferenceDrawTargetGetter& aRefDrawTargetGetter)
 {
     MOZ_ASSERT(!(aFlags & ~TEXT_ORIENT_MASK),
                "flags here should only be used to specify orientation");
     if (mCachedEllipsisTextRun &&
         (mCachedEllipsisTextRun->GetFlags() & TEXT_ORIENT_MASK) == aFlags &&
         mCachedEllipsisTextRun->GetAppUnitsPerDevUnit() == aAppUnitsPerDevPixel) {
-        return mCachedEllipsisTextRun;
+        return mCachedEllipsisTextRun.get();
     }
 
     // Use a Unicode ellipsis if the font supports it,
     // otherwise use three ASCII periods as fallback.
     gfxFont* firstFont = GetFirstValidFont(uint32_t(kEllipsisChar[0]));
     nsString ellipsis = firstFont->HasCharacter(kEllipsisChar[0])
         ? nsDependentString(kEllipsisChar,
                             ArrayLength(kEllipsisChar) - 1)
@@ -2565,17 +2565,17 @@ gfxFontGroup::GetEllipsisTextRun(int32_t
         refDT, nullptr, nullptr, nullptr, 0, aAppUnitsPerDevPixel
     };
     gfxTextRun* textRun =
         MakeTextRun(ellipsis.get(), ellipsis.Length(), &params,
                     aFlags | TEXT_IS_PERSISTENT, nullptr);
     if (!textRun) {
         return nullptr;
     }
-    mCachedEllipsisTextRun = textRun;
+    mCachedEllipsisTextRun.reset(textRun);
     textRun->ReleaseFontGroup(); // don't let the presence of a cached ellipsis
                                  // textrun prolong the fontgroup's life
     return textRun;
 }
 
 already_AddRefed<gfxFont>
 gfxFontGroup::FindFallbackFaceForChar(gfxFontFamily* aFamily, uint32_t aCh,
                                       int32_t aRunScript)
--- a/gfx/thebes/gfxTextRun.h
+++ b/gfx/thebes/gfxTextRun.h
@@ -1071,17 +1071,17 @@ protected:
 
     RefPtr<gfxUserFontSet> mUserFontSet;
     uint64_t mCurrGeneration;  // track the current user font set generation, rebuild font list if needed
 
     gfxTextPerfMetrics *mTextPerf;
 
     // Cache a textrun representing an ellipsis (useful for CSS text-overflow)
     // at a specific appUnitsPerDevPixel size and orientation
-    nsAutoPtr<gfxTextRun>   mCachedEllipsisTextRun;
+    mozilla::UniquePtr<gfxTextRun>   mCachedEllipsisTextRun;
 
     // cache the most recent pref font to avoid general pref font lookup
     RefPtr<gfxFontFamily> mLastPrefFamily;
     RefPtr<gfxFont>       mLastPrefFont;
     eFontPrefLang           mLastPrefLang;       // lang group for last pref font
     eFontPrefLang           mPageLang;
     bool                    mLastPrefFirstFont;  // is this the first font in the list of pref fonts for this lang group?
 
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -265,19 +265,19 @@ void
 gfxUserFontEntry::StoreUserFontData(gfxFontEntry* aFontEntry,
                                     bool aPrivate,
                                     const nsAString& aOriginalName,
                                     FallibleTArray<uint8_t>* aMetadata,
                                     uint32_t aMetaOrigLen,
                                     uint8_t aCompression)
 {
     if (!aFontEntry->mUserFontData) {
-        aFontEntry->mUserFontData = new gfxUserFontData;
+        aFontEntry->mUserFontData = MakeUnique<gfxUserFontData>();
     }
-    gfxUserFontData* userFontData = aFontEntry->mUserFontData;
+    gfxUserFontData* userFontData = aFontEntry->mUserFontData.get();
     userFontData->mSrcIndex = mSrcIndex;
     const gfxFontFaceSrc& src = mSrcList[mSrcIndex];
     switch (src.mSourceType) {
         case gfxFontFaceSrc::eSourceType_Local:
             userFontData->mLocalName = src.mLocalName;
             break;
         case gfxFontFaceSrc::eSourceType_URL:
             userFontData->mURI = src.mURI;
@@ -1115,17 +1115,17 @@ gfxUserFontSet::UserFontCache::CacheFont
     NS_ASSERTION(aFontEntry->mFamilyName.Length() != 0,
                  "caching a font associated with no family yet");
 
     // if caching is disabled, simply return
     if (Preferences::GetBool("gfx.downloadable_fonts.disable_cache")) {
         return;
     }
 
-    gfxUserFontData* data = aFontEntry->mUserFontData;
+    gfxUserFontData* data = aFontEntry->mUserFontData.get();
     if (data->mIsBuffer) {
 #ifdef DEBUG_USERFONT_CACHE
         printf("userfontcache skipped fontentry with buffer source: %p\n",
                aFontEntry);
 #endif
         return;
     }
 
--- a/gfx/thebes/gfxUserFontSet.h
+++ b/gfx/thebes/gfxUserFontSet.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_USER_FONT_SET_H
 #define GFX_USER_FONT_SET_H
 
 #include "gfxFont.h"
 #include "gfxFontFamilyList.h"
 #include "nsRefPtrHashtable.h"
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsIURI.h"
 #include "nsIPrincipal.h"
 #include "nsIScriptError.h"
 #include "nsURIHashKey.h"
 #include "mozilla/net/ReferrerPolicy.h"
 #include "gfxFontConstants.h"
 
--- a/gfx/thebes/gfxXlibSurface.cpp
+++ b/gfx/thebes/gfxXlibSurface.cpp
@@ -7,17 +7,16 @@
 
 #include "cairo.h"
 #include "cairo-xlib.h"
 #include "cairo-xlib-xrender.h"
 #include <X11/Xlibint.h>  /* For XESetCloseDisplay */
 #undef max // Xlibint.h defines this and it breaks std::max
 #undef min // Xlibint.h defines this and it breaks std::min
 
-#include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "nsAlgorithm.h"
 #include "mozilla/Preferences.h"
 #include <algorithm>
 #include "mozilla/CheckedInt.h"
 
 using namespace mozilla;
 
--- a/layout/inspector/nsFontFace.cpp
+++ b/layout/inspector/nsFontFace.cpp
@@ -182,17 +182,17 @@ nsFontFace::GetFormat(nsAString & aForma
 }
 
 NS_IMETHODIMP
 nsFontFace::GetMetadata(nsAString & aMetadata)
 {
   aMetadata.Truncate();
   if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
     NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
-    const gfxUserFontData* userFontData = mFontEntry->mUserFontData;
+    const gfxUserFontData* userFontData = mFontEntry->mUserFontData.get();
     if (userFontData->mMetadata.Length() && userFontData->mMetaOrigLen) {
       nsAutoCString str;
       str.SetLength(userFontData->mMetaOrigLen);
       if (str.Length() == userFontData->mMetaOrigLen) {
         switch (userFontData->mCompression) {
         case gfxUserFontData::kZlibCompression:
           {
             uLongf destLen = userFontData->mMetaOrigLen;