Bug 1125901 - Part a: Remove WrapNative functions in nsDOMClassInfo; r=jst
authorMs2ger <ms2ger@gmail.com>
Wed, 04 Feb 2015 09:40:59 +0100
changeset 244915 90797b19453e65ffc1769fd1eaeff33766990039
parent 244914 de6ab277539a57e3b7a68dc5acbdea57f898dda4
child 244916 5bcf7ecab9f9ee6a095deb3a7107a465955efcdc
push id7677
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 18:11:24 +0000
treeherdermozilla-aurora@f531d838c055 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs1125901
milestone38.0a1
Bug 1125901 - Part a: Remove WrapNative functions in nsDOMClassInfo; r=jst They are equivalent to the WrapNative functions on nsContentUtils.
dom/base/nsDOMClassInfo.cpp
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -313,53 +313,16 @@ FindObjectClass(JSContext* cx, JSObject*
   do {
     obj = proto;
     js::GetObjectProto(cx, obj, &proto);
   } while (proto);
 
   sObjectClass = js::GetObjectJSClass(obj);
 }
 
-static inline nsresult
-WrapNative(JSContext *cx, nsISupports *native,
-           nsWrapperCache *cache, const nsIID* aIID, JS::MutableHandle<JS::Value> vp,
-           bool aAllowWrapping)
-{
-  if (!native) {
-    vp.setNull();
-
-    return NS_OK;
-  }
-
-  JSObject *wrapper = xpc_FastGetCachedWrapper(cx, cache, vp);
-  if (wrapper) {
-    return NS_OK;
-  }
-
-  JS::Rooted<JSObject*> scope(cx, JS::CurrentGlobalOrNull(cx));
-  return nsDOMClassInfo::XPConnect()->WrapNativeToJSVal(cx, scope, native,
-                                                        cache, aIID,
-                                                        aAllowWrapping, vp);
-}
-
-static inline nsresult
-WrapNative(JSContext *cx, nsISupports *native, const nsIID* aIID,
-           bool aAllowWrapping, JS::MutableHandle<JS::Value> vp)
-{
-  return WrapNative(cx, native, nullptr, aIID, vp, aAllowWrapping);
-}
-
-// Same as the WrapNative above, but use these if aIID is nsISupports' IID.
-static inline nsresult
-WrapNative(JSContext *cx, nsISupports *native,
-           bool aAllowWrapping, JS::MutableHandle<JS::Value> vp)
-{
-  return WrapNative(cx, native, nullptr, nullptr, vp, aAllowWrapping);
-}
-
 // Helper to handle torn-down inner windows.
 static inline nsresult
 SetParentToWindow(nsGlobalWindow *win, JSObject **parent)
 {
   MOZ_ASSERT(win);
   MOZ_ASSERT(win->IsInnerWindow());
   *parent = win->FastGetGlobalJSObject();
 
@@ -1344,17 +1307,17 @@ BaseStubConstructor(nsIWeakReference* aW
     native = do_CreateInstance(*name_struct->mData->mConstructorCID, &rv);
   }
   if (NS_FAILED(rv)) {
     NS_ERROR("Failed to create the object");
     return rv;
   }
 
   js::AssertSameCompartment(cx, obj);
-  return WrapNative(cx, native, true, args.rval());
+  return nsContentUtils::WrapNative(cx, native, args.rval(), true);
 }
 
 static nsresult
 DefineInterfaceConstants(JSContext *cx, JS::Handle<JSObject*> obj, const nsIID *aIID)
 {
   nsCOMPtr<nsIInterfaceInfoManager>
     iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
   NS_ENSURE_TRUE(iim, NS_ERROR_UNEXPECTED);
@@ -1847,18 +1810,19 @@ ResolvePrototype(nsIXPConnect *aXPConnec
   nsRefPtr<nsDOMConstructor> constructor;
   nsresult rv = nsDOMConstructor::Create(name, ci_data, name_struct, aWin,
                                          getter_AddRefs(constructor));
   NS_ENSURE_SUCCESS(rv, rv);
 
   JS::Rooted<JS::Value> v(cx);
 
   js::AssertSameCompartment(cx, obj);
-  rv = WrapNative(cx, constructor, &NS_GET_IID(nsIDOMDOMConstructor),
-                  false, &v);
+  rv = nsContentUtils::WrapNative(cx, constructor,
+                                  &NS_GET_IID(nsIDOMDOMConstructor), &v,
+                                  false);
   NS_ENSURE_SUCCESS(rv, rv);
 
   FillPropertyDescriptor(ctorDesc, obj, 0, v);
   // And make sure we wrap the value into the right compartment.  Note that we
   // do this with ctorDesc.value(), not with v, because we need v to be in the
   // right compartment (that of the reflector of |constructor|) below.
   if (!JS_WrapValue(cx, ctorDesc.value())) {
     return NS_ERROR_UNEXPECTED;
@@ -2218,18 +2182,19 @@ nsWindowSH::GlobalResolve(nsGlobalWindow
                                   nullptr,
                                   name_struct,
                                   static_cast<nsPIDOMWindow*>(aWin),
                                   getter_AddRefs(constructor));
     NS_ENSURE_SUCCESS(rv, rv);
 
     JS::Rooted<JS::Value> v(cx);
     js::AssertSameCompartment(cx, obj);
-    rv = WrapNative(cx, constructor, &NS_GET_IID(nsIDOMDOMConstructor),
-                    false, &v);
+    rv = nsContentUtils::WrapNative(cx, constructor,
+                                    &NS_GET_IID(nsIDOMDOMConstructor), &v,
+                                    false);
     NS_ENSURE_SUCCESS(rv, rv);
 
     JS::Rooted<JSObject*> class_obj(cx, &v.toObject());
 
     // ... and define the constants from the DOM interface on that
     // constructor object.
 
     {
@@ -2327,18 +2292,19 @@ nsWindowSH::GlobalResolve(nsGlobalWindow
     nsRefPtr<nsDOMConstructor> constructor;
     rv = nsDOMConstructor::Create(class_name, nullptr, name_struct,
                                   static_cast<nsPIDOMWindow*>(aWin),
                                   getter_AddRefs(constructor));
     NS_ENSURE_SUCCESS(rv, rv);
 
     JS::Rooted<JS::Value> val(cx);
     js::AssertSameCompartment(cx, obj);
-    rv = WrapNative(cx, constructor, &NS_GET_IID(nsIDOMDOMConstructor),
-                    true, &val);
+    rv = nsContentUtils::WrapNative(cx, constructor,
+                                    &NS_GET_IID(nsIDOMDOMConstructor), &val,
+                                    true);
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ASSERTION(val.isObject(), "Why didn't we get a JSObject?");
 
     FillPropertyDescriptor(desc, obj, 0, val);
 
     return NS_OK;
   }
@@ -2365,17 +2331,17 @@ nsWindowSH::GlobalResolve(nsGlobalWindow
     }
 
     if (prop_val.isPrimitive() && !prop_val.isNull()) {
       if (aWin->IsOuterWindow()) {
         nsGlobalWindow *inner = aWin->GetCurrentInnerWindowInternal();
         NS_ENSURE_TRUE(inner, NS_ERROR_UNEXPECTED);
       }
 
-      rv = WrapNative(cx, native, true, &prop_val);
+      rv = nsContentUtils::WrapNative(cx, native, &prop_val, true);
     }
 
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!JS_WrapValue(cx, &prop_val)) {
       return NS_ERROR_UNEXPECTED;
     }