From eaf2b92fcadfd10ace9a8eecc9d425ccfee3f6de Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 6 Mar 2014 08:55:00 -0800 Subject: [PATCH] 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 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/js/xpconnect/src/XPCJSContextStack.cpp b/js/xpconnect/src/XPCJSContextStack.cpp index 1506a151cc6..88e2f9a4c7e 100644 --- a/js/xpconnect/src/XPCJSContextStack.cpp +++ b/js/xpconnect/src/XPCJSContextStack.cpp @@ -79,17 +79,17 @@ XPCJSContextStack::Push(JSContext *cx) 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; + } } }