Bug 996061 - part 2 - split out a method for getting an interface's typelib index; r=bholley
authorNathan Froyd <froydnj@mozilla.com>
Fri, 16 May 2014 16:49:34 -0400
changeset 205899 5c2eaff26d0c1b2b3ff47ecdc61d611369796468
parent 205898 d9e56658ef051dc9c4d973004cf93a3ffa26434a
child 205900 2c7acfdd623bdb725c036a1b1fbb2cbe15f392b6
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs996061
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 996061 - part 2 - split out a method for getting an interface's typelib index; r=bholley The code that looks up |xptiInterfaceEntry|s starts by figuring out where in the typelib the desired entry lives. We want to do the same thing for the purpose of getting shims, so we can ask the typelib for the name of the thing at that index. Split out a method to do this for us.
xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
xpcom/reflect/xptinfo/src/xptiprivate.h
--- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
@@ -299,26 +299,27 @@ xptiInterfaceEntry::GetConstant(uint16_t
     constant.set(v);
     *name = ToNewCString(nsDependentCString(c.name));
 
     return NS_OK;
 }
 
 // this is a private helper
 
-nsresult 
-xptiInterfaceEntry::GetEntryForParam(uint16_t methodIndex, 
-                                     const nsXPTParamInfo * param,
-                                     xptiInterfaceEntry** entry)
+nsresult
+xptiInterfaceEntry::GetInterfaceIndexForParam(uint16_t methodIndex,
+                                              const nsXPTParamInfo* param,
+                                              uint16_t* interfaceIndex)
 {
     if(!EnsureResolved())
         return NS_ERROR_UNEXPECTED;
 
     if(methodIndex < mMethodBaseIndex)
-        return mParent->GetEntryForParam(methodIndex, param, entry);
+        return mParent->GetInterfaceIndexForParam(methodIndex, param,
+                                                  interfaceIndex);
 
     if(methodIndex >= mMethodBaseIndex + 
                       mDescriptor->num_methods)
     {
         NS_ERROR("bad param");
         return NS_ERROR_INVALID_ARG;
     }
 
@@ -328,18 +329,39 @@ xptiInterfaceEntry::GetEntryForParam(uin
         td = &mDescriptor->additional_types[td->type.additional_type];
     }
 
     if(XPT_TDP_TAG(td->prefix) != TD_INTERFACE_TYPE) {
         NS_ERROR("not an interface");
         return NS_ERROR_INVALID_ARG;
     }
 
-    xptiInterfaceEntry* theEntry = mTypelib->
-        GetEntryAt(td->type.iface - 1);
+    *interfaceIndex = td->type.iface;
+    return NS_OK;
+}
+
+nsresult 
+xptiInterfaceEntry::GetEntryForParam(uint16_t methodIndex, 
+                                     const nsXPTParamInfo * param,
+                                     xptiInterfaceEntry** entry)
+{
+    if(!EnsureResolved())
+        return NS_ERROR_UNEXPECTED;
+
+    if(methodIndex < mMethodBaseIndex)
+        return mParent->GetEntryForParam(methodIndex, param, entry);
+
+    uint16_t interfaceIndex = 0;
+    nsresult rv = GetInterfaceIndexForParam(methodIndex, param,
+                                            &interfaceIndex);
+    if (NS_FAILED(rv)) {
+        return rv;
+    }
+
+    xptiInterfaceEntry* theEntry = mTypelib->GetEntryAt(interfaceIndex - 1);
     
     // This can happen if a declared interface is not available at runtime.
     if(!theEntry)
     {
         NS_WARNING("Declared InterfaceInfo not found");
         *entry = nullptr;
         return NS_ERROR_FAILURE;
     }
--- a/xpcom/reflect/xptinfo/src/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/src/xptiprivate.h
@@ -270,16 +270,20 @@ private:
     nsresult GetEntryForParam(uint16_t methodIndex, 
                               const nsXPTParamInfo * param,
                               xptiInterfaceEntry** entry);
 
     nsresult GetTypeInArray(const nsXPTParamInfo* param,
                             uint16_t dimension,
                             const XPTTypeDescriptor** type);
 
+    nsresult GetInterfaceIndexForParam(uint16_t methodIndex,
+                                       const nsXPTParamInfo* param,
+                                       uint16_t* interfaceIndex);
+
 private:
     nsID                    mIID;
     XPTInterfaceDescriptor* mDescriptor;
 
     uint16_t mMethodBaseIndex;
     uint16_t mConstantBaseIndex;
     xptiTypelibGuts* mTypelib;