Bug 851781. Make sure that we don't reenter scriptblocker removal when we don't expect to. r=smaug

This commit is contained in:
Boris Zbarsky 2013-03-30 00:13:52 -04:00
parent d9ddb778b5
commit 3756e8c33e

View File

@ -5035,10 +5035,15 @@ nsContentUtils::AddScriptBlocker()
++sScriptBlockerCount;
}
#ifdef DEBUG
static bool sRemovingScriptBlockers = false;
#endif
/* static */
void
nsContentUtils::RemoveScriptBlocker()
{
MOZ_ASSERT(!sRemovingScriptBlockers);
NS_ASSERTION(sScriptBlockerCount != 0, "Negative script blockers");
--sScriptBlockerCount;
if (sScriptBlockerCount) {
@ -5054,14 +5059,23 @@ nsContentUtils::RemoveScriptBlocker()
"bad sRunnersCountAtFirstBlocker");
while (firstBlocker < lastBlocker) {
nsCOMPtr<nsIRunnable> runnable = (*sBlockedScriptRunners)[firstBlocker];
nsCOMPtr<nsIRunnable> runnable;
runnable.swap((*sBlockedScriptRunners)[firstBlocker]);
++firstBlocker;
// Calling the runnable can reenter us
runnable->Run();
// So can dropping the reference to the runnable
runnable = nullptr;
NS_ASSERTION(sRunnersCountAtFirstBlocker == 0,
"Bad count");
NS_ASSERTION(!sScriptBlockerCount, "This is really bad");
}
#ifdef DEBUG
AutoRestore<bool> removingScriptBlockers(sRemovingScriptBlockers);
sRemovingScriptBlockers = true;
#endif
sBlockedScriptRunners->RemoveElementsAt(originalFirstBlocker, blockersCount);
}