Bug 797821 - Remove CreateNewGlobal. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Thu, 25 Oct 2012 17:01:07 +0200
changeset 111518 46dfef5f70f81a797fe48463c914ad0321a56b3b
parent 111517 a20072899a97aba0a18e34d3c653382776fccf38
child 111519 01a59c65c8b87c2a3a76ed45f10944b819e2612f
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmrbkap
bugs797821
milestone19.0a1
Bug 797821 - Remove CreateNewGlobal. r=mrbkap It doesn't do anything useful at this point.
js/xpconnect/src/nsXPConnect.cpp
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -995,39 +995,16 @@ nsXPConnect::InitClasses(JSContext * aJS
         return UnexpectedFailure(NS_ERROR_FAILURE);
 
     if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, aGlobalJSObj))
         return UnexpectedFailure(NS_ERROR_FAILURE);
 
     return NS_OK;
 }
 
-static bool
-CreateNewGlobal(JSContext *cx, JSClass *clasp, nsIPrincipal *principal,
-                xpc::CompartmentPrivate *priv, JSObject **global,
-                JSCompartment **compartment)
-{
-    // We take ownership of |priv|. Ensure that either we free it in the case
-    // of failure or give ownership to the compartment in case of success (in
-    // that case it will be free'd in CompartmentCallback during GC).
-    MOZ_ASSERT(priv);
-    nsAutoPtr<xpc::CompartmentPrivate> priv_holder(priv);
-    JSObject *tempGlobal =
-        JS_NewGlobalObject(cx, clasp, nsJSPrincipals::get(principal));
-
-    if (!tempGlobal)
-        return false;
-
-    *global = tempGlobal;
-    *compartment = js::GetObjectCompartment(tempGlobal);
-
-    JS_SetCompartmentPrivate(*compartment, priv_holder.forget());
-    return true;
-}
-
 #ifdef DEBUG
 struct VerifyTraceXPCGlobalCalledTracer
 {
     JSTracer base;
     bool ok;
 };
 
 static void
@@ -1103,19 +1080,21 @@ CreateGlobalObject(JSContext *cx, JSClas
                    bool wantXrays, JSObject **global, JSCompartment **compartment)
 {
     // Make sure that Type Inference is enabled for everything non-chrome.
     // Sandboxes and compilation scopes are exceptions. See bug 744034.
     CheckTypeInference(cx, clasp, principal);
 
     NS_ABORT_IF_FALSE(NS_IsMainThread(), "using a principal off the main thread?");
 
-    xpc::CompartmentPrivate *priv = new xpc::CompartmentPrivate(wantXrays);
-    if (!CreateNewGlobal(cx, clasp, principal, priv, global, compartment))
+    *global = JS_NewGlobalObject(cx, clasp, nsJSPrincipals::get(principal));
+    if (!*global)
         return UnexpectedFailure(NS_ERROR_FAILURE);
+    *compartment = js::GetObjectCompartment(*global);
+    JS_SetCompartmentPrivate(*compartment, new xpc::CompartmentPrivate(wantXrays));
 
     XPCCompartmentSet& set = nsXPConnect::GetRuntimeInstance()->GetCompartmentSet();
     if (!set.put(*compartment))
         return UnexpectedFailure(NS_ERROR_FAILURE);
 
 #ifdef DEBUG
     // Verify that the right trace hook is called. Note that this doesn't
     // work right for wrapped globals, since the tracing situation there is