2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* The long avoided variant support for xpcom. */
|
|
|
|
|
|
|
|
#include "nsVariant.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "prdtoa.h"
|
|
|
|
#include <math.h>
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-09-19 12:31:21 -07:00
|
|
|
#include "xpt_struct.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsMemory.h"
|
2013-09-23 10:25:00 -07:00
|
|
|
#include "nsString.h"
|
2013-09-19 12:31:21 -07:00
|
|
|
#include "nsCRTGlue.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// Helpers for static convert functions...
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
static nsresult
|
|
|
|
String2Double(const char* aString, double* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
char* next;
|
|
|
|
double value = PR_strtod(aString, &next);
|
|
|
|
if (next == aString) {
|
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
|
|
|
}
|
|
|
|
*aResult = value;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
static nsresult
|
|
|
|
AString2Double(const nsAString& aString, double* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
char* pChars = ToNewCString(aString);
|
|
|
|
if (!pChars) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsresult rv = String2Double(pChars, aResult);
|
|
|
|
nsMemory::Free(pChars);
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
static nsresult
|
|
|
|
AUTF8String2Double(const nsAUTF8String& aString, double* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return String2Double(PromiseFlatUTF8String(aString).get(), aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
static nsresult
|
|
|
|
ACString2Double(const nsACString& aString, double* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return String2Double(PromiseFlatCString(aString).get(), aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
// Fills outVariant with double, uint32_t, or int32_t.
|
2007-03-22 10:30:00 -07:00
|
|
|
// Returns NS_OK, an error code, or a non-NS_OK success code
|
2014-07-09 08:15:21 -07:00
|
|
|
static nsresult
|
|
|
|
ToManageableNumber(const nsDiscriminatedUnion& aInData,
|
|
|
|
nsDiscriminatedUnion* aOutData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
nsresult rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aInData.mType) {
|
2012-08-22 08:56:38 -07:00
|
|
|
// This group results in a int32_t...
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define CASE__NUMBER_INT32(type_, member_) \
|
|
|
|
case nsIDataType :: type_ : \
|
2014-07-09 08:15:21 -07:00
|
|
|
aOutData->u.mInt32Value = aInData.u. member_ ; \
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_INT32; \
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
CASE__NUMBER_INT32(VTYPE_INT8, mInt8Value)
|
|
|
|
CASE__NUMBER_INT32(VTYPE_INT16, mInt16Value)
|
|
|
|
CASE__NUMBER_INT32(VTYPE_INT32, mInt32Value)
|
|
|
|
CASE__NUMBER_INT32(VTYPE_UINT8, mUint8Value)
|
|
|
|
CASE__NUMBER_INT32(VTYPE_UINT16, mUint16Value)
|
|
|
|
CASE__NUMBER_INT32(VTYPE_BOOL, mBoolValue)
|
|
|
|
CASE__NUMBER_INT32(VTYPE_CHAR, mCharValue)
|
|
|
|
CASE__NUMBER_INT32(VTYPE_WCHAR, mWCharValue)
|
|
|
|
|
|
|
|
#undef CASE__NUMBER_INT32
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
// This group results in a uint32_t...
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
case nsIDataType::VTYPE_UINT32:
|
2014-07-09 08:15:21 -07:00
|
|
|
aOutData->u.mInt32Value = aInData.u.mUint32Value;
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_INT32;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// This group results in a double...
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_INT64:
|
|
|
|
case nsIDataType::VTYPE_UINT64:
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX Need boundary checking here.
|
|
|
|
// We may need to return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA
|
|
|
|
aOutData->u.mDoubleValue = double(aInData.u.mInt64Value);
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_DOUBLE;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_FLOAT:
|
2014-07-09 08:15:21 -07:00
|
|
|
aOutData->u.mDoubleValue = aInData.u.mFloatValue;
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_DOUBLE;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_DOUBLE:
|
2014-07-09 08:15:21 -07:00
|
|
|
aOutData->u.mDoubleValue = aInData.u.mDoubleValue;
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_DOUBLE;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = String2Double(aInData.u.str.mStringValue, &aOutData->u.mDoubleValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_DOUBLE;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = AString2Double(*aInData.u.mAStringValue, &aOutData->u.mDoubleValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_DOUBLE;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = AUTF8String2Double(*aInData.u.mUTF8StringValue,
|
|
|
|
&aOutData->u.mDoubleValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_DOUBLE;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = ACString2Double(*aInData.u.mCStringValue,
|
|
|
|
&aOutData->u.mDoubleValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_DOUBLE;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = AString2Double(nsDependentString(aInData.u.wstr.mWStringValue),
|
|
|
|
&aOutData->u.mDoubleValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
aOutData->mType = nsIDataType::VTYPE_DOUBLE;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// This group fails...
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_VOID:
|
|
|
|
case nsIDataType::VTYPE_ID:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// Array helpers...
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
static void
|
|
|
|
FreeArray(nsDiscriminatedUnion* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_ASSERTION(aData->mType == nsIDataType::VTYPE_ARRAY, "bad FreeArray call");
|
|
|
|
NS_ASSERTION(aData->u.array.mArrayValue, "bad array");
|
|
|
|
NS_ASSERTION(aData->u.array.mArrayCount, "bad array count");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define CASE__FREE_ARRAY_PTR(type_, ctype_) \
|
|
|
|
case nsIDataType:: type_ : \
|
|
|
|
{ \
|
2014-07-09 08:15:21 -07:00
|
|
|
ctype_ ** p = (ctype_ **) aData->u.array.mArrayValue; \
|
|
|
|
for(uint32_t i = aData->u.array.mArrayCount; i > 0; p++, i--) \
|
2007-03-22 10:30:00 -07:00
|
|
|
if(*p) \
|
|
|
|
nsMemory::Free((char*)*p); \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CASE__FREE_ARRAY_IFACE(type_, ctype_) \
|
|
|
|
case nsIDataType:: type_ : \
|
|
|
|
{ \
|
2014-07-09 08:15:21 -07:00
|
|
|
ctype_ ** p = (ctype_ **) aData->u.array.mArrayValue; \
|
|
|
|
for(uint32_t i = aData->u.array.mArrayCount; i > 0; p++, i--) \
|
2007-03-22 10:30:00 -07:00
|
|
|
if(*p) \
|
|
|
|
(*p)->Release(); \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData->u.array.mArrayType) {
|
|
|
|
case nsIDataType::VTYPE_INT8:
|
|
|
|
case nsIDataType::VTYPE_INT16:
|
|
|
|
case nsIDataType::VTYPE_INT32:
|
|
|
|
case nsIDataType::VTYPE_INT64:
|
|
|
|
case nsIDataType::VTYPE_UINT8:
|
|
|
|
case nsIDataType::VTYPE_UINT16:
|
|
|
|
case nsIDataType::VTYPE_UINT32:
|
|
|
|
case nsIDataType::VTYPE_UINT64:
|
|
|
|
case nsIDataType::VTYPE_FLOAT:
|
|
|
|
case nsIDataType::VTYPE_DOUBLE:
|
|
|
|
case nsIDataType::VTYPE_BOOL:
|
|
|
|
case nsIDataType::VTYPE_CHAR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
|
|
|
|
CASE__FREE_ARRAY_PTR(VTYPE_ID, nsID)
|
|
|
|
CASE__FREE_ARRAY_PTR(VTYPE_CHAR_STR, char)
|
|
|
|
CASE__FREE_ARRAY_PTR(VTYPE_WCHAR_STR, char16_t)
|
|
|
|
CASE__FREE_ARRAY_IFACE(VTYPE_INTERFACE, nsISupports)
|
|
|
|
CASE__FREE_ARRAY_IFACE(VTYPE_INTERFACE_IS, nsISupports)
|
|
|
|
|
|
|
|
// The rest are illegal.
|
|
|
|
case nsIDataType::VTYPE_VOID:
|
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad type in array!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free the array memory.
|
|
|
|
nsMemory::Free((char*)aData->u.array.mArrayValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#undef CASE__FREE_ARRAY_PTR
|
|
|
|
#undef CASE__FREE_ARRAY_IFACE
|
|
|
|
}
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
static nsresult
|
|
|
|
CloneArray(uint16_t aInType, const nsIID* aInIID,
|
|
|
|
uint32_t aInCount, void* aInValue,
|
|
|
|
uint16_t* aOutType, nsIID* aOutIID,
|
|
|
|
uint32_t* aOutCount, void** aOutValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_ASSERTION(aInCount, "bad param");
|
|
|
|
NS_ASSERTION(aInValue, "bad param");
|
|
|
|
NS_ASSERTION(aOutType, "bad param");
|
|
|
|
NS_ASSERTION(aOutCount, "bad param");
|
|
|
|
NS_ASSERTION(aOutValue, "bad param");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
uint32_t allocatedValueCount = 0;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
uint32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
// First we figure out the size of the elements for the new u.array.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
size_t elementSize;
|
|
|
|
size_t allocSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aInType) {
|
|
|
|
case nsIDataType::VTYPE_INT8:
|
|
|
|
elementSize = sizeof(int8_t);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_INT16:
|
|
|
|
elementSize = sizeof(int16_t);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_INT32:
|
|
|
|
elementSize = sizeof(int32_t);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_INT64:
|
|
|
|
elementSize = sizeof(int64_t);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_UINT8:
|
|
|
|
elementSize = sizeof(uint8_t);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_UINT16:
|
|
|
|
elementSize = sizeof(uint16_t);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_UINT32:
|
|
|
|
elementSize = sizeof(uint32_t);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_UINT64:
|
|
|
|
elementSize = sizeof(uint64_t);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_FLOAT:
|
|
|
|
elementSize = sizeof(float);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_DOUBLE:
|
|
|
|
elementSize = sizeof(double);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_BOOL:
|
|
|
|
elementSize = sizeof(bool);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_CHAR:
|
|
|
|
elementSize = sizeof(char);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
|
|
|
elementSize = sizeof(char16_t);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
|
|
|
|
case nsIDataType::VTYPE_ID:
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
|
|
|
elementSize = sizeof(void*);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
// The rest are illegal.
|
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_VOID:
|
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad type in array!");
|
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
// Alloc the u.array.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
allocSize = aInCount * elementSize;
|
|
|
|
*aOutValue = nsMemory::Alloc(allocSize);
|
|
|
|
if (!*aOutValue) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
// Clone the elements.
|
|
|
|
|
|
|
|
switch (aInType) {
|
|
|
|
case nsIDataType::VTYPE_INT8:
|
|
|
|
case nsIDataType::VTYPE_INT16:
|
|
|
|
case nsIDataType::VTYPE_INT32:
|
|
|
|
case nsIDataType::VTYPE_INT64:
|
|
|
|
case nsIDataType::VTYPE_UINT8:
|
|
|
|
case nsIDataType::VTYPE_UINT16:
|
|
|
|
case nsIDataType::VTYPE_UINT32:
|
|
|
|
case nsIDataType::VTYPE_UINT64:
|
|
|
|
case nsIDataType::VTYPE_FLOAT:
|
|
|
|
case nsIDataType::VTYPE_DOUBLE:
|
|
|
|
case nsIDataType::VTYPE_BOOL:
|
|
|
|
case nsIDataType::VTYPE_CHAR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
|
|
|
memcpy(*aOutValue, aInValue, allocSize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
|
|
|
if (aOutIID) {
|
|
|
|
*aOutIID = *aInIID;
|
|
|
|
}
|
|
|
|
// fall through...
|
|
|
|
case nsIDataType::VTYPE_INTERFACE: {
|
|
|
|
memcpy(*aOutValue, aInValue, allocSize);
|
|
|
|
|
|
|
|
nsISupports** p = (nsISupports**)*aOutValue;
|
|
|
|
for (i = aInCount; i > 0; ++p, --i)
|
|
|
|
if (*p) {
|
|
|
|
(*p)->AddRef();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
|
|
|
|
case nsIDataType::VTYPE_ID: {
|
|
|
|
nsID** inp = (nsID**)aInValue;
|
|
|
|
nsID** outp = (nsID**)*aOutValue;
|
|
|
|
for (i = aInCount; i > 0; --i) {
|
|
|
|
nsID* idp = *(inp++);
|
|
|
|
if (idp) {
|
|
|
|
if (!(*(outp++) = (nsID*)nsMemory::Clone((char*)idp, sizeof(nsID)))) {
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*(outp++) = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
allocatedValueCount++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_CHAR_STR: {
|
|
|
|
char** inp = (char**)aInValue;
|
|
|
|
char** outp = (char**)*aOutValue;
|
|
|
|
for (i = aInCount; i > 0; i--) {
|
|
|
|
char* str = *(inp++);
|
|
|
|
if (str) {
|
|
|
|
if (!(*(outp++) = (char*)nsMemory::Clone(
|
|
|
|
str, (strlen(str) + 1) * sizeof(char)))) {
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*(outp++) = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
allocatedValueCount++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_WCHAR_STR: {
|
|
|
|
char16_t** inp = (char16_t**)aInValue;
|
|
|
|
char16_t** outp = (char16_t**)*aOutValue;
|
|
|
|
for (i = aInCount; i > 0; i--) {
|
|
|
|
char16_t* str = *(inp++);
|
|
|
|
if (str) {
|
|
|
|
if (!(*(outp++) = (char16_t*)nsMemory::Clone(
|
|
|
|
str, (NS_strlen(str) + 1) * sizeof(char16_t)))) {
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*(outp++) = nullptr;
|
|
|
|
}
|
|
|
|
allocatedValueCount++;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
// The rest are illegal.
|
|
|
|
case nsIDataType::VTYPE_VOID:
|
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad type in array!");
|
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aOutType = aInType;
|
|
|
|
*aOutCount = aInCount;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
bad:
|
2014-07-09 08:15:21 -07:00
|
|
|
if (*aOutValue) {
|
|
|
|
char** p = (char**)*aOutValue;
|
|
|
|
for (i = allocatedValueCount; i > 0; ++p, --i)
|
|
|
|
if (*p) {
|
|
|
|
nsMemory::Free(*p);
|
|
|
|
}
|
|
|
|
nsMemory::Free((char*)*aOutValue);
|
|
|
|
*aOutValue = nullptr;
|
|
|
|
}
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
#define TRIVIAL_DATA_CONVERTER(type_, data_, member_, retval_) \
|
|
|
|
if(data_.mType == nsIDataType :: type_) { \
|
|
|
|
*retval_ = data_.u.member_; \
|
|
|
|
return NS_OK; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_) \
|
|
|
|
/* static */ nsresult \
|
|
|
|
nsVariant::ConvertTo##name_ (const nsDiscriminatedUnion& data, \
|
|
|
|
Ctype_ *_retval) \
|
|
|
|
{ \
|
|
|
|
TRIVIAL_DATA_CONVERTER(type_, data, m##name_##Value, _retval) \
|
|
|
|
nsDiscriminatedUnion tempData; \
|
|
|
|
nsVariant::Initialize(&tempData); \
|
|
|
|
nsresult rv = ToManageableNumber(data, &tempData); \
|
|
|
|
/* */ \
|
|
|
|
/* NOTE: rv may indicate a success code that we want to preserve */ \
|
|
|
|
/* For the final return. So all the return cases below should return */ \
|
|
|
|
/* this rv when indicating success. */ \
|
|
|
|
/* */ \
|
|
|
|
if(NS_FAILED(rv)) \
|
|
|
|
return rv; \
|
|
|
|
switch(tempData.mType) \
|
|
|
|
{
|
|
|
|
|
|
|
|
#define CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(Ctype_) \
|
|
|
|
case nsIDataType::VTYPE_INT32: \
|
|
|
|
*_retval = ( Ctype_ ) tempData.u.mInt32Value; \
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
#define CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(Ctype_, min_, max_) \
|
|
|
|
case nsIDataType::VTYPE_INT32: \
|
|
|
|
{ \
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t value = tempData.u.mInt32Value; \
|
2007-03-22 10:30:00 -07:00
|
|
|
if(value < min_ || value > max_) \
|
|
|
|
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; \
|
|
|
|
*_retval = ( Ctype_ ) value; \
|
|
|
|
return rv; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(Ctype_) \
|
|
|
|
case nsIDataType::VTYPE_UINT32: \
|
|
|
|
*_retval = ( Ctype_ ) tempData.u.mUint32Value; \
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
#define CASE__NUMERIC_CONVERSION_UINT32_MAX(Ctype_, max_) \
|
|
|
|
case nsIDataType::VTYPE_UINT32: \
|
|
|
|
{ \
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t value = tempData.u.mUint32Value; \
|
2007-03-22 10:30:00 -07:00
|
|
|
if(value > max_) \
|
|
|
|
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; \
|
|
|
|
*_retval = ( Ctype_ ) value; \
|
|
|
|
return rv; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST(Ctype_) \
|
|
|
|
case nsIDataType::VTYPE_DOUBLE: \
|
|
|
|
*_retval = ( Ctype_ ) tempData.u.mDoubleValue; \
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
#define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX(Ctype_, min_, max_) \
|
|
|
|
case nsIDataType::VTYPE_DOUBLE: \
|
|
|
|
{ \
|
|
|
|
double value = tempData.u.mDoubleValue; \
|
|
|
|
if(value < min_ || value > max_) \
|
|
|
|
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; \
|
|
|
|
*_retval = ( Ctype_ ) value; \
|
|
|
|
return rv; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(Ctype_, min_, max_) \
|
|
|
|
case nsIDataType::VTYPE_DOUBLE: \
|
|
|
|
{ \
|
|
|
|
double value = tempData.u.mDoubleValue; \
|
|
|
|
if(value < min_ || value > max_) \
|
|
|
|
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; \
|
|
|
|
*_retval = ( Ctype_ ) value; \
|
|
|
|
return (0.0 == fmod(value,1.0)) ? \
|
|
|
|
rv : NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CASES__NUMERIC_CONVERSION_NORMAL(Ctype_, min_, max_) \
|
|
|
|
CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(Ctype_, min_, max_) \
|
|
|
|
CASE__NUMERIC_CONVERSION_UINT32_MAX(Ctype_, max_) \
|
|
|
|
CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(Ctype_, min_, max_)
|
|
|
|
|
|
|
|
#define NUMERIC_CONVERSION_METHOD_END \
|
|
|
|
default: \
|
|
|
|
NS_ERROR("bad type returned from ToManageableNumber"); \
|
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NUMERIC_CONVERSION_METHOD_NORMAL(type_, Ctype_, name_, min_, max_) \
|
|
|
|
NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_) \
|
|
|
|
CASES__NUMERIC_CONVERSION_NORMAL(Ctype_, min_, max_) \
|
|
|
|
NUMERIC_CONVERSION_METHOD_END
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// These expand into full public methods...
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_NORMAL(VTYPE_INT8, uint8_t, Int8, (-127 - 1), 127)
|
|
|
|
NUMERIC_CONVERSION_METHOD_NORMAL(VTYPE_INT16, int16_t, Int16, (-32767 - 1), 32767)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_INT32, int32_t, Int32)
|
2014-07-09 08:15:21 -07:00
|
|
|
CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(int32_t)
|
|
|
|
CASE__NUMERIC_CONVERSION_UINT32_MAX(int32_t, 2147483647)
|
|
|
|
CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(int32_t, (-2147483647 - 1), 2147483647)
|
2007-03-22 10:30:00 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_END
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_NORMAL(VTYPE_UINT8, uint8_t, Uint8, 0, 255)
|
|
|
|
NUMERIC_CONVERSION_METHOD_NORMAL(VTYPE_UINT16, uint16_t, Uint16, 0, 65535)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_UINT32, uint32_t, Uint32)
|
2014-07-09 08:15:21 -07:00
|
|
|
CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(uint32_t, 0, 2147483647)
|
|
|
|
CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(uint32_t)
|
|
|
|
CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(uint32_t, 0, 4294967295U)
|
2007-03-22 10:30:00 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_END
|
|
|
|
|
|
|
|
// XXX toFloat convertions need to be fixed!
|
|
|
|
NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_FLOAT, float, Float)
|
2014-07-09 08:15:21 -07:00
|
|
|
CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(float)
|
|
|
|
CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(float)
|
|
|
|
CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST(float)
|
2007-03-22 10:30:00 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_END
|
|
|
|
|
|
|
|
NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_DOUBLE, double, Double)
|
2014-07-09 08:15:21 -07:00
|
|
|
CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(double)
|
|
|
|
CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(double)
|
|
|
|
CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST(double)
|
2007-03-22 10:30:00 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_END
|
|
|
|
|
|
|
|
// XXX toChar convertions need to be fixed!
|
|
|
|
NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_CHAR, char, Char)
|
2014-07-09 08:15:21 -07:00
|
|
|
CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(char)
|
|
|
|
CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(char)
|
|
|
|
CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST(char)
|
2007-03-22 10:30:00 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_END
|
|
|
|
|
|
|
|
// XXX toWChar convertions need to be fixed!
|
2014-01-04 07:02:17 -08:00
|
|
|
NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_WCHAR, char16_t, WChar)
|
2014-07-09 08:15:21 -07:00
|
|
|
CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(char16_t)
|
|
|
|
CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(char16_t)
|
|
|
|
CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST(char16_t)
|
2007-03-22 10:30:00 -07:00
|
|
|
NUMERIC_CONVERSION_METHOD_END
|
|
|
|
|
|
|
|
#undef NUMERIC_CONVERSION_METHOD_BEGIN
|
|
|
|
#undef CASE__NUMERIC_CONVERSION_INT32_JUST_CAST
|
|
|
|
#undef CASE__NUMERIC_CONVERSION_INT32_MIN_MAX
|
|
|
|
#undef CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST
|
|
|
|
#undef CASE__NUMERIC_CONVERSION_UINT32_MIN_MAX
|
|
|
|
#undef CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST
|
|
|
|
#undef CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX
|
|
|
|
#undef CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT
|
|
|
|
#undef CASES__NUMERIC_CONVERSION_NORMAL
|
|
|
|
#undef NUMERIC_CONVERSION_METHOD_END
|
|
|
|
#undef NUMERIC_CONVERSION_METHOD_NORMAL
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
// Just leverage a numeric converter for bool (but restrict the values).
|
|
|
|
// XXX Is this really what we want to do?
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToBool(const nsDiscriminatedUnion& aData, bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
TRIVIAL_DATA_CONVERTER(VTYPE_BOOL, aData, mBoolValue, aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
double val;
|
|
|
|
nsresult rv = nsVariant::ConvertToDouble(aData, &val);
|
|
|
|
if (NS_FAILED(rv)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
2014-07-09 08:15:21 -07:00
|
|
|
}
|
|
|
|
*aResult = 0.0 != val;
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToInt64(const nsDiscriminatedUnion& aData, int64_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
TRIVIAL_DATA_CONVERTER(VTYPE_INT64, aData, mInt64Value, aResult)
|
|
|
|
TRIVIAL_DATA_CONVERTER(VTYPE_UINT64, aData, mUint64Value, aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
nsDiscriminatedUnion tempData;
|
|
|
|
nsVariant::Initialize(&tempData);
|
|
|
|
nsresult rv = ToManageableNumber(aData, &tempData);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
switch (tempData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_INT32:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aResult = tempData.u.mInt32Value;
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_UINT32:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aResult = tempData.u.mUint32Value;
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_DOUBLE:
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX should check for data loss here!
|
|
|
|
*aResult = tempData.u.mDoubleValue;
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_ERROR("bad type returned from ToManageableNumber");
|
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToUint64(const nsDiscriminatedUnion& aData,
|
|
|
|
uint64_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToInt64(aData, (int64_t*)aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
static bool
|
|
|
|
String2ID(const nsDiscriminatedUnion& aData, nsID* aPid)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
nsAutoString tempString;
|
|
|
|
nsAString* pString;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
return aPid->Parse(aData.u.str.mStringValue);
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
return aPid->Parse(PromiseFlatCString(*aData.u.mCStringValue).get());
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
return aPid->Parse(PromiseFlatUTF8String(*aData.u.mUTF8StringValue).get());
|
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
pString = aData.u.mAStringValue;
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
tempString.Assign(aData.u.wstr.mWStringValue);
|
|
|
|
pString = &tempString;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad type in call to String2ID");
|
|
|
|
return false;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
char* pChars = ToNewCString(*pString);
|
|
|
|
if (!pChars) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool result = aPid->Parse(pChars);
|
|
|
|
nsMemory::Free(pChars);
|
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToID(const nsDiscriminatedUnion& aData, nsID* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
nsID id;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_ID:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aResult = aData.u.mIDValue;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aResult = NS_GET_IID(nsISupports);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aResult = aData.u.iface.mInterfaceID;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!String2ID(aData, &id)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
2014-07-09 08:15:21 -07:00
|
|
|
}
|
|
|
|
*aResult = id;
|
|
|
|
return NS_OK;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
static nsresult
|
|
|
|
ToString(const nsDiscriminatedUnion& aData, nsACString& aOutString)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
char* ptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// all the stuff we don't handle...
|
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_ERROR("ToString being called for a string type - screwy logic!");
|
|
|
|
// fall through...
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX We might want stringified versions of these... ???
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_VOID:
|
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
2014-07-09 08:15:21 -07:00
|
|
|
aOutString.Truncate();
|
|
|
|
aOutString.SetIsVoid(true);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-12 09:24:14 -07:00
|
|
|
// nsID has its own text formatter.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
case nsIDataType::VTYPE_ID:
|
2014-07-09 08:15:21 -07:00
|
|
|
ptr = aData.u.mIDValue.ToString();
|
|
|
|
if (!ptr) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aOutString.Assign(ptr);
|
|
|
|
nsMemory::Free(ptr);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Can't use PR_smprintf for floats, since it's locale-dependent
|
|
|
|
#define CASE__APPENDFLOAT_NUMBER(type_, member_) \
|
|
|
|
case nsIDataType :: type_ : \
|
|
|
|
{ \
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString str; \
|
2014-07-09 08:15:21 -07:00
|
|
|
str.AppendFloat(aData.u. member_); \
|
|
|
|
aOutString.Assign(str); \
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK; \
|
|
|
|
}
|
|
|
|
|
|
|
|
CASE__APPENDFLOAT_NUMBER(VTYPE_FLOAT, mFloatValue)
|
|
|
|
CASE__APPENDFLOAT_NUMBER(VTYPE_DOUBLE, mDoubleValue)
|
|
|
|
|
|
|
|
#undef CASE__APPENDFLOAT_NUMBER
|
|
|
|
|
|
|
|
// the rest can be PR_smprintf'd and use common code.
|
|
|
|
|
|
|
|
#define CASE__SMPRINTF_NUMBER(type_, format_, cast_, member_) \
|
|
|
|
case nsIDataType :: type_ : \
|
2014-07-09 08:15:21 -07:00
|
|
|
ptr = PR_smprintf( format_ , (cast_) aData.u. member_ ); \
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_INT8, "%d", int, mInt8Value)
|
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_INT16, "%d", int, mInt16Value)
|
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_INT32, "%d", int, mInt32Value)
|
2012-08-22 08:56:38 -07:00
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_INT64, "%lld", int64_t, mInt64Value)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_UINT8, "%u", unsigned, mUint8Value)
|
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_UINT16, "%u", unsigned, mUint16Value)
|
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_UINT32, "%u", unsigned, mUint32Value)
|
2012-08-22 08:56:38 -07:00
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_UINT64, "%llu", int64_t, mUint64Value)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX Would we rather print "true" / "false" ?
|
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_BOOL, "%d", int, mBoolValue)
|
|
|
|
|
|
|
|
CASE__SMPRINTF_NUMBER(VTYPE_CHAR, "%c", char, mCharValue)
|
|
|
|
|
|
|
|
#undef CASE__SMPRINTF_NUMBER
|
2014-07-09 08:15:21 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!ptr) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aOutString.Assign(ptr);
|
|
|
|
PR_smprintf_free(ptr);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToAString(const nsDiscriminatedUnion& aData,
|
|
|
|
nsAString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
aResult.Assign(*aData.u.mAStringValue);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
CopyASCIItoUTF16(*aData.u.mCStringValue, aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
CopyUTF8toUTF16(*aData.u.mUTF8StringValue, aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
2014-07-09 08:15:21 -07:00
|
|
|
CopyASCIItoUTF16(aData.u.str.mStringValue, aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
2014-07-09 08:15:21 -07:00
|
|
|
aResult.Assign(aData.u.wstr.mWStringValue);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
CopyASCIItoUTF16(nsDependentCString(aData.u.str.mStringValue,
|
|
|
|
aData.u.str.mStringLength),
|
|
|
|
aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
aResult.Assign(aData.u.wstr.mWStringValue, aData.u.wstr.mWStringLength);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
2014-07-09 08:15:21 -07:00
|
|
|
aResult.Assign(aData.u.mWCharValue);
|
|
|
|
return NS_OK;
|
|
|
|
default: {
|
|
|
|
nsAutoCString tempCString;
|
|
|
|
nsresult rv = ToString(aData, tempCString);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
CopyASCIItoUTF16(tempCString, aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToACString(const nsDiscriminatedUnion& aData,
|
|
|
|
nsACString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
LossyCopyUTF16toASCII(*aData.u.mAStringValue, aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
aResult.Assign(*aData.u.mCStringValue);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX This is an extra copy that should be avoided
|
|
|
|
// once Jag lands support for UTF8String and associated
|
|
|
|
// conversion methods.
|
|
|
|
LossyCopyUTF16toASCII(NS_ConvertUTF8toUTF16(*aData.u.mUTF8StringValue),
|
|
|
|
aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
2014-07-09 08:15:21 -07:00
|
|
|
aResult.Assign(*aData.u.str.mStringValue);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
2014-07-09 08:15:21 -07:00
|
|
|
LossyCopyUTF16toASCII(nsDependentString(aData.u.wstr.mWStringValue),
|
|
|
|
aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
aResult.Assign(aData.u.str.mStringValue, aData.u.str.mStringLength);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
LossyCopyUTF16toASCII(nsDependentString(aData.u.wstr.mWStringValue,
|
|
|
|
aData.u.wstr.mWStringLength),
|
|
|
|
aResult);
|
|
|
|
return NS_OK;
|
|
|
|
case nsIDataType::VTYPE_WCHAR: {
|
|
|
|
const char16_t* str = &aData.u.mWCharValue;
|
|
|
|
LossyCopyUTF16toASCII(Substring(str, 1), aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
return ToString(aData, aResult);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToAUTF8String(const nsDiscriminatedUnion& aData,
|
|
|
|
nsAUTF8String& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
CopyUTF16toUTF8(*aData.u.mAStringValue, aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX Extra copy, can be removed if we're sure CSTRING can
|
|
|
|
// only contain ASCII.
|
|
|
|
CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(*aData.u.mCStringValue),
|
|
|
|
aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
aResult.Assign(*aData.u.mUTF8StringValue);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX Extra copy, can be removed if we're sure CHAR_STR can
|
|
|
|
// only contain ASCII.
|
|
|
|
CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(aData.u.str.mStringValue),
|
|
|
|
aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
2014-07-09 08:15:21 -07:00
|
|
|
CopyUTF16toUTF8(aData.u.wstr.mWStringValue, aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX Extra copy, can be removed if we're sure CHAR_STR can
|
|
|
|
// only contain ASCII.
|
|
|
|
CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(
|
|
|
|
nsDependentCString(aData.u.str.mStringValue,
|
|
|
|
aData.u.str.mStringLength)), aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
CopyUTF16toUTF8(nsDependentString(aData.u.wstr.mWStringValue,
|
|
|
|
aData.u.wstr.mWStringLength),
|
|
|
|
aResult);
|
|
|
|
return NS_OK;
|
|
|
|
case nsIDataType::VTYPE_WCHAR: {
|
|
|
|
const char16_t* str = &aData.u.mWCharValue;
|
|
|
|
CopyUTF16toUTF8(Substring(str, 1), aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
default: {
|
|
|
|
nsAutoCString tempCString;
|
|
|
|
nsresult rv = ToString(aData, tempCString);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
// XXX Extra copy, can be removed if we're sure tempCString can
|
|
|
|
// only contain ASCII.
|
|
|
|
CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(tempCString), aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToString(const nsDiscriminatedUnion& aData, char** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
uint32_t ignored;
|
|
|
|
return nsVariant::ConvertToStringWithSize(aData, &ignored, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToWString(const nsDiscriminatedUnion& aData,
|
|
|
|
char16_t** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
uint32_t ignored;
|
|
|
|
return nsVariant::ConvertToWStringWithSize(aData, &ignored, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToStringWithSize(const nsDiscriminatedUnion& aData,
|
|
|
|
uint32_t* aSize, char** aStr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
nsAutoString tempString;
|
|
|
|
nsAutoCString tempCString;
|
|
|
|
nsresult rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aSize = aData.u.mAStringValue->Length();
|
|
|
|
*aStr = ToNewCString(*aData.u.mAStringValue);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aSize = aData.u.mCStringValue->Length();
|
|
|
|
*aStr = ToNewCString(*aData.u.mCStringValue);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING: {
|
|
|
|
// XXX This is doing 1 extra copy. Need to fix this
|
|
|
|
// when Jag lands UTF8String
|
|
|
|
// we want:
|
|
|
|
// *aSize = *aData.mUTF8StringValue->Length();
|
|
|
|
// *aStr = ToNewCString(*aData.mUTF8StringValue);
|
|
|
|
// But this will have to do for now.
|
|
|
|
NS_ConvertUTF8toUTF16 tempString(*aData.u.mUTF8StringValue);
|
|
|
|
*aSize = tempString.Length();
|
|
|
|
*aStr = ToNewCString(tempString);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_CHAR_STR: {
|
|
|
|
nsDependentCString cString(aData.u.str.mStringValue);
|
|
|
|
*aSize = cString.Length();
|
|
|
|
*aStr = ToNewCString(cString);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_WCHAR_STR: {
|
|
|
|
nsDependentString string(aData.u.wstr.mWStringValue);
|
|
|
|
*aSize = string.Length();
|
|
|
|
*aStr = ToNewCString(string);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS: {
|
|
|
|
nsDependentCString cString(aData.u.str.mStringValue,
|
|
|
|
aData.u.str.mStringLength);
|
|
|
|
*aSize = cString.Length();
|
|
|
|
*aStr = ToNewCString(cString);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS: {
|
|
|
|
nsDependentString string(aData.u.wstr.mWStringValue,
|
|
|
|
aData.u.wstr.mWStringLength);
|
|
|
|
*aSize = string.Length();
|
|
|
|
*aStr = ToNewCString(string);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
2014-07-09 08:15:21 -07:00
|
|
|
tempString.Assign(aData.u.mWCharValue);
|
|
|
|
*aSize = tempString.Length();
|
|
|
|
*aStr = ToNewCString(tempString);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = ToString(aData, tempCString);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*aSize = tempCString.Length();
|
|
|
|
*aStr = ToNewCString(tempCString);
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
return *aStr ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToWStringWithSize(const nsDiscriminatedUnion& aData,
|
|
|
|
uint32_t* aSize, char16_t** aStr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
nsAutoString tempString;
|
|
|
|
nsAutoCString tempCString;
|
|
|
|
nsresult rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aSize = aData.u.mAStringValue->Length();
|
|
|
|
*aStr = ToNewUnicode(*aData.u.mAStringValue);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
2014-07-09 08:15:21 -07:00
|
|
|
*aSize = aData.u.mCStringValue->Length();
|
|
|
|
*aStr = ToNewUnicode(*aData.u.mCStringValue);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING: {
|
|
|
|
*aStr = UTF8ToNewUnicode(*aData.u.mUTF8StringValue, aSize);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_CHAR_STR: {
|
|
|
|
nsDependentCString cString(aData.u.str.mStringValue);
|
|
|
|
*aSize = cString.Length();
|
|
|
|
*aStr = ToNewUnicode(cString);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_WCHAR_STR: {
|
|
|
|
nsDependentString string(aData.u.wstr.mWStringValue);
|
|
|
|
*aSize = string.Length();
|
|
|
|
*aStr = ToNewUnicode(string);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS: {
|
|
|
|
nsDependentCString cString(aData.u.str.mStringValue,
|
|
|
|
aData.u.str.mStringLength);
|
|
|
|
*aSize = cString.Length();
|
|
|
|
*aStr = ToNewUnicode(cString);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS: {
|
|
|
|
nsDependentString string(aData.u.wstr.mWStringValue,
|
|
|
|
aData.u.wstr.mWStringLength);
|
|
|
|
*aSize = string.Length();
|
|
|
|
*aStr = ToNewUnicode(string);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
2014-07-09 08:15:21 -07:00
|
|
|
tempString.Assign(aData.u.mWCharValue);
|
|
|
|
*aSize = tempString.Length();
|
|
|
|
*aStr = ToNewUnicode(tempString);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = ToString(aData, tempCString);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*aSize = tempCString.Length();
|
|
|
|
*aStr = ToNewUnicode(tempCString);
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
return *aStr ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToISupports(const nsDiscriminatedUnion& aData,
|
|
|
|
nsISupports** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
if (aData.u.iface.mInterfaceValue) {
|
|
|
|
return aData.u.iface.mInterfaceValue->
|
|
|
|
QueryInterface(NS_GET_IID(nsISupports), (void**)aResult);
|
|
|
|
} else {
|
|
|
|
*aResult = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToInterface(const nsDiscriminatedUnion& aData, nsIID** aIID,
|
|
|
|
void** aInterface)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
const nsIID* piid;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
2014-07-09 08:15:21 -07:00
|
|
|
piid = &NS_GET_IID(nsISupports);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
2014-07-09 08:15:21 -07:00
|
|
|
piid = &aData.u.iface.mInterfaceID;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
*aIID = (nsIID*)nsMemory::Clone(piid, sizeof(nsIID));
|
|
|
|
if (!*aIID) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
if (aData.u.iface.mInterfaceValue) {
|
|
|
|
return aData.u.iface.mInterfaceValue->QueryInterface(*piid,
|
|
|
|
aInterface);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
*aInterface = nullptr;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::ConvertToArray(const nsDiscriminatedUnion& aData, uint16_t* aType,
|
|
|
|
nsIID* aIID, uint32_t* aCount, void** aPtr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
// XXX perhaps we'd like to add support for converting each of the various
|
|
|
|
// types into an array containing one element of that type. We can leverage
|
|
|
|
// CloneArray to do this if we want to support this.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
if (aData.mType == nsIDataType::VTYPE_ARRAY) {
|
|
|
|
return CloneArray(aData.u.array.mArrayType, &aData.u.array.mArrayInterfaceID,
|
|
|
|
aData.u.array.mArrayCount, aData.u.array.mArrayValue,
|
|
|
|
aType, aIID, aCount, aPtr);
|
|
|
|
}
|
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// static setter functions...
|
|
|
|
|
|
|
|
#define DATA_SETTER_PROLOGUE(data_) \
|
|
|
|
nsVariant::Cleanup(data_);
|
|
|
|
|
|
|
|
#define DATA_SETTER_EPILOGUE(data_, type_) \
|
|
|
|
data_->mType = nsIDataType :: type_; \
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
#define DATA_SETTER(data_, type_, member_, value_) \
|
|
|
|
DATA_SETTER_PROLOGUE(data_) \
|
|
|
|
data_->u.member_ = value_; \
|
|
|
|
DATA_SETTER_EPILOGUE(data_, type_)
|
|
|
|
|
|
|
|
#define DATA_SETTER_WITH_CAST(data_, type_, member_, cast_, value_) \
|
|
|
|
DATA_SETTER_PROLOGUE(data_) \
|
|
|
|
data_->u.member_ = cast_ value_; \
|
|
|
|
DATA_SETTER_EPILOGUE(data_, type_)
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************/
|
|
|
|
|
|
|
|
#define CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_) \
|
|
|
|
{ \
|
|
|
|
|
|
|
|
#define CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_) \
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = aValue->GetAs##name_ (&(aData->u. member_ ));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_) \
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = aValue->GetAs##name_ ( cast_ &(aData->u. member_ ));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_) \
|
|
|
|
if(NS_SUCCEEDED(rv)) \
|
|
|
|
{ \
|
2014-07-09 08:15:21 -07:00
|
|
|
aData->mType = nsIDataType :: type_ ; \
|
2007-03-22 10:30:00 -07:00
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CASE__SET_FROM_VARIANT_TYPE(type_, member_, name_) \
|
|
|
|
case nsIDataType :: type_ : \
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_) \
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_) \
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
|
|
|
|
|
|
|
|
#define CASE__SET_FROM_VARIANT_VTYPE_CAST(type_, cast_, member_, name_) \
|
|
|
|
case nsIDataType :: type_ : \
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_) \
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_) \
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
|
|
|
|
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromVariant(nsDiscriminatedUnion* aData, nsIVariant* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
uint16_t type;
|
|
|
|
nsresult rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::Cleanup(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
rv = aValue->GetDataType(&type);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_CAST(VTYPE_INT8, (uint8_t*), mInt8Value,
|
|
|
|
Int8)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_INT16, mInt16Value, Int16)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_INT32, mInt32Value, Int32)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_UINT8, mUint8Value, Uint8)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_UINT16, mUint16Value, Uint16)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_UINT32, mUint32Value, Uint32)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_FLOAT, mFloatValue, Float)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_DOUBLE, mDoubleValue, Double)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_BOOL , mBoolValue, Bool)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_CHAR, mCharValue, Char)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_WCHAR, mWCharValue, WChar)
|
|
|
|
CASE__SET_FROM_VARIANT_TYPE(VTYPE_ID, mIDValue, ID)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_ASTRING);
|
|
|
|
aData->u.mAStringValue = new nsString();
|
|
|
|
if (!aData->u.mAStringValue) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
rv = aValue->GetAsAString(*aData->u.mAStringValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete aData->u.mAStringValue;
|
|
|
|
}
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_ASTRING)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_CSTRING);
|
|
|
|
aData->u.mCStringValue = new nsCString();
|
|
|
|
if (!aData->u.mCStringValue) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
rv = aValue->GetAsACString(*aData->u.mCStringValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete aData->u.mCStringValue;
|
|
|
|
}
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_CSTRING)
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_UTF8STRING);
|
|
|
|
aData->u.mUTF8StringValue = new nsUTF8String();
|
|
|
|
if (!aData->u.mUTF8StringValue) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
rv = aValue->GetAsAUTF8String(*aData->u.mUTF8StringValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete aData->u.mUTF8StringValue;
|
|
|
|
}
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_UTF8STRING)
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_STRING_SIZE_IS);
|
|
|
|
rv = aValue->GetAsStringWithSize(&aData->u.str.mStringLength,
|
|
|
|
&aData->u.str.mStringValue);
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_STRING_SIZE_IS)
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_INTERFACE_IS);
|
|
|
|
// XXX This iid handling is ugly!
|
|
|
|
nsIID* iid;
|
|
|
|
rv = aValue->GetAsInterface(&iid, (void**)&aData->u.iface.mInterfaceValue);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aData->u.iface.mInterfaceID = *iid;
|
|
|
|
nsMemory::Free((char*)iid);
|
|
|
|
}
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_INTERFACE_IS)
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_ARRAY);
|
|
|
|
rv = aValue->GetAsArray(&aData->u.array.mArrayType,
|
|
|
|
&aData->u.array.mArrayInterfaceID,
|
|
|
|
&aData->u.array.mArrayCount,
|
|
|
|
&aData->u.array.mArrayValue);
|
|
|
|
CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_ARRAY)
|
|
|
|
|
|
|
|
case nsIDataType::VTYPE_VOID:
|
|
|
|
rv = nsVariant::SetToVoid(aData);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
|
|
|
rv = nsVariant::SetToEmptyArray(aData);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
|
|
|
rv = nsVariant::SetToEmpty(aData);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad type in variant!");
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromInt8(nsDiscriminatedUnion* aData, uint8_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_WITH_CAST(aData, VTYPE_INT8, mInt8Value, (uint8_t), aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromInt16(nsDiscriminatedUnion* aData, int16_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_INT16, mInt16Value, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromInt32(nsDiscriminatedUnion* aData, int32_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_INT32, mInt32Value, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromInt64(nsDiscriminatedUnion* aData, int64_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_INT64, mInt64Value, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromUint8(nsDiscriminatedUnion* aData, uint8_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_UINT8, mUint8Value, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromUint16(nsDiscriminatedUnion* aData, uint16_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_UINT16, mUint16Value, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromUint32(nsDiscriminatedUnion* aData, uint32_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_UINT32, mUint32Value, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromUint64(nsDiscriminatedUnion* aData, uint64_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_UINT64, mUint64Value, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromFloat(nsDiscriminatedUnion* aData, float aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_FLOAT, mFloatValue, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromDouble(nsDiscriminatedUnion* aData, double aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_DOUBLE, mDoubleValue, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromBool(nsDiscriminatedUnion* aData, bool aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_BOOL, mBoolValue, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromChar(nsDiscriminatedUnion* aData, char aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_CHAR, mCharValue, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromWChar(nsDiscriminatedUnion* aData, char16_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_WCHAR, mWCharValue, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromID(nsDiscriminatedUnion* aData, const nsID& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER(aData, VTYPE_ID, mIDValue, aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromAString(nsDiscriminatedUnion* aData, const nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!(aData->u.mAStringValue = new nsString(aValue))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_ASTRING);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromACString(nsDiscriminatedUnion* aData,
|
|
|
|
const nsACString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!(aData->u.mCStringValue = new nsCString(aValue))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_CSTRING);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromAUTF8String(nsDiscriminatedUnion* aData,
|
|
|
|
const nsAUTF8String& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!(aData->u.mUTF8StringValue = new nsUTF8String(aValue))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_UTF8STRING);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromString(nsDiscriminatedUnion* aData, const char* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!aValue) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
return SetFromStringWithSize(aData, strlen(aValue), aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromWString(nsDiscriminatedUnion* aData, const char16_t* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!aValue) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
return SetFromWStringWithSize(aData, NS_strlen(aValue), aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromISupports(nsDiscriminatedUnion* aData, nsISupports* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return SetFromInterface(aData, NS_GET_IID(nsISupports), aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromInterface(nsDiscriminatedUnion* aData, const nsIID& aIID,
|
|
|
|
nsISupports* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
NS_IF_ADDREF(aValue);
|
|
|
|
aData->u.iface.mInterfaceValue = aValue;
|
|
|
|
aData->u.iface.mInterfaceID = aIID;
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_INTERFACE_IS);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromArray(nsDiscriminatedUnion* aData, uint16_t aType,
|
|
|
|
const nsIID* aIID, uint32_t aCount, void* aValue)
|
|
|
|
{
|
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!aValue || !aCount) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = CloneArray(aType, aIID, aCount, aValue,
|
|
|
|
&aData->u.array.mArrayType,
|
|
|
|
&aData->u.array.mArrayInterfaceID,
|
|
|
|
&aData->u.array.mArrayCount,
|
|
|
|
&aData->u.array.mArrayValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_ARRAY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromStringWithSize(nsDiscriminatedUnion* aData, uint32_t aSize,
|
|
|
|
const char* aValue)
|
|
|
|
{
|
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!aValue) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (!(aData->u.str.mStringValue =
|
|
|
|
(char*)nsMemory::Clone(aValue, (aSize + 1) * sizeof(char)))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aData->u.str.mStringLength = aSize;
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_STRING_SIZE_IS);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetFromWStringWithSize(nsDiscriminatedUnion* aData, uint32_t aSize,
|
|
|
|
const char16_t* aValue)
|
|
|
|
{
|
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!aValue) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (!(aData->u.wstr.mWStringValue =
|
|
|
|
(char16_t*)nsMemory::Clone(aValue, (aSize + 1) * sizeof(char16_t)))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aData->u.wstr.mWStringLength = aSize;
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_WSTRING_SIZE_IS);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-11 00:38:55 -07:00
|
|
|
nsVariant::AllocateWStringWithSize(nsDiscriminatedUnion* aData, uint32_t aSize)
|
|
|
|
{
|
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
if (!(aData->u.wstr.mWStringValue =
|
|
|
|
(char16_t*)NS_Alloc((aSize + 1) * sizeof(char16_t)))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aData->u.wstr.mWStringValue[aSize] = '\0';
|
|
|
|
aData->u.wstr.mWStringLength = aSize;
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_WSTRING_SIZE_IS);
|
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetToVoid(nsDiscriminatedUnion* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_VOID);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetToEmpty(nsDiscriminatedUnion* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_EMPTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::SetToEmptyArray(nsDiscriminatedUnion* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE(aData);
|
|
|
|
DATA_SETTER_EPILOGUE(aData, VTYPE_EMPTY_ARRAY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::Initialize(nsDiscriminatedUnion* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
aData->mType = nsIDataType::VTYPE_EMPTY;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::Cleanup(nsDiscriminatedUnion* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData->mType) {
|
|
|
|
case nsIDataType::VTYPE_INT8:
|
|
|
|
case nsIDataType::VTYPE_INT16:
|
|
|
|
case nsIDataType::VTYPE_INT32:
|
|
|
|
case nsIDataType::VTYPE_INT64:
|
|
|
|
case nsIDataType::VTYPE_UINT8:
|
|
|
|
case nsIDataType::VTYPE_UINT16:
|
|
|
|
case nsIDataType::VTYPE_UINT32:
|
|
|
|
case nsIDataType::VTYPE_UINT64:
|
|
|
|
case nsIDataType::VTYPE_FLOAT:
|
|
|
|
case nsIDataType::VTYPE_DOUBLE:
|
|
|
|
case nsIDataType::VTYPE_BOOL:
|
|
|
|
case nsIDataType::VTYPE_CHAR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
|
|
|
case nsIDataType::VTYPE_VOID:
|
|
|
|
case nsIDataType::VTYPE_ID:
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
delete aData->u.mAStringValue;
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
delete aData->u.mCStringValue;
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
delete aData->u.mUTF8StringValue;
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
nsMemory::Free((char*)aData->u.str.mStringValue);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
nsMemory::Free((char*)aData->u.wstr.mWStringValue);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
|
|
|
NS_IF_RELEASE(aData->u.iface.mInterfaceValue);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
FreeArray(aData);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad type in variant!");
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
aData->mType = nsIDataType::VTYPE_EMPTY;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::Traverse(const nsDiscriminatedUnion& aData,
|
|
|
|
nsCycleCollectionTraversalCallback& aCb)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
switch (aData.mType) {
|
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mData");
|
|
|
|
aCb.NoteXPCOMChild(aData.u.iface.mInterfaceValue);
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
switch (aData.u.array.mArrayType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
2014-07-09 08:15:21 -07:00
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS: {
|
|
|
|
nsISupports** p = (nsISupports**)aData.u.array.mArrayValue;
|
|
|
|
for (uint32_t i = aData.u.array.mArrayCount; i > 0; ++p, --i) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mData[i]");
|
|
|
|
aCb.NoteXPCOMChild(*p);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2014-07-09 08:15:21 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
// members...
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsVariant, nsIVariant, nsIWritableVariant)
|
2008-02-21 12:39:20 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsVariant::nsVariant()
|
2014-07-09 08:15:21 -07:00
|
|
|
: mWritable(true)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::Initialize(&mData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-07-09 08:15:21 -07:00
|
|
|
{
|
|
|
|
// Assert that the nsIDataType consts match the values #defined in
|
|
|
|
// xpt_struct.h. Bad things happen somewhere if they don't.
|
|
|
|
struct THE_TYPES
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
uint16_t a;
|
|
|
|
uint16_t b;
|
|
|
|
};
|
|
|
|
static const THE_TYPES array[] = {
|
|
|
|
{nsIDataType::VTYPE_INT8 , TD_INT8 },
|
|
|
|
{nsIDataType::VTYPE_INT16 , TD_INT16 },
|
|
|
|
{nsIDataType::VTYPE_INT32 , TD_INT32 },
|
|
|
|
{nsIDataType::VTYPE_INT64 , TD_INT64 },
|
|
|
|
{nsIDataType::VTYPE_UINT8 , TD_UINT8 },
|
|
|
|
{nsIDataType::VTYPE_UINT16 , TD_UINT16 },
|
|
|
|
{nsIDataType::VTYPE_UINT32 , TD_UINT32 },
|
|
|
|
{nsIDataType::VTYPE_UINT64 , TD_UINT64 },
|
|
|
|
{nsIDataType::VTYPE_FLOAT , TD_FLOAT },
|
|
|
|
{nsIDataType::VTYPE_DOUBLE , TD_DOUBLE },
|
|
|
|
{nsIDataType::VTYPE_BOOL , TD_BOOL },
|
|
|
|
{nsIDataType::VTYPE_CHAR , TD_CHAR },
|
|
|
|
{nsIDataType::VTYPE_WCHAR , TD_WCHAR },
|
|
|
|
{nsIDataType::VTYPE_VOID , TD_VOID },
|
|
|
|
{nsIDataType::VTYPE_ID , TD_PNSIID },
|
|
|
|
{nsIDataType::VTYPE_DOMSTRING , TD_DOMSTRING },
|
|
|
|
{nsIDataType::VTYPE_CHAR_STR , TD_PSTRING },
|
|
|
|
{nsIDataType::VTYPE_WCHAR_STR , TD_PWSTRING },
|
|
|
|
{nsIDataType::VTYPE_INTERFACE , TD_INTERFACE_TYPE },
|
|
|
|
{nsIDataType::VTYPE_INTERFACE_IS , TD_INTERFACE_IS_TYPE},
|
|
|
|
{nsIDataType::VTYPE_ARRAY , TD_ARRAY },
|
|
|
|
{nsIDataType::VTYPE_STRING_SIZE_IS , TD_PSTRING_SIZE_IS },
|
|
|
|
{nsIDataType::VTYPE_WSTRING_SIZE_IS , TD_PWSTRING_SIZE_IS },
|
|
|
|
{nsIDataType::VTYPE_UTF8STRING , TD_UTF8STRING },
|
|
|
|
{nsIDataType::VTYPE_CSTRING , TD_CSTRING },
|
|
|
|
{nsIDataType::VTYPE_ASTRING , TD_ASTRING }
|
|
|
|
};
|
|
|
|
static const int length = sizeof(array) / sizeof(array[0]);
|
|
|
|
static bool inited = false;
|
|
|
|
if (!inited) {
|
|
|
|
for (int i = 0; i < length; ++i) {
|
|
|
|
NS_ASSERTION(array[i].a == array[i].b, "bad const declaration");
|
|
|
|
}
|
|
|
|
inited = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsVariant::~nsVariant()
|
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
nsVariant::Cleanup(&mData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// For all the data getters we just forward to the static (and sharable)
|
|
|
|
// 'ConvertTo' functions.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* readonly attribute uint16_t dataType; */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetDataType(uint16_t* aDataType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
*aDataType = mData.mType;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* uint8_t getAsInt8 (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsInt8(uint8_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToInt8(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* int16_t getAsInt16 (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsInt16(int16_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToInt16(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* int32_t getAsInt32 (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsInt32(int32_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToInt32(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* int64_t getAsInt64 (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsInt64(int64_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToInt64(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* uint8_t getAsUint8 (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsUint8(uint8_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToUint8(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* uint16_t getAsUint16 (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsUint16(uint16_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToUint16(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* uint32_t getAsUint32 (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsUint32(uint32_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToUint32(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* uint64_t getAsUint64 (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsUint64(uint64_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToUint64(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* float getAsFloat (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsFloat(float* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToFloat(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* double getAsDouble (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsDouble(double* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToDouble(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* bool getAsBool (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsBool(bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToBool(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* char getAsChar (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsChar(char* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToChar(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* wchar getAsWChar (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsWChar(char16_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToWChar(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [notxpcom] nsresult getAsID (out nsID retval); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP_(nsresult)
|
|
|
|
nsVariant::GetAsID(nsID* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToID(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* AString getAsAString (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsAString(nsAString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToAString(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DOMString getAsDOMString (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsDOMString(nsAString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
// A DOMString maps to an AString internally, so we can re-use
|
|
|
|
// ConvertToAString here.
|
|
|
|
return nsVariant::ConvertToAString(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ACString getAsACString (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsACString(nsACString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToACString(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* AUTF8String getAsAUTF8String (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsAUTF8String(nsAUTF8String& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToAUTF8String(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* string getAsString (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsString(char** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToString(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* wstring getAsWString (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsWString(char16_t** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToWString(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* nsISupports getAsISupports (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsISupports(nsISupports** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToISupports(mData, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-01 09:45:05 -07:00
|
|
|
/* jsval getAsJSVal() */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsJSVal(JS::MutableHandleValue)
|
2009-09-01 09:45:05 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
// Can only get the jsval from an XPCVariant.
|
|
|
|
return NS_ERROR_CANNOT_CONVERT_DATA;
|
2009-09-01 09:45:05 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* void getAsInterface (out nsIIDPtr iid, [iid_is (iid), retval] out nsQIResult iface); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsInterface(nsIID** aIID, void** aInterface)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToInterface(mData, aIID, aInterface);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* [notxpcom] nsresult getAsArray (out uint16_t type, out nsIID iid, out uint32_t count, out voidPtr ptr); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP_(nsresult)
|
|
|
|
nsVariant::GetAsArray(uint16_t* aType, nsIID* aIID,
|
|
|
|
uint32_t* aCount, void** aPtr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToArray(mData, aType, aIID, aCount, aPtr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void getAsStringWithSize (out uint32_t size, [size_is (size), retval] out string str); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsStringWithSize(uint32_t* aSize, char** aStr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToStringWithSize(mData, aSize, aStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void getAsWStringWithSize (out uint32_t size, [size_is (size), retval] out wstring str); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetAsWStringWithSize(uint32_t* aSize, char16_t** aStr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
return nsVariant::ConvertToWStringWithSize(mData, aSize, aStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* attribute bool writable; */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::GetWritable(bool* aWritable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
*aWritable = mWritable;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetWritable(bool aWritable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable && aWritable) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mWritable = aWritable;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
// For all the data setters we just forward to the static (and sharable)
|
|
|
|
// 'SetFrom' functions.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsInt8 (in uint8_t aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsInt8(uint8_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromInt8(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsInt16 (in int16_t aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsInt16(int16_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromInt16(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsInt32 (in int32_t aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsInt32(int32_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromInt32(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsInt64 (in int64_t aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsInt64(int64_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromInt64(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsUint8 (in uint8_t aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsUint8(uint8_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromUint8(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsUint16 (in uint16_t aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsUint16(uint16_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromUint16(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsUint32 (in uint32_t aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsUint32(uint32_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromUint32(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsUint64 (in uint64_t aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsUint64(uint64_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromUint64(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsFloat (in float aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsFloat(float aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromFloat(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsDouble (in double aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsDouble(double aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromDouble(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* void setAsBool (in bool aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsBool(bool aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromBool(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsChar (in char aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsChar(char aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromChar(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsWChar (in wchar aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsWChar(char16_t aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromWChar(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsID (in nsIDRef aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsID(const nsID& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromID(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsAString (in AString aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsAString(const nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromAString(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsDOMString (in DOMString aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsDOMString(const nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-09 08:15:21 -07:00
|
|
|
DATA_SETTER_PROLOGUE((&mData));
|
|
|
|
if (!(mData.u.mAStringValue = new nsString(aValue))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
DATA_SETTER_EPILOGUE((&mData), VTYPE_DOMSTRING);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsACString (in ACString aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsACString(const nsACString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromACString(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsAUTF8String (in AUTF8String aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsAUTF8String(const nsAUTF8String& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromAUTF8String(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsString (in string aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsString(const char* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromString(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsWString (in wstring aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsWString(const char16_t* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromWString(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsISupports (in nsISupports aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsISupports(nsISupports* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromISupports(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsInterface (in nsIIDRef iid, [iid_is (iid)] in nsQIResult iface); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsInterface(const nsIID& aIID, void* aInterface)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromInterface(&mData, aIID, (nsISupports*)aInterface);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* [noscript] void setAsArray (in uint16_t type, in nsIIDPtr iid, in uint32_t count, in voidPtr ptr); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsArray(uint16_t aType, const nsIID* aIID,
|
|
|
|
uint32_t aCount, void* aPtr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromArray(&mData, aType, aIID, aCount, aPtr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsStringWithSize (in uint32_t size, [size_is (size)] in string str); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsStringWithSize(uint32_t aSize, const char* aStr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromStringWithSize(&mData, aSize, aStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* void setAsWStringWithSize (in uint32_t size, [size_is (size)] in wstring str); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsWStringWithSize(uint32_t aSize, const char16_t* aStr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromWStringWithSize(&mData, aSize, aStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsVoid (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsVoid()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetToVoid(&mData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsEmpty (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsEmpty()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetToEmpty(&mData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setAsEmptyArray (); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetAsEmptyArray()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetToEmptyArray(&mData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setFromVariant (in nsIVariant aValue); */
|
2014-07-09 08:15:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVariant::SetFromVariant(nsIVariant* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-09 08:15:21 -07:00
|
|
|
if (!mWritable) {
|
|
|
|
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
|
|
|
}
|
|
|
|
return nsVariant::SetFromVariant(&mData, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|