Bug 1289129. When setting up an AutoJSAPI with a global, make sure to expose that global to active JS. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 27 Jul 2016 11:05:36 -0400
changeset 349004 dddc81f6047d25c7a7ad85d2dbd0655940332fa6
parent 349003 45c51ccab098f766e3333c6f4c66c568fa6e79bf
child 349005 7d4e238cd15e480c122500bc9b6bfdf52059a177
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1289129
milestone50.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 1289129. When setting up an AutoJSAPI with a global, make sure to expose that global to active JS. r=mccr8
dom/base/ScriptSettings.cpp
dom/base/nsIGlobalObject.h
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -352,16 +352,19 @@ AutoJSAPI::InitInternal(nsIGlobalObject*
   mIsMainThread = aIsMainThread;
   mGlobalObject = aGlobalObject;
   if (aIsMainThread) {
     // We _could_ just unconditionally emplace mAutoRequest here.  It's just not
     // needed on worker threads, and we're hoping to kill it on the main thread
     // too.
     mAutoRequest.emplace(mCx);
   }
+  if (aGlobal) {
+    JS::ExposeObjectToActiveJS(aGlobal);
+  }
   mAutoNullableCompartment.emplace(mCx, aGlobal);
 
   ScriptSettingsStack::Push(this);
 
   mOldWarningReporter.emplace(JS::GetWarningReporter(aCx));
 
   JS::SetWarningReporter(aCx, WarningOnlyErrorReporter);
 
--- a/dom/base/nsIGlobalObject.h
+++ b/dom/base/nsIGlobalObject.h
@@ -51,17 +51,18 @@ public:
   IsDying() const
   {
     return mIsDying;
   }
 
   // GetGlobalJSObject may return a gray object.  If this ever changes so that
   // it stops doing that, please simplify the code in FindAssociatedGlobal in
   // BindingUtils.h that does JS::ExposeObjectToActiveJS on the return value of
-  // GetGlobalJSObject.
+  // GetGlobalJSObject.  Also, in that case the JS::ExposeObjectToActiveJS in
+  // AutoJSAPI::InitInternal can probably be removed.
   virtual JSObject* GetGlobalJSObject() = 0;
 
   // This method is not meant to be overridden.
   nsIPrincipal* PrincipalOrNull();
 
   void RegisterHostObjectURI(const nsACString& aURI);
 
   void UnregisterHostObjectURI(const nsACString& aURI);