Bug 979481 - Don't depend on the default global for the SafeJSContext in nsJSUtils::ReportPendingException. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Thu, 06 Mar 2014 08:55:00 -0800
changeset 172341 5423f1b0599ea06777db50e8729696fb26ceeb0d
parent 172340 5d9fb147f723d544046578f3ebae60064590367e
child 172342 670fb9adcd29826b0ab35db2380121e6c99aa433
push id26358
push usercbook@mozilla.com
push dateFri, 07 Mar 2014 11:48:31 +0000
treeherdermozilla-central@b9fc2eb18bd1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs979481
milestone30.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 979481 - Don't depend on the default global for the SafeJSContext in nsJSUtils::ReportPendingException. r=bz
dom/base/nsJSUtils.cpp
--- a/dom/base/nsJSUtils.cpp
+++ b/dom/base/nsJSUtils.cpp
@@ -115,16 +115,22 @@ nsJSUtils::ReportPendingException(JSCont
       // information from it to script via onerror handlers.  So it's very
       // important that the duck typing happen in the same compartment as the
       // onerror handler.  In practice, that's the compartment of the window (or
       // otherwise default global) of aContext, so use that here.
       nsIScriptContext* scx = GetScriptContextFromJSContext(aContext);
       JS::Rooted<JSObject*> scope(aContext);
       scope = scx ? scx->GetWindowProxy()
                   : js::DefaultObjectForContextOrNull(aContext);
+      if (!scope) {
+        // The SafeJSContext has no default object associated with it.
+        MOZ_ASSERT(NS_IsMainThread());
+        MOZ_ASSERT(aContext == nsContentUtils::GetSafeJSContext());
+        scope = xpc::GetSafeJSContextGlobal();
+      }
       JSAutoCompartment ac(aContext, scope);
       JS_ReportPendingException(aContext);
     }
     if (saved) {
       JS_RestoreFrameChain(aContext);
     }
   }
 }