Bug 1551099. Stop using [array] in nsISDBResults. r=asuth
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 14 May 2019 17:23:54 +0000
changeset 532632 32b8f9006e8516679ca63880b1e029d42e1839d2
parent 532631 f17162f343b657c6ac2f57937ff49a1840465a6b
child 532633 5e5a2115d0da387463725c290d8f9b9a6cbd8e93
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1551099
milestone68.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 1551099. Stop using [array] in nsISDBResults. r=asuth Though given that getAsArray is unused and untested, maybe we should just remove it? Differential Revision: https://phabricator.services.mozilla.com/D30832
dom/simpledb/SDBResults.cpp
dom/simpledb/nsISDBResults.idl
--- a/dom/simpledb/SDBResults.cpp
+++ b/dom/simpledb/SDBResults.cpp
@@ -11,34 +11,24 @@
 namespace mozilla {
 namespace dom {
 
 SDBResult::SDBResult(const nsACString& aData) : mData(aData) {}
 
 NS_IMPL_ISUPPORTS(SDBResult, nsISDBResult)
 
 NS_IMETHODIMP
-SDBResult::GetAsArray(uint32_t* aDataLen, uint8_t** aData) {
-  MOZ_ASSERT(aDataLen);
-  MOZ_ASSERT(aData);
+SDBResult::GetAsArray(nsTArray<uint8_t>& aData) {
+  uint32_t length = mData.Length();
+  aData.SetLength(length);
 
-  if (mData.IsEmpty()) {
-    *aDataLen = 0;
-    *aData = nullptr;
-    return NS_OK;
+  if (length != 0) {
+    memcpy(aData.Elements(), mData.BeginReading(), length * sizeof(uint8_t));
   }
 
-  uint32_t length = mData.Length();
-
-  uint8_t* data = static_cast<uint8_t*>(moz_xmalloc(length * sizeof(uint8_t)));
-
-  memcpy(data, mData.BeginReading(), length * sizeof(uint8_t));
-
-  *aDataLen = length;
-  *aData = data;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SDBResult::GetAsArrayBuffer(JSContext* aCx, JS::MutableHandleValue _retval) {
   JS::Rooted<JSObject*> arrayBuffer(aCx);
   nsresult rv =
       nsContentUtils::CreateArrayBuffer(aCx, mData, arrayBuffer.address());
--- a/dom/simpledb/nsISDBResults.idl
+++ b/dom/simpledb/nsISDBResults.idl
@@ -4,15 +4,14 @@
  * 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 "nsISupports.idl"
 
 [scriptable, uuid(bca19e01-b34e-4a48-8875-2f4cb871febf)]
 interface nsISDBResult : nsISupports
 {
-  [must_use] void
-  getAsArray([optional] out uint32_t dataLen,
-             [array, retval, size_is(dataLen)] out uint8_t data);
+  [must_use] Array<uint8_t>
+  getAsArray();
 
   [must_use, implicit_jscontext] jsval
   getAsArrayBuffer();
 };