diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index 56e80412e35c..5edea6111358 100644 --- a/image/RasterImage.cpp +++ b/image/RasterImage.cpp @@ -1009,13 +1009,12 @@ RasterImage::Undefine(const char* prop) { } NS_IMETHODIMP -RasterImage::GetKeys(uint32_t* count, char*** keys) { +RasterImage::GetKeys(nsTArray& keys) { if (!mProperties) { - *count = 0; - *keys = nullptr; + keys.Clear(); return NS_OK; } - return mProperties->GetKeys(count, keys); + return mProperties->GetKeys(keys); } void RasterImage::Discard() { diff --git a/xpcom/ds/nsIProperties.idl b/xpcom/ds/nsIProperties.idl index a87e14443846..cc80466bb524 100644 --- a/xpcom/ds/nsIProperties.idl +++ b/xpcom/ds/nsIProperties.idl @@ -42,5 +42,5 @@ interface nsIProperties : nsISupports /** * Returns an array of the keys. */ - void getKeys(out uint32_t count, [array, size_is(count), retval] out string keys); + Array getKeys(); }; diff --git a/xpcom/ds/nsPersistentProperties.cpp b/xpcom/ds/nsPersistentProperties.cpp index 823182865169..cdb1a3cc55d3 100644 --- a/xpcom/ds/nsPersistentProperties.cpp +++ b/xpcom/ds/nsPersistentProperties.cpp @@ -543,7 +543,7 @@ nsPersistentProperties::Has(const char* aProp, bool* aResult) { } NS_IMETHODIMP -nsPersistentProperties::GetKeys(uint32_t* aCount, char*** aKeys) { +nsPersistentProperties::GetKeys(nsTArray& aKeys) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/xpcom/ds/nsProperties.cpp b/xpcom/ds/nsProperties.cpp index 9322adae37f7..2a480c1e8a2b 100644 --- a/xpcom/ds/nsProperties.cpp +++ b/xpcom/ds/nsProperties.cpp @@ -52,32 +52,14 @@ nsProperties::Has(const char* prop, bool* result) { } NS_IMETHODIMP -nsProperties::GetKeys(uint32_t* aCount, char*** aKeys) { - if (NS_WARN_IF(!aCount) || NS_WARN_IF(!aKeys)) { - return NS_ERROR_INVALID_ARG; - } - +nsProperties::GetKeys(nsTArray& aKeys) { uint32_t count = Count(); - char** keys = (char**)moz_xmalloc(count * sizeof(char*)); - uint32_t j = 0; + aKeys.SetCapacity(count); for (auto iter = this->Iter(); !iter.Done(); iter.Next()) { - const char* key = iter.Key(); - keys[j] = strdup(key); - - if (!keys[j]) { - // Free 'em all - for (uint32_t i = 0; i < j; i++) { - free(keys[i]); - } - free(keys); - return NS_ERROR_OUT_OF_MEMORY; - } - j++; + aKeys.AppendElement(iter.Key()); } - *aCount = count; - *aKeys = keys; return NS_OK; } diff --git a/xpcom/io/nsDirectoryService.cpp b/xpcom/io/nsDirectoryService.cpp index 83cf6290d8b1..469c6611e706 100644 --- a/xpcom/io/nsDirectoryService.cpp +++ b/xpcom/io/nsDirectoryService.cpp @@ -122,7 +122,7 @@ nsDirectoryService::Undefine(const char* aProp) { } NS_IMETHODIMP -nsDirectoryService::GetKeys(uint32_t* aCount, char*** aKeys) { +nsDirectoryService::GetKeys(nsTArray& aKeys) { return NS_ERROR_NOT_IMPLEMENTED; }