зеркало из https://github.com/mozilla/gecko-dev.git
Bug 861269 - GC: Continuing the rooting of XPConnect - Root XPCJSID.cpp r=bholley
--HG-- extra : rebase_source : 3702d37309dd711a6db9173d0c6ab6142ce78544
This commit is contained in:
Родитель
af1f7cbb11
Коммит
b2767312e0
|
@ -169,8 +169,9 @@ XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s,
|
||||||
nsID* iid2 = *((nsID**)s);
|
nsID* iid2 = *((nsID**)s);
|
||||||
if (!iid2)
|
if (!iid2)
|
||||||
break;
|
break;
|
||||||
|
JS::RootedObject scope(cx, lccx.GetScopeForNewJSObjects());
|
||||||
JSObject* obj;
|
JSObject* obj;
|
||||||
if (!(obj = xpc_NewIDObject(cx, lccx.GetScopeForNewJSObjects(), *iid2)))
|
if (!(obj = xpc_NewIDObject(cx, scope, *iid2)))
|
||||||
return false;
|
return false;
|
||||||
*d = OBJECT_TO_JSVAL(obj);
|
*d = OBJECT_TO_JSVAL(obj);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "XPCWrapper.h"
|
#include "XPCWrapper.h"
|
||||||
|
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
|
using namespace JS;
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
// nsJSID
|
// nsJSID
|
||||||
|
@ -388,10 +389,12 @@ nsJSIID::NewID(nsIInterfaceInfo* aInfo)
|
||||||
/* bool resolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsval id); */
|
/* bool resolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsval id); */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
||||||
JSContext * cx, JSObject * obj,
|
JSContext * cx, JSObject * objArg,
|
||||||
jsid id, uint32_t flags,
|
jsid idArg, uint32_t flags,
|
||||||
JSObject * *objp, bool *_retval)
|
JSObject * *objp, bool *_retval)
|
||||||
{
|
{
|
||||||
|
RootedObject obj(cx, objArg);
|
||||||
|
RootedId id(cx, idArg);
|
||||||
XPCCallContext ccx(JS_CALLER, cx);
|
XPCCallContext ccx(JS_CALLER, cx);
|
||||||
|
|
||||||
AutoMarkingNativeInterfacePtr iface(ccx);
|
AutoMarkingNativeInterfacePtr iface(ccx);
|
||||||
|
@ -422,10 +425,11 @@ nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
||||||
/* bool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
/* bool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSIID::Enumerate(nsIXPConnectWrappedNative *wrapper,
|
nsJSIID::Enumerate(nsIXPConnectWrappedNative *wrapper,
|
||||||
JSContext * cx, JSObject * obj, bool *_retval)
|
JSContext * cx, JSObject * objArg, bool *_retval)
|
||||||
{
|
{
|
||||||
// In this case, let's just eagerly resolve...
|
// In this case, let's just eagerly resolve...
|
||||||
|
|
||||||
|
RootedObject obj(cx, objArg);
|
||||||
XPCCallContext ccx(JS_CALLER, cx);
|
XPCCallContext ccx(JS_CALLER, cx);
|
||||||
|
|
||||||
AutoMarkingNativeInterfacePtr iface(ccx);
|
AutoMarkingNativeInterfacePtr iface(ccx);
|
||||||
|
@ -470,13 +474,14 @@ nsJSIID::Enumerate(nsIXPConnectWrappedNative *wrapper,
|
||||||
* from |cx|.
|
* from |cx|.
|
||||||
*/
|
*/
|
||||||
static JSObject *
|
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))
|
while (obj && !IS_WRAPPER_CLASS(js::GetObjectClass(obj)) && !IsDOMObject(obj))
|
||||||
{
|
{
|
||||||
if (js::IsWrapper(obj))
|
if (js::IsWrapper(obj))
|
||||||
obj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
|
obj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
|
||||||
else if (!js::GetObjectProto(cx, obj, &obj))
|
else if (!js::GetObjectProto(cx, obj, obj.address()))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -494,7 +499,7 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
||||||
|
|
||||||
if (!JSVAL_IS_PRIMITIVE(val)) {
|
if (!JSVAL_IS_PRIMITIVE(val)) {
|
||||||
// we have a JSObject
|
// 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?");
|
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;
|
return iid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSObject*
|
static void
|
||||||
GetWrapperObject()
|
GetWrapperObject(MutableHandleObject obj)
|
||||||
{
|
{
|
||||||
|
obj.set(NULL);
|
||||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||||
if (!xpc)
|
if (!xpc)
|
||||||
return NULL;
|
return;
|
||||||
|
|
||||||
nsAXPCNativeCallContext *ccxp = NULL;
|
nsAXPCNativeCallContext *ccxp = NULL;
|
||||||
xpc->GetCurrentNativeCallContext(&ccxp);
|
xpc->GetCurrentNativeCallContext(&ccxp);
|
||||||
if (!ccxp)
|
if (!ccxp)
|
||||||
return NULL;
|
return;
|
||||||
|
|
||||||
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
||||||
ccxp->GetCalleeWrapper(getter_AddRefs(wrapper));
|
ccxp->GetCalleeWrapper(getter_AddRefs(wrapper));
|
||||||
JSObject* obj;
|
wrapper->GetJSObject(obj.address());
|
||||||
wrapper->GetJSObject(&obj);
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* nsISupports createInstance (); */
|
/* nsISupports createInstance (); */
|
||||||
|
@ -730,7 +734,8 @@ nsJSCID::CreateInstance(const JS::Value& iidval, JSContext* cx,
|
||||||
if (!mDetails.IsValid())
|
if (!mDetails.IsValid())
|
||||||
return NS_ERROR_XPC_BAD_CID;
|
return NS_ERROR_XPC_BAD_CID;
|
||||||
|
|
||||||
JSObject* obj = GetWrapperObject();
|
RootedObject obj(cx);
|
||||||
|
GetWrapperObject(&obj);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
@ -776,7 +781,8 @@ nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
|
||||||
if (!mDetails.IsValid())
|
if (!mDetails.IsValid())
|
||||||
return NS_ERROR_XPC_BAD_CID;
|
return NS_ERROR_XPC_BAD_CID;
|
||||||
|
|
||||||
JSObject* obj = GetWrapperObject();
|
RootedObject obj(cx);
|
||||||
|
GetWrapperObject(&obj);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
@ -808,10 +814,10 @@ nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
|
||||||
if (NS_FAILED(rv) || !srvc)
|
if (NS_FAILED(rv) || !srvc)
|
||||||
return NS_ERROR_XPC_GS_RETURNED_FAILURE;
|
return NS_ERROR_XPC_GS_RETURNED_FAILURE;
|
||||||
|
|
||||||
JSObject* instJSObj;
|
RootedObject instJSObj(cx);
|
||||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||||
rv = nsXPConnect::GetXPConnect()->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(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;
|
return NS_ERROR_XPC_CANT_CREATE_WN;
|
||||||
|
|
||||||
*retval = OBJECT_TO_JSVAL(instJSObj);
|
*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); */
|
/* bool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in uint32_t argc, in JSValPtr argv, in JSValPtr vp); */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSCID::Construct(nsIXPConnectWrappedNative *wrapper,
|
nsJSCID::Construct(nsIXPConnectWrappedNative *wrapper,
|
||||||
JSContext * cx, JSObject * obj,
|
JSContext * cx, JSObject * objArg,
|
||||||
uint32_t argc, jsval * argv, jsval * vp,
|
uint32_t argc, jsval * argv, jsval * vp,
|
||||||
bool *_retval)
|
bool *_retval)
|
||||||
{
|
{
|
||||||
|
RootedObject obj(cx, objArg);
|
||||||
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
|
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
|
||||||
if (!rt)
|
if (!rt)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
@ -849,7 +856,7 @@ nsJSCID::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
||||||
|
|
||||||
if (!JSVAL_IS_PRIMITIVE(val)) {
|
if (!JSVAL_IS_PRIMITIVE(val)) {
|
||||||
// we have a JSObject
|
// 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?");
|
NS_ASSERTION(obj, "when is an object not an object?");
|
||||||
|
|
||||||
|
@ -878,7 +885,7 @@ nsJSCID::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
||||||
// additional utilities...
|
// additional utilities...
|
||||||
|
|
||||||
JSObject *
|
JSObject *
|
||||||
xpc_NewIDObject(JSContext *cx, JSObject* jsobj, const nsID& aID)
|
xpc_NewIDObject(JSContext *cx, HandleObject jsobj, const nsID& aID)
|
||||||
{
|
{
|
||||||
JSObject *obj = nullptr;
|
JSObject *obj = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -3731,7 +3731,7 @@ private:
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
extern JSObject*
|
extern JSObject*
|
||||||
xpc_NewIDObject(JSContext *cx, JSObject* jsobj, const nsID& aID);
|
xpc_NewIDObject(JSContext *cx, JS::HandleObject jsobj, const nsID& aID);
|
||||||
|
|
||||||
extern const nsID*
|
extern const nsID*
|
||||||
xpc_JSObjectToID(JSContext *cx, JSObject* obj);
|
xpc_JSObjectToID(JSContext *cx, JSObject* obj);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче