Bug 1122758 - Get rid of XPCJSObjectHolder::newHolder(). r=gabor
authorAndrew McCreight <continuation@gmail.com>
Tue, 03 Feb 2015 09:13:54 -0800
changeset 227269 40aeb4e4292c6157d56922c3c709668d50303ebf
parent 227268 5fc092347f17567d1c9a5e40b395965621a7f997
child 227270 36e262cbbadb858f5e5af7556fc54488c82aa407
push id28225
push userryanvm@gmail.com
push dateTue, 03 Feb 2015 21:15:47 +0000
treeherdermozilla-central@0c2f7434c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1122758
milestone38.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 1122758 - Get rid of XPCJSObjectHolder::newHolder(). r=gabor
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/src/XPCWrappedNative.cpp
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -719,20 +719,19 @@ XPCConvert::JSData2Native(void* d, Handl
     return true;
 }
 
 static inline bool
 CreateHolderIfNeeded(HandleObject obj, MutableHandleValue d,
                      nsIXPConnectJSObjectHolder** dest)
 {
     if (dest) {
-        nsRefPtr<XPCJSObjectHolder> objHolder = XPCJSObjectHolder::newHolder(obj);
-        if (!objHolder)
+        if (!obj)
             return false;
-
+        nsRefPtr<XPCJSObjectHolder> objHolder = new XPCJSObjectHolder(obj);
         objHolder.forget(dest);
     }
 
     d.setObjectOrNull(obj);
 
     return true;
 }
 
@@ -851,21 +850,19 @@ XPCConvert::NativeInterface2JSObject(Mut
 
     d.setObjectOrNull(flat);
 
     if (dest) {
         // The wrapper still holds the original flat object.
         if (flat == original) {
             wrapper.forget(dest);
         } else {
-            nsRefPtr<XPCJSObjectHolder> objHolder =
-                XPCJSObjectHolder::newHolder(flat);
-            if (!objHolder)
+            if (!flat)
                 return false;
-
+            nsRefPtr<XPCJSObjectHolder> objHolder = new XPCJSObjectHolder(flat);
             objHolder.forget(dest);
         }
     }
 
     if (pErr)
         *pErr = NS_OK;
 
     return true;
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -2649,16 +2649,17 @@ XPCJSObjectHolder::GetJSObject()
 {
     NS_PRECONDITION(mJSObj, "bad object state");
     return mJSObj;
 }
 
 XPCJSObjectHolder::XPCJSObjectHolder(JSObject* obj)
     : mJSObj(obj)
 {
+    MOZ_ASSERT(obj);
     XPCJSRuntime::Get()->AddObjectHolderRoot(this);
 }
 
 XPCJSObjectHolder::~XPCJSObjectHolder()
 {
     RemoveFromRootSet();
 }
 
@@ -2671,19 +2672,8 @@ XPCJSObjectHolder::TraceJS(JSTracer *trc
 
 // static
 void
 XPCJSObjectHolder::GetTraceName(JSTracer* trc, char *buf, size_t bufsize)
 {
     JS_snprintf(buf, bufsize, "XPCJSObjectHolder[0x%p].mJSObj",
                 trc->debugPrintArg());
 }
-
-// static
-XPCJSObjectHolder*
-XPCJSObjectHolder::newHolder(JSObject* obj)
-{
-    if (!obj) {
-        NS_ERROR("bad param");
-        return nullptr;
-    }
-    return new XPCJSObjectHolder(obj);
-}
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -817,20 +817,19 @@ nsXPConnect::CreateSandbox(JSContext *cx
 
     RootedValue rval(cx);
     SandboxOptions options;
     nsresult rv = CreateSandboxObject(cx, &rval, principal, options);
     MOZ_ASSERT(NS_FAILED(rv) || !rval.isPrimitive(),
                "Bad return value from xpc_CreateSandboxObject()!");
 
     if (NS_SUCCEEDED(rv) && !rval.isPrimitive()) {
-        *_retval = XPCJSObjectHolder::newHolder(rval.toObjectOrNull());
-        NS_ENSURE_TRUE(*_retval, NS_ERROR_OUT_OF_MEMORY);
-
-        NS_ADDREF(*_retval);
+        JSObject *obj = rval.toObjectOrNull();
+        nsRefPtr<XPCJSObjectHolder> rval = new XPCJSObjectHolder(obj);
+        rval.forget(_retval);
     }
 
     return rv;
 }
 
 NS_IMETHODIMP
 nsXPConnect::EvalInSandboxObject(const nsAString& source, const char *filename,
                                  JSContext *cx, JSObject *sandboxArg,
@@ -867,22 +866,23 @@ nsXPConnect::GetWrappedNativePrototype(J
     XPCNativeScriptableCreateInfo sciProto;
     XPCWrappedNative::GatherProtoScriptableCreateInfo(aClassInfo, sciProto);
 
     AutoMarkingWrappedNativeProtoPtr proto(aJSContext);
     proto = XPCWrappedNativeProto::GetNewOrUsed(scope, aClassInfo, &sciProto);
     if (!proto)
         return UnexpectedFailure(NS_ERROR_FAILURE);
 
-    nsIXPConnectJSObjectHolder* holder;
-    *_retval = holder = XPCJSObjectHolder::newHolder(proto->GetJSProtoObject());
-    if (!holder)
+    JSObject *protoObj = proto->GetJSProtoObject();
+    if (!protoObj)
         return UnexpectedFailure(NS_ERROR_FAILURE);
 
-    NS_ADDREF(holder);
+    nsRefPtr<XPCJSObjectHolder> holder = new XPCJSObjectHolder(protoObj);
+    holder.forget(_retval);
+
     return NS_OK;
 }
 
 /* void debugDump (in short depth); */
 NS_IMETHODIMP
 nsXPConnect::DebugDump(int16_t depth)
 {
 #ifdef DEBUG
@@ -1194,21 +1194,20 @@ nsXPConnect::GetPrincipal(JSObject* obj,
     return nullptr;
 }
 
 NS_IMETHODIMP
 nsXPConnect::HoldObject(JSContext *aJSContext, JSObject *aObjectArg,
                         nsIXPConnectJSObjectHolder **aHolder)
 {
     RootedObject aObject(aJSContext, aObjectArg);
-    XPCJSObjectHolder* objHolder = XPCJSObjectHolder::newHolder(aObject);
-    if (!objHolder)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    NS_ADDREF(*aHolder = objHolder);
+    if (!aObject)
+        return NS_ERROR_FAILURE;
+    nsRefPtr<XPCJSObjectHolder> objHolder = new XPCJSObjectHolder(aObject);
+    objHolder.forget(aHolder);
     return NS_OK;
 }
 
 namespace xpc {
 
 bool
 Base64Encode(JSContext *cx, HandleValue val, MutableHandleValue out)
 {
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -2506,25 +2506,24 @@ class XPCJSObjectHolder : public nsIXPCo
 public:
     // all the interface method declarations...
     NS_DECL_ISUPPORTS
     NS_DECL_NSIXPCONNECTJSOBJECTHOLDER
 
     // non-interface implementation
 
 public:
-    static XPCJSObjectHolder* newHolder(JSObject* obj);
-
     void TraceJS(JSTracer *trc);
     static void GetTraceName(JSTracer* trc, char *buf, size_t bufsize);
 
+    explicit XPCJSObjectHolder(JSObject* obj);
+
 private:
     virtual ~XPCJSObjectHolder();
 
-    explicit XPCJSObjectHolder(JSObject* obj);
     XPCJSObjectHolder(); // not implemented
 
     JS::Heap<JSObject*> mJSObj;
 };
 
 /***************************************************************************
 ****************************************************************************
 *