Bug 996785 - Use more descriptive IPDL types for CPOW value variants (r=mrbkap)

This commit is contained in:
Bill McCloskey 2014-05-16 16:40:36 -07:00
parent 8da0418c4d
commit 7e6555161c
2 changed files with 25 additions and 22 deletions

View File

@ -173,22 +173,16 @@ JavaScriptShared::toVariant(JSContext *cx, JS::HandleValue from, JSVariant *to)
{
switch (JS_TypeOfValue(cx, from)) {
case JSTYPE_VOID:
*to = void_t();
*to = UndefinedVariant();
return true;
case JSTYPE_NULL:
{
*to = uint64_t(0);
return true;
}
case JSTYPE_OBJECT:
case JSTYPE_FUNCTION:
{
RootedObject obj(cx, from.toObjectOrNull());
if (!obj) {
MOZ_ASSERT(from == JSVAL_NULL);
*to = uint64_t(0);
*to = NullVariant();
return true;
}
@ -203,7 +197,7 @@ JavaScriptShared::toVariant(JSContext *cx, JS::HandleValue from, JSVariant *to)
ObjectId id;
if (!toId(cx, obj, &id))
return false;
*to = uint64_t(id);
*to = ObjectVariant(id);
return true;
}
@ -237,21 +231,21 @@ bool
JavaScriptShared::fromVariant(JSContext *cx, const JSVariant &from, MutableHandleValue to)
{
switch (from.type()) {
case JSVariant::Tvoid_t:
case JSVariant::TUndefinedVariant:
to.set(UndefinedValue());
return true;
case JSVariant::Tuint64_t:
case JSVariant::TNullVariant:
to.set(NullValue());
return true;
case JSVariant::TObjectVariant:
{
ObjectId id = from.get_uint64_t();
if (id) {
JSObject *obj = fromId(cx, id);
if (!obj)
return false;
to.set(ObjectValue(*obj));
} else {
to.set(JSVAL_NULL);
}
ObjectId id = from.get_ObjectVariant().id();
JSObject *obj = fromId(cx, id);
if (!obj)
return false;
to.set(ObjectValue(*obj));
return true;
}

View File

@ -27,11 +27,20 @@ struct JSIID
uint8_t m3_7;
};
struct ObjectVariant
{
uint64_t id;
};
struct UndefinedVariant {};
struct NullVariant {};
union JSVariant
{
void_t; /* |undefined| */
UndefinedVariant;
NullVariant;
ObjectVariant;
nsString; /* StringValue(x) */
uint64_t; /* ID that maps to a JSObject (cpow on parent, original on child). */
double; /* NumberValue(x) */
bool; /* BooleanValue(x) */
JSIID; /* XPC nsIID */