Bug 1165768 (part 1) - Convert |sNPObjWrappers| to |PLDHashTable2*|. r=froydnj.

This involves removing the last uses of PLDHashTable::SetOps(), which is a
nasty encapsulation-breaking hack. Hooray!

--HG--
extra : rebase_source : 87a9fcfe35e42d6e361906f0f4ef0d7fdf0b5dbb
This commit is contained in:
Nicholas Nethercote 2015-05-18 00:52:07 -07:00
Родитель 4a930bc0f3
Коммит c3bebace0a
1 изменённых файлов: 29 добавлений и 28 удалений

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

@ -83,7 +83,7 @@ static JSObjWrapperTable sJSObjWrappers;
static bool sJSObjWrappersAccessible = false;
// Hash of NPObject wrappers that wrap NPObjects as JSObjects.
static PLDHashTable sNPObjWrappers;
static PLDHashTable2* sNPObjWrappers;
// Global wrapper count. This includes JSObject wrappers *and*
// NPObject wrappers. When this count goes to zero, there are no more
@ -401,23 +401,24 @@ DestroyJSObjWrapperTable()
static bool
CreateNPObjWrapperTable()
{
MOZ_ASSERT(!sNPObjWrappers.IsInitialized());
MOZ_ASSERT(!sNPObjWrappers);
if (!RegisterGCCallbacks()) {
return false;
}
PL_DHashTableInit(&sNPObjWrappers, PL_DHashGetStubOps(),
sizeof(NPObjWrapperHashEntry));
sNPObjWrappers =
new PLDHashTable2(PL_DHashGetStubOps(), sizeof(NPObjWrapperHashEntry));
return true;
}
static void
DestroyNPObjWrapperTable()
{
MOZ_ASSERT(sNPObjWrappers.EntryCount() == 0);
MOZ_ASSERT(sNPObjWrappers->EntryCount() == 0);
PL_DHashTableFinish(&sNPObjWrappers);
delete sNPObjWrappers;
sNPObjWrappers = nullptr;
}
static void
@ -436,7 +437,7 @@ OnWrapperDestroyed()
DestroyJSObjWrapperTable();
}
if (sNPObjWrappers.IsInitialized()) {
if (sNPObjWrappers) {
// No more wrappers, and our hash was initialized. Finish the
// hash to prevent leaking it.
DestroyNPObjWrapperTable();
@ -1761,8 +1762,8 @@ NPObjWrapper_Finalize(js::FreeOp *fop, JSObject *obj)
{
NPObject *npobj = (NPObject *)::JS_GetPrivate(obj);
if (npobj) {
if (sNPObjWrappers.IsInitialized()) {
PL_DHashTableRemove(&sNPObjWrappers, npobj);
if (sNPObjWrappers) {
PL_DHashTableRemove(sNPObjWrappers, npobj);
}
}
@ -1777,7 +1778,7 @@ NPObjWrapper_ObjectMoved(JSObject *obj, const JSObject *old)
// The wrapper JSObject has been moved, so we need to update the entry in the
// sNPObjWrappers hash table, if present.
if (!sNPObjWrappers.IsInitialized()) {
if (!sNPObjWrappers) {
return;
}
@ -1790,7 +1791,7 @@ NPObjWrapper_ObjectMoved(JSObject *obj, const JSObject *old)
JS::AutoSuppressGCAnalysis nogc;
NPObjWrapperHashEntry *entry = static_cast<NPObjWrapperHashEntry *>
(PL_DHashTableSearch(&sNPObjWrappers, npobj));
(PL_DHashTableSearch(sNPObjWrappers, npobj));
MOZ_ASSERT(entry && entry->mJSObj);
MOZ_ASSERT(entry->mJSObj == old);
entry->mJSObj = obj;
@ -1836,14 +1837,14 @@ nsNPObjWrapper::OnDestroy(NPObject *npobj)
return;
}
if (!sNPObjWrappers.IsInitialized()) {
if (!sNPObjWrappers) {
// No hash yet (or any more), no used wrappers available.
return;
}
NPObjWrapperHashEntry *entry = static_cast<NPObjWrapperHashEntry *>
(PL_DHashTableSearch(&sNPObjWrappers, npobj));
(PL_DHashTableSearch(sNPObjWrappers, npobj));
if (entry && entry->mJSObj) {
// Found a live NPObject wrapper, null out its JSObjects' private
@ -1852,7 +1853,7 @@ nsNPObjWrapper::OnDestroy(NPObject *npobj)
::JS_SetPrivate(entry->mJSObj, nullptr);
// Remove the npobj from the hash now that it went away.
PL_DHashTableRawRemove(&sNPObjWrappers, entry);
PL_DHashTableRawRemove(sNPObjWrappers, entry);
// The finalize hook will call OnWrapperDestroyed().
}
@ -1886,7 +1887,7 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj)
return nullptr;
}
if (!sNPObjWrappers.IsInitialized()) {
if (!sNPObjWrappers) {
// No hash yet (or any more), initialize it.
if (!CreateNPObjWrapperTable()) {
return nullptr;
@ -1894,7 +1895,7 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj)
}
NPObjWrapperHashEntry *entry = static_cast<NPObjWrapperHashEntry *>
(PL_DHashTableAdd(&sNPObjWrappers, npobj, fallible));
(PL_DHashTableAdd(sNPObjWrappers, npobj, fallible));
if (!entry) {
// Out of memory
@ -1916,24 +1917,24 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj)
entry->mNPObj = npobj;
entry->mNpp = npp;
uint32_t generation = sNPObjWrappers.Generation();
uint32_t generation = sNPObjWrappers->Generation();
// No existing JSObject, create one.
JS::Rooted<JSObject*> obj(cx, ::JS_NewObject(cx, js::Jsvalify(&sNPObjectJSWrapperClass)));
if (generation != sNPObjWrappers.Generation()) {
if (generation != sNPObjWrappers->Generation()) {
// Reload entry if the JS_NewObject call caused a GC and reallocated
// the table (see bug 445229). This is guaranteed to succeed.
NS_ASSERTION(PL_DHashTableSearch(&sNPObjWrappers, npobj),
NS_ASSERTION(PL_DHashTableSearch(sNPObjWrappers, npobj),
"Hashtable didn't find what we just added?");
}
if (!obj) {
// OOM? Remove the stale entry from the hash.
PL_DHashTableRawRemove(&sNPObjWrappers, entry);
PL_DHashTableRawRemove(sNPObjWrappers, entry);
return nullptr;
}
@ -1967,10 +1968,10 @@ NPObjWrapperPluginDestroyedCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
NppAndCx *nppcx = reinterpret_cast<NppAndCx *>(arg);
if (entry->mNpp == nppcx->npp) {
// Prevent invalidate() and deallocate() from touching the hash
// we're enumerating.
const PLDHashTableOps *ops = table->Ops();
table->SetOps(nullptr);
// HACK: temporarily hide the hash we're enumerating so that invalidate()
// and deallocate() don't touch it.
PLDHashTable2 *tmp = static_cast<PLDHashTable2*>(table);
sNPObjWrappers = nullptr;
NPObject *npobj = entry->mNPObj;
@ -1998,7 +1999,7 @@ NPObjWrapperPluginDestroyedCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
::JS_SetPrivate(entry->mJSObj, nullptr);
table->SetOps(ops);
sNPObjWrappers = tmp;
if (sDelayedReleases && sDelayedReleases->RemoveElement(npobj)) {
OnWrapperDestroyed();
@ -2039,9 +2040,9 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
// 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.IsInitialized()) {
if (sNPObjWrappers) {
NppAndCx nppcx = { npp, cx };
PL_DHashTableEnumerate(&sNPObjWrappers,
PL_DHashTableEnumerate(sNPObjWrappers,
NPObjWrapperPluginDestroyedCallback, &nppcx);
}
}
@ -2074,7 +2075,7 @@ LookupNPP(NPObject *npobj)
}
NPObjWrapperHashEntry *entry = static_cast<NPObjWrapperHashEntry *>
(PL_DHashTableAdd(&sNPObjWrappers, npobj, fallible));
(PL_DHashTableAdd(sNPObjWrappers, npobj, fallible));
if (!entry) {
return nullptr;