Bug 936835 - Adding script runners or messing with mLinksToUpdate during FlushPendingLinkUpdates is not allowed. r=bz

This commit is contained in:
Mats Palmgren 2013-11-20 13:54:58 +00:00
parent fb3f5ea859
commit 5e94ba11ba
2 changed files with 16 additions and 1 deletions

View File

@ -2390,6 +2390,14 @@ protected:
// caches.
bool mDidDocumentOpen;
#ifdef DEBUG
/**
* This is true while FlushPendingLinkUpdates executes. Calls to
* [Un]RegisterPendingLinkUpdate will assert when this is true.
*/
bool mIsLinkUpdateRegistrationsForbidden;
#endif
// The document's script global object, the object from which the
// document can get its script context and scope. This is the
// *inner* window object.

View File

@ -10,6 +10,7 @@
#include "nsDocument.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Util.h"
@ -8812,6 +8813,7 @@ nsIDocument::EnumerateFreezableElements(FreezableElementEnumerator aEnumerator,
void
nsIDocument::RegisterPendingLinkUpdate(Link* aLink)
{
MOZ_ASSERT(!mIsLinkUpdateRegistrationsForbidden);
mLinksToUpdate.PutEntry(aLink);
mHasLinksToUpdate = true;
}
@ -8819,6 +8821,7 @@ nsIDocument::RegisterPendingLinkUpdate(Link* aLink)
void
nsIDocument::UnregisterPendingLinkUpdate(Link* aLink)
{
MOZ_ASSERT(!mIsLinkUpdateRegistrationsForbidden);
if (!mHasLinksToUpdate)
return;
@ -8835,10 +8838,14 @@ EnumeratePendingLinkUpdates(nsPtrHashKey<Link>* aEntry, void* aData)
void
nsIDocument::FlushPendingLinkUpdates()
{
MOZ_ASSERT(!mIsLinkUpdateRegistrationsForbidden);
if (!mHasLinksToUpdate)
return;
nsAutoScriptBlocker scriptBlocker;
#ifdef DEBUG
AutoRestore<bool> saved(mIsLinkUpdateRegistrationsForbidden);
mIsLinkUpdateRegistrationsForbidden = true;
#endif
mLinksToUpdate.EnumerateEntries(EnumeratePendingLinkUpdates, nullptr);
mLinksToUpdate.Clear();
mHasLinksToUpdate = false;