Try to handle people processing events from inside an XBL constructor somewhat sanely. Bug 401743, r+sr+a=sicking

This commit is contained in:
bzbarsky@mit.edu 2007-12-04 08:56:44 -08:00
parent 9a39d2a052
commit c281a1e8ab

View File

@ -899,28 +899,43 @@ nsBindingManager::AddToAttachedQueue(nsXBLBinding* aBinding)
// If we're in the middle of processing our queue already, don't
// bother posting the event.
if (!mProcessingAttachedStack && !mProcessAttachedQueueEvent) {
mProcessAttachedQueueEvent =
new nsRunnableMethod<nsBindingManager>(
this, &nsBindingManager::DoProcessAttachedQueue);
nsresult rv = NS_DispatchToCurrentThread(mProcessAttachedQueueEvent);
if (NS_SUCCEEDED(rv) && mDocument) {
mDocument->BlockOnload();
}
PostProcessAttachedQueueEvent();
}
return NS_OK;
}
void
nsBindingManager::PostProcessAttachedQueueEvent()
{
mProcessAttachedQueueEvent =
new nsRunnableMethod<nsBindingManager>(
this, &nsBindingManager::DoProcessAttachedQueue);
nsresult rv = NS_DispatchToCurrentThread(mProcessAttachedQueueEvent);
if (NS_SUCCEEDED(rv) && mDocument) {
mDocument->BlockOnload();
}
}
void
nsBindingManager::DoProcessAttachedQueue()
{
ProcessAttachedQueue();
if (!mProcessingAttachedStack) {
ProcessAttachedQueue();
NS_ASSERTION(mAttachedStack.Length() == 0,
NS_ASSERTION(mAttachedStack.Length() == 0,
"Shouldn't have pending bindings!");
mProcessAttachedQueueEvent = nsnull;
mProcessAttachedQueueEvent = nsnull;
} else {
// Someone's doing event processing from inside a constructor.
// They're evil, but we'll fight back! Just poll on them being
// done and repost the attached queue event.
PostProcessAttachedQueueEvent();
}
// No matter what, unblock onload for the event that's fired.
if (mDocument) {
// Hold a strong reference while calling UnblockOnload since that might
// run script.