Bug 952660, part 6 - Add and use nsXPCWrappedJS::FindOrFindInherited. r=bholley

FindInherited is only ever used after running Find, and the way the checks
are chained is a little weird.
This commit is contained in:
Andrew McCreight 2014-01-02 11:33:42 -08:00
parent a4ebfe78ef
commit 80cd1878d3
3 changed files with 10 additions and 12 deletions

View File

@ -351,8 +351,8 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
root = map->Find(rootJSObj);
if (root) {
if ((nullptr != (wrapper = root->Find(aIID))) ||
(nullptr != (wrapper = root->FindInherited(aIID)))) {
wrapper = root->FindOrFindInherited(aIID);
if (wrapper) {
NS_ADDREF(wrapper);
*wrapperResult = wrapper;
return NS_OK;

View File

@ -614,19 +614,11 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
return NS_OK;
}
nsXPCWrappedJS* sibling;
// Checks for any existing wrapper explicitly constructed for this iid.
// This includes the current 'self' wrapper. This also deals with the
// nsISupports case (for which it returns mRoot).
if (nullptr != (sibling = self->Find(aIID))) {
NS_ADDREF(sibling);
*aInstancePtr = sibling->GetXPTCStub();
return NS_OK;
}
// Check if asking for an interface from which one of our wrappers inherits.
if (nullptr != (sibling = self->FindInherited(aIID))) {
// Also check if asking for an interface from which one of our wrappers inherits.
if (nsXPCWrappedJS* sibling = self->FindOrFindInherited(aIID)) {
NS_ADDREF(sibling);
*aInstancePtr = sibling->GetXPTCStub();
return NS_OK;

View File

@ -2495,6 +2495,12 @@ public:
nsXPCWrappedJS* Find(REFNSIID aIID);
nsXPCWrappedJS* FindInherited(REFNSIID aIID);
nsXPCWrappedJS* FindOrFindInherited(REFNSIID aIID) {
nsXPCWrappedJS* wrapper = Find(aIID);
if (wrapper)
return wrapper;
return FindInherited(aIID);
}
bool IsRootWrapper() const {return mRoot == this;}
bool IsValid() const {return mJSObj != nullptr;}