2014-04-03 15:58:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=99: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2001-10-10 03:42:22 +04:00
|
|
|
|
|
|
|
/* nsIVariant implementation for xpconnect. */
|
|
|
|
|
2014-07-11 11:38:55 +04:00
|
|
|
#include "mozilla/Range.h"
|
|
|
|
|
2001-10-10 03:42:22 +04:00
|
|
|
#include "xpcprivate.h"
|
|
|
|
|
2012-01-15 12:13:11 +04:00
|
|
|
#include "jsfriendapi.h"
|
2013-08-18 02:50:18 +04:00
|
|
|
#include "jsprf.h"
|
2013-09-10 01:14:10 +04:00
|
|
|
#include "jswrapper.h"
|
2012-01-11 12:23:08 +04:00
|
|
|
|
2013-04-17 19:38:44 +04:00
|
|
|
using namespace JS;
|
2013-06-05 08:11:19 +04:00
|
|
|
using namespace mozilla;
|
2013-04-17 19:38:44 +04:00
|
|
|
|
2013-10-11 00:35:53 +04:00
|
|
|
NS_IMPL_CLASSINFO(XPCVariant, nullptr, 0, XPCVARIANT_CID)
|
2007-04-25 20:35:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XPCVariant)
|
2007-02-18 23:05:32 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(XPCVariant)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIVariant)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_IMPL_QUERY_CLASSINFO(XPCVariant)
|
|
|
|
NS_INTERFACE_MAP_END
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(XPCVariant, XPCVariant, nsIVariant)
|
2007-02-18 23:05:32 +03:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(XPCVariant)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(XPCVariant)
|
2001-10-10 03:42:22 +04:00
|
|
|
|
2012-09-20 17:03:28 +04:00
|
|
|
XPCVariant::XPCVariant(JSContext* cx, jsval aJSVal)
|
2012-01-26 17:52:25 +04:00
|
|
|
: mJSVal(aJSVal), mCCGeneration(0)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
nsVariant::Initialize(&mData);
|
2014-01-29 14:01:33 +04:00
|
|
|
if (!mJSVal.isPrimitive()) {
|
2013-03-21 19:20:44 +04:00
|
|
|
// XXXbholley - The innerization here was from bug 638026. Blake says
|
|
|
|
// the basic problem was that we were storing the C++ inner but the JS
|
|
|
|
// outer, which meant that, after navigation, the JS inner could be
|
|
|
|
// collected, which would cause us to try to recreate the JS inner at
|
|
|
|
// some later point after teardown, which would crash. This is shouldn't
|
|
|
|
// be a problem anymore because SetParentToWindow will do the right
|
|
|
|
// thing, but I'm saving the cleanup here for another day. Blake thinks
|
|
|
|
// that we should just not store the WN if we're creating a variant for
|
|
|
|
// an outer window.
|
2014-01-29 14:01:33 +04:00
|
|
|
JS::RootedObject obj(cx, &mJSVal.toObject());
|
|
|
|
obj = JS_ObjectToInnerObject(cx, obj);
|
|
|
|
mJSVal = JS::ObjectValue(*obj);
|
2011-03-09 02:04:59 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
JSObject* unwrapped = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
|
2013-04-19 23:58:30 +04:00
|
|
|
mReturnRawObject = !(unwrapped && IS_WN_REFLECTOR(unwrapped));
|
2011-10-14 21:52:48 +04:00
|
|
|
} else
|
2011-11-26 14:05:59 +04:00
|
|
|
mReturnRawObject = false;
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
|
|
|
|
2007-06-02 19:11:52 +04:00
|
|
|
XPCTraceableVariant::~XPCTraceableVariant()
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
2011-02-16 23:47:08 +03:00
|
|
|
jsval val = GetJSValPreserveColor();
|
2007-06-02 19:11:52 +04:00
|
|
|
|
2014-04-29 03:01:30 +04:00
|
|
|
MOZ_ASSERT(val.isGCThing(), "Must be traceable or unlinked");
|
2011-02-16 23:47:08 +03:00
|
|
|
|
2014-07-11 11:38:55 +04:00
|
|
|
nsVariant::Cleanup(&mData);
|
2007-06-02 19:11:52 +04:00
|
|
|
|
2014-04-28 06:30:51 +04:00
|
|
|
if (!val.isNull())
|
2013-11-24 22:27:51 +04:00
|
|
|
RemoveFromRootSet();
|
2007-06-02 19:11:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void XPCTraceableVariant::TraceJS(JSTracer* trc)
|
|
|
|
{
|
2014-04-17 12:36:32 +04:00
|
|
|
MOZ_ASSERT(mJSVal.isMarkable());
|
2014-08-13 13:05:22 +04:00
|
|
|
JS_CallValueTracer(trc, &mJSVal, "XPCTraceableVariant::mJSVal");
|
2007-06-02 19:11:52 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(XPCVariant)
|
|
|
|
|
2007-02-18 23:05:32 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XPCVariant)
|
2012-05-11 19:46:26 +04:00
|
|
|
JS::Value val = tmp->GetJSValPreserveColor();
|
2014-12-05 20:38:34 +03:00
|
|
|
if (val.isObject()) {
|
2012-01-24 03:25:53 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mJSVal");
|
2014-12-05 20:38:34 +03:00
|
|
|
cb.NoteJSObject(&val.toObject());
|
2012-01-24 03:25:53 +04:00
|
|
|
}
|
2007-02-18 23:05:32 +03:00
|
|
|
|
|
|
|
nsVariant::Traverse(tmp->mData, cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2007-11-02 01:51:57 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
|
2012-05-11 19:46:26 +04:00
|
|
|
JS::Value val = tmp->GetJSValPreserveColor();
|
2011-02-16 23:47:08 +03:00
|
|
|
|
2008-01-13 21:21:08 +03:00
|
|
|
nsVariant::Cleanup(&tmp->mData);
|
|
|
|
|
2012-05-11 19:46:26 +04:00
|
|
|
if (val.isMarkable()) {
|
2015-03-29 01:22:11 +03:00
|
|
|
XPCTraceableVariant* v = static_cast<XPCTraceableVariant*>(tmp);
|
2013-11-24 22:27:51 +04:00
|
|
|
v->RemoveFromRootSet();
|
2007-11-02 01:51:57 +03:00
|
|
|
}
|
2012-05-11 19:46:26 +04:00
|
|
|
tmp->mJSVal = JS::NullValue();
|
2007-11-02 01:51:57 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-02-18 23:05:32 +03:00
|
|
|
|
2011-10-14 21:52:47 +04:00
|
|
|
// static
|
2014-02-05 07:29:58 +04:00
|
|
|
already_AddRefed<XPCVariant>
|
|
|
|
XPCVariant::newVariant(JSContext* cx, jsval aJSVal)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
2014-02-05 07:29:58 +04:00
|
|
|
nsRefPtr<XPCVariant> variant;
|
2007-06-02 19:11:52 +04:00
|
|
|
|
2014-04-17 12:36:32 +04:00
|
|
|
if (!aJSVal.isMarkable())
|
2012-09-20 17:03:28 +04:00
|
|
|
variant = new XPCVariant(cx, aJSVal);
|
2007-06-02 19:11:52 +04:00
|
|
|
else
|
2012-09-20 17:03:28 +04:00
|
|
|
variant = new XPCTraceableVariant(cx, aJSVal);
|
2007-06-02 19:11:52 +04:00
|
|
|
|
2014-02-05 09:01:19 +04:00
|
|
|
if (!variant->InitializeData(cx))
|
2014-02-05 07:29:58 +04:00
|
|
|
return nullptr;
|
2001-10-10 03:42:22 +04:00
|
|
|
|
2014-02-05 07:29:58 +04:00
|
|
|
return variant.forget();
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
|
|
|
|
2002-02-05 09:45:08 +03:00
|
|
|
// Helper class to give us a namespace for the table based code below.
|
|
|
|
class XPCArrayHomogenizer
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
tNull = 0 , // null value
|
|
|
|
tInt , // Integer
|
|
|
|
tDbl , // Double
|
|
|
|
tBool , // Boolean
|
|
|
|
tStr , // String
|
|
|
|
tID , // ID
|
|
|
|
tArr , // Array
|
|
|
|
tISup , // nsISupports (really just a plain JSObject)
|
|
|
|
tUnk , // Unknown. Used only for initial state.
|
|
|
|
|
|
|
|
tTypeCount , // Just a count for table dimensioning.
|
|
|
|
|
|
|
|
tVar , // nsVariant - last ditch if no other common type found.
|
2011-10-14 21:52:47 +04:00
|
|
|
tErr // No valid state or type has this value.
|
2002-02-05 09:45:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Table has tUnk as a state (column) but not as a type (row).
|
2009-05-16 03:14:17 +04:00
|
|
|
static const Type StateTable[tTypeCount][tTypeCount-1];
|
2002-02-05 09:45:08 +03:00
|
|
|
|
|
|
|
public:
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool GetTypeForArray(JSContext* cx, HandleObject array,
|
|
|
|
uint32_t length,
|
|
|
|
nsXPTType* resultType, nsID* resultID);
|
2002-02-05 09:45:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-10-14 21:52:47 +04:00
|
|
|
// Current state is the column down the side.
|
|
|
|
// Current type is the row along the top.
|
2002-02-05 09:45:08 +03:00
|
|
|
// New state is in the box at the intersection.
|
|
|
|
|
2011-10-14 21:52:47 +04:00
|
|
|
const XPCArrayHomogenizer::Type
|
2002-02-05 09:45:08 +03:00
|
|
|
XPCArrayHomogenizer::StateTable[tTypeCount][tTypeCount-1] = {
|
|
|
|
/* tNull,tInt ,tDbl ,tBool,tStr ,tID ,tArr ,tISup */
|
|
|
|
/* tNull */{tNull,tVar ,tVar ,tVar ,tStr ,tID ,tVar ,tISup },
|
|
|
|
/* tInt */{tVar ,tInt ,tDbl ,tVar ,tVar ,tVar ,tVar ,tVar },
|
|
|
|
/* tDbl */{tVar ,tDbl ,tDbl ,tVar ,tVar ,tVar ,tVar ,tVar },
|
|
|
|
/* tBool */{tVar ,tVar ,tVar ,tBool,tVar ,tVar ,tVar ,tVar },
|
|
|
|
/* tStr */{tStr ,tVar ,tVar ,tVar ,tStr ,tVar ,tVar ,tVar },
|
|
|
|
/* tID */{tID ,tVar ,tVar ,tVar ,tVar ,tID ,tVar ,tVar },
|
|
|
|
/* tArr */{tErr ,tErr ,tErr ,tErr ,tErr ,tErr ,tErr ,tErr },
|
|
|
|
/* tISup */{tISup,tVar ,tVar ,tVar ,tVar ,tVar ,tVar ,tISup },
|
|
|
|
/* tUnk */{tNull,tInt ,tDbl ,tBool,tStr ,tID ,tVar ,tISup }};
|
|
|
|
|
|
|
|
// static
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
2013-04-17 19:38:44 +04:00
|
|
|
XPCArrayHomogenizer::GetTypeForArray(JSContext* cx, HandleObject array,
|
2012-03-07 03:52:55 +04:00
|
|
|
uint32_t length,
|
2011-10-14 21:52:47 +04:00
|
|
|
nsXPTType* resultType, nsID* resultID)
|
2002-02-05 09:45:08 +03:00
|
|
|
{
|
|
|
|
Type state = tUnk;
|
|
|
|
Type type;
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedValue val(cx);
|
|
|
|
RootedObject jsobj(cx);
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2013-08-05 17:02:47 +04:00
|
|
|
if (!JS_GetElement(cx, array, i, &val))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2012-05-11 19:46:26 +04:00
|
|
|
if (val.isInt32()) {
|
2002-02-05 09:45:08 +03:00
|
|
|
type = tInt;
|
2012-05-11 19:46:26 +04:00
|
|
|
} else if (val.isDouble()) {
|
2002-02-05 09:45:08 +03:00
|
|
|
type = tDbl;
|
2012-05-11 19:46:26 +04:00
|
|
|
} else if (val.isBoolean()) {
|
2002-02-05 09:45:08 +03:00
|
|
|
type = tBool;
|
2015-04-17 17:30:34 +03:00
|
|
|
} else if (val.isUndefined() || val.isSymbol()) {
|
2002-02-05 09:45:08 +03:00
|
|
|
state = tVar;
|
|
|
|
break;
|
2012-05-11 19:46:26 +04:00
|
|
|
} else if (val.isNull()) {
|
2002-02-05 09:45:08 +03:00
|
|
|
type = tNull;
|
2012-05-11 19:46:26 +04:00
|
|
|
} else if (val.isString()) {
|
2002-02-05 09:45:08 +03:00
|
|
|
type = tStr;
|
2012-05-11 19:46:26 +04:00
|
|
|
} else {
|
2013-08-14 11:00:34 +04:00
|
|
|
MOZ_ASSERT(val.isObject(), "invalid type of jsval!");
|
2013-04-17 19:38:44 +04:00
|
|
|
jsobj = &val.toObject();
|
2012-09-20 17:03:28 +04:00
|
|
|
if (JS_IsArrayObject(cx, jsobj))
|
2002-02-05 09:45:08 +03:00
|
|
|
type = tArr;
|
2012-09-20 17:03:28 +04:00
|
|
|
else if (xpc_JSObjectIsID(cx, jsobj))
|
2002-02-05 09:45:08 +03:00
|
|
|
type = tID;
|
|
|
|
else
|
|
|
|
type = tISup;
|
|
|
|
}
|
|
|
|
|
2013-08-14 11:00:34 +04:00
|
|
|
MOZ_ASSERT(state != tErr, "bad state table!");
|
|
|
|
MOZ_ASSERT(type != tErr, "bad type!");
|
|
|
|
MOZ_ASSERT(type != tVar, "bad type!");
|
|
|
|
MOZ_ASSERT(type != tUnk, "bad type!");
|
2002-02-05 09:45:08 +03:00
|
|
|
|
|
|
|
state = StateTable[state][type];
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2013-08-14 11:00:34 +04:00
|
|
|
MOZ_ASSERT(state != tErr, "bad state table!");
|
|
|
|
MOZ_ASSERT(state != tUnk, "bad state table!");
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2011-10-14 21:52:48 +04:00
|
|
|
if (state == tVar)
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-14 21:52:48 +04:00
|
|
|
switch (state) {
|
2011-10-14 21:52:47 +04:00
|
|
|
case tInt :
|
2012-01-02 22:05:19 +04:00
|
|
|
*resultType = nsXPTType((uint8_t)TD_INT32);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
2011-10-14 21:52:47 +04:00
|
|
|
case tDbl :
|
2012-01-02 22:05:19 +04:00
|
|
|
*resultType = nsXPTType((uint8_t)TD_DOUBLE);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
|
|
|
case tBool:
|
2012-01-02 22:05:19 +04:00
|
|
|
*resultType = nsXPTType((uint8_t)TD_BOOL);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
2011-10-14 21:52:47 +04:00
|
|
|
case tStr :
|
2012-01-02 22:05:19 +04:00
|
|
|
*resultType = nsXPTType((uint8_t)TD_PWSTRING);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
2011-10-14 21:52:47 +04:00
|
|
|
case tID :
|
2012-01-02 22:05:19 +04:00
|
|
|
*resultType = nsXPTType((uint8_t)TD_PNSIID);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
2011-10-14 21:52:47 +04:00
|
|
|
case tISup:
|
2012-01-02 22:05:19 +04:00
|
|
|
*resultType = nsXPTType((uint8_t)TD_INTERFACE_IS_TYPE);
|
2002-02-05 09:45:08 +03:00
|
|
|
*resultID = NS_GET_IID(nsISupports);
|
|
|
|
break;
|
2011-10-14 21:52:47 +04:00
|
|
|
case tNull:
|
2002-02-05 09:45:08 +03:00
|
|
|
// FALL THROUGH
|
|
|
|
case tVar :
|
2012-01-02 22:05:19 +04:00
|
|
|
*resultType = nsXPTType((uint8_t)TD_INTERFACE_IS_TYPE);
|
2002-02-05 09:45:08 +03:00
|
|
|
*resultID = NS_GET_IID(nsIVariant);
|
|
|
|
break;
|
2011-10-14 21:52:47 +04:00
|
|
|
case tArr :
|
2002-02-05 09:45:08 +03:00
|
|
|
// FALL THROUGH
|
2011-10-14 21:52:47 +04:00
|
|
|
case tUnk :
|
2002-02-05 09:45:08 +03:00
|
|
|
// FALL THROUGH
|
2011-10-14 21:52:47 +04:00
|
|
|
case tErr :
|
2002-02-05 09:45:08 +03:00
|
|
|
// FALL THROUGH
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad state");
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2002-02-05 09:45:08 +03:00
|
|
|
}
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2002-02-05 09:45:08 +03:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool XPCVariant::InitializeData(JSContext* cx)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
2012-09-20 17:03:28 +04:00
|
|
|
JS_CHECK_RECURSION(cx, return false);
|
2010-08-24 17:50:15 +04:00
|
|
|
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedValue val(cx, GetJSVal());
|
2012-05-11 19:46:26 +04:00
|
|
|
|
|
|
|
if (val.isInt32())
|
|
|
|
return NS_SUCCEEDED(nsVariant::SetFromInt32(&mData, val.toInt32()));
|
|
|
|
if (val.isDouble())
|
|
|
|
return NS_SUCCEEDED(nsVariant::SetFromDouble(&mData, val.toDouble()));
|
|
|
|
if (val.isBoolean())
|
|
|
|
return NS_SUCCEEDED(nsVariant::SetFromBool(&mData, val.toBoolean()));
|
2015-04-17 17:30:34 +03:00
|
|
|
// We can't represent symbol on C++ side, so pretend it is void.
|
|
|
|
if (val.isUndefined() || val.isSymbol())
|
2006-06-14 20:41:29 +04:00
|
|
|
return NS_SUCCEEDED(nsVariant::SetToVoid(&mData));
|
2012-05-11 19:46:26 +04:00
|
|
|
if (val.isNull())
|
2001-10-10 03:42:22 +04:00
|
|
|
return NS_SUCCEEDED(nsVariant::SetToEmpty(&mData));
|
2012-05-11 19:46:26 +04:00
|
|
|
if (val.isString()) {
|
|
|
|
JSString* str = val.toString();
|
2012-08-25 02:00:38 +04:00
|
|
|
if (!str)
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2006-09-24 20:44:51 +04:00
|
|
|
|
2013-08-14 11:00:34 +04:00
|
|
|
MOZ_ASSERT(mData.mType == nsIDataType::VTYPE_EMPTY,
|
|
|
|
"Why do we already have data?");
|
2006-09-24 20:44:51 +04:00
|
|
|
|
2014-07-11 11:38:55 +04:00
|
|
|
size_t length = JS_GetStringLength(str);
|
|
|
|
if (!NS_SUCCEEDED(nsVariant::AllocateWStringWithSize(&mData, length)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2010-12-03 11:24:17 +03:00
|
|
|
|
2014-07-22 08:43:21 +04:00
|
|
|
mozilla::Range<char16_t> destChars(mData.u.wstr.mWStringValue, length);
|
2014-07-11 11:38:55 +04:00
|
|
|
if (!JS_CopyStringChars(cx, destChars, str))
|
|
|
|
return false;
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2014-07-11 11:38:55 +04:00
|
|
|
MOZ_ASSERT(mData.u.wstr.mWStringValue[length] == '\0');
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// leaving only JSObject...
|
2013-08-14 11:00:34 +04:00
|
|
|
MOZ_ASSERT(val.isObject(), "invalid type of jsval!");
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedObject jsobj(cx, &val.toObject());
|
2001-10-10 03:42:22 +04:00
|
|
|
|
2002-02-05 09:45:08 +03:00
|
|
|
// Let's see if it is a xpcJSID.
|
2001-10-10 03:42:22 +04:00
|
|
|
|
2012-09-20 17:03:28 +04:00
|
|
|
const nsID* id = xpc_JSObjectToID(cx, jsobj);
|
2011-10-14 21:52:48 +04:00
|
|
|
if (id)
|
2008-01-12 07:30:42 +03:00
|
|
|
return NS_SUCCEEDED(nsVariant::SetFromID(&mData, *id));
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2002-02-05 09:45:08 +03:00
|
|
|
// Let's see if it is a js array object.
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t len;
|
2002-02-05 09:45:08 +03:00
|
|
|
|
2012-09-20 17:03:28 +04:00
|
|
|
if (JS_IsArrayObject(cx, jsobj) && JS_GetArrayLength(cx, jsobj, &len)) {
|
2011-10-14 21:52:48 +04:00
|
|
|
if (!len) {
|
2002-03-22 02:21:54 +03:00
|
|
|
// Zero length array
|
|
|
|
nsVariant::SetToEmptyArray(&mData);
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2002-03-22 02:21:54 +03:00
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2002-02-05 09:45:08 +03:00
|
|
|
nsXPTType type;
|
|
|
|
nsID id;
|
|
|
|
|
2012-09-20 17:03:28 +04:00
|
|
|
if (!XPCArrayHomogenizer::GetTypeForArray(cx, jsobj, len, &type, &id))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2002-02-05 09:45:08 +03:00
|
|
|
|
2013-06-05 08:11:19 +04:00
|
|
|
if (!XPCConvert::JSArray2Native(&mData.u.array.mArrayValue,
|
2012-07-30 18:20:58 +04:00
|
|
|
val, len, type, &id, nullptr))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2002-02-05 09:45:08 +03:00
|
|
|
|
|
|
|
mData.mType = nsIDataType::VTYPE_ARRAY;
|
2011-10-14 21:52:48 +04:00
|
|
|
if (type.IsInterfacePointer())
|
2002-02-05 09:45:08 +03:00
|
|
|
mData.u.array.mArrayInterfaceID = id;
|
|
|
|
mData.u.array.mArrayCount = len;
|
|
|
|
mData.u.array.mArrayType = type.TagPart();
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2011-10-14 21:52:47 +04:00
|
|
|
}
|
2002-02-05 09:45:08 +03:00
|
|
|
|
2001-10-10 03:42:22 +04:00
|
|
|
// XXX This could be smarter and pick some more interesting iface.
|
|
|
|
|
2013-05-17 09:49:41 +04:00
|
|
|
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
2001-10-10 03:42:22 +04:00
|
|
|
nsCOMPtr<nsISupports> wrapper;
|
|
|
|
const nsIID& iid = NS_GET_IID(nsISupports);
|
|
|
|
|
2013-05-17 09:49:41 +04:00
|
|
|
return NS_SUCCEEDED(xpc->WrapJS(cx, jsobj,
|
2011-10-14 21:52:48 +04:00
|
|
|
iid, getter_AddRefs(wrapper))) &&
|
2001-10-10 03:42:22 +04:00
|
|
|
NS_SUCCEEDED(nsVariant::SetFromInterface(&mData, iid, wrapper));
|
|
|
|
}
|
|
|
|
|
2009-09-01 20:45:05 +04:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 21:39:36 +04:00
|
|
|
XPCVariant::GetAsJSVal(MutableHandleValue result)
|
2009-09-01 20:45:05 +04:00
|
|
|
{
|
2014-01-09 21:39:36 +04:00
|
|
|
result.set(GetJSVal());
|
2009-09-01 20:45:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-14 21:52:47 +04:00
|
|
|
// static
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
2013-06-05 08:11:19 +04:00
|
|
|
XPCVariant::VariantDataToJS(nsIVariant* variant,
|
2013-10-12 09:02:39 +04:00
|
|
|
nsresult* pErr, MutableHandleValue pJSVal)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
// Get the type early because we might need to spoof it below.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t type;
|
2009-09-01 20:45:05 +04:00
|
|
|
if (NS_FAILED(variant->GetDataType(&type)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2001-10-10 03:42:22 +04:00
|
|
|
|
2013-06-05 08:11:19 +04:00
|
|
|
AutoJSContext cx;
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedValue realVal(cx);
|
2014-01-09 21:39:36 +04:00
|
|
|
nsresult rv = variant->GetAsJSVal(&realVal);
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2011-10-14 21:52:48 +04:00
|
|
|
if (NS_SUCCEEDED(rv) &&
|
2014-04-28 07:27:54 +04:00
|
|
|
(realVal.isPrimitive() ||
|
2011-10-14 21:52:48 +04:00
|
|
|
type == nsIDataType::VTYPE_ARRAY ||
|
|
|
|
type == nsIDataType::VTYPE_EMPTY_ARRAY ||
|
2011-10-14 21:52:48 +04:00
|
|
|
type == nsIDataType::VTYPE_ID)) {
|
2013-10-26 20:19:05 +04:00
|
|
|
if (!JS_WrapValue(cx, &realVal))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-10-12 09:02:39 +04:00
|
|
|
pJSVal.set(realVal);
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2009-09-01 20:45:05 +04:00
|
|
|
}
|
2010-01-30 05:50:46 +03:00
|
|
|
|
2009-09-01 20:45:05 +04:00
|
|
|
nsCOMPtr<XPCVariant> xpcvariant = do_QueryInterface(variant);
|
2011-10-14 21:52:48 +04:00
|
|
|
if (xpcvariant && xpcvariant->mReturnRawObject) {
|
2013-08-14 11:00:34 +04:00
|
|
|
MOZ_ASSERT(type == nsIDataType::VTYPE_INTERFACE ||
|
|
|
|
type == nsIDataType::VTYPE_INTERFACE_IS,
|
|
|
|
"Weird variant");
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2013-10-26 20:19:05 +04:00
|
|
|
if (!JS_WrapValue(cx, &realVal))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-10-12 09:02:39 +04:00
|
|
|
pJSVal.set(realVal);
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
|
|
|
|
2011-10-14 21:52:47 +04:00
|
|
|
// else, it's an object and we really need to double wrap it if we've
|
2010-06-24 02:09:00 +04:00
|
|
|
// 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.
|
|
|
|
|
2001-10-10 03:42:22 +04:00
|
|
|
// The nsIVariant is not a XPCVariant (or we act like it isn't).
|
|
|
|
// So we extract the data and do the Right Thing.
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2001-10-10 03:42:22 +04:00
|
|
|
// We ASSUME that the variant implementation can do these conversions...
|
|
|
|
|
|
|
|
nsID iid;
|
|
|
|
|
2011-10-14 21:52:48 +04:00
|
|
|
switch (type) {
|
2011-10-14 21:52:47 +04:00
|
|
|
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:
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
2013-05-09 13:39:21 +04:00
|
|
|
double d;
|
|
|
|
if (NS_FAILED(variant->GetAsDouble(&d)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-10-12 09:02:39 +04:00
|
|
|
pJSVal.setNumber(d);
|
2012-08-02 04:59:47 +04:00
|
|
|
return true;
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_BOOL:
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
2013-05-09 13:39:21 +04:00
|
|
|
bool b;
|
|
|
|
if (NS_FAILED(variant->GetAsBool(&b)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-10-12 09:02:39 +04:00
|
|
|
pJSVal.setBoolean(b);
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_CHAR:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
if (NS_FAILED(variant->GetAsChar(&c)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-06-05 08:11:19 +04:00
|
|
|
return XPCConvert::NativeData2JS(pJSVal, (const void*)&c, TD_CHAR, &iid, pErr);
|
2013-05-09 13:39:21 +04:00
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t wc;
|
2013-05-09 13:39:21 +04:00
|
|
|
if (NS_FAILED(variant->GetAsWChar(&wc)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-06-05 08:11:19 +04:00
|
|
|
return XPCConvert::NativeData2JS(pJSVal, (const void*)&wc, TD_WCHAR, &iid, pErr);
|
2013-05-09 13:39:21 +04:00
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_ID:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
2011-10-14 21:52:48 +04:00
|
|
|
if (NS_FAILED(variant->GetAsID(&iid)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2015-03-29 01:22:11 +03:00
|
|
|
nsID* v = &iid;
|
2013-06-05 08:11:19 +04:00
|
|
|
return XPCConvert::NativeData2JS(pJSVal, (const void*)&v, TD_PNSIID, &iid, pErr);
|
2013-05-09 13:39:21 +04:00
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
|
|
|
nsAutoString astring;
|
2011-10-14 21:52:48 +04:00
|
|
|
if (NS_FAILED(variant->GetAsAString(astring)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2015-03-29 01:22:11 +03:00
|
|
|
nsAutoString* v = &astring;
|
2013-06-05 08:11:19 +04:00
|
|
|
return XPCConvert::NativeData2JS(pJSVal, (const void*)&v, TD_ASTRING, &iid, pErr);
|
2013-05-09 13:39:21 +04:00
|
|
|
}
|
2002-03-05 05:22:02 +03:00
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
|
|
|
nsAutoString astring;
|
2011-10-14 21:52:48 +04:00
|
|
|
if (NS_FAILED(variant->GetAsAString(astring)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2015-03-29 01:22:11 +03:00
|
|
|
nsAutoString* v = &astring;
|
2013-06-05 08:11:19 +04:00
|
|
|
return XPCConvert::NativeData2JS(pJSVal, (const void*)&v,
|
2013-05-09 13:39:21 +04:00
|
|
|
TD_DOMSTRING, &iid, pErr);
|
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
|
|
|
nsAutoCString cString;
|
2011-10-14 21:52:48 +04:00
|
|
|
if (NS_FAILED(variant->GetAsACString(cString)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2015-03-29 01:22:11 +03:00
|
|
|
nsAutoCString* v = &cString;
|
2013-06-05 08:11:19 +04:00
|
|
|
return XPCConvert::NativeData2JS(pJSVal, (const void*)&v,
|
2013-05-09 13:39:21 +04:00
|
|
|
TD_CSTRING, &iid, pErr);
|
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
|
|
|
nsUTF8String utf8String;
|
2011-10-14 21:52:48 +04:00
|
|
|
if (NS_FAILED(variant->GetAsAUTF8String(utf8String)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2015-03-29 01:22:11 +03:00
|
|
|
nsUTF8String* v = &utf8String;
|
2013-06-05 08:11:19 +04:00
|
|
|
return XPCConvert::NativeData2JS(pJSVal, (const void*)&v,
|
2013-05-09 13:39:21 +04:00
|
|
|
TD_UTF8STRING, &iid, pErr);
|
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
char* pc;
|
2013-05-09 13:39:21 +04:00
|
|
|
if (NS_FAILED(variant->GetAsString(&pc)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-06-05 08:11:19 +04:00
|
|
|
bool success = XPCConvert::NativeData2JS(pJSVal, (const void*)&pc,
|
2013-05-09 13:39:21 +04:00
|
|
|
TD_PSTRING, &iid, pErr);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(pc);
|
2013-05-09 13:39:21 +04:00
|
|
|
return success;
|
|
|
|
}
|
2001-11-01 04:15:53 +03:00
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
char* pc;
|
2013-05-09 13:39:21 +04:00
|
|
|
uint32_t size;
|
|
|
|
if (NS_FAILED(variant->GetAsStringWithSize(&size, &pc)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-06-05 08:11:19 +04:00
|
|
|
bool success = XPCConvert::NativeStringWithSize2JS(pJSVal, (const void*)&pc,
|
2013-05-09 13:39:21 +04:00
|
|
|
TD_PSTRING_SIZE_IS, size, pErr);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(pc);
|
2013-05-09 13:39:21 +04:00
|
|
|
return success;
|
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
char16_t* pwc;
|
2013-05-09 13:39:21 +04:00
|
|
|
if (NS_FAILED(variant->GetAsWString(&pwc)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-06-05 08:11:19 +04:00
|
|
|
bool success = XPCConvert::NativeData2JS(pJSVal, (const void*)&pwc,
|
2013-05-09 13:39:21 +04:00
|
|
|
TD_PSTRING, &iid, pErr);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(pwc);
|
2013-05-09 13:39:21 +04:00
|
|
|
return success;
|
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
2013-05-09 13:39:21 +04:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
char16_t* pwc;
|
2013-05-09 13:39:21 +04:00
|
|
|
uint32_t size;
|
|
|
|
if (NS_FAILED(variant->GetAsWStringWithSize(&size, &pwc)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-06-05 08:11:19 +04:00
|
|
|
bool success = XPCConvert::NativeStringWithSize2JS(pJSVal, (const void*)&pwc,
|
2013-05-09 13:39:21 +04:00
|
|
|
TD_PWSTRING_SIZE_IS, size, pErr);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(pwc);
|
2013-05-09 13:39:21 +04:00
|
|
|
return success;
|
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
nsISupports* pi;
|
2001-10-10 03:42:22 +04:00
|
|
|
nsID* piid;
|
2015-03-29 01:22:11 +03:00
|
|
|
if (NS_FAILED(variant->GetAsInterface(&piid, (void**)&pi)))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2001-10-10 03:42:22 +04:00
|
|
|
|
|
|
|
iid = *piid;
|
2015-03-27 03:01:12 +03:00
|
|
|
free((char*)piid);
|
2001-10-10 03:42:22 +04:00
|
|
|
|
2013-06-05 08:11:19 +04:00
|
|
|
bool success = XPCConvert::NativeData2JS(pJSVal, (const void*)&pi,
|
2013-05-09 13:39:21 +04:00
|
|
|
TD_INTERFACE_IS_TYPE, &iid, pErr);
|
|
|
|
if (pi)
|
|
|
|
pi->Release();
|
|
|
|
return success;
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
2002-02-05 09:45:08 +03:00
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
|
|
|
{
|
|
|
|
nsDiscriminatedUnion du;
|
|
|
|
nsVariant::Initialize(&du);
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = variant->GetAsArray(&du.u.array.mArrayType,
|
|
|
|
&du.u.array.mArrayInterfaceID,
|
|
|
|
&du.u.array.mArrayCount,
|
|
|
|
&du.u.array.mArrayValue);
|
2011-10-14 21:52:48 +04:00
|
|
|
if (NS_FAILED(rv))
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2011-10-14 21:52:47 +04:00
|
|
|
|
2002-02-05 09:45:08 +03:00
|
|
|
// must exit via VARIANT_DONE from here on...
|
|
|
|
du.mType = nsIDataType::VTYPE_ARRAY;
|
|
|
|
|
|
|
|
nsXPTType conversionType;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t elementType = du.u.array.mArrayType;
|
2012-07-30 18:20:58 +04:00
|
|
|
const nsID* pid = nullptr;
|
2002-02-05 09:45:08 +03:00
|
|
|
|
2011-10-14 21:52:48 +04:00
|
|
|
switch (elementType) {
|
2011-10-14 21:52:47 +04:00
|
|
|
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:
|
2012-01-02 22:05:19 +04:00
|
|
|
conversionType = nsXPTType((uint8_t)elementType);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
|
|
|
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_ID:
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
2012-01-02 22:05:19 +04:00
|
|
|
conversionType = nsXPTType((uint8_t)elementType);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
|
|
|
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
2002-02-05 09:45:08 +03:00
|
|
|
pid = &NS_GET_IID(nsISupports);
|
2012-01-02 22:05:19 +04:00
|
|
|
conversionType = nsXPTType((uint8_t)elementType);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
|
|
|
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
2002-02-05 09:45:08 +03:00
|
|
|
pid = &du.u.array.mArrayInterfaceID;
|
2012-01-02 22:05:19 +04:00
|
|
|
conversionType = nsXPTType((uint8_t)elementType);
|
2002-02-05 09:45:08 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
// The rest are illegal.
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_VOID:
|
|
|
|
case nsIDataType::VTYPE_ASTRING:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
2002-02-05 09:45:08 +03:00
|
|
|
case nsIDataType::VTYPE_ARRAY:
|
2002-03-22 02:21:54 +03:00
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
2002-02-05 09:45:08 +03:00
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad type in array!");
|
2015-03-18 21:36:04 +03:00
|
|
|
nsVariant::Cleanup(&du);
|
|
|
|
return false;
|
2002-02-05 09:45:08 +03:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:36:04 +03:00
|
|
|
bool success =
|
2013-06-05 08:11:19 +04:00
|
|
|
XPCConvert::NativeArray2JS(pJSVal,
|
2002-02-05 09:45:08 +03:00
|
|
|
(const void**)&du.u.array.mArrayValue,
|
|
|
|
conversionType, pid,
|
2011-02-05 15:56:05 +03:00
|
|
|
du.u.array.mArrayCount, pErr);
|
2002-02-05 09:45:08 +03:00
|
|
|
|
|
|
|
nsVariant::Cleanup(&du);
|
|
|
|
return success;
|
2011-10-14 21:52:47 +04:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_EMPTY_ARRAY:
|
2002-03-22 02:21:54 +03:00
|
|
|
{
|
2014-02-12 14:50:46 +04:00
|
|
|
JSObject* array = JS_NewArrayObject(cx, 0);
|
2011-10-14 21:52:48 +04:00
|
|
|
if (!array)
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2013-10-12 09:02:39 +04:00
|
|
|
pJSVal.setObject(*array);
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2002-03-22 02:21:54 +03:00
|
|
|
}
|
2011-10-14 21:52:47 +04:00
|
|
|
case nsIDataType::VTYPE_VOID:
|
2013-10-12 09:02:39 +04:00
|
|
|
pJSVal.setUndefined();
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2006-06-14 20:41:29 +04:00
|
|
|
case nsIDataType::VTYPE_EMPTY:
|
2013-10-12 09:02:39 +04:00
|
|
|
pJSVal.setNull();
|
2011-11-26 14:05:59 +04:00
|
|
|
return true;
|
2001-10-10 03:42:22 +04:00
|
|
|
default:
|
|
|
|
NS_ERROR("bad type in variant!");
|
2011-11-26 14:05:59 +04:00
|
|
|
return false;
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
// XXX These default implementations need to be improved to allow for
|
|
|
|
// some more interesting conversions.
|
|
|
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* readonly attribute uint16_t dataType; */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetDataType(uint16_t* aDataType)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
*aDataType = mData.mType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* uint8_t getAsInt8 (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsInt8(uint8_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToInt8(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* int16_t getAsInt16 (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsInt16(int16_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToInt16(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* int32_t getAsInt32 (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsInt32(int32_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToInt32(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* int64_t getAsInt64 (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsInt64(int64_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToInt64(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* uint8_t getAsUint8 (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsUint8(uint8_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToUint8(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* uint16_t getAsUint16 (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsUint16(uint16_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToUint16(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* uint32_t getAsUint32 (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsUint32(uint32_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToUint32(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* uint64_t getAsUint64 (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsUint64(uint64_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToUint64(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* float getAsFloat (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsFloat(float* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToFloat(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* double getAsDouble (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsDouble(double* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToDouble(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* bool getAsBool (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsBool(bool* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToBool(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* char getAsChar (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsChar(char* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToChar(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wchar getAsWChar (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsWChar(char16_t* _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToWChar(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [notxpcom] nsresult getAsID (out nsID retval); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP_(nsresult) XPCVariant::GetAsID(nsID* retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToID(mData, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AString getAsAString (); */
|
2002-03-24 03:16:18 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsAString(nsAString & _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToAString(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2002-03-05 05:22:02 +03:00
|
|
|
/* DOMString getAsDOMString (); */
|
2002-03-24 03:16:18 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsDOMString(nsAString & _retval)
|
2002-03-05 05:22:02 +03:00
|
|
|
{
|
|
|
|
// A DOMString maps to an AString internally, so we can re-use
|
|
|
|
// ConvertToAString here.
|
|
|
|
return nsVariant::ConvertToAString(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ACString getAsACString (); */
|
|
|
|
NS_IMETHODIMP XPCVariant::GetAsACString(nsACString & _retval)
|
|
|
|
{
|
|
|
|
return nsVariant::ConvertToACString(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AUTF8String getAsAUTF8String (); */
|
|
|
|
NS_IMETHODIMP XPCVariant::GetAsAUTF8String(nsAUTF8String & _retval)
|
|
|
|
{
|
|
|
|
return nsVariant::ConvertToAUTF8String(mData, _retval);
|
|
|
|
}
|
|
|
|
|
2001-10-10 03:42:22 +04:00
|
|
|
/* string getAsString (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsString(char** _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToString(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wstring getAsWString (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsWString(char16_t** _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToWString(mData, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsISupports getAsISupports (); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsISupports(nsISupports** _retval)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-10-13 00:29:19 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* [notxpcom] nsresult getAsArray (out uint16_t type, out nsIID iid, out uint32_t count, out voidPtr ptr); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP_(nsresult) XPCVariant::GetAsArray(uint16_t* type, nsIID* iid, uint32_t* count, void * *ptr)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
2001-10-13 00:29:19 +04:00
|
|
|
return nsVariant::ConvertToArray(mData, type, iid, count, ptr);
|
2001-10-10 03:42:22 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* void getAsStringWithSize (out uint32_t size, [size_is (size), retval] out string str); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsStringWithSize(uint32_t* size, char** str)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToStringWithSize(mData, size, str);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* void getAsWStringWithSize (out uint32_t size, [size_is (size), retval] out wstring str); */
|
2015-03-29 01:22:11 +03:00
|
|
|
NS_IMETHODIMP XPCVariant::GetAsWStringWithSize(uint32_t* size, char16_t** str)
|
2001-10-10 03:42:22 +04:00
|
|
|
{
|
|
|
|
return nsVariant::ConvertToWStringWithSize(mData, size, str);
|
|
|
|
}
|