Bug 887334 - Enter a compartment between manual calls to JS_{Save,Restore}FrameChain. r=luke
authorBobby Holley <bobbyholley@gmail.com>
Wed, 17 Jul 2013 11:53:52 -0700
changeset 138959 fcb33ae736077a7a4f21d4137735746e12af1e3a
parent 138958 4f4167826bc2e2ed20ea7a3bf53a345e1668313a
child 138960 09a8607459c447424033028eca4c1859af0d4203
push id24977
push userryanvm@gmail.com
push dateFri, 19 Jul 2013 00:35:38 +0000
treeherdermozilla-central@0d0263a58f06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs887334
milestone25.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 887334 - Enter a compartment between manual calls to JS_{Save,Restore}FrameChain. r=luke The stuff in nsXBLProtoImplMethod is doing the same thing, so let's just have it call into nsJSUtils.
content/xbl/src/nsXBLProtoImplMethod.cpp
dom/base/nsJSUtils.cpp
--- a/content/xbl/src/nsXBLProtoImplMethod.cpp
+++ b/content/xbl/src/nsXBLProtoImplMethod.cpp
@@ -342,20 +342,17 @@ nsXBLProtoImplAnonymousMethod::Execute(n
                                 0 /* argc */, nullptr /* argv */, retval.address());
   }
 
   if (!ok) {
     // If a constructor or destructor threw an exception, it doesn't stop
     // anything else.  We just report it.  Note that we need to set aside the
     // frame chain here, since the constructor invocation is not related to
     // whatever is on the stack right now, really.
-    JSBool saved = JS_SaveFrameChain(cx);
-    JS_ReportPendingException(cx);
-    if (saved)
-        JS_RestoreFrameChain(cx);
+    nsJSUtils::ReportPendingException(cx);
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsXBLProtoImplAnonymousMethod::Write(nsIScriptContext* aContext,
--- a/dom/base/nsJSUtils.cpp
+++ b/dom/base/nsJSUtils.cpp
@@ -138,17 +138,20 @@ nsJSUtils::GetCurrentlyRunningCodeInnerW
   return innerWindowID;
 }
 
 void
 nsJSUtils::ReportPendingException(JSContext *aContext)
 {
   if (JS_IsExceptionPending(aContext)) {
     bool saved = JS_SaveFrameChain(aContext);
-    JS_ReportPendingException(aContext);
+    {
+      JSAutoCompartment ac(aContext, js::GetDefaultGlobalForContext(aContext));
+      JS_ReportPendingException(aContext);
+    }
     if (saved) {
       JS_RestoreFrameChain(aContext);
     }
   }
 }
 
 nsresult
 nsJSUtils::CompileFunction(JSContext* aCx,