Bug 1175810 (part 2) - Remove PL_DHashTableEnumerate() uses from nsJSNPRuntime. r=bz.

Also, remove the |AutoSafeJSContext| because it wasn't being used.

--HG--
extra : rebase_source : 7b03383f37ca92e8df455132c1993d44f092121a
This commit is contained in:
Nicholas Nethercote 2015-06-18 17:59:42 -07:00
parent 7aadcc8198
commit f4b6494f31

View File

@ -1942,66 +1942,6 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj)
return obj;
}
// Struct for passing an NPP and a JSContext to
// NPObjWrapperPluginDestroyedCallback
struct NppAndCx
{
NPP npp;
JSContext *cx;
};
static PLDHashOperator
NPObjWrapperPluginDestroyedCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
uint32_t number, void *arg)
{
NPObjWrapperHashEntry *entry = (NPObjWrapperHashEntry *)hdr;
NppAndCx *nppcx = reinterpret_cast<NppAndCx *>(arg);
if (entry->mNpp == nppcx->npp) {
// HACK: temporarily hide the hash we're enumerating so that invalidate()
// and deallocate() don't touch it.
PLDHashTable *tmp = static_cast<PLDHashTable*>(table);
sNPObjWrappers = nullptr;
NPObject *npobj = entry->mNPObj;
if (npobj->_class && npobj->_class->invalidate) {
npobj->_class->invalidate(npobj);
}
#ifdef NS_BUILD_REFCNT_LOGGING
{
int32_t refCnt = npobj->referenceCount;
while (refCnt) {
--refCnt;
NS_LOG_RELEASE(npobj, refCnt, "BrowserNPObject");
}
}
#endif
// Force deallocation of plugin objects since the plugin they came
// from is being torn down.
if (npobj->_class && npobj->_class->deallocate) {
npobj->_class->deallocate(npobj);
} else {
PR_Free(npobj);
}
::JS_SetPrivate(entry->mJSObj, nullptr);
sNPObjWrappers = tmp;
if (sDelayedReleases && sDelayedReleases->RemoveElement(npobj)) {
OnWrapperDestroyed();
}
return PL_DHASH_REMOVE;
}
return PL_DHASH_NEXT;
}
// static
void
nsJSNPRuntime::OnPluginDestroy(NPP npp)
@ -2028,13 +1968,51 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
sJSObjWrappersAccessible = true;
}
// Use the safe JSContext here as we're not always able to find the
// JSContext associated with the NPP any more.
AutoSafeJSContext cx;
if (sNPObjWrappers) {
NppAndCx nppcx = { npp, cx };
PL_DHashTableEnumerate(sNPObjWrappers,
NPObjWrapperPluginDestroyedCallback, &nppcx);
for (auto i = sNPObjWrappers->RemovingIter(); !i.Done(); i.Next()) {
auto entry = static_cast<NPObjWrapperHashEntry*>(i.Get());
if (entry->mNpp == npp) {
// HACK: temporarily hide the table we're enumerating so that
// invalidate() and deallocate() don't touch it.
PLDHashTable *tmp = sNPObjWrappers;
sNPObjWrappers = nullptr;
NPObject *npobj = entry->mNPObj;
if (npobj->_class && npobj->_class->invalidate) {
npobj->_class->invalidate(npobj);
}
#ifdef NS_BUILD_REFCNT_LOGGING
{
int32_t refCnt = npobj->referenceCount;
while (refCnt) {
--refCnt;
NS_LOG_RELEASE(npobj, refCnt, "BrowserNPObject");
}
}
#endif
// Force deallocation of plugin objects since the plugin they came
// from is being torn down.
if (npobj->_class && npobj->_class->deallocate) {
npobj->_class->deallocate(npobj);
} else {
PR_Free(npobj);
}
::JS_SetPrivate(entry->mJSObj, nullptr);
sNPObjWrappers = tmp;
if (sDelayedReleases && sDelayedReleases->RemoveElement(npobj)) {
OnWrapperDestroyed();
}
i.Remove();
}
}
}
}