Bug 1222475 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in dom/; r=baku,bz,terrence
authorNathan Froyd <froydnj@mozilla.com>
Tue, 03 Nov 2015 13:29:19 -0500
changeset 282520 8eeb8603b17a97ef1699409a9146b9e912094ca7
parent 282519 c337204b80ad4f3da051a3037808891c5a3c2269
child 282521 de6d4626e415e1aa93dc00209197e6daeaf15ddd
push id71200
push usernfroyd@mozilla.com
push dateMon, 01 Feb 2016 14:32:36 +0000
treeherdermozilla-inbound@8eeb8603b17a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, bz, terrence
bugs1222475
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1222475 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in dom/; r=baku,bz,terrence
dom/archivereader/ArchiveZipEvent.cpp
dom/camera/GonkCameraControl.cpp
dom/encoding/TextDecoder.cpp
dom/encoding/TextEncoder.cpp
dom/html/HTMLFrameSetElement.cpp
dom/html/HTMLFrameSetElement.h
dom/ipc/TabParent.cpp
dom/mobilemessage/MobileMessageManager.cpp
dom/mobilemessage/ipc/SmsParent.cpp
dom/svg/SVGFEConvolveMatrixElement.cpp
dom/telephony/ipc/TelephonyChild.cpp
dom/xslt/xpath/txXPCOMExtensionFunction.cpp
dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
dom/xslt/xslt/txStylesheetCompiler.cpp
--- a/dom/archivereader/ArchiveZipEvent.cpp
+++ b/dom/archivereader/ArchiveZipEvent.cpp
@@ -5,16 +5,19 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ArchiveZipEvent.h"
 #include "ArchiveZipFile.h"
 
 #include "nsContentUtils.h"
 #include "nsCExternalHandlerService.h"
 
+#include "mozilla/UniquePtr.h"
+
+using namespace mozilla;
 using namespace mozilla::dom;
 
 USING_ARCHIVEREADER_NAMESPACE
 
 #ifndef PATH_MAX
 #  define PATH_MAX 65536 // The filename length is stored in 2 bytes
 #endif
 
@@ -186,27 +189,28 @@ ArchiveReaderZipEvent::Exec()
 
     // Point to the next item at the top of loop
     centralOffset += ZIPCENTRAL_SIZE + filenameLen + extraLen + commentLen;
     if (filenameLen == 0 || filenameLen >= PATH_MAX || centralOffset >= size) {
       return RunShare(NS_ERROR_FILE_CORRUPTED);
     }
 
     // Read the name:
-    nsAutoArrayPtr<char> filename(new char[filenameLen + 1]);
-    rv = inputStream->Read(filename, filenameLen, &ret);
+    auto filename = MakeUnique<char[]>(filenameLen + 1);
+    rv = inputStream->Read(filename.get(), filenameLen, &ret);
     if (NS_FAILED(rv) || ret != filenameLen) {
       return RunShare(NS_ERROR_UNEXPECTED);
     }
 
     filename[filenameLen] = 0;
 
     // We ignore the directories:
     if (filename[filenameLen - 1] != '/') {
-      mFileList.AppendElement(new ArchiveZipItem(filename, centralStruct, mEncoding));
+      mFileList.AppendElement(new ArchiveZipItem(filename.get(), centralStruct,
+                                                 mEncoding));
     }
 
     // Ignore the rest
     seekableStream->Seek(nsISeekableStream::NS_SEEK_CUR, extraLen + commentLen);
   }
 
   return RunShare(NS_OK);
 }
--- a/dom/camera/GonkCameraControl.cpp
+++ b/dom/camera/GonkCameraControl.cpp
@@ -2268,28 +2268,27 @@ nsGonkCameraControl::CreatePoster(Image*
     NS_IMETHODIMP Run() override
     {
 #ifdef MOZ_WIDGET_GONK
       // NV21 (yuv420sp) is 12 bits / pixel
       size_t srcLength = (mWidth * mHeight * 3 + 1) / 2;
 
       // ARGB is 32 bits / pixel
       size_t tmpLength = mWidth * mHeight * sizeof(uint32_t);
-      nsAutoArrayPtr<uint8_t> tmp;
-      tmp = new uint8_t[tmpLength];
+      UniquePtr<uint8_t[]> tmp = MakeUnique<uint8_t[]>(tmpLength);
 
       GrallocImage* nativeImage = static_cast<GrallocImage*>(mImage.get());
       android::sp<GraphicBuffer> graphicBuffer = nativeImage->GetGraphicBuffer();
 
       void* graphicSrc = nullptr;
       graphicBuffer->lock(GraphicBuffer::USAGE_SW_READ_MASK, &graphicSrc);
 
       uint32_t stride = mWidth * 4;
       int err = libyuv::ConvertToARGB(static_cast<uint8_t*>(graphicSrc),
-                                      srcLength, tmp, stride, 0, 0,
+                                      srcLength, tmp.get(), stride, 0, 0,
                                       mWidth, mHeight, mWidth, mHeight,
                                       libyuv::kRotate0, libyuv::FOURCC_NV21);
 
       graphicBuffer->unlock();
       graphicSrc = nullptr;
       graphicBuffer.clear();
       nativeImage = nullptr;
       mImage = nullptr;
@@ -2302,17 +2301,17 @@ nsGonkCameraControl::CreatePoster(Image*
       nsCOMPtr<imgIEncoder> encoder =
         do_CreateInstance("@mozilla.org/image/encoder;2?type=image/jpeg");
       if (NS_WARN_IF(!encoder)) {
         DOM_CAMERA_LOGE("CreatePoster: no JPEG encoder\n");
         return NS_OK;
       }
 
       nsString opt;
-      nsresult rv = encoder->InitFromData(tmp, tmpLength, mWidth,
+      nsresult rv = encoder->InitFromData(tmp.get(), tmpLength, mWidth,
                                           mHeight, stride,
                                           imgIEncoder::INPUT_FORMAT_HOSTARGB,
                                           opt);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         DOM_CAMERA_LOGE("CreatePoster: encoder init failed (0x%x)\n",
                         rv);
         return NS_OK;
       }
--- a/dom/encoding/TextDecoder.cpp
+++ b/dom/encoding/TextDecoder.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "mozilla/dom/TextDecoder.h"
 #include "mozilla/dom/EncodingUtils.h"
 #include "mozilla/dom/UnionTypes.h"
+#include "mozilla/UniquePtrExtensions.h"
 #include "nsContentUtils.h"
 #include <stdint.h>
 
 namespace mozilla {
 namespace dom {
 
 static const char16_t kReplacementChar = static_cast<char16_t>(0xFFFD);
 
@@ -60,28 +61,28 @@ TextDecoder::Decode(const char* aInput, 
   int32_t outLen;
   nsresult rv = mDecoder->GetMaxLength(aInput, aLength, &outLen);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return;
   }
   // Need a fallible allocator because the caller may be a content
   // and the content can specify the length of the string.
-  nsAutoArrayPtr<char16_t> buf(new (fallible) char16_t[outLen + 1]);
+  auto buf = MakeUniqueFallible<char16_t[]>(outLen + 1);
   if (!buf) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return;
   }
 
   int32_t length = aLength;
-  rv = mDecoder->Convert(aInput, &length, buf, &outLen);
+  rv = mDecoder->Convert(aInput, &length, buf.get(), &outLen);
   MOZ_ASSERT(mFatal || rv != NS_ERROR_ILLEGAL_INPUT);
   buf[outLen] = 0;
 
-  if (!aOutDecodedString.Append(buf, outLen, fallible)) {
+  if (!aOutDecodedString.Append(buf.get(), outLen, fallible)) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return;
   }
 
   // If the internal streaming flag of the decoder object is not set,
   // then reset the encoding algorithm state to the default values
   if (!aStream) {
     mDecoder->Reset();
--- a/dom/encoding/TextEncoder.cpp
+++ b/dom/encoding/TextEncoder.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "mozilla/dom/TextEncoder.h"
 #include "mozilla/dom/EncodingUtils.h"
+#include "mozilla/UniquePtrExtensions.h"
 #include "nsContentUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 void
 TextEncoder::Init(const nsAString& aEncoding, ErrorResult& aRv)
 {
@@ -49,28 +50,28 @@ TextEncoder::Encode(JSContext* aCx,
   const char16_t* data = aString.BeginReading();
   nsresult rv = mEncoder->GetMaxLength(data, srcLen, &maxLen);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return;
   }
   // Need a fallible allocator because the caller may be a content
   // and the content can specify the length of the string.
-  nsAutoArrayPtr<char> buf(new (fallible) char[maxLen + 1]);
+  auto buf = MakeUniqueFallible<char[]>(maxLen + 1);
   if (!buf) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return;
   }
 
   int32_t dstLen = maxLen;
-  rv = mEncoder->Convert(data, &srcLen, buf, &dstLen);
+  rv = mEncoder->Convert(data, &srcLen, buf.get(), &dstLen);
 
   // Now reset the encoding algorithm state to the default values for encoding.
   int32_t finishLen = maxLen - dstLen;
-  rv = mEncoder->Finish(buf + dstLen, &finishLen);
+  rv = mEncoder->Finish(&buf[dstLen], &finishLen);
   if (NS_SUCCEEDED(rv)) {
     dstLen += finishLen;
   }
 
   JSObject* outView = nullptr;
   if (NS_SUCCEEDED(rv)) {
     buf[dstLen] = '\0';
     JSAutoCompartment ac(aCx, aObj);
--- a/dom/html/HTMLFrameSetElement.cpp
+++ b/dom/html/HTMLFrameSetElement.cpp
@@ -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/. */
 
 #include "HTMLFrameSetElement.h"
 #include "mozilla/dom/HTMLFrameSetElementBinding.h"
 #include "mozilla/dom/EventHandlerBinding.h"
 #include "nsGlobalWindow.h"
+#include "mozilla/UniquePtrExtensions.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(FrameSet)
 
 namespace mozilla {
 namespace dom {
 
 HTMLFrameSetElement::~HTMLFrameSetElement()
 {
@@ -76,25 +77,25 @@ HTMLFrameSetElement::SetAttr(int32_t aNa
    *  we want to reflow.  So we set mCurrentRowColHint here, then call
    *  nsGenericHTMLElement::SetAttr, which will end up calling
    *  GetAttributeChangeHint and notifying layout with that hint.
    *  Once nsGenericHTMLElement::SetAttr returns, we want to go back to our
    *  normal hint, which is NS_STYLE_HINT_REFLOW.
    */
   if (aAttribute == nsGkAtoms::rows && aNameSpaceID == kNameSpaceID_None) {
     int32_t oldRows = mNumRows;
-    ParseRowCol(aValue, mNumRows, getter_Transfers(mRowSpecs));
+    ParseRowCol(aValue, mNumRows, &mRowSpecs);
     
     if (mNumRows != oldRows) {
       mCurrentRowColHint = NS_STYLE_HINT_FRAMECHANGE;
     }
   } else if (aAttribute == nsGkAtoms::cols &&
              aNameSpaceID == kNameSpaceID_None) {
     int32_t oldCols = mNumCols;
-    ParseRowCol(aValue, mNumCols, getter_Transfers(mColSpecs));
+    ParseRowCol(aValue, mNumCols, &mColSpecs);
 
     if (mNumCols != oldCols) {
       mCurrentRowColHint = NS_STYLE_HINT_FRAMECHANGE;
     }
   }
   
   rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aAttribute, aPrefix,
                                      aValue, aNotify);
@@ -111,29 +112,29 @@ HTMLFrameSetElement::GetRowSpec(int32_t 
   NS_PRECONDITION(aSpecs, "Must have a pointer to an array of nsFramesetSpecs");
   *aNumValues = 0;
   *aSpecs = nullptr;
   
   if (!mRowSpecs) {
     const nsAttrValue* value = GetParsedAttr(nsGkAtoms::rows);
     if (value && value->Type() == nsAttrValue::eString) {
       nsresult rv = ParseRowCol(value->GetStringValue(), mNumRows,
-                                getter_Transfers(mRowSpecs));
+                                &mRowSpecs);
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     if (!mRowSpecs) {  // we may not have had an attr or had an empty attr
-      mRowSpecs = new nsFramesetSpec[1];
+      mRowSpecs = MakeUnique<nsFramesetSpec[]>(1);
       mNumRows = 1;
       mRowSpecs[0].mUnit  = eFramesetUnit_Relative;
       mRowSpecs[0].mValue = 1;
     }
   }
 
-  *aSpecs = mRowSpecs;
+  *aSpecs = mRowSpecs.get();
   *aNumValues = mNumRows;
   return NS_OK;
 }
 
 nsresult
 HTMLFrameSetElement::GetColSpec(int32_t *aNumValues,
                                 const nsFramesetSpec** aSpecs)
 {
@@ -141,29 +142,29 @@ HTMLFrameSetElement::GetColSpec(int32_t 
   NS_PRECONDITION(aSpecs, "Must have a pointer to an array of nsFramesetSpecs");
   *aNumValues = 0;
   *aSpecs = nullptr;
 
   if (!mColSpecs) {
     const nsAttrValue* value = GetParsedAttr(nsGkAtoms::cols);
     if (value && value->Type() == nsAttrValue::eString) {
       nsresult rv = ParseRowCol(value->GetStringValue(), mNumCols,
-                                getter_Transfers(mColSpecs));
+                                &mColSpecs);
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     if (!mColSpecs) {  // we may not have had an attr or had an empty attr
-      mColSpecs = new nsFramesetSpec[1];
+      mColSpecs = MakeUnique<nsFramesetSpec[]>(1);
       mNumCols = 1;
       mColSpecs[0].mUnit  = eFramesetUnit_Relative;
       mColSpecs[0].mValue = 1;
     }
   }
 
-  *aSpecs = mColSpecs;
+  *aSpecs = mColSpecs.get();
   *aNumValues = mNumCols;
   return NS_OK;
 }
 
 
 bool
 HTMLFrameSetElement::ParseAttribute(int32_t aNamespaceID,
                                     nsIAtom* aAttribute,
@@ -200,17 +201,17 @@ HTMLFrameSetElement::GetAttributeChangeH
 }
 
 /**
  * Translate a "rows" or "cols" spec into an array of nsFramesetSpecs
  */
 nsresult
 HTMLFrameSetElement::ParseRowCol(const nsAString & aValue,
                                  int32_t& aNumSpecs,
-                                 nsFramesetSpec** aSpecs) 
+                                 UniquePtr<nsFramesetSpec[]>* aSpecs)
 {
   if (aValue.IsEmpty()) {
     aNumSpecs = 0;
     *aSpecs = nullptr;
     return NS_OK;
   }
 
   static const char16_t sAster('*');
@@ -228,17 +229,17 @@ HTMLFrameSetElement::ParseRowCol(const n
                 "Too many frameset specs allowed to allocate");
   int32_t commaX = spec.FindChar(sComma);
   int32_t count = 1;
   while (commaX != kNotFound && count < NS_MAX_FRAMESET_SPEC_COUNT) {
     count++;
     commaX = spec.FindChar(sComma, commaX + 1);
   }
 
-  nsFramesetSpec* specs = new (fallible) nsFramesetSpec[count];
+  auto specs = MakeUniqueFallible<nsFramesetSpec[]>(count);
   if (!specs) {
     *aSpecs = nullptr;
     aNumSpecs = 0;
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   // Pre-grab the compat mode; we may need it later in the loop.
   bool isInQuirks = InNavQuirksMode(OwnerDoc());
@@ -322,18 +323,18 @@ HTMLFrameSetElement::ParseRowCol(const n
         specs[i].mValue = 0;
       }
       start = end + 1;
     }
   }
 
   aNumSpecs = count;
   // Transfer ownership to caller here
-  *aSpecs = specs;
-  
+  *aSpecs = Move(specs);
+
   return NS_OK;
 }
 
 bool
 HTMLFrameSetElement::IsEventAttributeName(nsIAtom *aName)
 {
   return nsContentUtils::IsEventAttributeName(aName,
                                               EventNameType_HTML |
--- a/dom/html/HTMLFrameSetElement.h
+++ b/dom/html/HTMLFrameSetElement.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 HTMLFrameSetElement_h
 #define HTMLFrameSetElement_h
 
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "nsIDOMHTMLFrameSetElement.h"
 #include "nsGenericHTMLElement.h"
 
 /**
  * The nsFramesetUnit enum is used to denote the type of each entry
  * in the row or column spec.
  */
 enum nsFramesetUnit {
@@ -139,18 +140,18 @@ public:
 
 protected:
   virtual ~HTMLFrameSetElement();
 
   virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
 
 private:
   nsresult ParseRowCol(const nsAString& aValue,
-                       int32_t&         aNumSpecs,
-                       nsFramesetSpec** aSpecs);
+                       int32_t& aNumSpecs,
+                       UniquePtr<nsFramesetSpec[]>* aSpecs);
 
   /**
    * The number of size specs in our "rows" attr
    */
   int32_t          mNumRows;
   /**
    * The number of size specs in our "cols" attr
    */
@@ -158,19 +159,19 @@ private:
   /**
    * The style hint to return for the rows/cols attrs in
    * GetAttributeChangeHint
    */
   nsChangeHint      mCurrentRowColHint;
   /**
    * The parsed representation of the "rows" attribute
    */
-  nsAutoArrayPtr<nsFramesetSpec>  mRowSpecs; // parsed, non-computed dimensions
+  UniquePtr<nsFramesetSpec[]>  mRowSpecs; // parsed, non-computed dimensions
   /**
    * The parsed representation of the "cols" attribute
    */
-  nsAutoArrayPtr<nsFramesetSpec>  mColSpecs; // parsed, non-computed dimensions
+  UniquePtr<nsFramesetSpec[]>  mColSpecs; // parsed, non-computed dimensions
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // HTMLFrameSetElement_h
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -33,16 +33,17 @@
 #include "mozilla/layers/InputAPZContext.h"
 #include "mozilla/layout/RenderFrameParent.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/net/NeckoChild.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
+#include "mozilla/UniquePtr.h"
 #include "mozilla/unused.h"
 #include "BlobParent.h"
 #include "nsCOMPtr.h"
 #include "nsContentAreaDragDrop.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsFocusManager.h"
 #include "nsFrameLoader.h"
@@ -2120,35 +2121,35 @@ TabParent::RecvRequestFocus(const bool& 
 
 bool
 TabParent::RecvEnableDisableCommands(const nsString& aAction,
                                      nsTArray<nsCString>&& aEnabledCommands,
                                      nsTArray<nsCString>&& aDisabledCommands)
 {
   nsCOMPtr<nsIRemoteBrowser> remoteBrowser = do_QueryInterface(mFrameElement);
   if (remoteBrowser) {
-    nsAutoArrayPtr<const char*> enabledCommands, disabledCommands;
+    UniquePtr<const char*[]> enabledCommands, disabledCommands;
 
     if (aEnabledCommands.Length()) {
-      enabledCommands = new const char* [aEnabledCommands.Length()];
+      enabledCommands = MakeUnique<const char*[]>(aEnabledCommands.Length());
       for (uint32_t c = 0; c < aEnabledCommands.Length(); c++) {
         enabledCommands[c] = aEnabledCommands[c].get();
       }
     }
 
     if (aDisabledCommands.Length()) {
-      disabledCommands = new const char* [aDisabledCommands.Length()];
+      disabledCommands = MakeUnique<const char*[]>(aDisabledCommands.Length());
       for (uint32_t c = 0; c < aDisabledCommands.Length(); c++) {
         disabledCommands[c] = aDisabledCommands[c].get();
       }
     }
 
     remoteBrowser->EnableDisableCommands(aAction,
-                                         aEnabledCommands.Length(), enabledCommands,
-                                         aDisabledCommands.Length(), disabledCommands);
+                                         aEnabledCommands.Length(), enabledCommands.get(),
+                                         aDisabledCommands.Length(), disabledCommands.get());
   }
 
   return true;
 }
 
 NS_IMETHODIMP
 TabParent::GetChildProcessOffset(int32_t* aOutCssX, int32_t* aOutCssY)
 {
--- a/dom/mobilemessage/MobileMessageManager.cpp
+++ b/dom/mobilemessage/MobileMessageManager.cpp
@@ -19,16 +19,17 @@
 #include "mozilla/dom/MozMessageDeletedEvent.h"
 #include "mozilla/dom/MozMmsEvent.h"
 #include "mozilla/dom/MozMobileMessageManagerBinding.h"
 #include "mozilla/dom/MozSmsEvent.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
+#include "mozilla/UniquePtr.h"
 #include "nsIMmsService.h"
 #include "nsIMobileMessageCallback.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "nsIMobileMessageService.h"
 #include "nsIObserverService.h"
 #include "nsISmsService.h"
 #include "nsServiceManagerUtils.h" // For do_GetService()
 
@@ -419,25 +420,25 @@ MobileMessageManager::GetMessages(const 
   }
 
   bool hasEndDate = !aFilter.mEndDate.IsNull();
   uint64_t endDate = 0;
   if (hasEndDate) {
     endDate = aFilter.mEndDate.Value();
   }
 
-  nsAutoArrayPtr<const char16_t*> ptrNumbers;
+  UniquePtr<const char16_t*[]> ptrNumbers;
   uint32_t numbersCount = 0;
   if (!aFilter.mNumbers.IsNull() &&
       aFilter.mNumbers.Value().Length()) {
     const FallibleTArray<nsString>& numbers = aFilter.mNumbers.Value();
     uint32_t index;
 
     numbersCount = numbers.Length();
-    ptrNumbers = new const char16_t* [numbersCount];
+    ptrNumbers = MakeUnique<const char16_t*[]>(numbersCount);
     for (index = 0; index < numbersCount; index++) {
       ptrNumbers[index] = numbers[index].get();
     }
   }
 
   nsString delivery;
   delivery.SetIsVoid(true);
   if (!aFilter.mDelivery.IsNull()) {
@@ -459,17 +460,17 @@ MobileMessageManager::GetMessages(const 
     threadId = aFilter.mThreadId.Value();
   }
 
   RefPtr<MobileMessageCursorCallback> cursorCallback =
     new MobileMessageCursorCallback();
   nsCOMPtr<nsICursorContinueCallback> continueCallback;
   nsresult rv = dbService->CreateMessageCursor(hasStartDate, startDate,
                                                hasEndDate, endDate,
-                                               ptrNumbers, numbersCount,
+                                               ptrNumbers.get(), numbersCount,
                                                delivery,
                                                hasRead, read,
                                                hasThreadId, threadId,
                                                aReverse, cursorCallback,
                                                getter_AddRefs(continueCallback));
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
--- a/dom/mobilemessage/ipc/SmsParent.cpp
+++ b/dom/mobilemessage/ipc/SmsParent.cpp
@@ -17,16 +17,17 @@
 #include "MmsMessageInternal.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "MobileMessageThreadInternal.h"
 #include "mozilla/dom/ipc/BlobParent.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
+#include "mozilla/UniquePtr.h"
 #include "nsContentUtils.h"
 #include "nsTArrayHelpers.h"
 #include "xpcpublic.h"
 #include "nsServiceManagerUtils.h"
 #include "DeletedMessageInfo.h"
 
 namespace mozilla {
 namespace dom {
@@ -825,32 +826,32 @@ MobileMessageCursorParent::DoRequest(con
   nsresult rv = NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
     do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
   if (dbService) {
     const SmsFilterData& filter = aRequest.filter();
 
     const nsTArray<nsString>& numbers = filter.numbers();
-    nsAutoArrayPtr<const char16_t*> ptrNumbers;
+    UniquePtr<const char16_t*[]> ptrNumbers;
     uint32_t numbersCount = numbers.Length();
     if (numbersCount) {
       uint32_t index;
 
-      ptrNumbers = new const char16_t* [numbersCount];
+      ptrNumbers = MakeUnique<const char16_t*[]>(numbersCount);
       for (index = 0; index < numbersCount; index++) {
         ptrNumbers[index] = numbers[index].get();
       }
     }
 
     rv = dbService->CreateMessageCursor(filter.hasStartDate(),
                                         filter.startDate(),
                                         filter.hasEndDate(),
                                         filter.endDate(),
-                                        ptrNumbers, numbersCount,
+                                        ptrNumbers.get(), numbersCount,
                                         filter.delivery(),
                                         filter.hasRead(),
                                         filter.read(),
                                         filter.hasThreadId(),
                                         filter.threadId(),
                                         aRequest.reverse(),
                                         this,
                                         getter_AddRefs(mContinueCallback));
--- a/dom/svg/SVGFEConvolveMatrixElement.cpp
+++ b/dom/svg/SVGFEConvolveMatrixElement.cpp
@@ -1,16 +1,18 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "mozilla/dom/SVGFEConvolveMatrixElement.h"
 #include "mozilla/dom/SVGFEConvolveMatrixElementBinding.h"
+#include "mozilla/UniquePtr.h"
+#include "mozilla/UniquePtrExtensions.h"
 #include "DOMSVGAnimatedNumberList.h"
 #include "nsSVGUtils.h"
 #include "nsSVGFilterInstance.h"
 
 NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEConvolveMatrix)
 
 using namespace mozilla::gfx;
 
@@ -198,17 +200,17 @@ SVGFEConvolveMatrixElement::GetPrimitive
       return failureDescription;
   } else {
     targetY = orderY / 2;
   }
 
   if (orderX > NS_SVG_OFFSCREEN_MAX_DIMENSION ||
       orderY > NS_SVG_OFFSCREEN_MAX_DIMENSION)
     return failureDescription;
-  nsAutoArrayPtr<float> kernel(new (fallible) float[orderX * orderY]);
+  UniquePtr<float[]> kernel = MakeUniqueFallible<float[]>(orderX * orderY);
   if (!kernel)
     return failureDescription;
   for (uint32_t i = 0; i < kmLength; i++) {
     kernel[kmLength - 1 - i] = kernelMatrix[i];
   }
 
   float divisor;
   if (mNumberAttributes[DIVISOR].IsExplicitlySet()) {
--- a/dom/telephony/ipc/TelephonyChild.cpp
+++ b/dom/telephony/ipc/TelephonyChild.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "TelephonyChild.h"
 
 #include "mozilla/dom/telephony/TelephonyDialCallback.h"
+#include "mozilla/UniquePtr.h"
 #include "TelephonyIPCService.h"
 
 USING_TELEPHONY_NAMESPACE
 
 /*******************************************************************************
  * TelephonyChild
  ******************************************************************************/
 
@@ -207,22 +208,23 @@ TelephonyRequestChild::DoResponse(const 
       break;
     case AdditionalInformation::Tuint16_t:
       callback->NotifyDialMMISuccessWithInteger(statusMessage, info.get_uint16_t());
       break;
     case AdditionalInformation::TArrayOfnsString: {
       uint32_t count = info.get_ArrayOfnsString().Length();
       const nsTArray<nsString>& additionalInformation = info.get_ArrayOfnsString();
 
-      nsAutoArrayPtr<const char16_t*> additionalInfoPtrs(new const char16_t*[count]);
+      auto additionalInfoPtrs = MakeUnique<const char16_t*[]>(count);
       for (size_t i = 0; i < count; ++i) {
         additionalInfoPtrs[i] = additionalInformation[i].get();
       }
 
-      callback->NotifyDialMMISuccessWithStrings(statusMessage, count, additionalInfoPtrs);
+      callback->NotifyDialMMISuccessWithStrings(statusMessage, count,
+                                                additionalInfoPtrs.get());
       break;
     }
     case AdditionalInformation::TArrayOfnsMobileCallForwardingOptions: {
       uint32_t count = info.get_ArrayOfnsMobileCallForwardingOptions().Length();
 
       nsTArray<nsCOMPtr<nsIMobileCallForwardingOptions>> results;
       for (uint32_t i = 0; i < count; i++) {
         // Use dont_AddRef here because these instances are already AddRef-ed in
--- a/dom/xslt/xpath/txXPCOMExtensionFunction.cpp
+++ b/dom/xslt/xpath/txXPCOMExtensionFunction.cpp
@@ -12,18 +12,21 @@
 #include "txExpr.h"
 #include "txIFunctionEvaluationContext.h"
 #include "txIXPathContext.h"
 #include "txNodeSetAdaptor.h"
 #include "txXPathTreeWalker.h"
 #include "xptcall.h"
 #include "txXPathObjectAdaptor.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
+#include "nsContentUtils.h"
 #include "nsIClassInfo.h"
 #include "nsIInterfaceInfo.h"
+#include "js/RootingAPI.h"
 
 NS_IMPL_ISUPPORTS(txXPathObjectAdaptor, txIXPathObject)
 
 class txFunctionEvaluationContext final : public txIFunctionEvaluationContext
 {
 public:
     txFunctionEvaluationContext(txIEvalContext *aContext, nsISupports *aState);
 
@@ -290,33 +293,48 @@ txXPCOMExtensionFunctionCall::GetParamTy
         default:
         {
             // XXX Error!
             return eUNKNOWN;
         }
     }
 }
 
-class txParamArrayHolder
+class txParamArrayHolder : public JS::Traceable
 {
 public:
     txParamArrayHolder()
         : mCount(0)
     {
     }
+    txParamArrayHolder(txParamArrayHolder&& rhs)
+      : mArray(mozilla::Move(rhs.mArray))
+      , mCount(rhs.mCount)
+    {
+        rhs.mCount = 0;
+    }
     ~txParamArrayHolder();
 
     bool Init(uint8_t aCount);
     operator nsXPTCVariant*() const
     {
-      return mArray;
+      return mArray.get();
+    }
+
+    static void trace(txParamArrayHolder* holder, JSTracer* trc) { holder->trace(trc); }
+    void trace(JSTracer* trc) {
+        for (uint8_t i = 0; i < mCount; ++i) {
+            if (mArray[i].type == nsXPTType::T_JSVAL) {
+                JS::UnsafeTraceRoot(trc, &mArray[i].val.j, "txParam value");
+            }
+        }
     }
 
 private:
-    nsAutoArrayPtr<nsXPTCVariant> mArray;
+    mozilla::UniquePtr<nsXPTCVariant[]> mArray;
     uint8_t mCount;
 };
 
 txParamArrayHolder::~txParamArrayHolder()
 {
     uint8_t i;
     for (i = 0; i < mCount; ++i) {
         nsXPTCVariant &variant = mArray[i];
@@ -333,18 +351,22 @@ txParamArrayHolder::~txParamArrayHolder(
         }
     }
 }
 
 bool
 txParamArrayHolder::Init(uint8_t aCount)
 {
     mCount = aCount;
-    mArray = new nsXPTCVariant[mCount];
-    memset(mArray, 0, mCount * sizeof(nsXPTCVariant));
+    mArray = mozilla::MakeUnique<nsXPTCVariant[]>(mCount);
+    if (!mArray) {
+        return false;
+    }
+
+    memset(mArray.get(), 0, mCount * sizeof(nsXPTCVariant));
 
     return true;
 }
 
 nsresult
 txXPCOMExtensionFunctionCall::evaluate(txIEvalContext* aContext,
                                        txAExprResult** aResult)
 {
@@ -358,18 +380,18 @@ txXPCOMExtensionFunctionCall::evaluate(t
 
     const nsXPTMethodInfo *methodInfo;
     rv = info->GetMethodInfo(mMethodIndex, &methodInfo);
     NS_ENSURE_SUCCESS(rv, rv);
 
     uint8_t paramCount = methodInfo->GetParamCount();
     uint8_t inArgs = paramCount - 1;
 
-    txParamArrayHolder invokeParams;
-    if (!invokeParams.Init(paramCount)) {
+    JS::Rooted<txParamArrayHolder> invokeParams(nsContentUtils::RootingCxForThread());
+    if (!invokeParams.get().Init(paramCount)) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
     const nsXPTParamInfo &paramInfo = methodInfo->GetParam(0);
     txArgumentType type = GetParamType(paramInfo, info);
     if (type == eUNKNOWN) {
         return NS_ERROR_FAILURE;
     }
@@ -380,17 +402,17 @@ txXPCOMExtensionFunctionCall::evaluate(t
         if (paramInfo.IsOut()) {
             // We don't support out values.
             return NS_ERROR_FAILURE;
         }
 
         // Create context wrapper.
         context = new txFunctionEvaluationContext(aContext, mState);
 
-        nsXPTCVariant &invokeParam = invokeParams[0];
+        nsXPTCVariant &invokeParam = invokeParams.get()[0];
         invokeParam.type = paramInfo.GetType();
         invokeParam.SetValNeedsCleanup();
         NS_ADDREF((txIFunctionEvaluationContext*&)invokeParam.val.p = context);
 
         // Skip first argument, since it's the context.
         paramStart = 1;
     }
     else {
@@ -407,17 +429,17 @@ txXPCOMExtensionFunctionCall::evaluate(t
         Expr* expr = mParams[i - paramStart];
 
         const nsXPTParamInfo &paramInfo = methodInfo->GetParam(i);
         txArgumentType type = GetParamType(paramInfo, info);
         if (type == eUNKNOWN) {
             return NS_ERROR_FAILURE;
         }
 
-        nsXPTCVariant &invokeParam = invokeParams[i];
+        nsXPTCVariant &invokeParam = invokeParams.get()[i];
         if (paramInfo.IsOut()) {
             // We don't support out values.
             return NS_ERROR_FAILURE;
         }
 
         invokeParam.type = paramInfo.GetType();
         switch (type) {
             case eNODESET:
@@ -495,31 +517,31 @@ txXPCOMExtensionFunctionCall::evaluate(t
     }
 
     const nsXPTParamInfo &returnInfo = methodInfo->GetParam(inArgs);
     txArgumentType returnType = GetParamType(returnInfo, info);
     if (returnType == eUNKNOWN) {
         return NS_ERROR_FAILURE;
     }
 
-    nsXPTCVariant &returnParam = invokeParams[inArgs];
+    nsXPTCVariant &returnParam = invokeParams.get()[inArgs];
     returnParam.type = returnInfo.GetType();
     if (returnType == eSTRING) {
         nsString *value = new nsString();
         returnParam.SetValNeedsCleanup();
         returnParam.val.p = value;
     }
     else {
         returnParam.SetIndirect();
         if (returnType == eNODESET || returnType == eOBJECT) {
             returnParam.SetValNeedsCleanup();
         }
     }
 
-    rv = NS_InvokeByIndex(mHelper, mMethodIndex, paramCount, invokeParams);
+    rv = NS_InvokeByIndex(mHelper, mMethodIndex, paramCount, invokeParams.get());
 
     // In case someone is holding on to the txFunctionEvaluationContext which
     // could thus stay alive longer than this function.
     if (context) {
         context->ClearContext();
     }
 
     NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
+++ b/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
@@ -34,16 +34,17 @@
 #include "nsAttrName.h"
 #include "nsIScriptError.h"
 #include "nsIURL.h"
 #include "nsCORSListenerProxy.h"
 #include "nsError.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/EncodingUtils.h"
+#include "mozilla/UniquePtr.h"
 
 using namespace mozilla;
 using mozilla::dom::EncodingUtils;
 using mozilla::net::ReferrerPolicy;
 
 static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
 
 static void
@@ -518,35 +519,35 @@ static nsresult
 handleNode(nsINode* aNode, txStylesheetCompiler* aCompiler)
 {
     nsresult rv = NS_OK;
     
     if (aNode->IsElement()) {
         dom::Element* element = aNode->AsElement();
 
         uint32_t attsCount = element->GetAttrCount();
-        nsAutoArrayPtr<txStylesheetAttr> atts;
+        UniquePtr<txStylesheetAttr[]> atts;
         if (attsCount > 0) {
-            atts = new txStylesheetAttr[attsCount];
+            atts = MakeUnique<txStylesheetAttr[]>(attsCount);
             uint32_t counter;
             for (counter = 0; counter < attsCount; ++counter) {
                 txStylesheetAttr& att = atts[counter];
                 const nsAttrName* name = element->GetAttrNameAt(counter);
                 att.mNamespaceID = name->NamespaceID();
                 att.mLocalName = name->LocalName();
                 att.mPrefix = name->GetPrefix();
                 element->GetAttr(att.mNamespaceID, att.mLocalName, att.mValue);
             }
         }
 
         mozilla::dom::NodeInfo *ni = element->NodeInfo();
 
         rv = aCompiler->startElement(ni->NamespaceID(),
                                      ni->NameAtom(),
-                                     ni->GetPrefixAtom(), atts,
+                                     ni->GetPrefixAtom(), atts.get(),
                                      attsCount);
         NS_ENSURE_SUCCESS(rv, rv);
 
         // explicitly destroy the attrs here since we no longer need it
         atts = nullptr;
 
         for (nsIContent* child = element->GetFirstChild();
              child;
--- a/dom/xslt/xslt/txStylesheetCompiler.cpp
+++ b/dom/xslt/xslt/txStylesheetCompiler.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; 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 "mozilla/ArrayUtils.h"
 #include "mozilla/Move.h"
+#include "mozilla/UniquePtr.h"
 
 #include "txStylesheetCompiler.h"
 #include "txStylesheetCompileHandlers.h"
 #include "nsGkAtoms.h"
 #include "txURIUtils.h"
 #include "nsWhitespaceTokenizer.h"
 #include "txStylesheet.h"
 #include "txInstructions.h"
@@ -119,19 +120,19 @@ txStylesheetCompiler::startElement(const
         // ignore content after failure
         // XXX reevaluate once expat stops on failure
         return NS_OK;
     }
 
     nsresult rv = flushCharacters();
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsAutoArrayPtr<txStylesheetAttr> atts;
+    UniquePtr<txStylesheetAttr[]> atts;
     if (aAttrCount > 0) {
-        atts = new txStylesheetAttr[aAttrCount];
+        atts = MakeUnique<txStylesheetAttr[]>(aAttrCount);
     }
 
     bool hasOwnNamespaceMap = false;
     int32_t i;
     for (i = 0; i < aAttrCount; ++i) {
         rv = XMLUtils::splitExpatName(aAttrs[i * 2],
                                       getter_AddRefs(atts[i].mPrefix),
                                       getter_AddRefs(atts[i].mLocalName),
@@ -164,17 +165,17 @@ txStylesheetCompiler::startElement(const
     }
 
     nsCOMPtr<nsIAtom> prefix, localname;
     int32_t namespaceID;
     rv = XMLUtils::splitExpatName(aName, getter_AddRefs(prefix),
                                   getter_AddRefs(localname), &namespaceID);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    return startElementInternal(namespaceID, localname, prefix, atts,
+    return startElementInternal(namespaceID, localname, prefix, atts.get(),
                                 aAttrCount);
 }
 
 nsresult
 txStylesheetCompiler::startElementInternal(int32_t aNamespaceID,
                                            nsIAtom* aLocalName,
                                            nsIAtom* aPrefix,
                                            txStylesheetAttr* aAttributes,