return rv;
break;
SetupParams(JNIEnv *env, const jobject aParam, const nsXPTParamInfo &aParamInfo,            const nsXPTMethodInfo* aMethodInfo, nsIInterfaceInfo* aIInfo,            PRUint16 aMethodIndex, nsXPTCVariant* aDispatchParams,            nsXPTCVariant &aVariant){  nsresult rv = NS_OK;  const nsXPTType &type = aParamInfo.GetType();  // defaults  aVariant.ptr = nsnull;  aVariant.type = type;  aVariant.flags = 0;  PRUint8 tag = type.TagPart();  switch (tag)  {    case nsXPTType::T_I8:    case nsXPTType::T_U8:    {      LOG(("byte\n"));      if (!aParamInfo.IsOut()) {        aVariant.val.u8 = env->CallByteMethod(aParam, byteValueMID);      } else {        jboolean isCopy = JNI_FALSE;        jbyte* buf = nsnull;        if (aParam) {          buf = env->GetByteArrayElements((jbyteArray) aParam, &isCopy);        }        aVariant.ptr = buf;        aVariant.flags = nsXPTCVariant::PTR_IS_DATA;        if (isCopy) {          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;        }      }    }    break;    case nsXPTType::T_I16:    case nsXPTType::T_U16:    {      LOG(("short\n"));      if (!aParamInfo.IsOut()) {        aVariant.val.u16 = env->CallShortMethod(aParam, shortValueMID);      } else {        jboolean isCopy = JNI_FALSE;        jshort* buf = nsnull;        if (aParam) {          buf = env->GetShortArrayElements((jshortArray) aParam, &isCopy);        }        aVariant.ptr = buf;        aVariant.flags = nsXPTCVariant::PTR_IS_DATA;        if (isCopy) {          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;        }      }    }    break;    case nsXPTType::T_I32:    case nsXPTType::T_U32:    {      LOG(("int\n"));      if (!aParamInfo.IsOut()) {        aVariant.val.u32 = env->CallIntMethod(aParam, intValueMID);      } else {        jboolean isCopy = JNI_FALSE;        jint* buf = nsnull;        if (aParam) {          buf = env->GetIntArrayElements((jintArray) aParam, &isCopy);        }        aVariant.ptr = buf;        aVariant.flags = nsXPTCVariant::PTR_IS_DATA;        if (isCopy) {          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;        }      }    }    break;    case nsXPTType::T_I64:    case nsXPTType::T_U64:    {      LOG(("long\n"));      if (!aParamInfo.IsOut()) {        aVariant.val.u64 = env->CallLongMethod(aParam, longValueMID);      } else {        jboolean isCopy = JNI_FALSE;        jlong* buf = nsnull;        if (aParam) {          buf = env->GetLongArrayElements((jlongArray) aParam, &isCopy);        }        aVariant.ptr = buf;        aVariant.flags = nsXPTCVariant::PTR_IS_DATA;        if (isCopy) {          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;        }      }    }    break;    case nsXPTType::T_FLOAT:    {      LOG(("float\n"));      if (!aParamInfo.IsOut()) {        aVariant.val.f = env->CallFloatMethod(aParam, floatValueMID);      } else {        jboolean isCopy = JNI_FALSE;        jfloat* buf = nsnull;        if (aParam) {          buf = env->GetFloatArrayElements((jfloatArray) aParam, &isCopy);        }        aVariant.ptr = buf;        aVariant.flags = nsXPTCVariant::PTR_IS_DATA;        if (isCopy) {          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;        }      }    }    break;    case nsXPTType::T_DOUBLE:    {      LOG(("double\n"));      if (!aParamInfo.IsOut()) {        aVariant.val.d = env->CallDoubleMethod(aParam, doubleValueMID);      } else {        jboolean isCopy = JNI_FALSE;        jdouble* buf = nsnull;        if (aParam) {          buf = env->GetDoubleArrayElements((jdoubleArray) aParam, &isCopy);        }        aVariant.ptr = buf;        aVariant.flags = nsXPTCVariant::PTR_IS_DATA;        if (isCopy) {          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;        }      }    }    break;    case nsXPTType::T_BOOL:    {      LOG(("boolean\n"));      if (!aParamInfo.IsOut()) {        aVariant.val.b = env->CallBooleanMethod(aParam, booleanValueMID);      } else {        jboolean isCopy = JNI_FALSE;        jboolean* buf = nsnull;        if (aParam) {          buf = env->GetBooleanArrayElements((jbooleanArray) aParam, &isCopy);        }        aVariant.ptr = buf;        aVariant.flags = nsXPTCVariant::PTR_IS_DATA;        if (isCopy) {          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;        }      }    }    break;    case nsXPTType::T_CHAR:    case nsXPTType::T_WCHAR:    {      LOG(("char\n"));      if (!aParamInfo.IsOut()) {        if (tag == nsXPTType::T_CHAR)          aVariant.val.c = env->CallCharMethod(aParam, charValueMID);        else          aVariant.val.wc = env->CallCharMethod(aParam, charValueMID);      } else {        jboolean isCopy = JNI_FALSE;        jchar* buf = nsnull;        if (aParam) {          buf = env->GetCharArrayElements((jcharArray) aParam, &isCopy);        }        aVariant.ptr = buf;        aVariant.flags = nsXPTCVariant::PTR_IS_DATA;        if (isCopy) {          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;        }      }    }    break;    case nsXPTType::T_CHAR_STR:    case nsXPTType::T_WCHAR_STR:    {      LOG(("String\n"));      jstring data = nsnull;      if (!aParamInfo.IsOut()) {        data = (jstring) aParam;      } else {        if (aParam)          data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam, 0);      }      jboolean isCopy = JNI_FALSE;      const void* buf = nsnull;      if (data) {        if (tag == nsXPTType::T_CHAR_STR) {          buf = env->GetStringUTFChars(data, &isCopy);        } else {          buf = env->GetStringChars(data, &isCopy);        }      }      aVariant.val.p = aVariant.ptr = NS_CONST_CAST(void*, buf);      aVariant.flags = nsXPTCVariant::PTR_IS_DATA;      if (isCopy) {        aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;      }    }    break;    case nsXPTType::T_IID:    {      LOG(("String(IID)\n"));      jstring data = nsnull;      if (!aParamInfo.IsOut()) {        data = (jstring) aParam;      } else {        if (aParam)          data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam, 0);      }      nsID* iid = new nsID;      if (data) {        jboolean isCopy;        const char* str = nsnull;        str = env->GetStringUTFChars(data, &isCopy);        iid->Parse(str);        if (isCopy) {          env->ReleaseStringUTFChars(data, str);        }      } else {        *iid = nullID;      }      aVariant.val.p = aVariant.ptr = iid;      aVariant.flags = nsXPTCVariant::PTR_IS_DATA;    }    break;    case nsXPTType::T_INTERFACE:    case nsXPTType::T_INTERFACE_IS:    {      LOG(("nsISupports\n"));      jobject java_obj = nsnull;      if (!aParamInfo.IsOut()) {        java_obj = (jobject) aParam;      } else {        if (aParam)          java_obj = (jobject) env->GetObjectArrayElement((jobjectArray) aParam, 0);      }      if (java_obj) {        // Check if we already have a corresponding XPCOM object        void* inst = GetMatchingXPCOMObject(env, java_obj);        // Get IID for this param        nsID iid;        rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo,                                  aMethodIndex, aDispatchParams, PR_TRUE,                                  iid);        if (NS_FAILED(rv))          return rv;        PRBool isWeakRef = iid.Equals(NS_GET_IID(nsIWeakReference));        if (inst == nsnull && !isWeakRef) {          // If there is not corresponding XPCOM object, then that means that the          // parameter is non-generated class (that is, it is not one of our          // Java stubs that represent an exising XPCOM object).  So we need to          // create an XPCOM stub, that can route any method calls to the class.          // Get interface info for class          nsCOMPtr<nsIInterfaceInfoManager> iim = XPTI_GetInterfaceInfoManager();          nsCOMPtr<nsIInterfaceInfo> iinfo;          iim->GetInfoForIID(&iid, getter_AddRefs(iinfo));          // Create XPCOM stub          nsJavaXPTCStub* xpcomStub = new nsJavaXPTCStub(env, java_obj, iinfo);          inst = SetAsXPTCStub(xpcomStub);          AddJavaXPCOMBinding(env, java_obj, inst);        }        if (isWeakRef) {          // If the function expects an weak reference, then we need to          // create it here.          nsJavaXPTCStubWeakRef* weakref =                                      new nsJavaXPTCStubWeakRef(env, java_obj);          NS_ADDREF(weakref);          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;          aVariant.val.p = aVariant.ptr = (void*) weakref;        } else if (IsXPTCStub(inst)) {          nsJavaXPTCStub* xpcomStub = GetXPTCStubAddr(inst);          NS_ADDREF(xpcomStub);          aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;          aVariant.val.p = aVariant.ptr = (void*) xpcomStub;        } else {          JavaXPCOMInstance* xpcomInst = (JavaXPCOMInstance*) inst;          aVariant.val.p = aVariant.ptr = (void*) xpcomInst->GetInstance();        }      } else {        aVariant.val.p = aVariant.ptr = nsnull;      }      aVariant.flags |= nsXPTCVariant::PTR_IS_DATA;      aVariant.SetValIsInterface();    }    break;    case nsXPTType::T_ASTRING:    case nsXPTType::T_DOMSTRING:    {      LOG(("String\n"));      jstring data = nsnull;      if (!aParamInfo.IsOut()) {        data = (jstring) aParam;      } else {        if (aParam)          data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam, 0);      }      nsAString* str = jstring_to_nsAString(env, data);      aVariant.val.p = aVariant.ptr = str;      aVariant.flags = nsXPTCVariant::PTR_IS_DATA | nsXPTCVariant::VAL_IS_DOMSTR;    }    break;    case nsXPTType::T_UTF8STRING:    case nsXPTType::T_CSTRING:    {      LOG(("StringUTF\n"));      jstring data = nsnull;      if (!aParamInfo.IsOut()) {        data = (jstring) aParam;      } else {        if (aParam)          data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam, 0);      }      nsACString* str = jstring_to_nsACString(env, data);      aVariant.val.p = aVariant.ptr = str;      aVariant.flags = nsXPTCVariant::PTR_IS_DATA;      if (tag == nsXPTType::T_CSTRING) {        aVariant.flags |= nsXPTCVariant::VAL_IS_CSTR;      } else {        aVariant.flags |= nsXPTCVariant::VAL_IS_UTF8STR;      }    }    break;    // handle "void *" as an "int" in Java    case nsXPTType::T_VOID:    {      if (env->IsInstanceOf(aParam, intClass))      {        if (env->IsInstanceOf(aParam, intArrayClass))        {          LOG(("int[] (void*)\n"));          jboolean isCopy = JNI_FALSE;          jint* buf = nsnull;          if (aParam) {            buf = env->GetIntArrayElements((jintArray) aParam, &isCopy);          }          aVariant.ptr = buf;          aVariant.flags = nsXPTCVariant::PTR_IS_DATA;          if (isCopy) {            aVariant.flags |= nsXPTCVariant::VAL_IS_ALLOCD;          }        } else {          LOG(("int (void*)\n"));          NS_ASSERTION(type.IsPointer(), "T_VOID 'int' handler received non-pointer type");          aVariant.val.p = (void*) env->CallIntMethod(aParam, intValueMID);        }      } else {        NS_WARNING("Unhandled T_VOID");        return NS_ERROR_UNEXPECTED;      }    }    break;    case nsXPTType::T_ARRAY:      NS_WARNING("array types are not yet supported");      return NS_ERROR_NOT_IMPLEMENTED;    case nsXPTType::T_PSTRING_SIZE_IS:    case nsXPTType::T_PWSTRING_SIZE_IS:    default:      NS_WARNING("unexpected parameter type");      return NS_ERROR_UNEXPECTED;  }  return rv;}