Bug 884410 - Handlify the JS_TransplantObject interfaces; r=jonco
authorTerrence Cole <terrence@mozilla.com>
Thu, 13 Jun 2013 17:09:55 -0700
changeset 148050 c55d7332c83aefea7834454feba80aad93561bf6
parent 148049 f26888376433c27927b3d9ff8cc1a175f1fc9298
child 148051 b07c97f12e348190caee088fd23aa182c6e57e8d
push id368
push userbbajaj@mozilla.com
push dateMon, 09 Sep 2013 22:57:58 +0000
treeherdermozilla-release@5a4f47ae1217 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs884410
milestone24.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 884410 - Handlify the JS_TransplantObject interfaces; r=jonco
dom/base/nsGlobalWindow.cpp
dom/bindings/BindingUtils.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/xpconnect/src/XPCWrappedNative.cpp
js/xpconnect/src/xpcpublic.h
js/xpconnect/wrappers/WrapperFactory.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -2390,25 +2390,27 @@ nsGlobalWindow::SetNewDocument(nsIDocume
       CreateOuterObject(newInnerWindow);
       mContext->DidInitializeContext();
 
       mJSObject = mContext->GetNativeGlobal();
       SetWrapper(mJSObject);
     } else {
       JS::Rooted<JSObject*> global(cx,
         xpc_UnmarkGrayObject(newInnerWindow->mJSObject));
-      JSObject* outerObject = NewOuterWindowProxy(cx, global, thisChrome);
+      JS::Rooted<JSObject*> outerObject(cx,
+        NewOuterWindowProxy(cx, global, thisChrome));
       if (!outerObject) {
         NS_ERROR("out of memory");
         return NS_ERROR_FAILURE;
       }
 
       js::SetProxyExtra(mJSObject, 0, js::PrivateValue(NULL));
 
-      outerObject = xpc::TransplantObject(cx, mJSObject, outerObject);
+      JS::Rooted<JSObject*> obj(cx, mJSObject);
+      outerObject = xpc::TransplantObject(cx, obj, outerObject);
       if (!outerObject) {
         NS_ERROR("unable to transplant wrappers, probably OOM");
         return NS_ERROR_FAILURE;
       }
 
       js::SetProxyExtra(outerObject, 0, js::PrivateValue(ToSupports(this)));
 
       mJSObject = outerObject;
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -1587,18 +1587,18 @@ ReparentWrapper(JSContext* aCx, JS::Hand
     js::SetReservedSlot(aObj, DOM_OBJECT_SLOT, JS::PrivateValue(nullptr));
   }
 
   nsWrapperCache* cache = nullptr;
   CallQueryInterface(native, &cache);
   if (ww != aObj) {
     MOZ_ASSERT(cache->HasSystemOnlyWrapper());
 
-    JSObject *newwrapper =
-      xpc::WrapperFactory::WrapSOWObject(aCx, newobj);
+    JS::RootedObject newwrapper(aCx,
+      xpc::WrapperFactory::WrapSOWObject(aCx, newobj));
     if (!newwrapper) {
       MOZ_CRASH();
     }
 
     // Ok, now we do the special object-plus-wrapper transplant.
     ww = xpc::TransplantObjectWithWrapper(aCx, aObj, ww, newobj, newwrapper);
     if (!ww) {
       MOZ_CRASH();
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1589,20 +1589,18 @@ JS_WrapId(JSContext *cx, jsid *idp)
  * Second, the new identity object's contents will be those of |target|. A swap()
  * is used to make this happen if an object other than |target| is used.
  *
  * We don't have a good way to recover from failure in this function, so
  * we intentionally crash instead.
  */
 
 JS_PUBLIC_API(JSObject *)
-JS_TransplantObject(JSContext *cx, JSObject *origobjArg, JSObject *targetArg)
-{
-    RootedObject origobj(cx, origobjArg);
-    RootedObject target(cx, targetArg);
+JS_TransplantObject(JSContext *cx, HandleObject origobj, HandleObject target)
+{
     AssertHeapIsIdle(cx);
     JS_ASSERT(origobj != target);
     JS_ASSERT(!IsCrossCompartmentWrapper(origobj));
     JS_ASSERT(!IsCrossCompartmentWrapper(target));
 
     AutoMaybeTouchDeadZones agc(cx);
     AutoDisableProxyCheck adpc(cx->runtime());
 
@@ -1662,26 +1660,21 @@ JS_TransplantObject(JSContext *cx, JSObj
  * Some C++ objects (such as the location object and XBL) require both an XPConnect
  * reflector and a security wrapper for that reflector. We expect that there are
  * no live references to the reflector, so when we perform the transplant we turn
  * the security wrapper into a cross-compartment wrapper. Just in case there
  * happen to be live references to the reflector, we swap it out to limit the harm.
  */
 JS_FRIEND_API(JSObject *)
 js_TransplantObjectWithWrapper(JSContext *cx,
-                               JSObject *origobjArg,
-                               JSObject *origwrapperArg,
-                               JSObject *targetobjArg,
-                               JSObject *targetwrapperArg)
-{
-    RootedObject origobj(cx, origobjArg);
-    RootedObject origwrapper(cx, origwrapperArg);
-    RootedObject targetobj(cx, targetobjArg);
-    RootedObject targetwrapper(cx, targetwrapperArg);
-
+                               HandleObject origobj,
+                               HandleObject origwrapper,
+                               HandleObject targetobj,
+                               HandleObject targetwrapper)
+{
     AutoMaybeTouchDeadZones agc(cx);
     AutoDisableProxyCheck adpc(cx->runtime());
 
     AssertHeapIsIdle(cx);
     JS_ASSERT(!IsCrossCompartmentWrapper(origobj));
     JS_ASSERT(!IsCrossCompartmentWrapper(origwrapper));
     JS_ASSERT(!IsCrossCompartmentWrapper(targetobj));
     JS_ASSERT(!IsCrossCompartmentWrapper(targetwrapper));
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1994,24 +1994,24 @@ JS_WrapObject(JSContext *cx, JSObject **
 
 extern JS_PUBLIC_API(JSBool)
 JS_WrapValue(JSContext *cx, jsval *vp);
 
 extern JS_PUBLIC_API(JSBool)
 JS_WrapId(JSContext *cx, jsid *idp);
 
 extern JS_PUBLIC_API(JSObject *)
-JS_TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target);
+JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target);
 
 extern JS_FRIEND_API(JSObject *)
 js_TransplantObjectWithWrapper(JSContext *cx,
-                               JSObject *origobj,
-                               JSObject *origwrapper,
-                               JSObject *targetobj,
-                               JSObject *targetwrapper);
+                               JS::HandleObject origobj,
+                               JS::HandleObject origwrapper,
+                               JS::HandleObject targetobj,
+                               JS::HandleObject targetwrapper);
 
 extern JS_PUBLIC_API(JSBool)
 JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *ob);
 
 /*
  * At any time, a JSContext has a current (possibly-NULL) compartment.
  * Compartments are described in:
  *
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -1459,19 +1459,19 @@ XPCWrappedNative::ReparentWrapperIfFound
             // Crash if the wrapper is already in the new scope.
             if (newMap->Find(wrapper->GetIdentityObject()))
                 MOZ_CRASH();
 
             if (!newMap->Add(wrapper))
                 MOZ_CRASH();
         }
 
-        JSObject *ww = wrapper->GetWrapper();
+        RootedObject ww(cx, wrapper->GetWrapper());
         if (ww) {
-            JSObject *newwrapper;
+            RootedObject newwrapper(cx);
             MOZ_ASSERT(wrapper->NeedsSOW(), "weird wrapper wrapper");
             newwrapper = xpc::WrapperFactory::WrapSOWObject(cx, newobj);
             if (!newwrapper)
                 MOZ_CRASH();
 
             // Ok, now we do the special object-plus-wrapper transplant.
             ww = xpc::TransplantObjectWithWrapper(cx, flat, ww, newobj,
                                                   newwrapper);
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -35,22 +35,22 @@ class nsScriptNameSpaceManager;
 class nsIGlobalObject;
 
 #ifndef BAD_TLS_INDEX
 #define BAD_TLS_INDEX ((uint32_t) -1)
 #endif
 
 namespace xpc {
 JSObject *
-TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target);
+TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target);
 
 JSObject *
 TransplantObjectWithWrapper(JSContext *cx,
-                            JSObject *origobj, JSObject *origwrapper,
-                            JSObject *targetobj, JSObject *targetwrapper);
+                            JS::HandleObject origobj, JS::HandleObject origwrapper,
+                            JS::HandleObject targetobj, JS::HandleObject targetwrapper);
 
 // Return a raw XBL scope object corresponding to contentScope, which must
 // be an object whose global is a DOM window.
 //
 // The return value is not wrapped into cx->compartment, so be sure to enter
 // its compartment before doing anything meaningful.
 //
 // Also note that XBL scopes are lazily created, so the return-value should be
--- a/js/xpconnect/wrappers/WrapperFactory.cpp
+++ b/js/xpconnect/wrappers/WrapperFactory.cpp
@@ -668,32 +668,32 @@ FixWaiverAfterTransplant(JSContext *cx, 
     XPCWrappedNativeScope *scope = GetObjectScope(oldWaiver);
     JSObject *key = Wrapper::wrappedObject(oldWaiver);
     MOZ_ASSERT(scope->mWaiverWrapperMap->Find(key));
     scope->mWaiverWrapperMap->Remove(key);
     return true;
 }
 
 JSObject *
-TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target)
+TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target)
 {
     RootedObject oldWaiver(cx, WrapperFactory::GetXrayWaiver(origobj));
     RootedObject newIdentity(cx, JS_TransplantObject(cx, origobj, target));
     if (!newIdentity || !oldWaiver)
        return newIdentity;
 
     if (!FixWaiverAfterTransplant(cx, oldWaiver, newIdentity))
         return NULL;
     return newIdentity;
 }
 
 JSObject *
 TransplantObjectWithWrapper(JSContext *cx,
-                            JSObject *origobj, JSObject *origwrapper,
-                            JSObject *targetobj, JSObject *targetwrapper)
+                            HandleObject origobj, HandleObject origwrapper,
+                            HandleObject targetobj, HandleObject targetwrapper)
 {
     RootedObject oldWaiver(cx, WrapperFactory::GetXrayWaiver(origobj));
     RootedObject newSameCompartmentWrapper(cx,
       js_TransplantObjectWithWrapper(cx, origobj, origwrapper, targetobj,
                                      targetwrapper));
     if (!newSameCompartmentWrapper || !oldWaiver)
         return newSameCompartmentWrapper;