Bug 861269 - GC: Continuing the rooting of XPConnect - Root XPCJSID.cpp r=bholley

--HG--
extra : rebase_source : 3702d37309dd711a6db9173d0c6ab6142ce78544
This commit is contained in:
Jon Coppeard 2013-04-15 15:30:05 +01:00
Родитель af1f7cbb11
Коммит b2767312e0
3 изменённых файлов: 30 добавлений и 22 удалений

Просмотреть файл

@ -169,8 +169,9 @@ XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s,
nsID* iid2 = *((nsID**)s);
if (!iid2)
break;
JS::RootedObject scope(cx, lccx.GetScopeForNewJSObjects());
JSObject* obj;
if (!(obj = xpc_NewIDObject(cx, lccx.GetScopeForNewJSObjects(), *iid2)))
if (!(obj = xpc_NewIDObject(cx, scope, *iid2)))
return false;
*d = OBJECT_TO_JSVAL(obj);
break;

Просмотреть файл

@ -13,6 +13,7 @@
#include "XPCWrapper.h"
using namespace mozilla::dom;
using namespace JS;
/***************************************************************************/
// nsJSID
@ -388,10 +389,12 @@ nsJSIID::NewID(nsIInterfaceInfo* aInfo)
/* bool resolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsval id); */
NS_IMETHODIMP
nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * obj,
jsid id, uint32_t flags,
JSContext * cx, JSObject * objArg,
jsid idArg, uint32_t flags,
JSObject * *objp, bool *_retval)
{
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
XPCCallContext ccx(JS_CALLER, cx);
AutoMarkingNativeInterfacePtr iface(ccx);
@ -422,10 +425,11 @@ nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper,
/* bool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
NS_IMETHODIMP
nsJSIID::Enumerate(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * obj, bool *_retval)
JSContext * cx, JSObject * objArg, bool *_retval)
{
// In this case, let's just eagerly resolve...
RootedObject obj(cx, objArg);
XPCCallContext ccx(JS_CALLER, cx);
AutoMarkingNativeInterfacePtr iface(ccx);
@ -470,13 +474,14 @@ nsJSIID::Enumerate(nsIXPConnectWrappedNative *wrapper,
* from |cx|.
*/
static JSObject *
FindObjectForHasInstance(JSContext *cx, JSObject *obj)
FindObjectForHasInstance(JSContext *cx, HandleObject objArg)
{
RootedObject obj(cx, objArg);
while (obj && !IS_WRAPPER_CLASS(js::GetObjectClass(obj)) && !IsDOMObject(obj))
{
if (js::IsWrapper(obj))
obj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
else if (!js::GetObjectProto(cx, obj, &obj))
else if (!js::GetObjectProto(cx, obj, obj.address()))
return nullptr;
}
return obj;
@ -494,7 +499,7 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
if (!JSVAL_IS_PRIMITIVE(val)) {
// we have a JSObject
JS::RootedObject obj(cx, JSVAL_TO_OBJECT(val));
RootedObject obj(cx, JSVAL_TO_OBJECT(val));
NS_ASSERTION(obj, "when is an object not an object?");
@ -703,23 +708,22 @@ GetIIDArg(uint32_t argc, const JS::Value& val, JSContext* cx)
return iid;
}
static JSObject*
GetWrapperObject()
static void
GetWrapperObject(MutableHandleObject obj)
{
obj.set(NULL);
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if (!xpc)
return NULL;
return;
nsAXPCNativeCallContext *ccxp = NULL;
xpc->GetCurrentNativeCallContext(&ccxp);
if (!ccxp)
return NULL;
return;
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
ccxp->GetCalleeWrapper(getter_AddRefs(wrapper));
JSObject* obj;
wrapper->GetJSObject(&obj);
return obj;
wrapper->GetJSObject(obj.address());
}
/* nsISupports createInstance (); */
@ -730,7 +734,8 @@ nsJSCID::CreateInstance(const JS::Value& iidval, JSContext* cx,
if (!mDetails.IsValid())
return NS_ERROR_XPC_BAD_CID;
JSObject* obj = GetWrapperObject();
RootedObject obj(cx);
GetWrapperObject(&obj);
if (!obj) {
return NS_ERROR_UNEXPECTED;
}
@ -776,7 +781,8 @@ nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
if (!mDetails.IsValid())
return NS_ERROR_XPC_BAD_CID;
JSObject* obj = GetWrapperObject();
RootedObject obj(cx);
GetWrapperObject(&obj);
if (!obj) {
return NS_ERROR_UNEXPECTED;
}
@ -808,10 +814,10 @@ nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
if (NS_FAILED(rv) || !srvc)
return NS_ERROR_XPC_GS_RETURNED_FAILURE;
JSObject* instJSObj;
RootedObject instJSObj(cx);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = nsXPConnect::GetXPConnect()->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(holder));
if (NS_FAILED(rv) || !holder || NS_FAILED(holder->GetJSObject(&instJSObj)))
if (NS_FAILED(rv) || !holder || NS_FAILED(holder->GetJSObject(instJSObj.address())))
return NS_ERROR_XPC_CANT_CREATE_WN;
*retval = OBJECT_TO_JSVAL(instJSObj);
@ -821,10 +827,11 @@ nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
/* bool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in uint32_t argc, in JSValPtr argv, in JSValPtr vp); */
NS_IMETHODIMP
nsJSCID::Construct(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * obj,
JSContext * cx, JSObject * objArg,
uint32_t argc, jsval * argv, jsval * vp,
bool *_retval)
{
RootedObject obj(cx, objArg);
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (!rt)
return NS_ERROR_FAILURE;
@ -849,7 +856,7 @@ nsJSCID::HasInstance(nsIXPConnectWrappedNative *wrapper,
if (!JSVAL_IS_PRIMITIVE(val)) {
// we have a JSObject
JSObject* obj = JSVAL_TO_OBJECT(val);
RootedObject obj(cx, &val.toObject());
NS_ASSERTION(obj, "when is an object not an object?");
@ -878,7 +885,7 @@ nsJSCID::HasInstance(nsIXPConnectWrappedNative *wrapper,
// additional utilities...
JSObject *
xpc_NewIDObject(JSContext *cx, JSObject* jsobj, const nsID& aID)
xpc_NewIDObject(JSContext *cx, HandleObject jsobj, const nsID& aID)
{
JSObject *obj = nullptr;

Просмотреть файл

@ -3731,7 +3731,7 @@ private:
/***************************************************************************/
extern JSObject*
xpc_NewIDObject(JSContext *cx, JSObject* jsobj, const nsID& aID);
xpc_NewIDObject(JSContext *cx, JS::HandleObject jsobj, const nsID& aID);
extern const nsID*
xpc_JSObjectToID(JSContext *cx, JSObject* obj);