Bug 1022773 - Fix AutoJSAPI initialization rooting by annotating nsIScriptContext.GetWindowProxy and (temporarily) runtime-rooting, r=bholley
authorSteve Fink <sfink@mozilla.com>
Tue, 01 Jul 2014 09:02:10 -0700
changeset 212505 f8feedcca4325c557ec59623abb33f421207caeb
parent 212504 92065bea99d228f3e251da3ca746bec35e532110
child 212506 265a7db190924cd87ffdc75f25d7651a2af0a79c
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1022773
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1022773 - Fix AutoJSAPI initialization rooting by annotating nsIScriptContext.GetWindowProxy and (temporarily) runtime-rooting, r=bholley
dom/base/ScriptSettings.cpp
js/src/devtools/rootAnalysis/annotations.js
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -227,20 +227,26 @@ AutoJSAPI::AutoJSAPI()
 {
 }
 
 void
 AutoJSAPI::InitInternal(JSObject* aGlobal, JSContext* aCx, bool aIsMainThread)
 {
   mCx = aCx;
   if (aIsMainThread) {
+    // This Rooted<> is necessary only as long as AutoCxPusher::AutoCxPusher
+    // can GC, which is only possible because XPCJSContextStack::Push calls
+    // nsIPrincipal.Equals. Once that is removed, the Rooted<> will no longer
+    // be necessary.
+    JS::Rooted<JSObject*> global(JS_GetRuntime(aCx), aGlobal);
     mCxPusher.construct(mCx);
+    mAutoNullableCompartment.construct(mCx, global);
+  } else {
+    mAutoNullableCompartment.construct(mCx, aGlobal);
   }
-
-  mAutoNullableCompartment.construct(mCx, aGlobal);
 }
 
 AutoJSAPI::AutoJSAPI(nsIGlobalObject* aGlobalObject,
                      bool aIsMainThread,
                      JSContext* aCx)
 {
   MOZ_ASSERT(aGlobalObject);
   MOZ_ASSERT(aGlobalObject->GetGlobalJSObject(), "Must have a JS global");
--- a/js/src/devtools/rootAnalysis/annotations.js
+++ b/js/src/devtools/rootAnalysis/annotations.js
@@ -245,11 +245,15 @@ function isOverridableField(initialCSU, 
     if (field == "GetGlobalJSObject")
         return false;
     if (field == "GetIsMainThread")
         return false;
     if (initialCSU == 'nsIXPConnectJSObjectHolder' && field == 'GetJSObject')
         return false;
     if (initialCSU == 'nsIXPConnect' && field == 'GetSafeJSContext')
         return false;
+    if (initialCSU == 'nsIScriptContext') {
+        if (field == 'GetWindowProxy' || field == 'GetWindowProxyPreserveColor')
+            return false;
+    }
 
     return true;
 }