Bug 587222 - Script caching in messageManager leaks; r=Olli.Pettay a=blocking-because-550936-is-a-blocker

This commit is contained in:
Alon Zakai 2010-08-16 16:40:04 -04:00
parent cc6b8b5e56
commit cf8363b4a5
2 changed files with 34 additions and 0 deletions

View File

@ -510,6 +510,7 @@ NS_NewGlobalMessageManager(nsIChromeFrameMessageManager** aResult)
nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>*
nsFrameScriptExecutor::sCachedScripts = nsnull;
nsRefPtr<nsScriptCacheCleaner> nsFrameScriptExecutor::sScriptCacheCleaner;
void
nsFrameScriptExecutor::DidCreateCx()
@ -519,6 +520,8 @@ nsFrameScriptExecutor::DidCreateCx()
sCachedScripts =
new nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>;
sCachedScripts->Init();
sScriptCacheCleaner = new nsScriptCacheCleaner();
}
}
@ -564,6 +567,8 @@ nsFrameScriptExecutor::Shutdown()
delete sCachedScripts;
sCachedScripts = nsnull;
sScriptCacheCleaner = nsnull;
}
}
@ -672,3 +677,6 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
nsContentUtils::ThreadJSContextStack()->Pop(&unused);
}
}
NS_IMPL_ISUPPORTS1(nsScriptCacheCleaner, nsIObserver);

View File

@ -38,6 +38,7 @@
#define nsFrameMessageManager_h__
#include "nsIFrameMessageManager.h"
#include "nsIObserver.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsCOMArray.h"
@ -48,6 +49,8 @@
#include "nsIPrincipal.h"
#include "nsIXPConnect.h"
#include "nsDataHashtable.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
class nsAXPCNativeCallContext;
struct JSContext;
@ -153,6 +156,8 @@ protected:
nsTArray<nsString> mPendingScripts;
};
class nsScriptCacheCleaner;
struct nsFrameScriptExecutorJSObjectHolder
{
nsFrameScriptExecutorJSObjectHolder(JSObject* aObject) : mObject(aObject) {}
@ -173,6 +178,27 @@ protected:
JSContext* mCx;
nsCOMPtr<nsIPrincipal> mPrincipal;
static nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>* sCachedScripts;
static nsRefPtr<nsScriptCacheCleaner> sScriptCacheCleaner;
};
class nsScriptCacheCleaner : public nsIObserver
{
NS_DECL_ISUPPORTS
nsScriptCacheCleaner()
{
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
if (obsSvc)
obsSvc->AddObserver(this, "xpcom-shutdown", PR_FALSE);
}
NS_IMETHODIMP Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
nsFrameScriptExecutor::Shutdown();
return NS_OK;
}
};
#endif