Bug 579535 - Remove AddScriptBlockerAndPreventAddingRunners() API and warn about script runner failures. r=bz

This commit is contained in:
Bobby Holley 2012-01-23 16:52:38 +01:00
parent 52a93f5d13
commit 76f009f4a9
3 changed files with 9 additions and 26 deletions

View File

@ -1451,13 +1451,6 @@ public:
*/
static void AddScriptBlocker();
/**
* Increases the count of blockers preventing scripts from running.
* Also, while this script blocker is active, script runners must not be
* added --- we'll assert if one is, and ignore it.
*/
static void AddScriptBlockerAndPreventAddingRunners();
/**
* Decreases the count of blockers preventing scripts from running.
* NOTE: You might want to use nsAutoScriptBlocker rather than calling

View File

@ -260,7 +260,6 @@ PRUint32 nsContentUtils::sDOMNodeRemovedSuppressCount = 0;
#endif
nsTArray< nsCOMPtr<nsIRunnable> >* nsContentUtils::sBlockedScriptRunners = nsnull;
PRUint32 nsContentUtils::sRunnersCountAtFirstBlocker = 0;
PRUint32 nsContentUtils::sScriptBlockerCountWhereRunnersPrevented = 0;
nsIInterfaceRequestor* nsContentUtils::sSameOriginChecker = nsnull;
bool nsContentUtils::sIsHandlingKeyBoardEvent = false;
@ -4417,25 +4416,12 @@ nsContentUtils::AddScriptBlocker()
++sScriptBlockerCount;
}
/* static */
void
nsContentUtils::AddScriptBlockerAndPreventAddingRunners()
{
AddScriptBlocker();
if (sScriptBlockerCountWhereRunnersPrevented == 0) {
sScriptBlockerCountWhereRunnersPrevented = sScriptBlockerCount;
}
}
/* static */
void
nsContentUtils::RemoveScriptBlocker()
{
NS_ASSERTION(sScriptBlockerCount != 0, "Negative script blockers");
--sScriptBlockerCount;
if (sScriptBlockerCount < sScriptBlockerCountWhereRunnersPrevented) {
sScriptBlockerCountWhereRunnersPrevented = 0;
}
if (sScriptBlockerCount) {
return;
}
@ -4469,10 +4455,6 @@ nsContentUtils::AddScriptRunner(nsIRunnable* aRunnable)
}
if (sScriptBlockerCount) {
if (sScriptBlockerCountWhereRunnersPrevented > 0) {
NS_ERROR("Adding a script runner when that is prevented!");
return false;
}
return sBlockedScriptRunners->AppendElement(aRunnable) != nsnull;
}

View File

@ -7097,8 +7097,16 @@ nsDocument::BlockOnload()
// block onload only when there are no script blockers.
++mAsyncOnloadBlockCount;
if (mAsyncOnloadBlockCount == 1) {
nsContentUtils::AddScriptRunner(
bool success = nsContentUtils::AddScriptRunner(
NS_NewRunnableMethod(this, &nsDocument::AsyncBlockOnload));
// The script runner shouldn't fail to add. But if somebody broke
// something and it does, we'll thrash at 100% cpu forever. The best
// response is just to ignore the onload blocking request. See bug 579535.
if (!success) {
NS_WARNING("Disaster! Onload blocking script runner failed to add - expect bad things!");
mAsyncOnloadBlockCount = 0;
}
}
return;
}