Bug 1279746 - Optimize xpc_TryUnmarkWrappedGrayObject, r=mccr8

This commit is contained in:
Olli Pettay 2016-06-14 13:14:21 +01:00
Родитель 47c21b1f75
Коммит 6371f21e0c
4 изменённых файлов: 26 добавлений и 6 удалений

Просмотреть файл

@ -129,6 +129,14 @@ interface nsIXPConnectWrappedJS : nsIXPConnectJSObjectHolder
}; };
// Special interface to unmark the internal JSObject.
// QIing to nsIXPConnectWrappedJSUnmarkGray does *not* addref, it only unmarks,
// and QIing to nsIXPConnectWrappedJSUnmarkGray is always supposed to fail.
[builtinclass, uuid(c02a0ce6-275f-4ea1-9c23-08494898b070)]
interface nsIXPConnectWrappedJSUnmarkGray : nsIXPConnectWrappedJS
{
};
/***************************************************************************/ /***************************************************************************/
/** /**

Просмотреть файл

@ -204,6 +204,18 @@ nsXPCWrappedJS::QueryInterface(REFNSIID aIID, void** aInstancePtr)
if (!IsValid()) if (!IsValid())
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJSUnmarkGray))) {
*aInstancePtr = nullptr;
// No need to null check mJSObj because IsValid() call above did
// that already.
JS::ExposeObjectToActiveJS(mJSObj);
// Just return some error value since one isn't supposed to use
// nsIXPConnectWrappedJSUnmarkGray objects for anything.
return NS_ERROR_FAILURE;
}
// Always check for this first so that our 'outer' can get this interface // Always check for this first so that our 'outer' can get this interface
// from us without recurring into a call to the outer's QI! // from us without recurring into a call to the outer's QI!
if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJS))) { if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJS))) {

Просмотреть файл

@ -341,11 +341,10 @@ xpc_MarkInCCGeneration(nsISupports* aVariant, uint32_t aGeneration)
void void
xpc_TryUnmarkWrappedGrayObject(nsISupports* aWrappedJS) xpc_TryUnmarkWrappedGrayObject(nsISupports* aWrappedJS)
{ {
nsCOMPtr<nsIXPConnectWrappedJS> wjs = do_QueryInterface(aWrappedJS); nsCOMPtr<nsIXPConnectWrappedJSUnmarkGray> wjsug =
if (wjs) { do_QueryInterface(aWrappedJS);
// Unmarks gray JSObject. MOZ_ASSERT(!wjsug, "One should never be able to QI to "
static_cast<nsXPCWrappedJS*>(wjs.get())->GetJSObject(); "nsIXPConnectWrappedJSUnmarkGray successfully!");
}
} }
/***************************************************************************/ /***************************************************************************/

Просмотреть файл

@ -2329,7 +2329,7 @@ private:
// interface on the single underlying (possibly aggregate) JSObject. // interface on the single underlying (possibly aggregate) JSObject.
class nsXPCWrappedJS final : protected nsAutoXPTCStub, class nsXPCWrappedJS final : protected nsAutoXPTCStub,
public nsIXPConnectWrappedJS, public nsIXPConnectWrappedJSUnmarkGray,
public nsSupportsWeakReference, public nsSupportsWeakReference,
public nsIPropertyBag, public nsIPropertyBag,
public XPCRootSetElem public XPCRootSetElem
@ -2338,6 +2338,7 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIXPCONNECTJSOBJECTHOLDER NS_DECL_NSIXPCONNECTJSOBJECTHOLDER
NS_DECL_NSIXPCONNECTWRAPPEDJS NS_DECL_NSIXPCONNECTWRAPPEDJS
NS_DECL_NSIXPCONNECTWRAPPEDJSUNMARKGRAY
NS_DECL_NSISUPPORTSWEAKREFERENCE NS_DECL_NSISUPPORTSWEAKREFERENCE
NS_DECL_NSIPROPERTYBAG NS_DECL_NSIPROPERTYBAG