From 339b69262aaf97c6e1778eab1c8eb7fafdd1c701 Mon Sep 17 00:00:00 2001 From: "dp%netscape.com" Date: Fri, 24 Sep 1999 01:37:44 +0000 Subject: [PATCH] Fixing jsloader not to hold reference to component manager. (shaver) Some initialization of members and checking at desctruction. (dp) git-svn-id: svn://10.0.0.236/trunk@48952 18797224-902f-48f8-a5cc-f745e15eee43 --- .../xpconnect/loader/mozJSComponentLoader.cpp | 32 +++++++++++++------ .../xpconnect/loader/mozJSComponentLoader.h | 5 ++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp index 80448823b4d..ee7e2eecc58 100644 --- a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp +++ b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp @@ -73,7 +73,8 @@ static JSClass gGlobalClass = { JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; -mozJSComponentLoader::mozJSComponentLoader() +mozJSComponentLoader::mozJSComponentLoader() : + mContext(NULL), mModules(NULL), mGlobals(NULL), mInitialized(PR_FALSE) { NS_INIT_REFCNT(); } @@ -98,12 +99,16 @@ RemoveRoot_enumerate(PLHashEntry *he, PRIntn cnt, void *arg) mozJSComponentLoader::~mozJSComponentLoader() { - PL_HashTableEnumerateEntries(mModules, Release_enumerate, 0); - PL_HashTableDestroy(mModules); + if (mModules) { + PL_HashTableEnumerateEntries(mModules, Release_enumerate, 0); + PL_HashTableDestroy(mModules); + } - if (mContext) - PL_HashTableEnumerateEntries(mGlobals, RemoveRoot_enumerate, mContext); - PL_HashTableDestroy(mGlobals); + if (mGlobals) { + if (mContext) + PL_HashTableEnumerateEntries(mGlobals, RemoveRoot_enumerate, mContext); + PL_HashTableDestroy(mGlobals); + } if (mContext) { JS_RemoveRoot(mContext, &mCompMgrWrapper); @@ -113,7 +118,6 @@ mozJSComponentLoader::~mozJSComponentLoader() JS_DestroyContext(mContext); } mXPC = nsnull; - mCompMgr = nsnull; mRegistry = nsnull; } @@ -187,7 +191,13 @@ mozJSComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) /* if we can't get the XPCOM key, just skip all registry ops */ mRegistry = nsnull; } + return NS_OK; +} +NS_IMETHODIMP +mozJSComponentLoader::ReallyInit() +{ + nsresult rv; NS_WITH_SERVICE(nsIJSRuntimeService, rtsvc, "nsJSRuntimeService", &rv); // get the JSRuntime from the runtime svc, if possible if (NS_FAILED(rv)) @@ -229,7 +239,7 @@ mozJSComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) if (NS_FAILED(rv)) { #ifdef DEBUG_shaver fprintf(stderr, "WrapNative(%p,%p,nsIComponentManager) failed: %x\n", - mContext, mCompMgr.get(), rv); + mContext, mCompMgr, rv); #endif return rv; } @@ -256,6 +266,7 @@ mozJSComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) #ifdef DEBUG_shaver fprintf(stderr, "mJCL: context initialized!\n"); #endif + mInitialized = PR_TRUE; return NS_OK; } @@ -513,7 +524,6 @@ JSObject * mozJSComponentLoader::GlobalForLocation(const char *aLocation, nsIFileSpec *component) { - PRBool needRelease = PR_FALSE; PLHashNumber hash = PL_HashString(aLocation); PLHashEntry **hep = PL_HashTableRawLookup(mGlobals, hash, @@ -521,6 +531,10 @@ mozJSComponentLoader::GlobalForLocation(const char *aLocation, PLHashEntry *he = *hep; if (he) return (JSObject *)he->value; + + if (!mInitialized && + NS_FAILED(ReallyInit())) + return nsnull; JSObject *obj = JS_NewObject(mContext, &gGlobalClass, mSuperGlobal, mSuperGlobal); diff --git a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.h b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.h index 7356201b833..c712182319e 100644 --- a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.h +++ b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.h @@ -43,6 +43,7 @@ public: virtual ~mozJSComponentLoader(); protected: + nsresult ReallyInit(); nsresult RegisterComponentsInDir(PRInt32 when, nsIFileSpec *dir); JSObject *GlobalForLocation(const char *aLocation, nsIFileSpec *component); nsIModule *ModuleForLocation(const char *aLocation, @@ -51,7 +52,7 @@ public: nsresult SetRegistryInfo(const char *registryLocation, nsIFileSpec *component); - nsCOMPtr mCompMgr; + nsIComponentManager* mCompMgr; // XXX weak ref nsCOMPtr mRegistry; nsCOMPtr mXPC; @@ -63,4 +64,6 @@ public: PLHashTable *mModules; PLHashTable *mGlobals; nsIRegistry::Key mXPCOMKey; + + PRBool mInitialized; };