Bug 819791 - Part 10: Don't return FallibletArrays by value in Variant.h. r=mak

Returning *TArray's by value isn't compattible with explicit *TArray
copy constructors, which will be added in a later cset.
This commit is contained in:
Justin Lebar 2012-12-18 20:16:07 -05:00
parent 07d79d1bf4
commit 3e3205ba3e

View File

@ -59,7 +59,10 @@ struct variant_storage_traits
{
typedef DataType ConstructorType;
typedef DataType StorageType;
static inline StorageType storage_conversion(ConstructorType aData) { return aData; }
static inline void storage_conversion(const ConstructorType aData, StorageType* _storage)
{
*_storage = aData;
}
};
#define NO_CONVERSION return NS_ERROR_CANNOT_CONVERT_DATA;
@ -68,30 +71,30 @@ template <typename DataType>
struct variant_integer_traits
{
typedef typename variant_storage_traits<DataType>::StorageType StorageType;
static inline nsresult asInt32(StorageType, int32_t *) { NO_CONVERSION }
static inline nsresult asInt64(StorageType, int64_t *) { NO_CONVERSION }
static inline nsresult asInt32(const StorageType &, int32_t *) { NO_CONVERSION }
static inline nsresult asInt64(const StorageType &, int64_t *) { NO_CONVERSION }
};
template <typename DataType>
struct variant_float_traits
{
typedef typename variant_storage_traits<DataType>::StorageType StorageType;
static inline nsresult asDouble(StorageType, double *) { NO_CONVERSION }
static inline nsresult asDouble(const StorageType &, double *) { NO_CONVERSION }
};
template <typename DataType>
struct variant_text_traits
{
typedef typename variant_storage_traits<DataType>::StorageType StorageType;
static inline nsresult asUTF8String(StorageType, nsACString &) { NO_CONVERSION }
static inline nsresult asString(StorageType, nsAString &) { NO_CONVERSION }
static inline nsresult asUTF8String(const StorageType &, nsACString &) { NO_CONVERSION }
static inline nsresult asString(const StorageType &, nsAString &) { NO_CONVERSION }
};
template <typename DataType>
struct variant_blob_traits
{
typedef typename variant_storage_traits<DataType>::StorageType StorageType;
static inline nsresult asArray(StorageType, uint16_t *, uint32_t *, void **)
static inline nsresult asArray(const StorageType &, uint16_t *, uint32_t *, void **)
{ NO_CONVERSION }
};
@ -171,9 +174,9 @@ struct variant_storage_traits<nsString>
{
typedef const nsAString & ConstructorType;
typedef nsString StorageType;
static inline StorageType storage_conversion(ConstructorType aText)
static inline void storage_conversion(ConstructorType aText, StorageType* _outData)
{
return StorageType(aText);
*_outData = aText;
}
};
template < >
@ -203,9 +206,9 @@ struct variant_storage_traits<nsCString>
{
typedef const nsACString & ConstructorType;
typedef nsCString StorageType;
static inline StorageType storage_conversion(ConstructorType aText)
static inline void storage_conversion(ConstructorType aText, StorageType* _outData)
{
return StorageType(aText);
*_outData = aText;
}
};
template < >
@ -239,12 +242,12 @@ struct variant_storage_traits<uint8_t[]>
{
typedef std::pair<const void *, int> ConstructorType;
typedef FallibleTArray<uint8_t> StorageType;
static inline StorageType storage_conversion(ConstructorType aBlob)
static inline void storage_conversion(ConstructorType aBlob, StorageType* _outData)
{
StorageType data(aBlob.second);
(void)data.AppendElements(static_cast<const uint8_t *>(aBlob.first),
aBlob.second);
return data;
_outData->Clear();
_outData->SetCapacity(aBlob.second);
(void)_outData->AppendElements(static_cast<const uint8_t *>(aBlob.first),
aBlob.second);
}
};
template < >
@ -312,9 +315,9 @@ template <typename DataType>
class Variant : public Variant_base
{
public:
Variant(typename variant_storage_traits<DataType>::ConstructorType aData)
: mData(variant_storage_traits<DataType>::storage_conversion(aData))
Variant(const typename variant_storage_traits<DataType>::ConstructorType& aData)
{
variant_storage_traits<DataType>::storage_conversion(aData, &mData);
}
NS_IMETHOD GetDataType(uint16_t *_type)