From dbec7d4975099edd707ba1dec71ce4200774a17e Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Wed, 13 Feb 2019 21:42:08 +0000 Subject: [PATCH] Bug 1526382 - Part 2: Make nsIClassInfo use Array for 'interfaces', r=mccr8 This is a follow-up to the previous part, which actually changes one of these callers to use Array instead of [array] nsIIDPtr. From doing this patch, it seems like we should consider changing the type `nsIIDRef` to instead simply be `nsIID`, and treat it more like the `AString` types from the POV of XPIDL. `nsIIDPtr` would then continue to exist for backwards compatibility, but we can probably remove almost all current consumers over time. Depends on D19175 Differential Revision: https://phabricator.services.mozilla.com/D19176 --HG-- extra : moz-landing-system : lando --- dom/file/uri/BlobURL.cpp | 5 +- js/xpconnect/src/XPCComponents.cpp | 60 ++++-------- js/xpconnect/src/XPCRuntimeService.cpp | 10 +- js/xpconnect/src/XPCWrappedNativeInfo.cpp | 92 +++++++------------ js/xpconnect/tests/unit/component-blob.js | 6 +- js/xpconnect/tests/unit/component-file.js | 6 +- js/xpconnect/tests/unit/component_import.js | 11 +-- js/xpconnect/tests/unit/test_import.js | 8 +- modules/libjar/nsJARURI.cpp | 5 +- netwerk/base/nsSimpleURI.cpp | 5 +- netwerk/base/nsSocketTransport2.cpp | 4 +- netwerk/base/nsStandardURL.cpp | 5 +- .../manager/ssl/TransportSecurityInfo.cpp | 5 +- security/manager/ssl/nsNSSCertificate.cpp | 5 +- storage/mozStorageAsyncStatement.cpp | 4 +- storage/mozStorageStatement.cpp | 4 +- .../update/tests/data/xpcshellUtilsAUS.js | 6 +- xpcom/base/nsClassInfoImpl.cpp | 4 +- xpcom/base/nsIClassInfoImpl.h | 26 +++--- xpcom/base/nsISupportsImpl.h | 78 ++++++++-------- xpcom/components/nsIClassInfo.idl | 12 +-- xpcom/threads/nsThread.cpp | 4 +- 22 files changed, 141 insertions(+), 224 deletions(-) diff --git a/dom/file/uri/BlobURL.cpp b/dom/file/uri/BlobURL.cpp index f6819c72ef05..0285b4ebb2a1 100644 --- a/dom/file/uri/BlobURL.cpp +++ b/dom/file/uri/BlobURL.cpp @@ -166,9 +166,8 @@ BlobURL::Mutate(nsIURIMutator** aMutator) { // nsIClassInfo methods: NS_IMETHODIMP -BlobURL::GetInterfaces(uint32_t* count, nsIID*** array) { - *count = 0; - *array = nullptr; +BlobURL::GetInterfaces(nsTArray& array) { + array.Clear(); return NS_OK; } diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index bdd13fec2943..264d4221bd33 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -118,13 +118,9 @@ class nsXPCComponents_Interfaces final : public nsIXPCComponents_Interfaces, }; NS_IMETHODIMP -nsXPCComponents_Interfaces::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - *aCount = 2; - nsIID** array = static_cast(moz_xmalloc(2 * sizeof(nsIID*))); - *aArray = array; - - array[0] = NS_GET_IID(nsIXPCComponents_Interfaces).Clone(); - array[1] = NS_GET_IID(nsIXPCScriptable).Clone(); +nsXPCComponents_Interfaces::GetInterfaces(nsTArray& aArray) { + aArray = nsTArray{NS_GET_IID(nsIXPCComponents_Interfaces), + NS_GET_IID(nsIXPCScriptable)}; return NS_OK; } @@ -275,13 +271,9 @@ class nsXPCComponents_Classes final : public nsIXPCComponents_Classes, /***************************************************************************/ NS_IMETHODIMP -nsXPCComponents_Classes::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - *aCount = 2; - nsIID** array = static_cast(moz_xmalloc(2 * sizeof(nsIID*))); - *aArray = array; - - array[0] = NS_GET_IID(nsIXPCComponents_Classes).Clone(); - array[1] = NS_GET_IID(nsIXPCScriptable).Clone(); +nsXPCComponents_Classes::GetInterfaces(nsTArray& aArray) { + aArray = nsTArray{NS_GET_IID(nsIXPCComponents_Classes), + NS_GET_IID(nsIXPCScriptable)}; return NS_OK; } @@ -432,13 +424,9 @@ class nsXPCComponents_Results final : public nsIXPCComponents_Results, /***************************************************************************/ NS_IMETHODIMP -nsXPCComponents_Results::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - *aCount = 2; - nsIID** array = static_cast(moz_xmalloc(2 * sizeof(nsIID*))); - *aArray = array; - - array[0] = NS_GET_IID(nsIXPCComponents_Results).Clone(); - array[1] = NS_GET_IID(nsIXPCScriptable).Clone(); +nsXPCComponents_Results::GetInterfaces(nsTArray& aArray) { + aArray = nsTArray{NS_GET_IID(nsIXPCComponents_Results), + NS_GET_IID(nsIXPCScriptable)}; return NS_OK; } @@ -577,13 +565,9 @@ class nsXPCComponents_ID final : public nsIXPCComponents_ID, /***************************************************************************/ NS_IMETHODIMP -nsXPCComponents_ID::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - *aCount = 2; - nsIID** array = static_cast(moz_xmalloc(2 * sizeof(nsIID*))); - *aArray = array; - - array[0] = NS_GET_IID(nsIXPCComponents_ID).Clone(); - array[1] = NS_GET_IID(nsIXPCScriptable).Clone(); +nsXPCComponents_ID::GetInterfaces(nsTArray& aArray) { + aArray = nsTArray{NS_GET_IID(nsIXPCComponents_ID), + NS_GET_IID(nsIXPCScriptable)}; return NS_OK; } @@ -732,13 +716,9 @@ class nsXPCComponents_Exception final : public nsIXPCComponents_Exception, /***************************************************************************/ NS_IMETHODIMP -nsXPCComponents_Exception::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - *aCount = 2; - nsIID** array = static_cast(moz_xmalloc(2 * sizeof(nsIID*))); - *aArray = array; - - array[0] = NS_GET_IID(nsIXPCComponents_Exception).Clone(); - array[1] = NS_GET_IID(nsIXPCScriptable).Clone(); +nsXPCComponents_Exception::GetInterfaces(nsTArray& aArray) { + aArray = nsTArray{NS_GET_IID(nsIXPCComponents_Exception), + NS_GET_IID(nsIXPCScriptable)}; return NS_OK; } @@ -1027,13 +1007,9 @@ class nsXPCComponents_Constructor final : public nsIXPCComponents_Constructor, /***************************************************************************/ NS_IMETHODIMP -nsXPCComponents_Constructor::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - *aCount = 2; - nsIID** array = static_cast(moz_xmalloc(2 * sizeof(nsIID*))); - *aArray = array; - - array[0] = NS_GET_IID(nsIXPCComponents_Constructor).Clone(); - array[1] = NS_GET_IID(nsIXPCScriptable).Clone(); +nsXPCComponents_Constructor::GetInterfaces(nsTArray& aArray) { + aArray = nsTArray{NS_GET_IID(nsIXPCComponents_Constructor), + NS_GET_IID(nsIXPCScriptable)}; return NS_OK; } diff --git a/js/xpconnect/src/XPCRuntimeService.cpp b/js/xpconnect/src/XPCRuntimeService.cpp index 07819b271c15..d8e540aece95 100644 --- a/js/xpconnect/src/XPCRuntimeService.cpp +++ b/js/xpconnect/src/XPCRuntimeService.cpp @@ -71,13 +71,9 @@ BackstagePass::NewEnumerate(nsIXPConnectWrappedNative* wrapper, JSContext* cx, /***************************************************************************/ NS_IMETHODIMP -BackstagePass::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - *aCount = 2; - nsIID** array = static_cast(moz_xmalloc(2 * sizeof(nsIID*))); - *aArray = array; - - array[0] = NS_GET_IID(nsIXPCScriptable).Clone(); - array[1] = NS_GET_IID(nsIScriptObjectPrincipal).Clone(); +BackstagePass::GetInterfaces(nsTArray& aArray) { + aArray = nsTArray{NS_GET_IID(nsIXPCScriptable), + NS_GET_IID(nsIScriptObjectPrincipal)}; return NS_OK; } diff --git a/js/xpconnect/src/XPCWrappedNativeInfo.cpp b/js/xpconnect/src/XPCWrappedNativeInfo.cpp index b8ed28e774d7..e9b355cf844c 100644 --- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp +++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp @@ -513,71 +513,50 @@ already_AddRefed XPCNativeSet::GetNewOrUsed( return set.forget(); } - nsIID** iidArray = nullptr; - uint32_t iidCount = 0; - - if (NS_FAILED(classInfo->GetInterfaces(&iidCount, &iidArray))) { + AutoTArray iids; + if (NS_FAILED(classInfo->GetInterfaces(iids))) { // Note: I'm making it OK for this call to fail so that one can add // nsIClassInfo to classes implemented in script without requiring this // method to be implemented. // Make sure these are set correctly... - iidArray = nullptr; - iidCount = 0; + iids.Clear(); } - MOZ_ASSERT((iidCount && iidArray) || !(iidCount || iidArray), - "GetInterfaces returned bad array"); - - // !!! from here on we only exit through the 'out' label !!! - - if (iidCount) { - nsTArray> interfaceArray(iidCount); - nsIID** currentIID = iidArray; - - for (uint32_t i = 0; i < iidCount; i++) { - nsIID* iid = *(currentIID++); - if (!iid) { - NS_ERROR("Null found in classinfo interface list"); - continue; - } - - RefPtr iface = XPCNativeInterface::GetNewOrUsed(iid); - - if (!iface) { - // XXX warn here - continue; - } - - interfaceArray.AppendElement(iface.forget()); + // Try to look up each IID's XPCNativeInterface object. + nsTArray> interfaces(iids.Length()); + for (auto& iid : iids) { + RefPtr iface = XPCNativeInterface::GetNewOrUsed(&iid); + if (iface) { + interfaces.AppendElement(iface.forget()); } + } - if (interfaceArray.Length() > 0) { - set = NewInstance(std::move(interfaceArray)); - if (set) { - NativeSetMap* map2 = xpcrt->GetNativeSetMap(); - if (!map2) { - goto out; - } - - XPCNativeSetKey key(set); - - XPCNativeSet* set2 = map2->Add(&key, set); - if (!set2) { - NS_ERROR("failed to add our set!"); - set = nullptr; - goto out; - } - // It is okay to find an existing entry here because - // we did not look for one before we called Add(). - if (set2 != set) { - set = set2; - } + // Build a set from the interfaces specified here. + if (interfaces.Length() > 0) { + set = NewInstance(std::move(interfaces)); + if (set) { + NativeSetMap* map2 = xpcrt->GetNativeSetMap(); + if (!map2) { + return set.forget(); } - } else - set = GetNewOrUsed(&NS_GET_IID(nsISupports)); - } else + + XPCNativeSetKey key(set); + XPCNativeSet* set2 = map2->Add(&key, set); + if (!set2) { + NS_ERROR("failed to add our set"); + return nullptr; + } + + // It is okay to find an existing entry here because + // we did not look for one before we called Add(). + if (set2 != set) { + set = set2; + } + } + } else { set = GetNewOrUsed(&NS_GET_IID(nsISupports)); + } if (set) { #ifdef DEBUG @@ -588,11 +567,6 @@ already_AddRefed XPCNativeSet::GetNewOrUsed( MOZ_ASSERT(set2 == set, "hashtables inconsistent!"); } -out: - if (iidArray) { - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(iidCount, iidArray); - } - return set.forget(); } diff --git a/js/xpconnect/tests/unit/component-blob.js b/js/xpconnect/tests/unit/component-blob.js index e0472bda4272..0cf16e6184ae 100644 --- a/js/xpconnect/tests/unit/component-blob.js +++ b/js/xpconnect/tests/unit/component-blob.js @@ -59,11 +59,7 @@ BlobComponent.prototype = // nsIClassInfo flags: 0, - getInterfaces: function getInterfaces(aCount) { - var interfaces = [Ci.nsIClassInfo]; - aCount.value = interfaces.length; - return interfaces; - }, + interfaces: [Ci.nsIClassInfo], getScriptableHelper: function getScriptableHelper() { return null; diff --git a/js/xpconnect/tests/unit/component-file.js b/js/xpconnect/tests/unit/component-file.js index bc4e5c39faee..0f2cb59b8e3b 100644 --- a/js/xpconnect/tests/unit/component-file.js +++ b/js/xpconnect/tests/unit/component-file.js @@ -90,11 +90,7 @@ FileComponent.prototype = // nsIClassInfo flags: 0, - getInterfaces: function getInterfaces(aCount) { - var interfaces = [Ci.nsIClassInfo]; - aCount.value = interfaces.length; - return interfaces; - }, + interfaces: [Ci.nsIClassInfo], getScriptableHelper: function getScriptableHelper() { return null; diff --git a/js/xpconnect/tests/unit/component_import.js b/js/xpconnect/tests/unit/component_import.js index 7b2ea40a5045..b8823fa03b42 100644 --- a/js/xpconnect/tests/unit/component_import.js +++ b/js/xpconnect/tests/unit/component_import.js @@ -17,9 +17,8 @@ FooComponent.prototype = // nsIClassInfo flags: 0, - getInterfaces: function getInterfaces(aCount) { + get interfaces() { var interfaces = [Ci.nsIClassInfo]; - aCount.value = interfaces.length; // Guerilla test for line numbers hiding in this method var threw = true; @@ -27,7 +26,7 @@ FooComponent.prototype = thereIsNoSuchIdentifier; threw = false; } catch (ex) { - Assert.ok(ex.lineNumber == 27); + Assert.ok(ex.lineNumber == 26); } Assert.ok(threw); @@ -60,11 +59,7 @@ BarComponent.prototype = // nsIClassInfo flags: 0, - getInterfaces: function getInterfaces(aCount) { - var interfaces = [Ci.nsIClassInfo]; - aCount.value = interfaces.length; - return interfaces; - }, + interfaces: [Ci.nsIClassInfo], getScriptableHelper: function getScriptableHelper() { return null; diff --git a/js/xpconnect/tests/unit/test_import.js b/js/xpconnect/tests/unit/test_import.js index fc190b3d33b3..90bf68b8b9ea 100644 --- a/js/xpconnect/tests/unit/test_import.js +++ b/js/xpconnect/tests/unit/test_import.js @@ -75,10 +75,10 @@ function run_test() { // Call getInterfaces to test line numbers in JS components. But as long as // we're doing that, why not test what it returns too? - // Kind of odd that this is not returning an array containing the - // number... Or for that matter not returning an array containing an object? - var interfaces = foo.getInterfaces({}); - Assert.equal(interfaces, Ci.nsIClassInfo.number); + var interfaces = foo.interfaces; + Assert.ok(Array.isArray(interfaces)); + Assert.equal(interfaces.length, 1); + Assert.ok(interfaces[0].equals(Ci.nsIClassInfo)) // try to create another component which doesn't directly implement QI Assert.ok((contractID + "2") in Cc); diff --git a/modules/libjar/nsJARURI.cpp b/modules/libjar/nsJARURI.cpp index 26b80897db30..b4c7f58da4dc 100644 --- a/modules/libjar/nsJARURI.cpp +++ b/modules/libjar/nsJARURI.cpp @@ -136,9 +136,8 @@ nsJARURI::Write(nsIObjectOutputStream *aOutputStream) { // nsIClassInfo methods: NS_IMETHODIMP -nsJARURI::GetInterfaces(uint32_t *count, nsIID ***array) { - *count = 0; - *array = nullptr; +nsJARURI::GetInterfaces(nsTArray &array) { + array.Clear(); return NS_OK; } diff --git a/netwerk/base/nsSimpleURI.cpp b/netwerk/base/nsSimpleURI.cpp index 5f7928c9387b..98879d0f01dc 100644 --- a/netwerk/base/nsSimpleURI.cpp +++ b/netwerk/base/nsSimpleURI.cpp @@ -607,9 +607,8 @@ nsSimpleURI::GetAsciiHost(nsACString &result) { //---------------------------------------------------------------------------- NS_IMETHODIMP -nsSimpleURI::GetInterfaces(uint32_t *count, nsIID ***array) { - *count = 0; - *array = nullptr; +nsSimpleURI::GetInterfaces(nsTArray &array) { + array.Clear(); return NS_OK; } diff --git a/netwerk/base/nsSocketTransport2.cpp b/netwerk/base/nsSocketTransport2.cpp index 24b93310a1b1..737f97274c03 100644 --- a/netwerk/base/nsSocketTransport2.cpp +++ b/netwerk/base/nsSocketTransport2.cpp @@ -2944,8 +2944,8 @@ nsSocketTransport::GetInterface(const nsIID &iid, void **result) { } NS_IMETHODIMP -nsSocketTransport::GetInterfaces(uint32_t *count, nsIID ***array) { - return NS_CI_INTERFACE_GETTER_NAME(nsSocketTransport)(count, array); +nsSocketTransport::GetInterfaces(nsTArray& array) { + return NS_CI_INTERFACE_GETTER_NAME(nsSocketTransport)(array); } NS_IMETHODIMP diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp index b847887d8aaa..391562a8f634 100644 --- a/netwerk/base/nsStandardURL.cpp +++ b/netwerk/base/nsStandardURL.cpp @@ -3447,9 +3447,8 @@ bool nsStandardURL::Deserialize(const URIParams &aParams) { //---------------------------------------------------------------------------- NS_IMETHODIMP -nsStandardURL::GetInterfaces(uint32_t *count, nsIID ***array) { - *count = 0; - *array = nullptr; +nsStandardURL::GetInterfaces(nsTArray &array) { + array.Clear(); return NS_OK; } diff --git a/security/manager/ssl/TransportSecurityInfo.cpp b/security/manager/ssl/TransportSecurityInfo.cpp index 78601f835d01..e598aabad17b 100644 --- a/security/manager/ssl/TransportSecurityInfo.cpp +++ b/security/manager/ssl/TransportSecurityInfo.cpp @@ -516,9 +516,8 @@ TransportSecurityInfo::Read(nsIObjectInputStream* aStream) { } NS_IMETHODIMP -TransportSecurityInfo::GetInterfaces(uint32_t* count, nsIID*** array) { - *count = 0; - *array = nullptr; +TransportSecurityInfo::GetInterfaces(nsTArray& array) { + array.Clear(); return NS_OK; } diff --git a/security/manager/ssl/nsNSSCertificate.cpp b/security/manager/ssl/nsNSSCertificate.cpp index 7ad95debe61c..1e60516e6da9 100644 --- a/security/manager/ssl/nsNSSCertificate.cpp +++ b/security/manager/ssl/nsNSSCertificate.cpp @@ -1227,9 +1227,8 @@ nsNSSCertificate::Read(nsIObjectInputStream* aStream) { } NS_IMETHODIMP -nsNSSCertificate::GetInterfaces(uint32_t* count, nsIID*** array) { - *count = 0; - *array = nullptr; +nsNSSCertificate::GetInterfaces(nsTArray& array) { + array.Clear(); return NS_OK; } diff --git a/storage/mozStorageAsyncStatement.cpp b/storage/mozStorageAsyncStatement.cpp index 5e4839bb81c6..30b7d38ed474 100644 --- a/storage/mozStorageAsyncStatement.cpp +++ b/storage/mozStorageAsyncStatement.cpp @@ -45,8 +45,8 @@ class AsyncStatementClassInfo : public nsIClassInfo { NS_DECL_ISUPPORTS_INHERITED NS_IMETHOD - GetInterfaces(uint32_t *_count, nsIID ***_array) override { - return NS_CI_INTERFACE_GETTER_NAME(AsyncStatement)(_count, _array); + GetInterfaces(nsTArray &_array) override { + return NS_CI_INTERFACE_GETTER_NAME(AsyncStatement)(_array); } NS_IMETHOD diff --git a/storage/mozStorageStatement.cpp b/storage/mozStorageStatement.cpp index ac26756c5364..5ff1b7360774 100644 --- a/storage/mozStorageStatement.cpp +++ b/storage/mozStorageStatement.cpp @@ -47,8 +47,8 @@ class StatementClassInfo : public nsIClassInfo { NS_DECL_ISUPPORTS_INHERITED NS_IMETHOD - GetInterfaces(uint32_t *_count, nsIID ***_array) override { - return NS_CI_INTERFACE_GETTER_NAME(Statement)(_count, _array); + GetInterfaces(nsTArray &_array) override { + return NS_CI_INTERFACE_GETTER_NAME(Statement)(_array); } NS_IMETHOD diff --git a/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js b/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js index c75b35e65b44..bb06d7ef1458 100644 --- a/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js +++ b/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js @@ -3562,11 +3562,7 @@ function UpdatePrompt(aCallback) { UpdatePrompt.prototype = { flags: Ci.nsIClassInfo.SINGLETON, getScriptableHelper: () => null, - getInterfaces(aCount) { - let interfaces = [Ci.nsISupports, Ci.nsIUpdatePrompt]; - aCount.value = interfaces.length; - return interfaces; - }, + interfaces: [Ci.nsISupports, Ci.nsIUpdatePrompt], QueryInterface: ChromeUtils.generateQI([Ci.nsIClassInfo, Ci.nsIUpdatePrompt]), }; diff --git a/xpcom/base/nsClassInfoImpl.cpp b/xpcom/base/nsClassInfoImpl.cpp index 672ba5ffd1cf..2189863a98fe 100644 --- a/xpcom/base/nsClassInfoImpl.cpp +++ b/xpcom/base/nsClassInfoImpl.cpp @@ -16,8 +16,8 @@ GenericClassInfo::Release() { return 1; } NS_IMPL_QUERY_INTERFACE(GenericClassInfo, nsIClassInfo) NS_IMETHODIMP -GenericClassInfo::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - return mData->getinterfaces(aCount, aArray); +GenericClassInfo::GetInterfaces(nsTArray& aArray) { + return mData->getinterfaces(aArray); } NS_IMETHODIMP diff --git a/xpcom/base/nsIClassInfoImpl.h b/xpcom/base/nsIClassInfoImpl.h index 37da02bf71f3..dd77c1ca8049 100644 --- a/xpcom/base/nsIClassInfoImpl.h +++ b/xpcom/base/nsIClassInfoImpl.h @@ -89,8 +89,7 @@ class GenericClassInfo : public nsIClassInfo { struct ClassInfoData { // This function pointer uses NS_CALLBACK_ because it's always set to an // NS_IMETHOD function, which uses __stdcall on Win32. - typedef NS_CALLBACK_(nsresult, GetInterfacesProc)(uint32_t* aCountP, - nsIID*** aArray); + typedef NS_CALLBACK_(nsresult, GetInterfacesProc)(nsTArray& aArray); GetInterfacesProc getinterfaces; // This function pointer doesn't use NS_CALLBACK_ because it's always set to @@ -113,8 +112,9 @@ class GenericClassInfo : public nsIClassInfo { #define NS_CLASSINFO_NAME(_class) g##_class##_classInfoGlobal #define NS_CI_INTERFACE_GETTER_NAME(_class) _class##_GetInterfacesHelper -#define NS_DECL_CI_INTERFACE_GETTER(_class) \ - extern NS_IMETHODIMP NS_CI_INTERFACE_GETTER_NAME(_class)(uint32_t*, nsIID***); +#define NS_DECL_CI_INTERFACE_GETTER(_class) \ + extern NS_IMETHODIMP NS_CI_INTERFACE_GETTER_NAME(_class)(nsTArray & \ + array); #define NS_IMPL_CLASSINFO(_class, _getscriptablehelper, _flags, _cid) \ NS_DECL_CI_INTERFACE_GETTER(_class) \ @@ -135,19 +135,17 @@ class GenericClassInfo : public nsIClassInfo { foundInterface = NS_CLASSINFO_NAME(_class); \ } else -#define NS_CLASSINFO_HELPER_BEGIN(_class, _c) \ - NS_IMETHODIMP \ - NS_CI_INTERFACE_GETTER_NAME(_class)(uint32_t * count, nsIID * **array) { \ - *count = _c; \ - *array = (nsIID**)moz_xmalloc(sizeof(nsIID*) * _c); \ - uint32_t i = 0; +#define NS_CLASSINFO_HELPER_BEGIN(_class, _c) \ + NS_IMETHODIMP \ + NS_CI_INTERFACE_GETTER_NAME(_class)(nsTArray & array) { \ + array.Clear(); \ + array.SetCapacity(_c); #define NS_CLASSINFO_HELPER_ENTRY(_interface) \ - (*array)[i++] = NS_GET_IID(_interface).Clone(); + array.AppendElement(NS_GET_IID(_interface)); -#define NS_CLASSINFO_HELPER_END \ - MOZ_ASSERT(i == *count, "Incorrent number of entries"); \ - return NS_OK; \ +#define NS_CLASSINFO_HELPER_END \ + return NS_OK; \ } #define NS_IMPL_CI_INTERFACE_GETTER(aClass, ...) \ diff --git a/xpcom/base/nsISupportsImpl.h b/xpcom/base/nsISupportsImpl.h index dc5f197e3bf0..6b30b81d953d 100644 --- a/xpcom/base/nsISupportsImpl.h +++ b/xpcom/base/nsISupportsImpl.h @@ -1247,45 +1247,45 @@ class Runnable; * Macro to generate nsIClassInfo methods for classes which do not have * corresponding nsIFactory implementations. */ -#define NS_IMPL_THREADSAFE_CI(_class) \ - NS_IMETHODIMP \ - _class::GetInterfaces(uint32_t* _count, nsIID*** _array) { \ - return NS_CI_INTERFACE_GETTER_NAME(_class)(_count, _array); \ - } \ - \ - NS_IMETHODIMP \ - _class::GetScriptableHelper(nsIXPCScriptable** _retval) { \ - *_retval = nullptr; \ - return NS_OK; \ - } \ - \ - NS_IMETHODIMP \ - _class::GetContractID(nsACString& _contractID) { \ - _contractID.SetIsVoid(true); \ - return NS_OK; \ - } \ - \ - NS_IMETHODIMP \ - _class::GetClassDescription(nsACString& _classDescription) { \ - _classDescription.SetIsVoid(true); \ - return NS_OK; \ - } \ - \ - NS_IMETHODIMP \ - _class::GetClassID(nsCID** _classID) { \ - *_classID = nullptr; \ - return NS_OK; \ - } \ - \ - NS_IMETHODIMP \ - _class::GetFlags(uint32_t* _flags) { \ - *_flags = nsIClassInfo::THREADSAFE; \ - return NS_OK; \ - } \ - \ - NS_IMETHODIMP \ - _class::GetClassIDNoAlloc(nsCID* _classIDNoAlloc) { \ - return NS_ERROR_NOT_AVAILABLE; \ +#define NS_IMPL_THREADSAFE_CI(_class) \ + NS_IMETHODIMP \ + _class::GetInterfaces(nsTArray& _array) { \ + return NS_CI_INTERFACE_GETTER_NAME(_class)(_array); \ + } \ + \ + NS_IMETHODIMP \ + _class::GetScriptableHelper(nsIXPCScriptable** _retval) { \ + *_retval = nullptr; \ + return NS_OK; \ + } \ + \ + NS_IMETHODIMP \ + _class::GetContractID(nsACString& _contractID) { \ + _contractID.SetIsVoid(true); \ + return NS_OK; \ + } \ + \ + NS_IMETHODIMP \ + _class::GetClassDescription(nsACString& _classDescription) { \ + _classDescription.SetIsVoid(true); \ + return NS_OK; \ + } \ + \ + NS_IMETHODIMP \ + _class::GetClassID(nsCID** _classID) { \ + *_classID = nullptr; \ + return NS_OK; \ + } \ + \ + NS_IMETHODIMP \ + _class::GetFlags(uint32_t* _flags) { \ + *_flags = nsIClassInfo::THREADSAFE; \ + return NS_OK; \ + } \ + \ + NS_IMETHODIMP \ + _class::GetClassIDNoAlloc(nsCID* _classIDNoAlloc) { \ + return NS_ERROR_NOT_AVAILABLE; \ } #endif diff --git a/xpcom/components/nsIClassInfo.idl b/xpcom/components/nsIClassInfo.idl index e498259acff6..5890a10923ed 100644 --- a/xpcom/components/nsIClassInfo.idl +++ b/xpcom/components/nsIClassInfo.idl @@ -18,15 +18,11 @@ interface nsIXPCScriptable; interface nsIClassInfo : nsISupports { /** - * Get an ordered list of the interface ids that instances of the class - * promise to implement. Note that nsISupports is an implicit member - * of any such list and need not be included. - * - * Should set *count = 0 and *array = null and return NS_OK if getting the - * list is not supported. + * Returns a list of the interfaces which instances of this class promise + * to implement. Note that nsISupports is an implicit member of any such + * list, and need not be included. */ - void getInterfaces(out uint32_t count, - [array, size_is(count), retval] out nsIIDPtr array); + readonly attribute Array interfaces; /** * Return an object to assist XPConnect in supplying JavaScript-specific diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index 0d5bcd7bf8ff..c729e81138e1 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -140,8 +140,8 @@ nsThreadClassInfo::Release() { return 1; } NS_IMPL_QUERY_INTERFACE(nsThreadClassInfo, nsIClassInfo) NS_IMETHODIMP -nsThreadClassInfo::GetInterfaces(uint32_t* aCount, nsIID*** aArray) { - return NS_CI_INTERFACE_GETTER_NAME(nsThread)(aCount, aArray); +nsThreadClassInfo::GetInterfaces(nsTArray& aArray) { + return NS_CI_INTERFACE_GETTER_NAME(nsThread)(aArray); } NS_IMETHODIMP