mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 18:08:58 +00:00
bug 49748. Fix crash due to JS loader holding xpconnect service too long. Also add unimplemented method to xpconnect service and fix cast for bug 49641. r=shaver@mozilla.org a=brendan@mozilla.org
This commit is contained in:
parent
437a98156c
commit
47af0b5999
@ -304,7 +304,7 @@ interface nsIXPConnect : nsISupports
|
||||
initClasses(in JSContextPtr aJSContext,
|
||||
in JSObjectPtr aGlobalJSObj);
|
||||
|
||||
nsIXPConnectWrappedNative
|
||||
nsIXPConnectJSObjectHolder
|
||||
initClassesWithNewWrappedGlobal(
|
||||
in JSContextPtr aJSContext,
|
||||
in nsISupports aCOMObj,
|
||||
|
@ -234,7 +234,6 @@ mozJSComponentLoader::~mozJSComponentLoader()
|
||||
|
||||
JS_DestroyContext(mContext);
|
||||
mContext = nsnull;
|
||||
mXPC = nsnull;
|
||||
mRuntimeService = nsnull;
|
||||
}
|
||||
}
|
||||
@ -365,9 +364,9 @@ mozJSComponentLoader::ReallyInit()
|
||||
/*
|
||||
* Get the XPConnect service.
|
||||
*/
|
||||
mXPC = do_GetService(kXPConnectServiceProgID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIXPConnect> xpc = do_GetService(kXPConnectServiceProgID);
|
||||
if (!xpc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mContext = JS_NewContext(mRuntime, 8192 /* pref? */);
|
||||
if (!mContext)
|
||||
@ -394,14 +393,14 @@ mozJSComponentLoader::ReallyInit()
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
rv = mXPC->InitClasses(mContext, mSuperGlobal);
|
||||
rv = xpc->InitClasses(mContext, mSuperGlobal);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = mXPC->WrapNative(mContext, mSuperGlobal, mCompMgr,
|
||||
NS_GET_IID(nsIComponentManager),
|
||||
getter_AddRefs(holder));
|
||||
rv = xpc->WrapNative(mContext, mSuperGlobal, mCompMgr,
|
||||
NS_GET_IID(nsIComponentManager),
|
||||
getter_AddRefs(holder));
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG_shaver
|
||||
@ -852,7 +851,7 @@ mozJSComponentLoader::RegisterDeferredComponents(PRInt32 aWhen,
|
||||
rv = mDeferredComponents.QueryElementAt(i, NS_GET_IID(nsIFile), getter_AddRefs(component));
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
|
||||
rv = AttemptRegistration(component, PR_TRUE /* deferred */);
|
||||
if (rv != NS_ERROR_FACTORY_REGISTER_AGAIN) {
|
||||
if (NS_SUCCEEDED(rv))
|
||||
@ -901,6 +900,10 @@ mozJSComponentLoader::ModuleForLocation(const char *registryLocation,
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPConnect> xpc = do_GetService(kXPConnectServiceProgID);
|
||||
if (!xpc)
|
||||
return nsnull;
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIJSContextStack, cxstack, kJSContextStackProgID, &rv);
|
||||
if (NS_FAILED(rv) ||
|
||||
@ -935,8 +938,8 @@ mozJSComponentLoader::ModuleForLocation(const char *registryLocation,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (NS_FAILED(mXPC->WrapJS(mContext, jsModuleObj, NS_GET_IID(nsIModule),
|
||||
(void **)&module))) {
|
||||
if (NS_FAILED(xpc->WrapJS(mContext, jsModuleObj, NS_GET_IID(nsIModule),
|
||||
(void **)&module))) {
|
||||
/* XXX report error properly */
|
||||
fprintf(stderr, "mJCL: couldn't get nsIModule from jsval\n");
|
||||
goto out;
|
||||
@ -985,10 +988,14 @@ mozJSComponentLoader::GlobalForLocation(const char *aLocation,
|
||||
new BackstagePass();
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIXPConnect> xpc = do_GetService(kXPConnectServiceProgID);
|
||||
if (!xpc)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = mXPC->WrapNative(mContext, mSuperGlobal, backstagePass,
|
||||
NS_GET_IID(nsISupports),
|
||||
getter_AddRefs(holder));
|
||||
rv = xpc->WrapNative(mContext, mSuperGlobal, backstagePass,
|
||||
NS_GET_IID(nsISupports),
|
||||
getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
|
||||
|
@ -64,7 +64,6 @@ public:
|
||||
|
||||
nsIComponentManager* mCompMgr; // weak ref, should make it strong?
|
||||
nsCOMPtr<nsIRegistry> mRegistry;
|
||||
nsCOMPtr<nsIXPConnect> mXPC;
|
||||
nsCOMPtr<nsIJSRuntimeService> mRuntimeService;
|
||||
#ifndef XPCONNECT_STANDALONE
|
||||
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
||||
|
@ -41,6 +41,7 @@
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsXPConnect,nsIXPConnect)
|
||||
|
||||
nsXPConnect* nsXPConnect::gSelf = nsnull;
|
||||
JSBool nsXPConnect::gOnceAliveNowDead = JS_FALSE;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@ -197,6 +198,7 @@ nsXPConnect::~nsXPConnect()
|
||||
if(mRuntime)
|
||||
delete mRuntime;
|
||||
gSelf = nsnull;
|
||||
gOnceAliveNowDead = JS_TRUE;
|
||||
}
|
||||
|
||||
// static
|
||||
@ -205,6 +207,8 @@ nsXPConnect::GetXPConnect()
|
||||
{
|
||||
if(!gSelf)
|
||||
{
|
||||
if(gOnceAliveNowDead)
|
||||
return nsnull;
|
||||
gSelf = new nsXPConnect();
|
||||
if (!gSelf ||
|
||||
!gSelf->mArbitraryScriptable ||
|
||||
@ -438,12 +442,53 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIXPConnectWrappedNative initClassesWithNewWrappedGlobal (in JSContextPtr aJSContext, in nsISupports aCOMObj, in nsIIDRef aIID); */
|
||||
NS_IMETHODIMP
|
||||
nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext, nsISupports *aCOMObj, const nsIID & aIID, nsIXPConnectWrappedNative **_retval)
|
||||
static JSClass xpcTempGlobalClass = {
|
||||
"xpcTempGlobalClass", 0,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
||||
};
|
||||
|
||||
|
||||
/* nsIXPConnectJSObjectHolder initClassesWithNewWrappedGlobal (in JSContextPtr aJSContext, in nsISupports aCOMObj, in nsIIDRef aIID); */
|
||||
NS_IMETHODIMP
|
||||
nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext, nsISupports *aCOMObj, const nsIID & aIID, nsIXPConnectJSObjectHolder **_retval)
|
||||
{
|
||||
// XXX need to implement InitClassesWithNewWrappedGlobal
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
NS_ENSURE_ARG_POINTER(aJSContext);
|
||||
NS_ENSURE_ARG_POINTER(aCOMObj);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
// XXX This is not pretty. We make a temporary global object and
|
||||
// init it with all the Components object junk just so we have a
|
||||
// parent with an xpc scope to use when wrapping the object that will
|
||||
// become the 'real' global.
|
||||
|
||||
JSObject* tempGlobal = JS_NewObject(aJSContext, &xpcTempGlobalClass,
|
||||
nsnull, nsnull);
|
||||
|
||||
if(!tempGlobal ||
|
||||
!JS_InitStandardClasses(aJSContext, tempGlobal))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if(NS_FAILED(InitClasses(aJSContext, tempGlobal)))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
if(NS_FAILED(WrapNative(aJSContext, tempGlobal, aCOMObj, aIID,
|
||||
getter_AddRefs(holder))) || !holder)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
JSObject* aGlobalJSObj;
|
||||
if(NS_FAILED(holder->GetJSObject(&aGlobalJSObj)) || !aGlobalJSObj)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
JS_SetParent(aJSContext, aGlobalJSObj, nsnull);
|
||||
|
||||
if(NS_FAILED(InitClasses(aJSContext, aGlobalJSObj)))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ADDREF(*_retval = holder);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIXPConnectJSObjectHolder wrapNative (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDRef aIID); */
|
||||
|
@ -971,9 +971,9 @@ XPCConvert::JSValToXPCException(JSContext* cx,
|
||||
XPCContext* xpcc;
|
||||
if(nsnull != (xpcc = nsXPConnect::GetContext(cx)))
|
||||
{
|
||||
return (nsIXPCException*)
|
||||
return NS_REINTERPRET_CAST(nsIXPCException*,
|
||||
nsXPCWrappedJS::GetNewOrUsedWrapper(xpcc, obj,
|
||||
NS_GET_IID(nsIXPCException));
|
||||
NS_GET_IID(nsIXPCException)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,6 +174,7 @@ private:
|
||||
private:
|
||||
// Singleton instance
|
||||
static nsXPConnect* gSelf;
|
||||
static JSBool gOnceAliveNowDead;
|
||||
|
||||
XPCJSRuntime* mRuntime;
|
||||
nsIXPCScriptable* mArbitraryScriptable;
|
||||
|
Loading…
Reference in New Issue
Block a user