mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 942528 - Make XPCWN more of a normal cycle collected class. r=smaug
This commit is contained in:
parent
d7d019c197
commit
89520b7407
@ -41,6 +41,10 @@ xpc_OkToHandOutWrapper(nsWrapperCache *cache)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(XPCWrappedNative)
|
||||
|
||||
// No need to unlink the JS objects: if the XPCWrappedNative is cycle
|
||||
// collected then its mFlatJSObject will be cycle collected too and
|
||||
// finalization of the mFlatJSObject will unlink the JS objects (see
|
||||
// XPC_WN_NoHelper_Finalize and FlatJSObjectFinalized).
|
||||
NS_IMETHODIMP_(void)
|
||||
NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Unlink(void *p)
|
||||
{
|
||||
@ -600,6 +604,8 @@ XPCWrappedNative::XPCWrappedNative(already_AddRefed<nsISupports> aIdentity,
|
||||
mSet(aProto->GetSet()),
|
||||
mScriptableInfo(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mIdentity = aIdentity.get();
|
||||
mFlatJSObject.setFlags(FLAT_JS_OBJECT_VALID);
|
||||
|
||||
@ -616,6 +622,8 @@ XPCWrappedNative::XPCWrappedNative(already_AddRefed<nsISupports> aIdentity,
|
||||
mSet(aSet),
|
||||
mScriptableInfo(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mIdentity = aIdentity.get();
|
||||
mFlatJSObject.setFlags(FLAT_JS_OBJECT_VALID);
|
||||
|
||||
@ -905,10 +913,14 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XPCWrappedNative)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIXPConnectWrappedNative)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIXPConnectJSObjectHolder)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPConnectWrappedNative)
|
||||
NS_INTERFACE_MAP_END_THREADSAFE
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(XPCWrappedNative)
|
||||
NS_IMPL_RELEASE(XPCWrappedNative)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(XPCWrappedNative)
|
||||
|
||||
// Release calls Destroy() immediately when the refcount drops to 0 to
|
||||
// clear the weak references nsXPConnect has to XPCWNs and to ensure there
|
||||
// are no pointers to dying protos.
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(XPCWrappedNative, Destroy())
|
||||
|
||||
/*
|
||||
* Wrapped Native lifetime management is messy!
|
||||
|
@ -2007,29 +2007,11 @@ TraceXPCGlobal(JSTracer *trc, JSObject *obj);
|
||||
class XPCWrappedNative : public nsIXPConnectWrappedNative
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSIXPCONNECTJSOBJECTHOLDER
|
||||
NS_DECL_NSIXPCONNECTWRAPPEDNATIVE
|
||||
// No need to unlink the JS objects, if the XPCWrappedNative will be cycle
|
||||
// collected then its mFlatJSObject will be cycle collected too and
|
||||
// finalization of the mFlatJSObject will unlink the js objects (see
|
||||
// XPC_WN_NoHelper_Finalize and FlatJSObjectFinalized).
|
||||
// We also give XPCWrappedNative empty Root/Unroot methods, to avoid
|
||||
// root/unrooting the JS objects from addrefing/releasing the
|
||||
// XPCWrappedNative during unlinking, which would make the JS objects
|
||||
// uncollectable to the JS GC.
|
||||
class NS_CYCLE_COLLECTION_INNERCLASS
|
||||
: public nsXPCOMCycleCollectionParticipant
|
||||
{
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_BODY(XPCWrappedNative, XPCWrappedNative)
|
||||
NS_IMETHOD_(void) Root(void *p) { }
|
||||
NS_IMETHOD_(void) Unroot(void *p) { }
|
||||
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(XPCWrappedNative)
|
||||
};
|
||||
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(XPCWrappedNative);
|
||||
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
|
||||
|
||||
void DeleteCycleCollectable() {}
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(XPCWrappedNative)
|
||||
|
||||
nsIPrincipal* GetObjectPrincipal() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user