Bug 797821 - Remove FindInJSObjectScope and friends. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Thu, 25 Oct 2012 17:01:08 +0200
changeset 111529 847b5f4208be99860fac5b64e05aa0e04c67846c
parent 111528 f060ac1febfb878360274ca36f3a0cc17db63d5c
child 111530 884c4954bbb3cd1e0393eef31346121f02d08529
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmrbkap
bugs797821
milestone19.0a1
Bug 797821 - Remove FindInJSObjectScope and friends. r=mrbkap \o/
js/xpconnect/src/XPCWrappedNativeScope.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCWrappedNativeScope.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp
@@ -588,106 +588,16 @@ XPCWrappedNativeScope::SystemIsBeingShut
         printf("deleting nsXPConnect  with %d live XPCWrappedNativeScopes\n",
                liveScopeCount);
 #endif
 }
 
 
 /***************************************************************************/
 
-static
-XPCWrappedNativeScope*
-GetScopeOfObject(JSObject* obj)
-{
-    nsISupports* supports;
-    js::Class* clazz = js::GetObjectClass(obj);
-    JSBool isWrapper = IS_WRAPPER_CLASS(clazz);
-
-    if (isWrapper && IS_SLIM_WRAPPER_OBJECT(obj))
-        return GetSlimWrapperProto(obj)->GetScope();
-
-    if (!isWrapper || !(supports = (nsISupports*) xpc_GetJSPrivate(obj)))
-        return nullptr;
-
-#ifdef DEBUG
-    {
-        nsCOMPtr<nsIXPConnectWrappedNative> iface = do_QueryInterface(supports);
-
-        NS_ASSERTION(iface, "Uh, how'd this happen?");
-    }
-#endif
-
-    // obj is one of our nsXPConnectWrappedNative objects.
-    return ((XPCWrappedNative*)supports)->GetScope();
-}
-
-// static
-XPCWrappedNativeScope*
-XPCWrappedNativeScope::FindInJSObjectScope(JSContext* cx, JSObject* obj,
-                                           JSBool OKIfNotInitialized,
-                                           XPCJSRuntime* runtime)
-{
-    XPCWrappedNativeScope* scope;
-
-    if (!obj)
-        return nullptr;
-
-    // If this object is itself a wrapped native then we can get the
-    // scope directly.
-
-    scope = GetScopeOfObject(obj);
-    if (scope)
-        return scope;
-
-    // Else we'll have to look up the parent chain to get the scope
-
-    JSAutoCompartment ac(cx, obj);
-    obj = JS_GetGlobalForObject(cx, obj);
-
-    if (js::GetObjectClass(obj)->flags & JSCLASS_XPCONNECT_GLOBAL) {
-        scope = XPCWrappedNativeScope::GetNativeScope(obj);
-        if (scope)
-            return scope;
-    }
-
-    if (!runtime) {
-        runtime = nsXPConnect::GetRuntimeInstance();
-        NS_ASSERTION(runtime, "This should never be null!");
-    }
-
-    // XXX We are assuming that the scope count is low enough that traversing
-    // the linked list is more reasonable then doing a hashtable lookup.
-    XPCWrappedNativeScope* found = nullptr;
-    {   // scoped lock
-        XPCAutoLock lock(runtime->GetMapLock());
-
-        DEBUG_TrackScopeTraversal();
-
-        for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
-            if (obj == cur->GetGlobalJSObjectPreserveColor()) {
-                found = cur;
-                break;
-            }
-        }
-    }
-
-    if (found) {
-        // This cannot be called within the map lock!
-        return found;
-    }
-
-    // Failure to find the scope is only OK if the caller told us it might fail.
-    // This flag would only be set in the call from
-    // XPCWrappedNativeScope::GetNewOrUsed
-    NS_ASSERTION(OKIfNotInitialized, "No scope has this global object!");
-    return nullptr;
-}
-
-/***************************************************************************/
-
 static JSDHashOperator
 WNProtoSecPolicyClearer(JSDHashTable *table, JSDHashEntryHdr *hdr,
                         uint32_t number, void *arg)
 {
     XPCWrappedNativeProto* proto =
         ((ClassInfo2WrappedNativeProtoMap::Entry*)hdr)->value;
     *(proto->GetSecurityInfoAddr()) = nullptr;
     return JS_DHASH_NEXT;
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1641,29 +1641,16 @@ public:
         if (!mGlobalJSObject)
             return nullptr;
         JSCompartment *c = js::GetObjectCompartment(mGlobalJSObject);
         return nsJSPrincipals::get(JS_GetCompartmentPrincipals(c));
     }
 
     void RemoveWrappedNativeProtos();
 
-    static XPCWrappedNativeScope*
-    FindInJSObjectScope(JSContext* cx, JSObject* obj,
-                        JSBool OKIfNotInitialized = false,
-                        XPCJSRuntime* runtime = nullptr);
-
-    static XPCWrappedNativeScope*
-    FindInJSObjectScope(XPCCallContext& ccx, JSObject* obj,
-                        JSBool OKIfNotInitialized = false)
-    {
-        return FindInJSObjectScope(ccx, obj, OKIfNotInitialized,
-                                   ccx.GetRuntime());
-    }
-
     static void
     SystemIsBeingShutDown();
 
     static void
     TraceWrappedNativesInAllScopes(JSTracer* trc, XPCJSRuntime* rt);
 
     void TraceSelf(JSTracer *trc) {
         JSObject *obj = GetGlobalJSObjectPreserveColor();