Bug 950909 - Forward native aggregation to the root XPCWrappedJS. r=mccr8,sr=smaug

This commit is contained in:
Bobby Holley 2013-12-19 18:08:07 -08:00
Родитель 3489773efd
Коммит 3e1858537b
7 изменённых файлов: 26 добавлений и 22 удалений

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

@ -242,8 +242,7 @@ CallbackObjectHolderBase::ToXPCOMCallback(CallbackObject* aCallback,
JSAutoCompartment ac(cx, callback);
nsRefPtr<nsXPCWrappedJS> wrappedJS;
nsresult rv =
nsXPCWrappedJS::GetNewOrUsed(callback, aIID,
nullptr, getter_AddRefs(wrappedJS));
nsXPCWrappedJS::GetNewOrUsed(callback, aIID, getter_AddRefs(wrappedJS));
if (NS_FAILED(rv) || !wrappedJS) {
return nullptr;
}

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

@ -1028,10 +1028,16 @@ XPCConvert::JSObject2NativeInterface(void** dest, HandleObject src,
// else...
nsXPCWrappedJS* wrapper;
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(src, *iid, aOuter, &wrapper);
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(src, *iid, &wrapper);
if (pErr)
*pErr = rv;
if (NS_SUCCEEDED(rv) && wrapper) {
// If the caller wanted to aggregate this JS object to a native,
// attach it to the wrapper. Note that we allow a maximum of one
// aggregated native for a given XPCWrappedJS.
if (aOuter)
wrapper->SetAggregatedNativeObject(aOuter);
// We need to go through the QueryInterface logic to make this return
// the right thing for the various 'special' interfaces; e.g.
// nsIPropertyBag. We must use AggregatedQueryInterface in cases where
@ -1184,8 +1190,7 @@ XPCConvert::JSValToXPCException(MutableHandleValue s,
// lets try to build a wrapper around the JSObject
nsXPCWrappedJS* jswrapper;
nsresult rv =
nsXPCWrappedJS::GetNewOrUsed(obj, NS_GET_IID(nsIException),
nullptr, &jswrapper);
nsXPCWrappedJS::GetNewOrUsed(obj, NS_GET_IID(nsIException), &jswrapper);
if (NS_FAILED(rv))
return rv;

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

@ -43,7 +43,6 @@ nsresult xpcJSWeakReference::Init(JSContext* cx, const JS::Value& object)
nsRefPtr<nsXPCWrappedJS> wrapped;
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(obj,
NS_GET_IID(nsISupports),
nullptr,
getter_AddRefs(wrapped));
if (!wrapped) {
NS_ERROR("can't get nsISupportsWeakReference wrapper for obj");

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

@ -735,8 +735,7 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
}
nsRefPtr<nsXPCWrappedJS> wrappedJS;
rv = nsXPCWrappedJS::GetNewOrUsed(src, iid, nullptr,
getter_AddRefs(wrappedJS));
rv = nsXPCWrappedJS::GetNewOrUsed(src, iid, getter_AddRefs(wrappedJS));
if (NS_FAILED(rv) || !wrappedJS) {
*ppArgRef = nullptr;
return rv;

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

@ -320,7 +320,6 @@ nsXPCWrappedJS::GetJSObject()
nsresult
nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
REFNSIID aIID,
nsISupports* aOuter,
nsXPCWrappedJS** wrapperResult)
{
// Do a release-mode assert against accessing nsXPCWrappedJS off-main-thread.
@ -364,8 +363,7 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
// build the root wrapper
if (rootJSObj == jsObj) {
// the root will do double duty as the interface wrapper
wrapper = root = new nsXPCWrappedJS(cx, jsObj, clazz, nullptr,
aOuter);
wrapper = root = new nsXPCWrappedJS(cx, jsObj, clazz, nullptr);
if (!root)
goto return_wrapper;
@ -380,7 +378,7 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
if (!rootClazz)
goto return_wrapper;
root = new nsXPCWrappedJS(cx, rootJSObj, rootClazz, nullptr, aOuter);
root = new nsXPCWrappedJS(cx, rootJSObj, rootClazz, nullptr);
NS_RELEASE(rootClazz);
if (!root)
@ -397,7 +395,7 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
MOZ_ASSERT(clazz,"bad clazz");
if (!wrapper) {
wrapper = new nsXPCWrappedJS(cx, jsObj, clazz, root, aOuter);
wrapper = new nsXPCWrappedJS(cx, jsObj, clazz, root);
if (!wrapper)
goto return_wrapper;
}
@ -422,13 +420,12 @@ return_wrapper:
nsXPCWrappedJS::nsXPCWrappedJS(JSContext* cx,
JSObject* aJSObj,
nsXPCWrappedJSClass* aClass,
nsXPCWrappedJS* root,
nsISupports* aOuter)
nsXPCWrappedJS* root)
: mJSObj(aJSObj),
mClass(aClass),
mRoot(root ? root : MOZ_THIS_IN_INITIALIZER_LIST()),
mNext(nullptr),
mOuter(root ? nullptr : aOuter)
mOuter(nullptr)
{
InitStub(GetClass()->GetIID());
@ -439,7 +436,6 @@ nsXPCWrappedJS::nsXPCWrappedJS(JSContext* cx,
NS_ADDREF_THIS();
NS_ADDREF(aClass);
NS_IF_ADDREF(mOuter);
if (!IsRootWrapper())
NS_ADDREF(mRoot);

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

@ -700,8 +700,7 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
// XPConvert::JSObject2NativeInterface() here to make sure we
// get a new (or used) nsXPCWrappedJS.
nsXPCWrappedJS* wrapper;
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(jsobj, aIID, nullptr,
&wrapper);
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(jsobj, aIID, &wrapper);
if (NS_SUCCEEDED(rv) && wrapper) {
// We need to go through the QueryInterface logic to make
// this return the right thing for the various 'special'

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

@ -2474,7 +2474,6 @@ public:
static nsresult
GetNewOrUsed(JS::HandleObject aJSObj,
REFNSIID aIID,
nsISupports* aOuter,
nsXPCWrappedJS** wrapper);
nsISomeInterface* GetXPTCStub() { return mXPTCStub; }
@ -2509,6 +2508,15 @@ public:
bool IsAggregatedToNative() const {return mRoot->mOuter != nullptr;}
nsISupports* GetAggregatedNativeObject() const {return mRoot->mOuter;}
void SetAggregatedNativeObject(nsISupports *aNative) {
MOZ_ASSERT(aNative);
if (mRoot->mOuter) {
MOZ_ASSERT(mRoot->mOuter == aNative,
"Only one aggregated native can be set");
return;
}
NS_ADDREF(mRoot->mOuter = aNative);
}
void TraceJS(JSTracer* trc);
static void GetTraceName(JSTracer* trc, char *buf, size_t bufsize);
@ -2519,8 +2527,7 @@ protected:
nsXPCWrappedJS(JSContext* cx,
JSObject* aJSObj,
nsXPCWrappedJSClass* aClass,
nsXPCWrappedJS* root,
nsISupports* aOuter);
nsXPCWrappedJS* root);
bool CanSkip();
void Destroy();