From 075d3313908aadceb1bd139845c05a998228fdb6 Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Thu, 13 Jun 2013 17:09:55 -0700 Subject: [PATCH] Bug 884410 - Handlify the JS_TransplantObject interfaces; r=jonco --HG-- extra : rebase_source : f1c2adc7380e5806ce6b4fce5bb41f9400b9e1b1 --- dom/base/nsGlobalWindow.cpp | 6 ++++-- dom/bindings/BindingUtils.cpp | 4 ++-- js/src/jsapi.cpp | 17 +++++------------ js/src/jsapi.h | 10 +++++----- js/xpconnect/src/XPCWrappedNative.cpp | 4 ++-- js/xpconnect/src/xpcpublic.h | 6 +++--- js/xpconnect/wrappers/WrapperFactory.cpp | 6 +++--- 7 files changed, 24 insertions(+), 29 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index e5ca3930daa..0d9369ce952 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2395,7 +2395,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, } else { JS::Rooted global(cx, xpc_UnmarkGrayObject(newInnerWindow->mJSObject)); - JSObject* outerObject = NewOuterWindowProxy(cx, global, thisChrome); + JS::Rooted outerObject(cx, + NewOuterWindowProxy(cx, global, thisChrome)); if (!outerObject) { NS_ERROR("out of memory"); return NS_ERROR_FAILURE; @@ -2403,7 +2404,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, js::SetProxyExtra(mJSObject, 0, js::PrivateValue(NULL)); - outerObject = xpc::TransplantObject(cx, mJSObject, outerObject); + JS::Rooted obj(cx, mJSObject); + outerObject = xpc::TransplantObject(cx, obj, outerObject); if (!outerObject) { NS_ERROR("unable to transplant wrappers, probably OOM"); return NS_ERROR_FAILURE; diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 283da6c21c0..feef9f820b1 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -1592,8 +1592,8 @@ ReparentWrapper(JSContext* aCx, JS::HandleObject aObjArg) 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(); } diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 9165b45d0e3..e77a89a5fbd 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1594,10 +1594,8 @@ JS_WrapId(JSContext *cx, jsid *idp) */ JS_PUBLIC_API(JSObject *) -JS_TransplantObject(JSContext *cx, JSObject *origobjArg, JSObject *targetArg) +JS_TransplantObject(JSContext *cx, HandleObject origobj, HandleObject target) { - RootedObject origobj(cx, origobjArg); - RootedObject target(cx, targetArg); AssertHeapIsIdle(cx); JS_ASSERT(origobj != target); JS_ASSERT(!IsCrossCompartmentWrapper(origobj)); @@ -1667,16 +1665,11 @@ JS_TransplantObject(JSContext *cx, JSObject *origobjArg, JSObject *targetArg) */ JS_FRIEND_API(JSObject *) js_TransplantObjectWithWrapper(JSContext *cx, - JSObject *origobjArg, - JSObject *origwrapperArg, - JSObject *targetobjArg, - JSObject *targetwrapperArg) + HandleObject origobj, + HandleObject origwrapper, + HandleObject targetobj, + HandleObject targetwrapper) { - RootedObject origobj(cx, origobjArg); - RootedObject origwrapper(cx, origwrapperArg); - RootedObject targetobj(cx, targetobjArg); - RootedObject targetwrapper(cx, targetwrapperArg); - AutoMaybeTouchDeadZones agc(cx); AutoDisableProxyCheck adpc(cx->runtime()); diff --git a/js/src/jsapi.h b/js/src/jsapi.h index dcb583315ce..b3689e991ba 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -1999,14 +1999,14 @@ 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); diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index e4e4569217a..027670b7d08 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -1464,9 +1464,9 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCWrappedNativeScope* aOldScope, 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) diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index ac71e2abeb4..724f135eba6 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -40,12 +40,12 @@ class nsIGlobalObject; 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. diff --git a/js/xpconnect/wrappers/WrapperFactory.cpp b/js/xpconnect/wrappers/WrapperFactory.cpp index 1a0a9406754..92a232c1504 100644 --- a/js/xpconnect/wrappers/WrapperFactory.cpp +++ b/js/xpconnect/wrappers/WrapperFactory.cpp @@ -673,7 +673,7 @@ FixWaiverAfterTransplant(JSContext *cx, HandleObject oldWaiver, HandleObject new } 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)); @@ -687,8 +687,8 @@ TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target) 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,