Bug 979481 - Don't depend on the default global for the SafeJSContext in nsJSUtils::ReportPendingException. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Wed, 26 Mar 2014 10:59:03 -0300
changeset 175372 70108e99c116f6f2e7eee8b3f2c4e5254ea426d3
parent 175371 4846ef638fad7164a372def044fab677f113d6d1
child 175373 ae9c10bf7be8766453352e0d4a497a2856aa027f
push id41516
push userbobbyholley@gmail.com
push dateWed, 26 Mar 2014 13:59:34 +0000
treeherdermozilla-inbound@15ceb48e2bf6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs979481
milestone31.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);
     }
   }
 }