Bug 583777 - Fix violations of the new JS request model. r=igor a=blocking-beta3 ok to check into a CLOSED TREE GECKO20b3_20100804_RELBRANCH FIREFOX_4_0b3_BUILD3 FIREFOX_4_0b3_RELEASE
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 05 Aug 2010 12:57:39 -0700
branchGECKO20b3_20100804_RELBRANCH
changeset 48965 900fdd7fb8b2635653ccbaac3daf4685a29c5c17
parent 48964 efab2edfa91be2d20a7a89427b38c51a747f6a91
child 48970 fb95988e1a860c870c91357eb950084ff65360be
push idunknown
push userunknown
push dateunknown
reviewersigor, blocking-beta3
bugs583777
milestone2.0b3
Bug 583777 - Fix violations of the new JS request model. r=igor a=blocking-beta3 ok to check into a CLOSED TREE
content/base/src/nsInProcessTabChildGlobal.cpp
--- a/content/base/src/nsInProcessTabChildGlobal.cpp
+++ b/content/base/src/nsInProcessTabChildGlobal.cpp
@@ -339,37 +339,39 @@ nsInProcessTabChildGlobal::LoadFrameScri
         read = 0;
       }
     }
     nsScriptLoader::ConvertToUTF16(channel, (PRUint8*)data.get(), data.Length(),
                                    EmptyString(), nsnull, dataString);
   }
 
   if (!dataString.IsEmpty()) {
-    JSAutoRequest ar(mCx);
-    jsval retval;
-    JSObject* global = nsnull;
-    mGlobal->GetJSObject(&global);
-    if (!global) {
-      return;
-    }
-
-    JSPrincipals* jsprin = nsnull;
-    mPrincipal->GetJSPrincipals(mCx, &jsprin);
-    nsContentUtils::XPConnect()->FlagSystemFilenamePrefix(url.get(), PR_TRUE);
     nsContentUtils::ThreadJSContextStack()->Push(mCx);
-    PRBool tmp = mLoadingScript;
-    mLoadingScript = PR_TRUE;
-    JS_EvaluateUCScriptForPrincipals(mCx, global, jsprin,
-                                     (jschar*)dataString.get(),
-                                     dataString.Length(),
-                                     url.get(), 1, &retval);
-    //XXX Argh, JSPrincipals are manually refcounted!
-    JSPRINCIPALS_DROP(mCx, jsprin);
-    mLoadingScript = tmp;
+    {
+      // Need to scope JSAutoRequest to happen after Push but before Pop,
+      // at least for now. See bug 584673.
+      JSAutoRequest ar(mCx);
+      jsval retval;
+      JSObject* global = nsnull;
+      mGlobal->GetJSObject(&global);
+      if (global) {
+        JSPrincipals* jsprin = nsnull;
+        mPrincipal->GetJSPrincipals(mCx, &jsprin);
+        nsContentUtils::XPConnect()->FlagSystemFilenamePrefix(url.get(), PR_TRUE);
+        PRBool tmp = mLoadingScript;
+        mLoadingScript = PR_TRUE;
+        JS_EvaluateUCScriptForPrincipals(mCx, global, jsprin,
+                                         (jschar*)dataString.get(),
+                                         dataString.Length(),
+                                         url.get(), 1, &retval);
+        //XXX Argh, JSPrincipals are manually refcounted!
+        JSPRINCIPALS_DROP(mCx, jsprin);
+        mLoadingScript = tmp;
+      }
+    } 
     JSContext* unused;
     nsContentUtils::ThreadJSContextStack()->Pop(&unused);
   }
   if (!mLoadingScript && mDelayedDisconnect) {
     mDelayedDisconnect = PR_FALSE;
     Disconnect();
   }
 }