Bug 931571, part 10 - Turn SetFromVariant into a method. r=froydnj

This commit is contained in:
Andrew McCreight 2015-07-23 12:28:30 -07:00
Родитель cb922209d3
Коммит 2cca253ff3
2 изменённых файлов: 32 добавлений и 33 удалений

Просмотреть файл

@ -1220,14 +1220,14 @@ nsDiscriminatedUnion::ConvertToArray(uint16_t* aType, nsIID* aIID,
{ \ { \
#define CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_) \ #define CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_) \
rv = aValue->GetAs##name_ (&(aData->u. member_ )); rv = aValue->GetAs##name_ (&(u. member_ ));
#define CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_) \ #define CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_) \
rv = aValue->GetAs##name_ ( cast_ &(aData->u. member_ )); rv = aValue->GetAs##name_ ( cast_ &(u. member_ ));
#define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_) \ #define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_) \
if (NS_SUCCEEDED(rv)) { \ if (NS_SUCCEEDED(rv)) { \
aData->mType = nsIDataType :: type_ ; \ mType = nsIDataType :: type_ ; \
} \ } \
break; \ break; \
} }
@ -1245,13 +1245,13 @@ nsDiscriminatedUnion::ConvertToArray(uint16_t* aType, nsIID* aIID,
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_) CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
/* static */ nsresult nsresult
nsVariant::SetFromVariant(nsDiscriminatedUnion* aData, nsIVariant* aValue) nsDiscriminatedUnion::SetFromVariant(nsIVariant* aValue)
{ {
uint16_t type; uint16_t type;
nsresult rv; nsresult rv;
aData->Cleanup(); Cleanup();
rv = aValue->GetDataType(&type); rv = aValue->GetDataType(&type);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
@ -1278,45 +1278,45 @@ nsVariant::SetFromVariant(nsDiscriminatedUnion* aData, nsIVariant* aValue)
case nsIDataType::VTYPE_WCHAR_STR: case nsIDataType::VTYPE_WCHAR_STR:
case nsIDataType::VTYPE_WSTRING_SIZE_IS: case nsIDataType::VTYPE_WSTRING_SIZE_IS:
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_ASTRING); CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_ASTRING);
aData->u.mAStringValue = new nsString(); u.mAStringValue = new nsString();
if (!aData->u.mAStringValue) { if (!u.mAStringValue) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
rv = aValue->GetAsAString(*aData->u.mAStringValue); rv = aValue->GetAsAString(*u.mAStringValue);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
delete aData->u.mAStringValue; delete u.mAStringValue;
} }
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_ASTRING) CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_ASTRING)
case nsIDataType::VTYPE_CSTRING: case nsIDataType::VTYPE_CSTRING:
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_CSTRING); CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_CSTRING);
aData->u.mCStringValue = new nsCString(); u.mCStringValue = new nsCString();
if (!aData->u.mCStringValue) { if (!u.mCStringValue) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
rv = aValue->GetAsACString(*aData->u.mCStringValue); rv = aValue->GetAsACString(*u.mCStringValue);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
delete aData->u.mCStringValue; delete u.mCStringValue;
} }
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_CSTRING) CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_CSTRING)
case nsIDataType::VTYPE_UTF8STRING: case nsIDataType::VTYPE_UTF8STRING:
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_UTF8STRING); CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_UTF8STRING);
aData->u.mUTF8StringValue = new nsUTF8String(); u.mUTF8StringValue = new nsUTF8String();
if (!aData->u.mUTF8StringValue) { if (!u.mUTF8StringValue) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
rv = aValue->GetAsAUTF8String(*aData->u.mUTF8StringValue); rv = aValue->GetAsAUTF8String(*u.mUTF8StringValue);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
delete aData->u.mUTF8StringValue; delete u.mUTF8StringValue;
} }
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_UTF8STRING) CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_UTF8STRING)
case nsIDataType::VTYPE_CHAR_STR: case nsIDataType::VTYPE_CHAR_STR:
case nsIDataType::VTYPE_STRING_SIZE_IS: case nsIDataType::VTYPE_STRING_SIZE_IS:
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_STRING_SIZE_IS); CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_STRING_SIZE_IS);
rv = aValue->GetAsStringWithSize(&aData->u.str.mStringLength, rv = aValue->GetAsStringWithSize(&u.str.mStringLength,
&aData->u.str.mStringValue); &u.str.mStringValue);
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_STRING_SIZE_IS) CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_STRING_SIZE_IS)
case nsIDataType::VTYPE_INTERFACE: case nsIDataType::VTYPE_INTERFACE:
@ -1324,29 +1324,29 @@ nsVariant::SetFromVariant(nsDiscriminatedUnion* aData, nsIVariant* aValue)
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_INTERFACE_IS); CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_INTERFACE_IS);
// XXX This iid handling is ugly! // XXX This iid handling is ugly!
nsIID* iid; nsIID* iid;
rv = aValue->GetAsInterface(&iid, (void**)&aData->u.iface.mInterfaceValue); rv = aValue->GetAsInterface(&iid, (void**)&u.iface.mInterfaceValue);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
aData->u.iface.mInterfaceID = *iid; u.iface.mInterfaceID = *iid;
free((char*)iid); free((char*)iid);
} }
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_INTERFACE_IS) CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_INTERFACE_IS)
case nsIDataType::VTYPE_ARRAY: case nsIDataType::VTYPE_ARRAY:
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_ARRAY); CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_ARRAY);
rv = aValue->GetAsArray(&aData->u.array.mArrayType, rv = aValue->GetAsArray(&u.array.mArrayType,
&aData->u.array.mArrayInterfaceID, &u.array.mArrayInterfaceID,
&aData->u.array.mArrayCount, &u.array.mArrayCount,
&aData->u.array.mArrayValue); &u.array.mArrayValue);
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_ARRAY) CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_ARRAY)
case nsIDataType::VTYPE_VOID: case nsIDataType::VTYPE_VOID:
rv = aData->SetToVoid(); rv = SetToVoid();
break; break;
case nsIDataType::VTYPE_EMPTY_ARRAY: case nsIDataType::VTYPE_EMPTY_ARRAY:
rv = aData->SetToEmptyArray(); rv = SetToEmptyArray();
break; break;
case nsIDataType::VTYPE_EMPTY: case nsIDataType::VTYPE_EMPTY:
rv = aData->SetToEmpty(); rv = SetToEmpty();
break; break;
default: default:
NS_ERROR("bad type in variant!"); NS_ERROR("bad type in variant!");
@ -2237,5 +2237,5 @@ nsVariant::SetFromVariant(nsIVariant* aValue)
if (!mWritable) { if (!mWritable) {
return NS_ERROR_OBJECT_IS_IMMUTABLE; return NS_ERROR_OBJECT_IS_IMMUTABLE;
} }
return nsVariant::SetFromVariant(&mData, aValue); return mData.SetFromVariant(aValue);
} }

Просмотреть файл

@ -64,6 +64,8 @@ public:
nsresult ConvertToArray(uint16_t* aType, nsIID* aIID, nsresult ConvertToArray(uint16_t* aType, nsIID* aIID,
uint32_t* aCount, void** aPtr) const; uint32_t* aCount, void** aPtr) const;
nsresult SetFromVariant(nsIVariant* aValue);
nsresult SetFromInt8(uint8_t aValue); nsresult SetFromInt8(uint8_t aValue);
nsresult SetFromInt16(int16_t aValue); nsresult SetFromInt16(int16_t aValue);
nsresult SetFromInt32(int32_t aValue); nsresult SetFromInt32(int32_t aValue);
@ -174,9 +176,6 @@ public:
nsVariant(); nsVariant();
static nsresult SetFromVariant(nsDiscriminatedUnion* aData,
nsIVariant* aValue);
static void Traverse(const nsDiscriminatedUnion& aData, static void Traverse(const nsDiscriminatedUnion& aData,
nsCycleCollectionTraversalCallback& aCb); nsCycleCollectionTraversalCallback& aCb);