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

This commit is contained in:
Gabor Krizsanits 2012-04-24 21:47:54 -04:00
Родитель 1d9db6868d
Коммит 244e16e5eb
3 изменённых файлов: 22 добавлений и 8 удалений

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

@ -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;

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

@ -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);

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

@ -1610,6 +1610,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; }
@ -1659,7 +1660,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,
@ -3911,10 +3912,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;