if (NS_FAILED(rc)) return rc; if (type == nsIDataType::VTYPE_EMPTY || type == nsIDataType::VTYPE_VOID || type == nsIDataType::VTYPE_EMPTY_ARRAY) {
NS_ENSURE_SUCCESS(rc, rc);  if (type == nsIDataType::VTYPE_EMPTY || type == nsIDataType::VTYPE_VOID || type == nsIDataType::VTYPE_EMPTY_ARRAY) {
static nsresult GetArrayType(nsIVariant* aSource, PRUint32 aDimensionCount, PRUint32 * aDimensionSizes, PRUint16 * aType){  if (!aSource) {    *aType = nsIDataType::VTYPE_EMPTY;    return NS_OK;  }  PRUint16 type;  nsIID iid;  PRUint32 count;  void* array;  nsresult rc;  PRUint32 i;  rc = aSource->GetDataType(&type);  if (NS_FAILED(rc))    return rc;  if (type == nsIDataType::VTYPE_EMPTY      || type == nsIDataType::VTYPE_VOID      || type == nsIDataType::VTYPE_EMPTY_ARRAY) {    rc = NS_OK;    count = 0;    type = nsIDataType::VTYPE_EMPTY;    array = nsnull;  }  else {    rc = aSource->GetAsArray(&type, &iid, &count, &array);        // First, get the array, if any.    if (NS_FAILED(rc))      return rc;  }  if (count > aDimensionSizes[0]) {    aDimensionSizes[0] = count;  }  if (aDimensionCount > 1) {    if (type != nsIDataType::VTYPE_INTERFACE_IS      || !iid.Equals(NS_GET_IID(nsIVariant))) {      rc = SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_ARRAY_OBJECTS","When encoding as an array, an array of array objects is required");                                  //  All nested arrays (which is what multi-dimensional arrays are) are variants.    }    else {      nsIVariant** a = NS_STATIC_CAST(nsIVariant**,array);      PRUint16 rtype = nsIDataType::VTYPE_EMPTY;      for (i = 0; i < count; i++) {        PRUint16 nexttype;        rc = GetArrayType(a[i], aDimensionCount - 1, aDimensionSizes + 1, &nexttype);        if (NS_FAILED(rc))          break;        if (rtype == nsIDataType::VTYPE_EMPTY)          rtype = nexttype;        else if (nexttype != nsIDataType::VTYPE_EMPTY                 && nexttype != rtype)          rtype = nsIDataType::VTYPE_INTERFACE_IS;      }      *aType = rtype;    }  }  else {    *aType = type;  }  //  The memory model for variant arrays' GetAsArray is difficult to manage  switch (type) {    case nsIDataType::VTYPE_INTERFACE_IS:      {        nsISupports** values = NS_STATIC_CAST(nsISupports**,array);        for (i = 0; i < count; i++)          NS_RELEASE(values[i]);      }      break;    case nsIDataType::VTYPE_WCHAR_STR:    case nsIDataType::VTYPE_CHAR_STR:      {        void** ptrs = NS_STATIC_CAST(void**,array);        for (i = 0; i < count; i++) {          nsMemory::Free(ptrs[i]);        }      }      break;  }  nsMemory::Free(array);  {  //  Individual lengths guaranteed to fit because variant array length is 32-bit.    PRUint64 tot = 1;  //  Collect in 64 bits, just to make sure combo fits    for (i = 0; i < aDimensionCount; i++) {      tot = tot * aDimensionSizes[i];      if (tot > 0xffffffffU) {        return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_ARRAY_TOO_BIG","When encoding an object as an array, the total count of items exceeded maximum.");      }    }  }  return rc;}