Bug 632064 - remove JS_GetScopeChain (r=mrbkap)
authorLuke Wagner <luke@mozilla.com>
Wed, 28 Sep 2011 17:57:27 -0700
changeset 78992 151f190c27ab2c8906d8a86b5b41e00d9e5810c0
parent 78991 58c9046d8485f1dac0b9b678185ad175d3a0f7fe
child 78993 d749864ebd018016cf577bc85a281c120fa871d8
push idunknown
push userunknown
push dateunknown
reviewersmrbkap
bugs632064
milestone10.0a1
Bug 632064 - remove JS_GetScopeChain (r=mrbkap)
content/base/src/nsXMLHttpRequest.cpp
content/html/content/src/nsDOMStringMap.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsJSUtils.cpp
dom/base/nsLocation.cpp
dom/indexedDB/IDBKeyRange.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsdbgapi.cpp
js/src/jsdbgapi.h
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
js/src/vm/Debugger.cpp
js/src/vm/Stack-inl.h
js/src/xpconnect/shell/xpcshell.cpp
js/src/xpconnect/src/xpccomponents.cpp
js/src/xpconnect/src/xpcdebug.cpp
js/src/xpconnect/src/xpcthrower.cpp
js/src/xpconnect/wrappers/AccessCheck.cpp
js/src/xpconnect/wrappers/XrayWrapper.cpp
toolkit/components/perf/PerfMeasurement.cpp
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -1043,27 +1043,27 @@ NS_IMETHODIMP nsXMLHttpRequest::GetRespo
       *aResult = OBJECT_TO_JSVAL(mResultArrayBuffer);
     } else {
       *aResult = JSVAL_NULL;
     }
     break;
 
   case XML_HTTP_RESPONSE_TYPE_BLOB:
     if (mState & XML_HTTP_REQUEST_DONE && mResponseBlob) {
-      JSObject* scope = JS_GetScopeChain(aCx);
+      JSObject* scope = JS_GetGlobalForScopeChain(aCx);
       rv = nsContentUtils::WrapNative(aCx, scope, mResponseBlob, aResult,
                                       nsnull, PR_TRUE);
     } else {
       *aResult = JSVAL_NULL;
     }
     break;
 
   case XML_HTTP_RESPONSE_TYPE_DOCUMENT:
     if (mState & XML_HTTP_REQUEST_DONE && mResponseXML) {
-      JSObject* scope = JS_GetScopeChain(aCx);
+      JSObject* scope = JS_GetGlobalForScopeChain(aCx);
       rv = nsContentUtils::WrapNative(aCx, scope, mResponseXML, aResult,
                                       nsnull, PR_TRUE);
     } else {
       *aResult = JSVAL_NULL;
     }
     break;
 
   case XML_HTTP_RESPONSE_TYPE_JSON:
--- a/content/html/content/src/nsDOMStringMap.cpp
+++ b/content/html/content/src/nsDOMStringMap.cpp
@@ -191,17 +191,17 @@ nsresult nsDOMStringMap::RemovePropInter
 {
   nsAutoString attr;
   aAttr->ToString(attr);
   nsAutoString prop;
   NS_ENSURE_TRUE(AttrToDataProp(attr, prop), NS_OK);
 
   jsval val;
   JSContext* cx = nsContentUtils::GetCurrentJSContext();
-  nsresult rv = nsContentUtils::WrapNative(cx, JS_GetScopeChain(cx),
+  nsresult rv = nsContentUtils::WrapNative(cx, JS_GetGlobalForScopeChain(cx),
                                            this, &val);
   NS_ENSURE_SUCCESS(rv, rv);
 
   JSAutoEnterCompartment ac;
   if (!ac.enter(cx, JSVAL_TO_OBJECT(val))) {
     return NS_ERROR_FAILURE;
   }
 
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -61,17 +61,17 @@
 #include "nsDOMError.h"
 
 // Helper Classes
 #include "nsXPIDLString.h"
 #include "nsJSUtils.h"
 #include "prmem.h"
 #include "jsapi.h"              // for JSAutoRequest
 #include "jsdbgapi.h"           // for JS_ClearWatchPointsForObject
-#include "jsfriendapi.h"        // for JS_GetFrameScopeChainRaw
+#include "jsfriendapi.h"        // for JS_GetGlobalForFrame
 #include "nsReadableUtils.h"
 #include "nsDOMClassInfo.h"
 #include "nsJSEnvironment.h"
 #include "nsCharSeparatedTokenizer.h" // for Accept-Language parsing
 #include "nsUnicharUtils.h"
 #include "mozilla/Preferences.h"
 
 // Other Classes
@@ -5901,30 +5901,29 @@ nsGlobalWindow::CallerInnerWindow()
   JS_FrameIterator(cx, &fp);
   if (fp) {
     while (!JS_IsScriptFrame(cx, fp)) {
       if (!JS_FrameIterator(cx, &fp))
         break;
     }
 
     if (fp)
-      scope = JS_GetFrameScopeChainRaw(fp);
+      scope = JS_GetGlobalForFrame(fp);
   }
 
   if (!scope)
-    scope = JS_GetScopeChain(cx);
+    scope = JS_GetGlobalForScopeChain(cx);
 
   JSAutoEnterCompartment ac;
   if (!ac.enter(cx, scope))
     return nsnull;
 
   nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
   nsContentUtils::XPConnect()->
-    GetWrappedNativeOfJSObject(cx, ::JS_GetGlobalForObject(cx, scope),
-                               getter_AddRefs(wrapper));
+    GetWrappedNativeOfJSObject(cx, scope, getter_AddRefs(wrapper));
   if (!wrapper)
     return nsnull;
 
   // The calling window must be holding a reference, so we can just return a
   // raw pointer here and let the QI's addref be balanced by the nsCOMPtr
   // destructor's release.
   nsCOMPtr<nsPIDOMWindow> win = do_QueryWrappedNative(wrapper);
   if (!win)
@@ -6002,17 +6001,17 @@ PostMessageReadStructuredClone(JSContext
 {
   NS_ASSERTION(closure, "Must have closure!");
 
   if (tag == SCTAG_DOM_BLOB || tag == SCTAG_DOM_FILELIST) {
     NS_ASSERTION(!data, "Data should be empty");
 
     nsISupports* supports;
     if (JS_ReadBytes(reader, &supports, sizeof(supports))) {
-      JSObject* global = JS_GetGlobalForObject(cx, JS_GetScopeChain(cx));
+      JSObject* global = JS_GetGlobalForScopeChain(cx);
       if (global) {
         jsval val;
         nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
         if (NS_SUCCEEDED(nsContentUtils::WrapNative(cx, global, supports,
                                                     &val,
                                                     getter_AddRefs(wrapper)))) {
           return JSVAL_TO_OBJECT(val);
         }
--- a/dom/base/nsJSUtils.cpp
+++ b/dom/base/nsJSUtils.cpp
@@ -96,24 +96,23 @@ nsJSUtils::GetCallingLocation(JSContext*
   return JS_FALSE;
 }
 
 nsIScriptGlobalObject *
 nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj)
 {
   nsISupports* supports;
   JSClass* clazz;
-  JSObject* parent;
   JSObject* glob = aObj; // starting point for search
 
   if (!glob)
     return nsnull;
 
-  while ((parent = ::JS_GetParent(aContext, glob)))
-    glob = parent;
+  glob = JS_GetGlobalForObject(aContext, glob);
+  NS_ABORT_IF_FALSE(glob, "Infallible returns null");
 
   clazz = JS_GET_CLASS(aContext, glob);
 
   if (!clazz ||
       !(clazz->flags & JSCLASS_HAS_PRIVATE) ||
       !(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) ||
       !(supports = (nsISupports*)::JS_GetPrivate(aContext, glob))) {
     return nsnull;
--- a/dom/base/nsLocation.cpp
+++ b/dom/base/nsLocation.cpp
@@ -66,17 +66,17 @@
 #include "nsDOMError.h"
 #include "nsDOMClassInfoID.h"
 #include "nsCRT.h"
 #include "nsIProtocolHandler.h"
 #include "nsReadableUtils.h"
 #include "nsITextToSubURI.h"
 #include "nsContentUtils.h"
 #include "nsJSUtils.h"
-#include "jsdbgapi.h"
+#include "jsfriendapi.h"
 
 static nsresult
 GetContextFromStack(nsIJSContextStack *aStack, JSContext **aContext)
 {
   nsCOMPtr<nsIJSContextStackIterator>
     iterator(do_CreateInstance("@mozilla.org/js/xpc/ContextStackIterator;1"));
   NS_ENSURE_TRUE(iterator, NS_ERROR_FAILURE);
 
@@ -174,17 +174,17 @@ nsLocation::GetDocShell()
 
 // Try to get the the document corresponding to the given JSStackFrame.
 static already_AddRefed<nsIDocument>
 GetFrameDocument(JSContext *cx, JSStackFrame *fp)
 {
   if (!cx || !fp)
     return nsnull;
 
-  JSObject* scope = JS_GetFrameScopeChain(cx, fp);
+  JSObject* scope = JS_GetGlobalForFrame(fp);
   if (!scope)
     return nsnull;
 
   JSAutoEnterCompartment ac;
   if (!ac.enter(cx, scope))
      return nsnull;
 
   nsCOMPtr<nsIDOMWindow> window =
--- a/dom/indexedDB/IDBKeyRange.cpp
+++ b/dom/indexedDB/IDBKeyRange.cpp
@@ -109,17 +109,17 @@ ReturnKeyRange(JSContext* aCx,
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(aCx, "Null pointer!");
   NS_ASSERTION(aVp, "Null pointer!");
   NS_ASSERTION(aKeyRange, "Null pointer!");
 
   nsIXPConnect* xpc = nsContentUtils::XPConnect();
   NS_ASSERTION(xpc, "This should never be null!");
 
-  JSObject* global = JS_GetGlobalForObject(aCx, JS_GetScopeChain(aCx));
+  JSObject* global = JS_GetGlobalForScopeChain(aCx);
   NS_ENSURE_TRUE(global, JS_FALSE);
 
   nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
   if (NS_FAILED(xpc->WrapNative(aCx, global, aKeyRange,
                                 NS_GET_IID(nsIIDBKeyRange),
                                 getter_AddRefs(holder)))) {
     JS_ReportError(aCx, "Couldn't wrap IDBKeyRange object.");
     return JS_FALSE;
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -2053,23 +2053,16 @@ JS_PUBLIC_API(JSBool)
 JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject **objp)
 {
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, obj);
     return js_GetClassObject(cx, obj, key, objp);
 }
 
 JS_PUBLIC_API(JSObject *)
-JS_GetScopeChain(JSContext *cx)
-{
-    CHECK_REQUEST(cx);
-    return GetScopeChain(cx);
-}
-
-JS_PUBLIC_API(JSObject *)
 JS_GetGlobalForObject(JSContext *cx, JSObject *obj)
 {
     assertSameCompartment(cx, obj);
     return obj->getGlobal();
 }
 
 JS_PUBLIC_API(JSObject *)
 JS_GetGlobalForScopeChain(JSContext *cx)
@@ -4298,17 +4291,17 @@ JS_NewFunctionById(JSContext *cx, JSNati
 
 JS_PUBLIC_API(JSObject *)
 JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent)
 {
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, parent);  // XXX no funobj for now
     if (!parent) {
         if (cx->hasfp())
-            parent = GetScopeChain(cx, cx->fp());
+            parent = &cx->fp()->scopeChain();
         if (!parent)
             parent = cx->globalObject;
         JS_ASSERT(parent);
     }
 
     if (!funobj->isFunction()) {
         /*
          * We cannot clone this object, so fail (we used to return funobj, bad
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -2302,19 +2302,16 @@ extern JS_PUBLIC_API(JSIdArray *)
 JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
                                     JSIdArray *ida);
 
 extern JS_PUBLIC_API(JSBool)
 JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
                   JSObject **objp);
 
 extern JS_PUBLIC_API(JSObject *)
-JS_GetScopeChain(JSContext *cx);
-
-extern JS_PUBLIC_API(JSObject *)
 JS_GetGlobalForObject(JSContext *cx, JSObject *obj);
 
 extern JS_PUBLIC_API(JSObject *)
 JS_GetGlobalForScopeChain(JSContext *cx);
 
 /*
  * Initialize the 'Reflect' object on a global object.
  */
--- a/js/src/jsdbgapi.cpp
+++ b/js/src/jsdbgapi.cpp
@@ -573,23 +573,16 @@ JS_GetFramePrincipalArray(JSContext *cx,
 }
 
 JS_PUBLIC_API(JSBool)
 JS_IsScriptFrame(JSContext *cx, JSStackFrame *fp)
 {
     return !Valueify(fp)->isDummyFrame();
 }
 
-/* this is deprecated, use JS_GetFrameScopeChain instead */
-JS_PUBLIC_API(JSObject *)
-JS_GetFrameObject(JSContext *cx, JSStackFrame *fp)
-{
-    return &Valueify(fp)->scopeChain();
-}
-
 JS_PUBLIC_API(JSObject *)
 JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fpArg)
 {
     StackFrame *fp = Valueify(fpArg);
     JS_ASSERT(cx->stack.containsSlow(fp));
 
     js::AutoCompartment ac(cx, &fp->scopeChain());
     if (!ac.enter())
--- a/js/src/jsdbgapi.h
+++ b/js/src/jsdbgapi.h
@@ -259,20 +259,16 @@ extern JS_PUBLIC_API(void)
 JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
 
 extern JS_PUBLIC_API(void *)
 JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
 
 extern JS_PUBLIC_API(JSBool)
 JS_IsScriptFrame(JSContext *cx, JSStackFrame *fp);
 
-/* this is deprecated, use JS_GetFrameScopeChain instead */
-extern JS_PUBLIC_API(JSObject *)
-JS_GetFrameObject(JSContext *cx, JSStackFrame *fp);
-
 extern JS_PUBLIC_API(JSObject *)
 JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp);
 
 extern JS_PUBLIC_API(JSObject *)
 JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp);
 
 extern JS_PUBLIC_API(JSBool)
 JS_GetFrameThis(JSContext *cx, JSStackFrame *fp, jsval *thisv);
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -77,19 +77,19 @@ JS_FRIEND_API(JSFunction *)
 JS_GetObjectFunction(JSObject *obj)
 {
     if (obj->isFunction())
         return obj->getFunctionPrivate();
     return NULL;
 }
 
 JS_FRIEND_API(JSObject *)
-JS_GetFrameScopeChainRaw(JSStackFrame *fp)
+JS_GetGlobalForFrame(JSStackFrame *fp)
 {
-    return &Valueify(fp)->scopeChain();
+    return Valueify(fp)->scopeChain().getGlobal();
 }
 
 JS_FRIEND_API(JSBool)
 JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto)
 {
     /*
      * Change the prototype of an object which hasn't been used anywhere
      * and does not share its type with another object. Unlike JS_SetPrototype,
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -51,17 +51,17 @@ JS_GetAnonymousString(JSRuntime *rt);
 
 extern JS_FRIEND_API(JSObject *)
 JS_FindCompilationScope(JSContext *cx, JSObject *obj);
 
 extern JS_FRIEND_API(JSFunction *)
 JS_GetObjectFunction(JSObject *obj);
 
 extern JS_FRIEND_API(JSObject *)
-JS_GetFrameScopeChainRaw(JSStackFrame *fp);
+JS_GetGlobalForFrame(JSStackFrame *fp);
 
 extern JS_FRIEND_API(JSBool)
 JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto);
 
 extern JS_FRIEND_API(JSObject *)
 JS_NewObjectWithUniqueType(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
 
 extern JS_FRIEND_API(uint32)
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -2801,20 +2801,17 @@ DebuggerFrameEval(JSContext *cx, uintN a
             }
         }
     }
 
     AutoCompartment ac(cx, &fp->scopeChain());
     if (!ac.enter())
         return false;
 
-    /* Get a scope object. */
-    if (fp->isNonEvalFunctionFrame() && !fp->hasCallObj() && !CreateFunCallObject(cx, fp))
-        return false;
-    JSObject *scobj = GetScopeChain(cx, fp);
+    JSObject *scobj = JS_GetFrameScopeChain(cx, Jsvalify(fp));
     if (!scobj)
         return false;
 
     /* If evalWithBindings, create the inner scope object. */
     if (mode == WithBindings) {
         /* TODO - Should probably create a With object here. */
         scobj = NewNonFunction<WithProto::Given>(cx, &ObjectClass, NULL, scobj);
         if (!scobj)
--- a/js/src/vm/Stack-inl.h
+++ b/js/src/vm/Stack-inl.h
@@ -351,20 +351,18 @@ StackFrame::setScopeChainWithOwnCallObj(
 }
 
 inline CallObject &
 StackFrame::callObj() const
 {
     JS_ASSERT_IF(isNonEvalFunctionFrame() || isStrictEvalFrame(), hasCallObj());
 
     JSObject *pobj = &scopeChain();
-    while (JS_UNLIKELY(!pobj->isCall())) {
-        JS_ASSERT(IsCacheableNonGlobalScope(pobj) || pobj->isWith());
+    while (JS_UNLIKELY(!pobj->isCall()))
         pobj = pobj->getParent();
-    }
     return pobj->asCall();
 }
 
 inline bool
 StackFrame::maintainNestingState() const
 {
     /*
      * Whether to invoke the nesting epilogue/prologue to maintain active
--- a/js/src/xpconnect/shell/xpcshell.cpp
+++ b/js/src/xpconnect/shell/xpcshell.cpp
@@ -261,17 +261,17 @@ GetLine(JSContext *cx, char *bufp, FILE 
         *bufp++ = '\n';
         *bufp = '\0';
     } else
 #endif
     {
         char line[256] = { '\0' };
         fputs(prompt, gOutFile);
         fflush(gOutFile);
-        if (!fgets(line, sizeof line, file) && errno != EINTR || feof(file))
+        if ((!fgets(line, sizeof line, file) && errno != EINTR) || feof(file))
             return JS_FALSE;
         strcpy(bufp, line);
     }
     return JS_TRUE;
 }
 
 static void
 my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
--- a/js/src/xpconnect/src/xpccomponents.cpp
+++ b/js/src/xpconnect/src/xpccomponents.cpp
@@ -3623,21 +3623,20 @@ xpc_EvalInSandbox(JSContext *cx, JSObjec
         !jsPrincipals) {
         return NS_ERROR_FAILURE;
     }
 
     JSObject *callingScope;
     {
         JSAutoRequest req(cx);
 
-        callingScope = JS_GetScopeChain(cx);
+        callingScope = JS_GetGlobalForScopeChain(cx);
         if (!callingScope) {
             return NS_ERROR_FAILURE;
         }
-        callingScope = JS_GetGlobalForObject(cx, callingScope);
     }
 
     nsRefPtr<ContextHolder> sandcx = new ContextHolder(cx, sandbox);
     if(!sandcx || !sandcx->GetJSContext()) {
         JS_ReportError(cx, "Can't prepare context for evalInSandbox");
         JSPRINCIPALS_DROP(cx, jsPrincipals);
         return NS_ERROR_OUT_OF_MEMORY;
     }
--- a/js/src/xpconnect/src/xpcdebug.cpp
+++ b/js/src/xpconnect/src/xpcdebug.cpp
@@ -85,17 +85,17 @@ static char* FormatJSFrame(JSContext* cx
 
     // get the info for this stack frame
 
     JSScript* script = JS_GetFrameScript(cx, fp);
     jsbytecode* pc = JS_GetFramePC(cx, fp);
 
     JSAutoRequest ar(cx);
     JSAutoEnterCompartment ac;
-    if(!ac.enter(cx, JS_GetFrameScopeChain(cx, fp)))
+    if(!ac.enter(cx, JS_GetGlobalForFrame(fp)))
         return buf;
 
     if(script && pc)
     {
         filename = JS_GetScriptFilename(cx, script);
         lineno =  (PRInt32) JS_PCToLineNumber(cx, script, pc);
         fun = JS_GetFrameFunction(cx, fp);
         if(fun)
--- a/js/src/xpconnect/src/xpcthrower.cpp
+++ b/js/src/xpconnect/src/xpcthrower.cpp
@@ -293,20 +293,19 @@ XPCThrower::ThrowExceptionObject(JSConte
         {
             if (!JS_WrapValue(cx, &thrown))
                 return JS_FALSE;
             JS_SetPendingException(cx, thrown);
             success = JS_TRUE;
         }
         else if((xpc = nsXPConnect::GetXPConnect()))
         {
-            JSObject* glob = JS_GetScopeChain(cx);
+            JSObject* glob = JS_GetGlobalForScopeChain(cx);
             if(!glob)
                 return JS_FALSE;
-            glob = JS_GetGlobalForObject(cx, glob);
 
             nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
             nsresult rv = xpc->WrapNative(cx, glob, e,
                                           NS_GET_IID(nsIException),
                                           getter_AddRefs(holder));
             if(NS_SUCCEEDED(rv) && holder)
             {
                 JSObject* obj;
--- a/js/src/xpconnect/wrappers/AccessCheck.cpp
+++ b/js/src/xpconnect/wrappers/AccessCheck.cpp
@@ -242,32 +242,32 @@ AccessCheck::documentDomainMakesSameOrig
     JS_FrameIterator(cx, &fp);
     if (fp) {
         while (!JS_IsScriptFrame(cx, fp)) {
             if (!JS_FrameIterator(cx, &fp))
                 break;
         }
 
         if (fp)
-            scope = JS_GetFrameScopeChainRaw(fp);
+            scope = JS_GetGlobalForFrame(fp);
     }
 
     if (!scope)
-        scope = JS_GetScopeChain(cx);
+        scope = JS_GetGlobalForScopeChain(cx);
 
     nsIPrincipal *subject;
     nsIPrincipal *object;
 
     {
         JSAutoEnterCompartment ac;
 
         if (!ac.enter(cx, scope))
             return false;
 
-        subject = GetPrincipal(JS_GetGlobalForObject(cx, scope));
+        subject = GetPrincipal(scope);
     }
 
     if (!subject)
         return false;
 
     {
         JSAutoEnterCompartment ac;
 
--- a/js/src/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/src/xpconnect/wrappers/XrayWrapper.cpp
@@ -565,22 +565,22 @@ XrayWrapper<Base>::resolveOwnProperty(JS
     XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
     if (!WrapperFactory::IsPartiallyTransparent(wrapper) &&
         (id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT) ||
          // Check for baseURIObject and nodePrincipal no nodes and
          // documentURIObject on documents, but only from privileged scripts.
          // Do the id checks before the QIs and IsPrivilegedScript() checks,
          // since they're cheaper and will tend to fail most of the time
          // anyway.
-         (((id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT) ||
-            id == rt->GetStringID(XPCJSRuntime::IDX_NODEPRINCIPAL)) &&
-           Is<nsINode>(wrapper)) ||
-          (id == rt->GetStringID(XPCJSRuntime::IDX_DOCUMENTURIOBJECT) &&
-           Is<nsIDocument>(wrapper))) &&
-         IsPrivilegedScript())) {
+         ((((id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT) ||
+             id == rt->GetStringID(XPCJSRuntime::IDX_NODEPRINCIPAL)) &&
+            Is<nsINode>(wrapper)) ||
+           (id == rt->GetStringID(XPCJSRuntime::IDX_DOCUMENTURIOBJECT) &&
+            Is<nsIDocument>(wrapper))) &&
+          IsPrivilegedScript()))) {
         bool status;
         Wrapper::Action action = set ? Wrapper::SET : Wrapper::GET;
         desc->obj = NULL; // default value
         if (!this->enter(cx, wrapper, id, action, &status))
             return status;
 
         AutoLeaveHelper<Base> helper(*this, cx, wrapper);
 
--- a/toolkit/components/perf/PerfMeasurement.cpp
+++ b/toolkit/components/perf/PerfMeasurement.cpp
@@ -107,21 +107,17 @@ NS_IMETHODIMP
 Module::Call(nsIXPConnectWrappedNative* wrapper,
              JSContext* cx,
              JSObject* obj,
              PRUint32 argc,
              jsval* argv,
              jsval* vp,
              bool* _retval)
 {
-  JSObject* scope = JS_GetScopeChain(cx);
-  if (!scope)
-    return NS_ERROR_NOT_AVAILABLE;
-
-  JSObject* global = JS_GetGlobalForObject(cx, scope);
+  JSObject* global = JS_GetGlobalForScopeChain(cx);
   if (!global)
     return NS_ERROR_NOT_AVAILABLE;
 
   *_retval = InitAndSealPerfMeasurementClass(cx, global);
   return NS_OK;
 }
 
 }