Bug 737075 - unmark gray strongly held observers implemented in JS. r=bsmedberg, smaug

This commit is contained in:
Andrew McCreight 2012-04-30 12:01:11 -07:00
Родитель 4b321f4886
Коммит 05fb8bb993
6 изменённых файлов: 43 добавлений и 0 удалений

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

@ -62,6 +62,7 @@
#include "nsFrameLoader.h"
#include "nsGenericElement.h"
#include "xpcpublic.h"
#include "nsObserverService.h"
static bool sInited = 0;
PRUint32 nsCCUncollectableMarker::sGeneration = 0;
@ -373,6 +374,10 @@ nsCCUncollectableMarker::Observe(nsISupports* aSubject, const char* aTopic,
if (cleanupJS) {
nsContentUtils::UnmarkGrayJSListenersInCCGenerationDocuments(sGeneration);
MarkMessageManagers();
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
static_cast<nsObserverService *>(obs.get())->UnmarkGrayStrongObservers();
previousWasJSCleanup = true;
} else if (previousWasJSCleanup) {
previousWasJSCleanup = false;

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

@ -101,6 +101,7 @@ EXPORTS = \
nsIByteBuffer.h \
nsIUnicharBuffer.h \
nsMathUtils.h \
nsObserverList.h \
nsObserverService.h \
nsStaticNameTable.h \
nsStaticAtom.h \

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

@ -40,6 +40,7 @@
#include "nsAutoPtr.h"
#include "nsCOMArray.h"
#include "nsISimpleEnumerator.h"
#include "xpcpublic.h"
nsresult
nsObserverList::AddObserver(nsIObserver* anObserver, bool ownsWeak)
@ -131,6 +132,16 @@ nsObserverList::NotifyObservers(nsISupports *aSubject,
}
}
void
nsObserverList::UnmarkGrayStrongObservers()
{
for (PRUint32 i = 0; i < mObservers.Length(); ++i) {
if (!mObservers[i].isWeakRef) {
xpc_TryUnmarkWrappedGrayObject(mObservers[i].asObserver());
}
}
}
NS_IMPL_ISUPPORTS1(nsObserverEnumerator, nsISimpleEnumerator)
nsObserverEnumerator::nsObserverEnumerator(nsObserverList* aObserverList)

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

@ -91,6 +91,10 @@ public:
// The array is filled in last-added-first order.
void FillObserverArray(nsCOMArray<nsIObserver> &aArray);
// Unmark any strongly held observers implemented in JS so the cycle
// collector will not traverse them.
void UnmarkGrayStrongObservers();
private:
nsTArray<ObserverRef> mObservers;
};

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

@ -190,3 +190,21 @@ NS_IMETHODIMP nsObserverService::NotifyObservers(nsISupports *aSubject,
return NS_OK;
}
static PLDHashOperator
UnmarkGrayObserverEntry(nsObserverList* aObserverList, void* aClosure)
{
if (aObserverList) {
aObserverList->UnmarkGrayStrongObservers();
}
return PL_DHASH_NEXT;
}
NS_IMETHODIMP
nsObserverService::UnmarkGrayStrongObservers()
{
NS_ENSURE_VALIDCALL
mObserverTopicTable.EnumerateEntries(UnmarkGrayObserverEntry, nsnull);
return NS_OK;
}

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

@ -62,6 +62,10 @@ public:
static nsresult
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
// Unmark any strongly held observers implemented in JS so the cycle
// collector will not traverse them.
NS_IMETHOD UnmarkGrayStrongObservers();
private:
~nsObserverService(void);