Bug 527870: Fix theoretical bug in async loading code. r=jst
authorJonas Sicking <jonas@sicking.cc>
Tue, 10 Nov 2009 21:45:54 -0800
changeset 34756 d2429d660af80fd862931cd911b3a960e00a432e
parent 34755 3c6b5f5ef7d62e4cfb17486c4ecada7c6a704c34
child 34757 c8f2a90879fba83b24b6f5310c986ed48145ac63
push idunknown
push userunknown
push dateunknown
reviewersjst
bugs527870
milestone1.9.3a1pre
Bug 527870: Fix theoretical bug in async loading code. r=jst
content/base/src/nsScriptLoader.cpp
--- a/content/base/src/nsScriptLoader.cpp
+++ b/content/base/src/nsScriptLoader.cpp
@@ -752,32 +752,41 @@ nsScriptLoader::ProcessPendingRequestsAs
 
     NS_DispatchToCurrentThread(ev);
   }
 }
 
 void
 nsScriptLoader::ProcessPendingRequests()
 {
-  nsRefPtr<nsScriptLoadRequest> request;
-  while (ReadyToExecuteScripts() &&
-         (request = GetFirstPendingRequest()) &&
-         !request->mLoading) {
-    mRequests.RemoveObject(request);
-    ProcessRequest(request);
-  }
+  while (1) {
+    nsRefPtr<nsScriptLoadRequest> request;
+    if (ReadyToExecuteScripts()) {
+      request = GetFirstPendingRequest();
+      if (request && !request->mLoading) {
+        mRequests.RemoveObject(request);
+      }
+      else {
+        request = nsnull;
+      }
+    }
 
-  // Async scripts don't wait for scriptblockers
-  for (PRInt32 i = 0; mEnabled && i < mAsyncRequests.Count(); ++i) {
-    if (!mAsyncRequests[i]->mLoading) {
-      request = mAsyncRequests[i];
-      mAsyncRequests.RemoveObjectAt(i);
-      ProcessRequest(request);
-      i = 0;
+    for (PRInt32 i = 0;
+         !request && mEnabled && i < mAsyncRequests.Count();
+         ++i) {
+      if (!mAsyncRequests[i]->mLoading) {
+        request = mAsyncRequests[i];
+        mAsyncRequests.RemoveObjectAt(i);
+      }
     }
+
+    if (!request)
+      break;
+
+    ProcessRequest(request);
   }
 
   while (!mPendingChildLoaders.IsEmpty() && ReadyToExecuteScripts()) {
     nsRefPtr<nsScriptLoader> child = mPendingChildLoaders[0];
     mPendingChildLoaders.RemoveElementAt(0);
     child->RemoveExecuteBlocker();
   }