зеркало из https://github.com/mozilla/pjs.git
NOT PART OF BUILD. bug 44675. bug 98209. New files
This commit is contained in:
Родитель
cb51588cc2
Коммит
9151e75d3c
|
@ -0,0 +1,453 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Bandhauer <jband@netscape.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
/* nsIVariant implementation for xpconnect. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS2(XPCVariant, XPCVariant, nsIVariant)
|
||||
|
||||
XPCVariant::XPCVariant()
|
||||
: mJSVal(JSVAL_VOID)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
nsVariant::Initialize(&mData);
|
||||
}
|
||||
|
||||
XPCVariant::~XPCVariant()
|
||||
{
|
||||
nsVariant::Cleanup(&mData);
|
||||
|
||||
if(JSVAL_IS_GCTHING(mJSVal))
|
||||
{
|
||||
JSRuntime* rt;
|
||||
nsIJSRuntimeService* rtsrvc = nsXPConnect::GetJSRuntimeService();
|
||||
|
||||
if(rtsrvc && NS_SUCCEEDED(rtsrvc->GetRuntime(&rt)))
|
||||
JS_RemoveRootRT(rt, &mJSVal);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
XPCVariant* XPCVariant::newVariant(XPCCallContext& ccx, jsval aJSVal)
|
||||
{
|
||||
XPCVariant* variant = new XPCVariant();
|
||||
if(!variant)
|
||||
return nsnull;
|
||||
|
||||
NS_ADDREF(variant);
|
||||
|
||||
variant->mJSVal = aJSVal;
|
||||
|
||||
if(JSVAL_IS_GCTHING(variant->mJSVal))
|
||||
{
|
||||
JSRuntime* rt;
|
||||
if(NS_FAILED(ccx.GetRuntime()->GetJSRuntimeService()->GetRuntime(&rt))||
|
||||
!JS_AddNamedRootRT(rt, &variant->mJSVal, "XPCVariant::mJSVal"))
|
||||
{
|
||||
NS_RELEASE(variant); // Also sets variant to nsnull.
|
||||
}
|
||||
}
|
||||
|
||||
if(variant && !variant->InitializeData(ccx))
|
||||
NS_RELEASE(variant); // Also sets variant to nsnull.
|
||||
|
||||
return variant;
|
||||
}
|
||||
|
||||
JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
|
||||
{
|
||||
if(JSVAL_IS_INT(mJSVal))
|
||||
return NS_SUCCEEDED(nsVariant::SetFromInt32(&mData,
|
||||
JSVAL_TO_INT(mJSVal)));
|
||||
if(JSVAL_IS_DOUBLE(mJSVal))
|
||||
return NS_SUCCEEDED(nsVariant::SetFromDouble(&mData,
|
||||
*JSVAL_TO_DOUBLE(mJSVal)));
|
||||
if(JSVAL_IS_BOOLEAN(mJSVal))
|
||||
return NS_SUCCEEDED(nsVariant::SetFromBool(&mData,
|
||||
JSVAL_TO_BOOLEAN(mJSVal)));
|
||||
if(JSVAL_IS_VOID(mJSVal))
|
||||
return NS_SUCCEEDED(nsVariant::SetToEmpty(&mData));
|
||||
if(JSVAL_IS_NULL(mJSVal))
|
||||
return NS_SUCCEEDED(nsVariant::SetToEmpty(&mData));
|
||||
if(JSVAL_IS_STRING(mJSVal))
|
||||
{
|
||||
return NS_SUCCEEDED(nsVariant::SetFromWStringWithSize(&mData,
|
||||
(PRUint32)JS_GetStringLength(JSVAL_TO_STRING(mJSVal)),
|
||||
(PRUnichar*)JS_GetStringChars(JSVAL_TO_STRING(mJSVal))));
|
||||
}
|
||||
|
||||
// leaving only JSObject...
|
||||
NS_ASSERTION(JSVAL_IS_OBJECT(mJSVal), "invalid type of jsval!");
|
||||
|
||||
// let's see if it is a xpcJSID
|
||||
|
||||
// XXX It might be nice to have a non-allocing version of xpc_JSObjectToID.
|
||||
nsID* id = xpc_JSObjectToID(ccx, JSVAL_TO_OBJECT(mJSVal));
|
||||
if(id)
|
||||
{
|
||||
JSBool success = NS_SUCCEEDED(nsVariant::SetFromID(&mData, *id));
|
||||
nsMemory::Free((char*)id);
|
||||
return success;
|
||||
}
|
||||
|
||||
// XXX This could be smarter and pick some more interesting iface.
|
||||
|
||||
nsXPConnect* xpc;
|
||||
nsCOMPtr<nsISupports> wrapper;
|
||||
const nsIID& iid = NS_GET_IID(nsISupports);
|
||||
|
||||
return nsnull != (xpc = nsXPConnect::GetXPConnect()) &&
|
||||
NS_SUCCEEDED(xpc->WrapJS(ccx, JSVAL_TO_OBJECT(mJSVal),
|
||||
iid, getter_AddRefs(wrapper))) &&
|
||||
NS_SUCCEEDED(nsVariant::SetFromInterface(&mData, iid, wrapper));
|
||||
}
|
||||
|
||||
// static
|
||||
JSBool
|
||||
XPCVariant::VariantDataToJS(XPCCallContext& ccx,
|
||||
nsIVariant* variant,
|
||||
JSObject* scope, nsresult* pErr,
|
||||
jsval* pJSVal)
|
||||
{
|
||||
// Get the type early because we might need to spoof it below.
|
||||
PRUint16 type;
|
||||
if(NS_FAILED(variant->GetDataType(&type)))
|
||||
return JS_FALSE;
|
||||
|
||||
nsCOMPtr<XPCVariant> xpcvariant = do_QueryInterface(variant);
|
||||
if(xpcvariant)
|
||||
{
|
||||
jsval realVal = xpcvariant->GetJSVal();
|
||||
if(JSVAL_IS_PRIMITIVE(realVal) || type == nsIDataType::TYPE_ID)
|
||||
{
|
||||
// Not a JSObject (or is a JSObject representing an nsID),.
|
||||
// So, just pass through the underlying data.
|
||||
*pJSVal = realVal;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
// XXX Need to deal with the Array case!
|
||||
|
||||
// else, it's an object and we really need to double wrap it if we've
|
||||
// already decided that its 'natural' type is as some sort of interface.
|
||||
|
||||
// We just fall through to the code below and let it do what it does.
|
||||
}
|
||||
|
||||
// The nsIVariant is not a XPCVariant (or we act like it isn't).
|
||||
// So we extract the data and do the Right Thing.
|
||||
|
||||
// We ASSUME that the variant implementation can do these conversions...
|
||||
|
||||
nsXPTCVariant xpctvar;
|
||||
nsID iid;
|
||||
nsAutoString astring;
|
||||
PRUint32 size;
|
||||
xpctvar.flags = 0;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case nsIDataType::TYPE_INT8:
|
||||
case nsIDataType::TYPE_INT16:
|
||||
case nsIDataType::TYPE_INT32:
|
||||
case nsIDataType::TYPE_INT64:
|
||||
case nsIDataType::TYPE_UINT8:
|
||||
case nsIDataType::TYPE_UINT16:
|
||||
case nsIDataType::TYPE_UINT32:
|
||||
case nsIDataType::TYPE_UINT64:
|
||||
case nsIDataType::TYPE_FLOAT:
|
||||
case nsIDataType::TYPE_DOUBLE:
|
||||
{
|
||||
// Easy. Handle inline.
|
||||
if(NS_FAILED(variant->GetAsDouble(&xpctvar.val.d)))
|
||||
return JS_FALSE;
|
||||
return JS_NewNumberValue(ccx, xpctvar.val.d, pJSVal);
|
||||
}
|
||||
case nsIDataType::TYPE_BOOL:
|
||||
{
|
||||
// Easy. Handle inline.
|
||||
if(NS_FAILED(variant->GetAsBool(&xpctvar.val.b)))
|
||||
return JS_FALSE;
|
||||
*pJSVal = BOOLEAN_TO_JSVAL(xpctvar.val.b);
|
||||
return JS_TRUE;
|
||||
}
|
||||
case nsIDataType::TYPE_CHAR:
|
||||
if(NS_FAILED(variant->GetAsChar(&xpctvar.val.c)))
|
||||
return JS_FALSE;
|
||||
xpctvar.type = (uint8)TD_CHAR;
|
||||
break;
|
||||
case nsIDataType::TYPE_WCHAR:
|
||||
if(NS_FAILED(variant->GetAsWChar(&xpctvar.val.wc)))
|
||||
return JS_FALSE;
|
||||
xpctvar.type = (uint8)TD_WCHAR;
|
||||
break;
|
||||
case nsIDataType::TYPE_ID:
|
||||
if(NS_FAILED(variant->GetAsID(&iid)))
|
||||
return JS_FALSE;
|
||||
xpctvar.type = (uint8)(TD_PNSIID | XPT_TDP_POINTER);
|
||||
xpctvar.val.p = &iid;
|
||||
break;
|
||||
case nsIDataType::TYPE_ASTRING:
|
||||
if(NS_FAILED(variant->GetAsAString(astring)))
|
||||
return JS_FALSE;
|
||||
xpctvar.type = (uint8)(TD_DOMSTRING | XPT_TDP_POINTER);
|
||||
xpctvar.val.p = &astring;
|
||||
break;
|
||||
case nsIDataType::TYPE_CHAR_STR:
|
||||
if(NS_FAILED(variant->GetAsString((char**)&xpctvar.val.p)))
|
||||
return JS_FALSE;
|
||||
xpctvar.type = (uint8)(TD_PSTRING | XPT_TDP_POINTER);
|
||||
xpctvar.SetValIsAllocated();
|
||||
break;
|
||||
case nsIDataType::TYPE_STRING_SIZE_IS:
|
||||
if(NS_FAILED(variant->GetAsStringWithSize(&size,
|
||||
(char**)&xpctvar.val.p)))
|
||||
return JS_FALSE;
|
||||
xpctvar.type = (uint8)(TD_PSTRING_SIZE_IS | XPT_TDP_POINTER);
|
||||
break;
|
||||
case nsIDataType::TYPE_WCHAR_STR:
|
||||
if(NS_FAILED(variant->GetAsWString((PRUnichar**)&xpctvar.val.p)))
|
||||
return JS_FALSE;
|
||||
xpctvar.type = (uint8)(TD_PWSTRING | XPT_TDP_POINTER);
|
||||
xpctvar.SetValIsAllocated();
|
||||
break;
|
||||
case nsIDataType::TYPE_WSTRING_SIZE_IS:
|
||||
if(NS_FAILED(variant->GetAsWStringWithSize(&size,
|
||||
(PRUnichar**)&xpctvar.val.p)))
|
||||
return JS_FALSE;
|
||||
xpctvar.type = (uint8)(TD_PWSTRING_SIZE_IS | XPT_TDP_POINTER);
|
||||
break;
|
||||
case nsIDataType::TYPE_INTERFACE:
|
||||
case nsIDataType::TYPE_INTERFACE_IS:
|
||||
{
|
||||
nsID* piid;
|
||||
if(NS_FAILED(variant->GetAsInterface(&piid, &xpctvar.val.p)))
|
||||
return JS_FALSE;
|
||||
|
||||
iid = *piid;
|
||||
nsMemory::Free((char*)piid);
|
||||
|
||||
xpctvar.type = (uint8)(TD_INTERFACE_IS_TYPE | XPT_TDP_POINTER);
|
||||
if(xpctvar.val.p)
|
||||
xpctvar.SetValIsInterface();
|
||||
break;
|
||||
}
|
||||
case nsIDataType::TYPE_ARRAY:
|
||||
// XXX FIXME
|
||||
return JS_FALSE;
|
||||
case nsIDataType::TYPE_VOID:
|
||||
case nsIDataType::TYPE_EMPTY:
|
||||
*pJSVal = JSVAL_VOID;
|
||||
return JS_TRUE;
|
||||
default:
|
||||
NS_ERROR("bad type in variant!");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// If we are here then we need to convert the data in the xpctvar.
|
||||
|
||||
PRBool success;
|
||||
|
||||
if(xpctvar.type.TagPart() == TD_PSTRING_SIZE_IS ||
|
||||
xpctvar.type.TagPart() == TD_PWSTRING_SIZE_IS)
|
||||
{
|
||||
success = XPCConvert::NativeStringWithSize2JS(ccx, pJSVal,
|
||||
(const void*)&xpctvar.val,
|
||||
xpctvar.type,
|
||||
size, pErr);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = XPCConvert::NativeData2JS(ccx, pJSVal,
|
||||
(const void*)&xpctvar.val,
|
||||
xpctvar.type,
|
||||
&iid, scope, pErr);
|
||||
}
|
||||
|
||||
if(xpctvar.IsValAllocated())
|
||||
nsMemory::Free((char*)xpctvar.val.p);
|
||||
else if(xpctvar.IsValInterface())
|
||||
((nsISupports*)xpctvar.val.p)->Release();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
// XXX These default implementations need to be improved to allow for
|
||||
// some more interesting conversions.
|
||||
|
||||
|
||||
/* readonly attribute PRUint16 dataType; */
|
||||
NS_IMETHODIMP XPCVariant::GetDataType(PRUint16 *aDataType)
|
||||
{
|
||||
*aDataType = mData.mType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRUint8 getAsInt8 (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsInt8(PRUint8 *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToInt8(mData, _retval);
|
||||
}
|
||||
|
||||
/* PRInt16 getAsInt16 (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsInt16(PRInt16 *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToInt16(mData, _retval);
|
||||
}
|
||||
|
||||
/* PRInt32 getAsInt32 (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsInt32(PRInt32 *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToInt32(mData, _retval);
|
||||
}
|
||||
|
||||
/* PRInt64 getAsInt64 (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsInt64(PRInt64 *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToInt64(mData, _retval);
|
||||
}
|
||||
|
||||
/* PRUint8 getAsUint8 (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsUint8(PRUint8 *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToUint8(mData, _retval);
|
||||
}
|
||||
|
||||
/* PRUint16 getAsUint16 (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsUint16(PRUint16 *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToUint16(mData, _retval);
|
||||
}
|
||||
|
||||
/* PRUint32 getAsUint32 (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsUint32(PRUint32 *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToUint32(mData, _retval);
|
||||
}
|
||||
|
||||
/* PRUint64 getAsUint64 (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsUint64(PRUint64 *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToUint64(mData, _retval);
|
||||
}
|
||||
|
||||
/* float getAsFloat (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsFloat(float *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToFloat(mData, _retval);
|
||||
}
|
||||
|
||||
/* double getAsDouble (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsDouble(double *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToDouble(mData, _retval);
|
||||
}
|
||||
|
||||
/* PRBool getAsBool (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsBool(PRBool *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToBool(mData, _retval);
|
||||
}
|
||||
|
||||
/* char getAsChar (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsChar(char *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToChar(mData, _retval);
|
||||
}
|
||||
|
||||
/* wchar getAsWChar (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsWChar(PRUnichar *_retval)
|
||||
{
|
||||
return nsVariant::ConvertToWChar(mData, _retval);
|
||||
}
|
||||
|
||||
/* [notxpcom] nsresult getAsID (out nsID retval); */
|
||||
NS_IMETHODIMP_(nsresult) XPCVariant::GetAsID(nsID *retval)
|
||||
{
|
||||
return nsVariant::ConvertToID(mData, retval);
|
||||
}
|
||||
|
||||
/* AString getAsAString (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsAString(nsAWritableString & _retval)
|
||||
{
|
||||
return nsVariant::ConvertToAString(mData, _retval);
|
||||
}
|
||||
|
||||
/* string getAsString (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsString(char **_retval)
|
||||
{
|
||||
return nsVariant::ConvertToString(mData, _retval);
|
||||
}
|
||||
|
||||
/* wstring getAsWString (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsWString(PRUnichar **_retval)
|
||||
{
|
||||
return nsVariant::ConvertToWString(mData, _retval);
|
||||
}
|
||||
|
||||
/* nsISupports getAsISupports (); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsISupports(nsISupports **_retval)
|
||||
{
|
||||
return nsVariant::ConvertToISupports(mData, _retval);
|
||||
}
|
||||
|
||||
/* void getAsInterface (out nsIIDPtr iid, [iid_is (iid), retval] out nsQIResult iface); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsInterface(nsIID * *iid, void * *iface)
|
||||
{
|
||||
return nsVariant::ConvertToInterface(mData, iid, iface);
|
||||
}
|
||||
|
||||
/* [noscript] void getAsArray (out PRUint16 type, out PRUint32 count, out voidPtr ptr); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsArray(PRUint16 *type, PRUint32 *count, void * *ptr)
|
||||
{
|
||||
return nsVariant::ConvertToArray(mData, type, count, ptr);
|
||||
}
|
||||
|
||||
/* void getAsStringWithSize (out PRUint32 size, [size_is (size), retval] out string str); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsStringWithSize(PRUint32 *size, char **str)
|
||||
{
|
||||
return nsVariant::ConvertToStringWithSize(mData, size, str);
|
||||
}
|
||||
|
||||
/* void getAsWStringWithSize (out PRUint32 size, [size_is (size), retval] out wstring str); */
|
||||
NS_IMETHODIMP XPCVariant::GetAsWStringWithSize(PRUint32 *size, PRUnichar **str)
|
||||
{
|
||||
return nsVariant::ConvertToWStringWithSize(mData, size, str);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,314 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Bandhauer <jband@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
/* implement nsITestVariant for testing. */
|
||||
|
||||
#include "xpctest_private.h"
|
||||
|
||||
class nsTestVariant : public nsITestVariant
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITESTVARIANT
|
||||
|
||||
nsTestVariant();
|
||||
virtual ~nsTestVariant();
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsTestVariant, nsITestVariant)
|
||||
|
||||
nsTestVariant::nsTestVariant()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsTestVariant::~nsTestVariant()
|
||||
{
|
||||
}
|
||||
|
||||
/* nsIVariant passThruVariant (in nsIVariant value); */
|
||||
NS_IMETHODIMP nsTestVariant::PassThruVariant(nsIVariant *value, nsIVariant **_retval)
|
||||
{
|
||||
*_retval = value;
|
||||
NS_IF_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRUint16 returnVariantType (in nsIVariant value); */
|
||||
NS_IMETHODIMP nsTestVariant::ReturnVariantType(nsIVariant *value, PRUint16 *_retval)
|
||||
{
|
||||
return value->GetDataType(_retval);
|
||||
}
|
||||
|
||||
#define MEMBER_COPY(type_) \
|
||||
rv = inVar->GetAs##type_(&u.m##type_##Value); \
|
||||
if(NS_FAILED(rv)) return rv; \
|
||||
rv = outVar->SetAs##type_(u.m##type_##Value); \
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
#define MEMBER_COPY_CAST(type_, cast_) \
|
||||
rv = inVar->GetAs##type_( (cast_*) &u.m##type_##Value); \
|
||||
if(NS_FAILED(rv)) return rv; \
|
||||
rv = outVar->SetAs##type_( (cast_) u.m##type_##Value); \
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
static nsresult ConvertAndCopyVariant(nsIVariant *inVar, PRUint16 type, nsIVariant **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIWritableVariant> outVar;
|
||||
outVar = do_CreateInstance("@mozilla.org/variant;1");
|
||||
if(!outVar)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRUint16 inVarType;
|
||||
rv = inVar->GetDataType(&inVarType);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsDiscriminatedUnion u;
|
||||
nsVariant::Initialize(&u);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case nsIDataType::TYPE_INT8:
|
||||
MEMBER_COPY_CAST(Int8, PRUint8)
|
||||
break;
|
||||
case nsIDataType::TYPE_INT16:
|
||||
MEMBER_COPY(Int16)
|
||||
break;
|
||||
case nsIDataType::TYPE_INT32:
|
||||
MEMBER_COPY(Int32)
|
||||
break;
|
||||
case nsIDataType::TYPE_INT64:
|
||||
MEMBER_COPY(Int64)
|
||||
break;
|
||||
case nsIDataType::TYPE_UINT8:
|
||||
MEMBER_COPY(Uint8)
|
||||
break;
|
||||
case nsIDataType::TYPE_UINT16:
|
||||
MEMBER_COPY(Uint16)
|
||||
break;
|
||||
case nsIDataType::TYPE_UINT32:
|
||||
MEMBER_COPY(Uint32)
|
||||
break;
|
||||
case nsIDataType::TYPE_UINT64:
|
||||
MEMBER_COPY(Uint64)
|
||||
break;
|
||||
case nsIDataType::TYPE_FLOAT:
|
||||
MEMBER_COPY(Float)
|
||||
break;
|
||||
case nsIDataType::TYPE_DOUBLE:
|
||||
MEMBER_COPY(Double)
|
||||
break;
|
||||
case nsIDataType::TYPE_BOOL:
|
||||
MEMBER_COPY(Bool)
|
||||
break;
|
||||
case nsIDataType::TYPE_CHAR:
|
||||
MEMBER_COPY(Char)
|
||||
break;
|
||||
case nsIDataType::TYPE_WCHAR:
|
||||
MEMBER_COPY(WChar)
|
||||
break;
|
||||
case nsIDataType::TYPE_VOID:
|
||||
if(inVarType != nsIDataType::TYPE_VOID)
|
||||
return NS_ERROR_CANNOT_CONVERT_DATA;
|
||||
rv = outVar->SetAsVoid();
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
case nsIDataType::TYPE_ID:
|
||||
MEMBER_COPY(ID)
|
||||
break;
|
||||
case nsIDataType::TYPE_ASTRING:
|
||||
{
|
||||
nsAutoString str;
|
||||
rv = inVar->GetAsAString(str);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
rv = outVar->SetAsAString(str);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
}
|
||||
case nsIDataType::TYPE_CHAR_STR:
|
||||
{
|
||||
char* str;
|
||||
rv = inVar->GetAsString(&str);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
rv = outVar->SetAsString(str);
|
||||
if(str) nsMemory::Free(str);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
}
|
||||
case nsIDataType::TYPE_STRING_SIZE_IS:
|
||||
{
|
||||
char* str;
|
||||
PRUint32 size;
|
||||
rv = inVar->GetAsStringWithSize(&size, &str);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
rv = outVar->SetAsStringWithSize(size, str);
|
||||
if(str) nsMemory::Free(str);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
}
|
||||
case nsIDataType::TYPE_WCHAR_STR:
|
||||
{
|
||||
PRUnichar* str;
|
||||
rv = inVar->GetAsWString(&str);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
rv = outVar->SetAsWString(str);
|
||||
if(str) nsMemory::Free((char*)str);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
}
|
||||
case nsIDataType::TYPE_WSTRING_SIZE_IS:
|
||||
{
|
||||
PRUnichar* str;
|
||||
PRUint32 size;
|
||||
rv = inVar->GetAsWStringWithSize(&size, &str);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
rv = outVar->SetAsWStringWithSize(size, str);
|
||||
if(str) nsMemory::Free((char*)str);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
}
|
||||
case nsIDataType::TYPE_INTERFACE:
|
||||
{
|
||||
nsISupports* ptr;
|
||||
rv = inVar->GetAsISupports(&ptr);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
rv = outVar->SetAsISupports(ptr);
|
||||
NS_IF_RELEASE(ptr);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
}
|
||||
case nsIDataType::TYPE_INTERFACE_IS:
|
||||
{
|
||||
nsISupports* ptr;
|
||||
nsIID* iid;
|
||||
rv = inVar->GetAsInterface(&iid, (void**)&ptr);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
rv = outVar->SetAsInterface(*iid, ptr);
|
||||
NS_IF_RELEASE(ptr);
|
||||
if(iid) nsMemory::Free((char*)iid);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case nsIDataType::TYPE_ARRAY:
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
case nsIDataType::TYPE_EMPTY:
|
||||
if(inVarType != nsIDataType::TYPE_EMPTY)
|
||||
return NS_ERROR_CANNOT_CONVERT_DATA;
|
||||
rv = outVar->SetAsEmpty();
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
default:
|
||||
NS_ERROR("bad type in variant!");
|
||||
break;
|
||||
}
|
||||
|
||||
nsVariant::Cleanup(&u);
|
||||
*_retval = outVar;
|
||||
NS_IF_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* nsIVariant copyVariant (in nsIVariant value); */
|
||||
NS_IMETHODIMP nsTestVariant::CopyVariant(nsIVariant *value, nsIVariant **_retval)
|
||||
{
|
||||
PRUint16 type;
|
||||
if(NS_FAILED(value->GetDataType(&type)))
|
||||
return NS_ERROR_FAILURE;
|
||||
return ConvertAndCopyVariant(value, type, _retval);
|
||||
}
|
||||
|
||||
/* nsIVariant copyVariantAsType (in nsIVariant value, in PRUint16 type); */
|
||||
NS_IMETHODIMP nsTestVariant::CopyVariantAsType(nsIVariant *value, PRUint16 type, nsIVariant **_retval)
|
||||
{
|
||||
return ConvertAndCopyVariant(value, type, _retval);
|
||||
}
|
||||
|
||||
/* nsIVariant copyVariantAsTypeTwice (in nsIVariant value, in PRUint16 type1, in PRUint16 type2); */
|
||||
NS_IMETHODIMP nsTestVariant::CopyVariantAsTypeTwice(nsIVariant *value, PRUint16 type1, PRUint16 type2, nsIVariant **_retval)
|
||||
{
|
||||
nsCOMPtr<nsIVariant> temp;
|
||||
nsresult rv = ConvertAndCopyVariant(value, type1, getter_AddRefs(temp));
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
return ConvertAndCopyVariant(temp, type2, _retval);
|
||||
}
|
||||
|
||||
/* nsIVariant getNamedProperty (in nsISupports aBag, in AString aName); */
|
||||
NS_IMETHODIMP nsTestVariant::GetNamedProperty(nsISupports *aObj, const nsAReadableString & aName, nsIVariant **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPropertyBag> bag = do_QueryInterface(aObj, &rv);
|
||||
if(!bag)
|
||||
return rv;
|
||||
return bag->GetProperty(aName, _retval);
|
||||
}
|
||||
|
||||
/* nsISimpleEnumerator getEnumerator (in nsISupports aBag); */
|
||||
NS_IMETHODIMP nsTestVariant::GetEnumerator(nsISupports *aObj, nsISimpleEnumerator **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPropertyBag> bag = do_QueryInterface(aObj, &rv);
|
||||
if(!bag)
|
||||
return rv;
|
||||
return bag->GetEnumerator(_retval);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// static
|
||||
NS_IMETHODIMP
|
||||
xpctest::ConstructXPCTestVariant(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ASSERTION(aOuter == nsnull, "no aggregation");
|
||||
nsTestVariant* obj = new nsTestVariant();
|
||||
|
||||
if(!obj)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_ADDREF(obj);
|
||||
rv = obj->QueryInterface(aIID, aResult);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
|
||||
NS_RELEASE(obj);
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
const nsIVariant = Components.interfaces.nsIVariant;
|
||||
const nsIProperty = Components.interfaces.nsIProperty;
|
||||
|
||||
const TestVariant = Components.Constructor("@mozilla.org/js/xpc/test/TestVariant;1",
|
||||
"nsITestVariant");
|
||||
|
||||
var tv = new TestVariant;
|
||||
|
||||
var obj = {foo : "fooString",
|
||||
five : "5",
|
||||
bar : {},
|
||||
6 : "six",
|
||||
fun : function(){},
|
||||
bignum : 1.2345678901234567890,
|
||||
now : new Date().toString() };
|
||||
|
||||
print();
|
||||
print(tv.getNamedProperty(obj, "foo"));
|
||||
print(tv.getNamedProperty(obj, "five"));
|
||||
print(tv.getNamedProperty(obj, "bar"));
|
||||
print(tv.getNamedProperty(obj, 6));
|
||||
print(tv.getNamedProperty(obj, "fun"));
|
||||
print(tv.getNamedProperty(obj, "fun"));
|
||||
print(tv.getNamedProperty(obj, "bignum"));
|
||||
print(tv.getNamedProperty(obj, "now"));
|
||||
print();
|
||||
|
||||
var e = tv.getEnumerator(obj);
|
||||
|
||||
while(e.hasMoreElements()) {
|
||||
var prop = e.getNext().QueryInterface(nsIProperty)
|
||||
print(prop.name+" = "+prop.value);
|
||||
}
|
||||
|
||||
print();
|
|
@ -0,0 +1,323 @@
|
|||
|
||||
const TestVariant = Components.Constructor("@mozilla.org/js/xpc/test/TestVariant;1",
|
||||
"nsITestVariant");
|
||||
|
||||
var tv = new TestVariant;
|
||||
|
||||
const DataTypeArray = [
|
||||
Components.interfaces.nsIDataType.TYPE_INT8 ,
|
||||
Components.interfaces.nsIDataType.TYPE_INT16 ,
|
||||
Components.interfaces.nsIDataType.TYPE_INT32 ,
|
||||
Components.interfaces.nsIDataType.TYPE_INT64 ,
|
||||
Components.interfaces.nsIDataType.TYPE_UINT8 ,
|
||||
Components.interfaces.nsIDataType.TYPE_UINT16 ,
|
||||
Components.interfaces.nsIDataType.TYPE_UINT32 ,
|
||||
Components.interfaces.nsIDataType.TYPE_UINT64 ,
|
||||
Components.interfaces.nsIDataType.TYPE_FLOAT ,
|
||||
Components.interfaces.nsIDataType.TYPE_DOUBLE ,
|
||||
Components.interfaces.nsIDataType.TYPE_BOOL ,
|
||||
Components.interfaces.nsIDataType.TYPE_CHAR ,
|
||||
Components.interfaces.nsIDataType.TYPE_WCHAR ,
|
||||
Components.interfaces.nsIDataType.TYPE_VOID ,
|
||||
Components.interfaces.nsIDataType.TYPE_ID ,
|
||||
Components.interfaces.nsIDataType.TYPE_ASTRING ,
|
||||
Components.interfaces.nsIDataType.TYPE_CHAR_STR ,
|
||||
Components.interfaces.nsIDataType.TYPE_WCHAR_STR ,
|
||||
Components.interfaces.nsIDataType.TYPE_INTERFACE ,
|
||||
Components.interfaces.nsIDataType.TYPE_INTERFACE_IS ,
|
||||
Components.interfaces.nsIDataType.TYPE_ARRAY ,
|
||||
Components.interfaces.nsIDataType.TYPE_STRING_SIZE_IS ,
|
||||
Components.interfaces.nsIDataType.TYPE_WSTRING_SIZE_IS ,
|
||||
Components.interfaces.nsIDataType.TYPE_EMPTY
|
||||
];
|
||||
|
||||
const ShortNames = [
|
||||
{name: "I1", number: Components.interfaces.nsIDataType.TYPE_INT8 },
|
||||
{name: "I2", number: Components.interfaces.nsIDataType.TYPE_INT16 },
|
||||
{name: "I4", number: Components.interfaces.nsIDataType.TYPE_INT32 },
|
||||
{name: "I8", number: Components.interfaces.nsIDataType.TYPE_INT64 },
|
||||
{name: "U1", number: Components.interfaces.nsIDataType.TYPE_UINT8 },
|
||||
{name: "U2", number: Components.interfaces.nsIDataType.TYPE_UINT16 },
|
||||
{name: "U4", number: Components.interfaces.nsIDataType.TYPE_UINT32 },
|
||||
{name: "U8", number: Components.interfaces.nsIDataType.TYPE_UINT64 },
|
||||
{name: "FL", number: Components.interfaces.nsIDataType.TYPE_FLOAT },
|
||||
{name: "DB", number: Components.interfaces.nsIDataType.TYPE_DOUBLE },
|
||||
{name: "BO", number: Components.interfaces.nsIDataType.TYPE_BOOL },
|
||||
{name: "CH", number: Components.interfaces.nsIDataType.TYPE_CHAR },
|
||||
{name: "WC", number: Components.interfaces.nsIDataType.TYPE_WCHAR },
|
||||
{name: "VD", number: Components.interfaces.nsIDataType.TYPE_VOID },
|
||||
{name: "ID", number: Components.interfaces.nsIDataType.TYPE_ID },
|
||||
{name: "AS", number: Components.interfaces.nsIDataType.TYPE_ASTRING },
|
||||
{name: "ST", number: Components.interfaces.nsIDataType.TYPE_CHAR_STR },
|
||||
{name: "WS", number: Components.interfaces.nsIDataType.TYPE_WCHAR_STR },
|
||||
{name: "NS", number: Components.interfaces.nsIDataType.TYPE_INTERFACE },
|
||||
{name: "IF", number: Components.interfaces.nsIDataType.TYPE_INTERFACE_IS },
|
||||
{name: "AR", number: Components.interfaces.nsIDataType.TYPE_ARRAY },
|
||||
{name: "Ss", number: Components.interfaces.nsIDataType.TYPE_STRING_SIZE_IS },
|
||||
{name: "Ws", number: Components.interfaces.nsIDataType.TYPE_WSTRING_SIZE_IS},
|
||||
{name: "EM", number: Components.interfaces.nsIDataType.TYPE_EMPTY }
|
||||
];
|
||||
|
||||
|
||||
function getDataTypeName(number) {
|
||||
var iface = Components.interfaces.nsIDataType
|
||||
for(var n in iface)
|
||||
if(iface[n] == number)
|
||||
return n;
|
||||
return "unknown type!";
|
||||
}
|
||||
|
||||
function getDataTypeShortName(number) {
|
||||
for(var i = 0; i < ShortNames.length; i++)
|
||||
if(ShortNames[i].number == number)
|
||||
return ShortNames[i].name;
|
||||
return "???";
|
||||
}
|
||||
|
||||
function eqOp(o1, o2) {return o1 == o2;}
|
||||
function eqObj(o1, o2) {return o1.equals(o2);}
|
||||
function eqNumber(o1, o2) {return parseFloat(o1) == parseFloat(o2);}
|
||||
|
||||
const eq = {string: "equal result"};
|
||||
const _e = {string: "exception"};
|
||||
const NE = {string: "un-equal result"};
|
||||
const _0 = {string: "zero result"};
|
||||
const _1 = {string: "one result"};
|
||||
const _T = {string: "true result"};
|
||||
const _F = {string: "false result"};
|
||||
|
||||
function TestSingleConvert(value, comment, eq_fun, table) {
|
||||
print("<h3>convert test for: "+value+" "+comment+"</h3>");
|
||||
|
||||
print('<TABLE BORDER="1" COLS='+table.length+'>');
|
||||
print('<TR>');
|
||||
for(var i = 0; i < table.length; i++) {
|
||||
print('<TH>'+getDataTypeShortName(DataTypeArray[i])+'</TH>');
|
||||
}
|
||||
print('</TR>');
|
||||
|
||||
print('<TR>');
|
||||
for(var i = 0; i < table.length; i++) {
|
||||
var exception = undefined;
|
||||
var value2 = undefined;
|
||||
try {
|
||||
value2 = tv.copyVariantAsType(value, DataTypeArray[i]);
|
||||
var same = eq_fun(value, value2);
|
||||
success = (same && table[i] == eq) ||
|
||||
(!same && table[i] == NE) ||
|
||||
(table[i] == _0 && 0 == value2) ||
|
||||
(table[i] == _T && true == value2) ||
|
||||
(table[i] == _F && false == value2);
|
||||
} catch(e) {
|
||||
exception = e;
|
||||
success = table[i] == _e;
|
||||
}
|
||||
if(success)
|
||||
print('<TD><font color="green">OK</font></TD>');
|
||||
else if(exception) {
|
||||
var alertText = "Exception thrown. Expected: "+table[i].string;
|
||||
print('<TD><font color="red"><A HREF="" '+
|
||||
'onclick="alert(\''+alertText+'\'); return false;"'+
|
||||
'>X</A></font></TD>');
|
||||
}
|
||||
else {
|
||||
var alertText = "Result = "+value2+". Expected: "+table[i].string;
|
||||
print('<TD><font color="red"><A HREF="" '+
|
||||
'onclick="alert(\''+alertText+'\'); return false;"'+
|
||||
'>X</A></font></TD>');
|
||||
}
|
||||
}
|
||||
|
||||
print('</TR>');
|
||||
print('</TABLE>');
|
||||
}
|
||||
|
||||
function TestDoubleConvert(value, comment, eq_fun, table) {
|
||||
print("<h3>convert test for: "+value+" "+comment+"</h3>");
|
||||
|
||||
print('<TABLE BORDER="1" COLS='+table.length+2+'>');
|
||||
print('<TR>');
|
||||
print('<TH></TH>');
|
||||
for(var i = 0; i < table.length; i++) {
|
||||
print('<TH>'+getDataTypeShortName(DataTypeArray[i])+'</TH>');
|
||||
}
|
||||
print('<TH></TH>');
|
||||
print('</TR>');
|
||||
|
||||
for(var i = 0; i < table.length; i++) {
|
||||
print('<TR>');
|
||||
print('<TD>'+getDataTypeShortName(DataTypeArray[i])+'</TD>');
|
||||
for(var k = 0; k < table.length; k++) {
|
||||
var exception = undefined;
|
||||
var value2 = undefined;
|
||||
var expected = table[i][k];
|
||||
try {
|
||||
value2 = tv.copyVariantAsTypeTwice(value,
|
||||
DataTypeArray[k],
|
||||
DataTypeArray[i]);
|
||||
var same = eq_fun(value, value2);
|
||||
success = (same && expected == eq) ||
|
||||
(!same && expected == NE) ||
|
||||
(expected == _0 && 0 == value2) ||
|
||||
(expected == _T && true == value2) ||
|
||||
(expected == _F && false == value2);
|
||||
} catch(e) {
|
||||
exception = e;
|
||||
success = expected == _e;
|
||||
}
|
||||
if(success)
|
||||
print('<TD><font color="green">OK</font></TD>');
|
||||
else if(exception) {
|
||||
var alertText = "Exception thrown. Expected: "+expected.string;
|
||||
print('<TD><font color="red"><A HREF="" '+
|
||||
'onclick="alert(\''+alertText+'\'); return false;"'+
|
||||
'>X</A></font></TD>');
|
||||
}
|
||||
else {
|
||||
var alertText = "Result = was wrong. Expected: "+expected.string;
|
||||
print('<TD><font color="red"><A HREF="" '+
|
||||
'onclick="alert(\''+alertText+'\'); return false;"'+
|
||||
'>X</A></font></TD>');
|
||||
}
|
||||
}
|
||||
print('<TD>'+getDataTypeShortName(DataTypeArray[i])+'</TD>');
|
||||
print('</TR>');
|
||||
}
|
||||
|
||||
print('</TABLE>');
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
const SingleConvertResultsTableFor_String_Foo = [
|
||||
/*I1,I2,I4,I8,U1,U2,U4,U8,FL,DB,BO,CH,WC,VD,ID,AS,ST,WS,NS,IF,AR,Ss,Ws,EM */
|
||||
_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,_e
|
||||
];
|
||||
|
||||
const SingleConvertResultsTableFor_String_5 = [
|
||||
/*I1,I2,I4,I8,U1,U2,U4,U8,FL,DB,BO,CH,WC,VD,ID,AS,ST,WS,NS,IF,AR,Ss,Ws,EM */
|
||||
eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,_e
|
||||
];
|
||||
|
||||
const SingleConvertResultsTableFor_Number_20 = [
|
||||
/*I1,I2,I4,I8,U1,U2,U4,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q,eq,_e],/*ST*/
|
||||
/*WS*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,_e],/*WS*/
|
||||
/*NS*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*NS*/
|
||||
/*IF*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*IF*/
|
||||
/*AR*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*AR*/
|
||||
/*Ss*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,_e],/*Ss*/
|
||||
/*Ws*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,_e],/*Ws*/
|
||||
/*EM*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e] /*EM*/
|
||||
];
|
||||
|
||||
var values = [
|
||||
"foo",
|
||||
0,
|
||||
5,
|
||||
1.01,
|
||||
Components,
|
||||
{},
|
||||
Components.interfaces.nsISupports,
|
||||
null,
|
||||
true,
|
||||
undefined
|
||||
];
|
||||
|
||||
var i;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
if(0){
|
||||
|
||||
print();
|
||||
|
||||
for(i = 0; i < values.length; i++)
|
||||
print(getDataTypeName(tv.returnVariantType(values[i])));
|
||||
|
||||
print();
|
||||
print();
|
||||
|
||||
for(i = 0; i < values.length; i++)
|
||||
print(tv.passThruVariant(values[i]));
|
||||
|
||||
print();
|
||||
print();
|
||||
|
||||
for(i = 0; i < values.length; i++)
|
||||
print(tv.copyVariant(values[i]));
|
||||
|
||||
}
|
||||
|
||||
function RunSingleConvertTests() {
|
||||
TestSingleConvert("foo", "a string", eqOp, SingleConvertResultsTableFor_String_Foo);
|
||||
TestSingleConvert("5", "a string", eqNumber, SingleConvertResultsTableFor_String_5);
|
||||
TestSingleConvert(20, "a number", eqNumber, SingleConvertResultsTableFor_Number_20);
|
||||
print("<P>");
|
||||
}
|
||||
|
||||
function RunDoubleConvertTests() {
|
||||
TestDoubleConvert("foo", "a string", eqOp, DoubleConvertResultsTableFor_String_Foo);
|
||||
TestDoubleConvert("5", "a string", eqNumber, DoubleConvertResultsTableFor_String_Five);
|
||||
print("<P>");
|
||||
}
|
||||
|
||||
// main...
|
||||
|
||||
print("<html><body>")
|
||||
|
||||
RunSingleConvertTests();
|
||||
RunDoubleConvertTests();
|
||||
|
||||
print("</body></html>")
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Bandhauer <jband@netscape.com>
|
||||
*/
|
||||
|
||||
/* nsIVariant based Property Bag support. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIVariant.idl"
|
||||
#include "nsIEnumerator.idl"
|
||||
|
||||
[scriptable, uuid(6dcf9030-a49f-11d5-910d-0010a4e73d9a)]
|
||||
interface nsIProperty : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get the name of the property.
|
||||
*/
|
||||
readonly attribute AString name;
|
||||
|
||||
/**
|
||||
* Get the value of the property.
|
||||
*/
|
||||
readonly attribute nsIVariant value;
|
||||
};
|
||||
|
||||
[scriptable, uuid(bfcd37b0-a49f-11d5-910d-0010a4e73d9a)]
|
||||
interface nsIPropertyBag : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get a nsISimpleEnumerator whose elements are nsIProperty objects.
|
||||
*/
|
||||
readonly attribute nsISimpleEnumerator enumerator;
|
||||
|
||||
/**
|
||||
* Get a property value for the given name.
|
||||
* @return NS_ERROR_FAILURE if a property with that name doesn't
|
||||
* exist.
|
||||
*/
|
||||
nsIVariant getProperty(in AString name);
|
||||
};
|
||||
|
||||
// We can add nsIWritableProperty and nsIWritablePropertyBag when we need them.
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Bandhauer <jband@netscape.com>
|
||||
*/
|
||||
|
||||
/* The long avoided variant support for xpcom. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{ C++
|
||||
#include "nsString.h" // needed for AString -> nsAReadableString, unfortunately
|
||||
%}
|
||||
|
||||
[scriptable,uuid(4d12e540-83d7-11d5-90ed-0010a4e73d9a)]
|
||||
interface nsIDataType : nsISupports
|
||||
{
|
||||
// These MUST match the declarations in xpt_struct.h.
|
||||
// Otherwise the world is likely to explode.
|
||||
// From xpt_struct.h ...
|
||||
const PRUint16 TYPE_INT8 = 0; // TD_INT8 = 0,
|
||||
const PRUint16 TYPE_INT16 = 1; // TD_INT16 = 1,
|
||||
const PRUint16 TYPE_INT32 = 2; // TD_INT32 = 2,
|
||||
const PRUint16 TYPE_INT64 = 3; // TD_INT64 = 3,
|
||||
const PRUint16 TYPE_UINT8 = 4; // TD_UINT8 = 4,
|
||||
const PRUint16 TYPE_UINT16 = 5; // TD_UINT16 = 5,
|
||||
const PRUint16 TYPE_UINT32 = 6; // TD_UINT32 = 6,
|
||||
const PRUint16 TYPE_UINT64 = 7; // TD_UINT64 = 7,
|
||||
const PRUint16 TYPE_FLOAT = 8; // TD_FLOAT = 8,
|
||||
const PRUint16 TYPE_DOUBLE = 9; // TD_DOUBLE = 9,
|
||||
const PRUint16 TYPE_BOOL = 10; // TD_BOOL = 10,
|
||||
const PRUint16 TYPE_CHAR = 11; // TD_CHAR = 11,
|
||||
const PRUint16 TYPE_WCHAR = 12; // TD_WCHAR = 12,
|
||||
const PRUint16 TYPE_VOID = 13; // TD_VOID = 13,
|
||||
const PRUint16 TYPE_ID = 14; // TD_PNSIID = 14,
|
||||
const PRUint16 TYPE_ASTRING = 15; // TD_DOMSTRING = 15,
|
||||
const PRUint16 TYPE_CHAR_STR = 16; // TD_PSTRING = 16,
|
||||
const PRUint16 TYPE_WCHAR_STR = 17; // TD_PWSTRING = 17,
|
||||
const PRUint16 TYPE_INTERFACE = 18; // TD_INTERFACE_TYPE = 18,
|
||||
const PRUint16 TYPE_INTERFACE_IS = 19; // TD_INTERFACE_IS_TYPE = 19,
|
||||
const PRUint16 TYPE_ARRAY = 20; // TD_ARRAY = 20,
|
||||
const PRUint16 TYPE_STRING_SIZE_IS = 21; // TD_PSTRING_SIZE_IS = 21,
|
||||
const PRUint16 TYPE_WSTRING_SIZE_IS = 22; // TD_PWSTRING_SIZE_IS = 22
|
||||
|
||||
const PRUint16 TYPE_EMPTY = 255;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* XPConnect has magic to transparently convert between nsIVariant and JS types.
|
||||
* We mark the interface [scriptable] so that JS can use methods
|
||||
* that refer to this interface. But we mark all the methods and attributes
|
||||
* [noscript] since any nsIVariant object will be automatically converted to a
|
||||
* JS type anyway.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(6c9eb060-8c6a-11d5-90f3-0010a4e73d9a)]
|
||||
interface nsIVariant : nsISupports
|
||||
{
|
||||
[noscript] readonly attribute PRUint16 dataType;
|
||||
|
||||
[noscript] PRUint8 getAsInt8();
|
||||
[noscript] PRInt16 getAsInt16();
|
||||
[noscript] PRInt32 getAsInt32();
|
||||
[noscript] PRInt64 getAsInt64();
|
||||
[noscript] PRUint8 getAsUint8();
|
||||
[noscript] PRUint16 getAsUint16();
|
||||
[noscript] PRUint32 getAsUint32();
|
||||
[noscript] PRUint64 getAsUint64();
|
||||
[noscript] float getAsFloat();
|
||||
[noscript] double getAsDouble();
|
||||
[noscript] PRBool getAsBool();
|
||||
[noscript] char getAsChar();
|
||||
[noscript] wchar getAsWChar();
|
||||
[notxpcom] nsresult getAsID(out nsID retval);
|
||||
[noscript] AString getAsAString();
|
||||
[noscript] string getAsString();
|
||||
[noscript] wstring getAsWString();
|
||||
[noscript] nsISupports getAsISupports();
|
||||
|
||||
[noscript] void getAsInterface(out nsIIDPtr iid,
|
||||
[iid_is(iid), retval] out nsQIResult iface);
|
||||
|
||||
[noscript] void getAsArray(out PRUint16 type, out PRUint32 count,
|
||||
out voidPtr ptr);
|
||||
|
||||
[noscript] void getAsStringWithSize(out PRUint32 size,
|
||||
[size_is(size), retval] out string str);
|
||||
|
||||
[noscript] void getAsWStringWithSize(out PRUint32 size,
|
||||
[size_is(size), retval] out wstring str);
|
||||
};
|
||||
|
||||
/**
|
||||
* An object that implements nsIVariant may or may NOT also implement this
|
||||
* nsIWritableVariant.
|
||||
*
|
||||
* If the 'writable' attribute is false then attempts to call any of the 'set'
|
||||
* methods can be expected to fail. Setting the 'writable' attribute may or
|
||||
* may not succeed.
|
||||
*
|
||||
*/
|
||||
|
||||
[scriptable, uuid(5586a590-8c82-11d5-90f3-0010a4e73d9a)]
|
||||
interface nsIWritableVariant : nsIVariant
|
||||
{
|
||||
attribute PRBool writable;
|
||||
|
||||
void setAsInt8(in PRUint8 aValue);
|
||||
void setAsInt16(in PRInt16 aValue);
|
||||
void setAsInt32(in PRInt32 aValue);
|
||||
void setAsInt64(in PRInt64 aValue);
|
||||
void setAsUint8(in PRUint8 aValue);
|
||||
void setAsUint16(in PRUint16 aValue);
|
||||
void setAsUint32(in PRUint32 aValue);
|
||||
void setAsUint64(in PRUint64 aValue);
|
||||
void setAsFloat(in float aValue);
|
||||
void setAsDouble(in double aValue);
|
||||
void setAsBool(in PRBool aValue);
|
||||
void setAsChar(in char aValue);
|
||||
void setAsWChar(in wchar aValue);
|
||||
void setAsID(in nsIDRef aValue);
|
||||
void setAsAString(in AString aValue);
|
||||
void setAsString(in string aValue);
|
||||
void setAsWString(in wstring aValue);
|
||||
void setAsISupports(in nsISupports aValue);
|
||||
|
||||
void setAsInterface(in nsIIDRef iid,
|
||||
[iid_is(iid)] in nsQIResult iface);
|
||||
|
||||
[noscript] void setAsArray(in PRUint16 type, in PRUint32 count,
|
||||
in voidPtr ptr);
|
||||
|
||||
void setAsStringWithSize(in PRUint32 size,
|
||||
[size_is(size)] in string str);
|
||||
|
||||
void setAsWStringWithSize(in PRUint32 size,
|
||||
[size_is(size)] in wstring str);
|
||||
|
||||
void setAsVoid();
|
||||
void setAsEmpty();
|
||||
|
||||
void setFromVariant(in nsIVariant aValue);
|
||||
};
|
||||
|
||||
%{C++
|
||||
// The contractID for the generic implementation built in to xpcom.
|
||||
#define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
|
||||
%}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,167 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Bandhauer <jband@netscape.com>
|
||||
*/
|
||||
|
||||
/* The long avoided variant support for xpcom. */
|
||||
|
||||
#include "nsIVariant.h"
|
||||
#include "xpt_struct.h"
|
||||
|
||||
/**
|
||||
* nsDiscriminatedUnion is a type that nsIVariant implementors *may* use
|
||||
* to hold underlying data. It has no methods. So, its use requires no linkage
|
||||
* to the xpcom module.
|
||||
*/
|
||||
|
||||
struct NS_COM nsDiscriminatedUnion
|
||||
{
|
||||
union {
|
||||
PRInt8 mInt8Value;
|
||||
PRInt16 mInt16Value;
|
||||
PRInt32 mInt32Value;
|
||||
PRInt64 mInt64Value;
|
||||
PRUint8 mUint8Value;
|
||||
PRUint16 mUint16Value;
|
||||
PRUint32 mUint32Value;
|
||||
PRUint64 mUint64Value;
|
||||
float mFloatValue;
|
||||
double mDoubleValue;
|
||||
PRBool mBoolValue;
|
||||
char mCharValue;
|
||||
PRUnichar mWCharValue;
|
||||
nsIID mIDValue;
|
||||
nsAString* mAStringValue;
|
||||
struct {
|
||||
nsISupports* mInterfaceValue;
|
||||
nsIID mInterfaceID;
|
||||
};
|
||||
struct {
|
||||
void* mArrayValue;
|
||||
PRUint32 mArrayCount;
|
||||
PRUint16 mArrayType;
|
||||
};
|
||||
struct {
|
||||
char* mStringValue;
|
||||
PRUint32 mStringLength;
|
||||
};
|
||||
struct {
|
||||
PRUnichar* mWStringValue;
|
||||
PRUint32 mWStringLength;
|
||||
};
|
||||
};
|
||||
PRUint16 mType;
|
||||
};
|
||||
|
||||
/**
|
||||
* nsVariant implements the generic variant support. The xpcom module registers
|
||||
* a factory (see NS_VARIANT_CONTRACTID in nsIVariant.idl) that will create
|
||||
* these objects. They are created 'empty' and 'writable'.
|
||||
*
|
||||
* nsIVariant users won't usually need to see this class.
|
||||
*
|
||||
* This class also has static helper methods that nsIVariant *implementors* can
|
||||
* use to help them do all the 'standard' nsIVariant data conversions.
|
||||
*/
|
||||
|
||||
class NS_COM nsVariant : public nsIWritableVariant
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIVARIANT
|
||||
NS_DECL_NSIWRITABLEVARIANT
|
||||
|
||||
nsVariant();
|
||||
virtual ~nsVariant();
|
||||
|
||||
static nsresult Initialize(nsDiscriminatedUnion* data);
|
||||
static nsresult Cleanup(nsDiscriminatedUnion* data);
|
||||
|
||||
static nsresult ConvertToInt8(const nsDiscriminatedUnion& data, PRUint8 *_retval);
|
||||
static nsresult ConvertToInt16(const nsDiscriminatedUnion& data, PRInt16 *_retval);
|
||||
static nsresult ConvertToInt32(const nsDiscriminatedUnion& data, PRInt32 *_retval);
|
||||
static nsresult ConvertToInt64(const nsDiscriminatedUnion& data, PRInt64 *_retval);
|
||||
static nsresult ConvertToUint8(const nsDiscriminatedUnion& data, PRUint8 *_retval);
|
||||
static nsresult ConvertToUint16(const nsDiscriminatedUnion& data, PRUint16 *_retval);
|
||||
static nsresult ConvertToUint32(const nsDiscriminatedUnion& data, PRUint32 *_retval);
|
||||
static nsresult ConvertToUint64(const nsDiscriminatedUnion& data, PRUint64 *_retval);
|
||||
static nsresult ConvertToFloat(const nsDiscriminatedUnion& data, float *_retval);
|
||||
static nsresult ConvertToDouble(const nsDiscriminatedUnion& data, double *_retval);
|
||||
static nsresult ConvertToBool(const nsDiscriminatedUnion& data, PRBool *_retval);
|
||||
static nsresult ConvertToChar(const nsDiscriminatedUnion& data, char *_retval);
|
||||
static nsresult ConvertToWChar(const nsDiscriminatedUnion& data, PRUnichar *_retval);
|
||||
static nsresult ConvertToID(const nsDiscriminatedUnion& data, nsID * _retval);
|
||||
static nsresult ConvertToAString(const nsDiscriminatedUnion& data, nsAWritableString & _retval);
|
||||
static nsresult ConvertToString(const nsDiscriminatedUnion& data, char **_retval);
|
||||
static nsresult ConvertToWString(const nsDiscriminatedUnion& data, PRUnichar **_retval);
|
||||
static nsresult ConvertToISupports(const nsDiscriminatedUnion& data, nsISupports **_retval);
|
||||
static nsresult ConvertToInterface(const nsDiscriminatedUnion& data, nsIID * *iid, void * *iface);
|
||||
static nsresult ConvertToArray(const nsDiscriminatedUnion& data, PRUint16 *type, PRUint32 *count, void * *ptr);
|
||||
static nsresult ConvertToStringWithSize(const nsDiscriminatedUnion& data, PRUint32 *size, char **str);
|
||||
static nsresult ConvertToWStringWithSize(const nsDiscriminatedUnion& data, PRUint32 *size, PRUnichar **str);
|
||||
|
||||
static nsresult SetFromVariant(nsDiscriminatedUnion* data, nsIVariant* aValue);
|
||||
|
||||
static nsresult SetFromInt8(nsDiscriminatedUnion* data, PRUint8 aValue);
|
||||
static nsresult SetFromInt16(nsDiscriminatedUnion* data, PRInt16 aValue);
|
||||
static nsresult SetFromInt32(nsDiscriminatedUnion* data, PRInt32 aValue);
|
||||
static nsresult SetFromInt64(nsDiscriminatedUnion* data, PRInt64 aValue);
|
||||
static nsresult SetFromUint8(nsDiscriminatedUnion* data, PRUint8 aValue);
|
||||
static nsresult SetFromUint16(nsDiscriminatedUnion* data, PRUint16 aValue);
|
||||
static nsresult SetFromUint32(nsDiscriminatedUnion* data, PRUint32 aValue);
|
||||
static nsresult SetFromUint64(nsDiscriminatedUnion* data, PRUint64 aValue);
|
||||
static nsresult SetFromFloat(nsDiscriminatedUnion* data, float aValue);
|
||||
static nsresult SetFromDouble(nsDiscriminatedUnion* data, double aValue);
|
||||
static nsresult SetFromBool(nsDiscriminatedUnion* data, PRBool aValue);
|
||||
static nsresult SetFromChar(nsDiscriminatedUnion* data, char aValue);
|
||||
static nsresult SetFromWChar(nsDiscriminatedUnion* data, PRUnichar aValue);
|
||||
static nsresult SetFromID(nsDiscriminatedUnion* data, const nsID & aValue);
|
||||
static nsresult SetFromAString(nsDiscriminatedUnion* data, const nsAReadableString & aValue);
|
||||
static nsresult SetFromString(nsDiscriminatedUnion* data, const char *aValue);
|
||||
static nsresult SetFromWString(nsDiscriminatedUnion* data, const PRUnichar *aValue);
|
||||
static nsresult SetFromISupports(nsDiscriminatedUnion* data, nsISupports *aValue);
|
||||
static nsresult SetFromInterface(nsDiscriminatedUnion* data, const nsIID& iid, nsISupports *aValue);
|
||||
static nsresult SetFromArray(nsDiscriminatedUnion* data, PRUint16 type, PRUint32 count, void * aValue);
|
||||
static nsresult SetFromStringWithSize(nsDiscriminatedUnion* data, PRUint32 size, const char *aValue);
|
||||
static nsresult SetFromWStringWithSize(nsDiscriminatedUnion* data, PRUint32 size, const PRUnichar *aValue);
|
||||
|
||||
static nsresult SetToVoid(nsDiscriminatedUnion* data);
|
||||
static nsresult SetToEmpty(nsDiscriminatedUnion* data);
|
||||
|
||||
protected:
|
||||
nsDiscriminatedUnion mData;
|
||||
PRBool mWritable;
|
||||
};
|
||||
|
||||
/**
|
||||
* Users of nsIVariant should be using the contractID and not this CID.
|
||||
* - see NS_VARIANT_CONTRACTID in nsIVariant.idl.
|
||||
*/
|
||||
|
||||
#define NS_VARIANT_CID \
|
||||
{ /* 0D6EA1D0-879C-11d5-90EF-0010A4E73D9A */ \
|
||||
0xd6ea1d0, \
|
||||
0x879c, \
|
||||
0x11d5, \
|
||||
{0x90, 0xef, 0x0, 0x10, 0xa4, 0xe7, 0x3d, 0x9a}}
|
||||
|
||||
#define NS_VARIANT_CLASSNAME "Variant"
|
||||
|
Загрузка…
Ссылка в новой задаче