fix XPCContext leak bug 25911 r=beard. fix DOM wrapping case where static called object does not have a static DOM scope, but is run in a DOM context; e.g. calling a JS component from within a window that calls some native service that returns a DOM window - the serive is not a DOm object and has no static DOm scope, but the call is made on a DOM context so a dynamic lookup works. r=mscott

This commit is contained in:
jband%netscape.com 2000-02-03 03:25:53 +00:00
Родитель f07d9f22a1
Коммит 610d83d7b1
3 изменённых файлов: 51 добавлений и 8 удалений

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

@ -135,7 +135,7 @@ GetISupportsFromJSObject(JSContext* cx, JSObject* obj, nsISupports** iface)
}
/***************************************************************************/
// This copied from nsJSUtils.cpp in DOMLand
// These are copied from nsJSUtils.cpp in DOMLand
static nsresult
GetStaticScriptGlobal(JSContext* aContext,
@ -174,6 +174,34 @@ GetStaticScriptContext(JSContext* aContext,
return scriptContext ? NS_OK : NS_ERROR_FAILURE;
}
static nsresult
GetDynamicScriptContext(JSContext *aContext,
nsIScriptContext** aScriptContext)
{
// XXX We rely on the rule that if any JSContext in our JSRuntime has a
// private set then that private *must* be a pointer to an nsISupports.
nsISupports *supports = (nsIScriptContext*) JS_GetContextPrivate(aContext);
if (!supports)
return nsnull;
return supports->QueryInterface(NS_GET_IID(nsIScriptContext),
(void**)aScriptContext);
}
#if 0
// never called.
static nsresult
GetDynamicScriptGlobal(JSContext* aContext,
nsIScriptGlobalObject** aNativeGlobal)
{
nsIScriptGlobalObject* nativeGlobal = nsnull;
nsCOMPtr<nsIScriptContext> scriptCX;
GetDynamicScriptContext(aContext, getter_AddRefs(scriptCX));
if (scriptCX) {
*aNativeGlobal = nativeGlobal = scriptCX->GetGlobalObject();
}
return nativeGlobal ? NS_OK : NS_ERROR_FAILURE;
}
#endif
/***************************************************************************/
/***************************************************************************/
@ -668,6 +696,8 @@ XPCConvert::NativeInterface2JSObject(JSContext* cx,
// is a DOM object
nsCOMPtr<nsIScriptContext> scriptCX;
GetStaticScriptContext(cx, scope, getter_AddRefs(scriptCX));
if(!scriptCX)
GetDynamicScriptContext(cx, getter_AddRefs(scriptCX));
JSObject* aJSObj = nsnull;
if(scriptCX &&
NS_SUCCEEDED(owner->GetScriptObject(scriptCX, (void **)&aJSObj)))

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

@ -61,7 +61,7 @@ XPCJSRuntime::~XPCJSRuntime()
while(JS_ContextIterator(mJSRuntime, &iter))
count ++;
if(count)
printf("deleting XPCJSRuntime with %d total live JSContexts\n", count);
printf("deleting XPCJSRuntime with %d live JSContexts\n", count);
}
#endif
@ -69,12 +69,7 @@ XPCJSRuntime::~XPCJSRuntime()
if(mContextMap)
{
SyncXPCContextList();
#ifdef DEBUG_jband
uint32 count = mContextMap->Count();
if(count)
printf("deleting XPCJSRuntime with %d live JSContexts known by xpconnect\n", (int)count);
#endif
PurgeXPCContextList();
delete mContextMap;
}
@ -239,6 +234,23 @@ XPCJSRuntime::SyncXPCContextList(JSContext* cx /* = nsnull */)
return found;
}
JS_STATIC_DLL_CALLBACK(intN)
PurgeContextsCB(JSHashEntry *he, intN i, void *arg)
{
delete (XPCContext*) he->value;
return HT_ENUMERATE_REMOVE;
}
void
XPCJSRuntime::PurgeXPCContextList()
{
// hold the map lock through this whole thing
nsAutoLock lock(mMapLock);
// get rid of all XPCContexts
mContextMap->Enumerate(PurgeContextsCB, nsnull);
}
JSBool
XPCJSRuntime::GenerateStringIDs(JSContext* cx)
{

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

@ -228,6 +228,7 @@ private:
JSContext2XPCContextMap* GetContextMap() const {return mContextMap;}
JSBool GenerateStringIDs(JSContext* cx);
void PurgeXPCContextList();
private:
static const char* mStrings[IDX_TOTAL_COUNT];