Bug 735280 - Part 1: Connect XPCWrappedNativeScope and Components. r=bholley

This commit is contained in:
Gabor Krizsanits 2012-04-25 20:12:33 -04:00
parent 38d1f89f66
commit a9ded93717
3 changed files with 23 additions and 9 deletions

View File

@ -4245,8 +4245,9 @@ nsXPCComponents::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
return NS_ERROR_NOT_AVAILABLE;
}
nsXPCComponents::nsXPCComponents()
: mInterfaces(nsnull),
nsXPCComponents::nsXPCComponents(XPCWrappedNativeScope* aScope)
: mScope(aScope),
mInterfaces(nsnull),
mInterfacesByID(nsnull),
mClasses(nsnull),
mClassesByID(nsnull),
@ -4256,6 +4257,7 @@ nsXPCComponents::nsXPCComponents()
mConstructor(nsnull),
mUtils(nsnull)
{
MOZ_ASSERT(aScope, "aScope must not be null");
}
nsXPCComponents::~nsXPCComponents()
@ -4434,7 +4436,7 @@ nsXPCComponents::AttachNewComponentsObject(XPCCallContext& ccx,
if (!aGlobal)
return false;
nsXPCComponents* components = new nsXPCComponents();
nsXPCComponents* components = new nsXPCComponents(aScope);
if (!components)
return false;

View File

@ -190,11 +190,15 @@ XPCWrappedNativeScope::IsDyingScope(XPCWrappedNativeScope *scope)
void
XPCWrappedNativeScope::SetComponents(nsXPCComponents* aComponents)
{
NS_IF_ADDREF(aComponents);
NS_IF_RELEASE(mComponents);
mComponents = aComponents;
}
nsXPCComponents*
XPCWrappedNativeScope::GetComponents()
{
return mComponents;
}
// Dummy JS class to let wrappers w/o an xpc prototype share
// scopes. By doing this we avoid allocating a new scope for every
// wrapper on creation of the wrapper, and most wrappers won't need
@ -308,9 +312,14 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
if (mContext)
mContext->RemoveScope(this);
// This should not be necessary, since the Components object should die
// with the scope but just in case.
if (mComponents)
mComponents->mScope = nsnull;
// XXX we should assert that we are dead or that xpconnect has shutdown
// XXX might not want to do this at xpconnect shutdown time???
NS_IF_RELEASE(mComponents);
mComponents = nsnull;
JSRuntime *rt = mRuntime->GetJSRuntime();
mGlobalJSObject.finalize(rt);
@ -906,7 +915,7 @@ XPCWrappedNativeScope::DebugDump(PRInt16 depth)
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("mRuntime @ %x", mRuntime));
XPC_LOG_ALWAYS(("mNext @ %x", mNext));
XPC_LOG_ALWAYS(("mComponents @ %x", mComponents));
XPC_LOG_ALWAYS(("mComponents @ %x", mComponents.get()));
XPC_LOG_ALWAYS(("mGlobalJSObject @ %x", mGlobalJSObject.get()));
XPC_LOG_ALWAYS(("mPrototypeJSObject @ %x", mPrototypeJSObject.get()));
XPC_LOG_ALWAYS(("mPrototypeNoHelper @ %x", mPrototypeNoHelper));

View File

@ -1594,6 +1594,7 @@ public:
IsDyingScope(XPCWrappedNativeScope *scope);
void SetComponents(nsXPCComponents* aComponents);
nsXPCComponents *GetComponents();
void SetGlobal(XPCCallContext& ccx, JSObject* aGlobal, nsISupports* aNative);
static void InitStatics() { gScopes = nsnull; gDyingScopes = nsnull; }
@ -1643,7 +1644,7 @@ private:
Native2WrappedNativeMap* mWrappedNativeMap;
ClassInfo2WrappedNativeProtoMap* mWrappedNativeProtoMap;
ClassInfo2WrappedNativeProtoMap* mMainThreadWrappedNativeProtoMap;
nsXPCComponents* mComponents;
nsRefPtr<nsXPCComponents> mComponents;
XPCWrappedNativeScope* mNext;
// The JS global object for this scope. If non-null, this will be the
// default parent for the XPCWrappedNatives that have us as the scope,
@ -3896,10 +3897,12 @@ public:
virtual ~nsXPCComponents();
private:
nsXPCComponents();
nsXPCComponents(XPCWrappedNativeScope* aScope);
void ClearMembers();
private:
friend class XPCWrappedNativeScope;
XPCWrappedNativeScope* mScope;
nsXPCComponents_Interfaces* mInterfaces;
nsXPCComponents_InterfacesByID* mInterfacesByID;
nsXPCComponents_Classes* mClasses;