Bug 979481 - Prepare the cx stack machinery for a world where a cx has no default compartment object. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Wed, 26 Mar 2014 10:59:02 -0300
changeset 175371 4846ef638fad7164a372def044fab677f113d6d1
parent 175370 53f42355b2c88730457227eb437648acf41f62c8
child 175372 70108e99c116f6f2e7eee8b3f2c4e5254ea426d3
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 - Prepare the cx stack machinery for a world where a cx has no default compartment object. r=bz
js/xpconnect/src/XPCJSContextStack.cpp
--- a/js/xpconnect/src/XPCJSContextStack.cpp
+++ b/js/xpconnect/src/XPCJSContextStack.cpp
@@ -74,27 +74,27 @@ XPCJSContextStack::Push(JSContext *cx)
     if (e.cx) {
         // The cx we're pushing is also stack-top. In general we still need to
         // call JS_SaveFrameChain here. But if that would put us in a
         // compartment that's same-origin with the current one, we can skip it.
         nsIScriptSecurityManager* ssm = XPCWrapper::GetSecurityManager();
         if ((e.cx == cx) && ssm) {
             // DOM JSContexts don't store their default compartment object on
             // the cx, so in those cases we need to fetch it via the scx
-            // instead.
+            // instead. And in some cases (i.e. the SafeJSContext), we have no
+            // default compartment object at all.
             RootedObject defaultScope(cx, GetDefaultScopeFromJSContext(cx));
-
-            nsIPrincipal *currentPrincipal =
-              GetCompartmentPrincipal(js::GetContextCompartment(cx));
-            nsIPrincipal *defaultPrincipal = GetObjectPrincipal(defaultScope);
-            bool equal = false;
-            currentPrincipal->Equals(defaultPrincipal, &equal);
-            if (equal) {
-                mStack.AppendElement(cx);
-                return true;
+            if (defaultScope) {
+                nsIPrincipal *currentPrincipal =
+                  GetCompartmentPrincipal(js::GetContextCompartment(cx));
+                nsIPrincipal *defaultPrincipal = GetObjectPrincipal(defaultScope);
+                if (currentPrincipal->Equals(defaultPrincipal)) {
+                    mStack.AppendElement(cx);
+                    return true;
+                }
             }
         }
 
         {
             // Push() can be called outside any request for e.cx.
             JSAutoRequest ar(e.cx);
             if (!JS_SaveFrameChain(e.cx))
                 return false;