Bug 996785 - Use more descriptive IPDL types for CPOW value variants (r=mrbkap)
authorBill McCloskey <wmccloskey@mozilla.com>
Fri, 16 May 2014 16:40:36 -0700
changeset 183648 1e495c6dba19835297494eb2a128301fe9e55848
parent 183647 05fa4a69cb9818df96d82c9fc37fdad57ed85f68
child 183649 990ea6bcfa07a5ca68d6439f275a18c249f222c9
push id26799
push userphilringnalda@gmail.com
push dateSun, 18 May 2014 00:55:16 +0000
treeherdermozilla-central@00ef3a7d7aa7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs996785
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 996785 - Use more descriptive IPDL types for CPOW value variants (r=mrbkap)
js/ipc/JavaScriptShared.cpp
js/ipc/JavaScriptTypes.ipdlh
--- a/js/ipc/JavaScriptShared.cpp
+++ b/js/ipc/JavaScriptShared.cpp
@@ -168,47 +168,41 @@ JavaScriptShared::convertGeckoStringToId
     return JS_StringToId(cx, str, to);
 }
 
 bool
 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;
         }
 
         if (xpc_JSObjectIsID(cx, obj)) {
             JSIID iid;
             const nsID *id = xpc_JSObjectToID(cx, obj);
             ConvertID(*id, &iid);
             *to = iid;
             return true;
         }
 
         ObjectId id;
         if (!toId(cx, obj, &id))
             return false;
-        *to = uint64_t(id);
+        *to = ObjectVariant(id);
         return true;
       }
 
       case JSTYPE_STRING:
       {
         nsDependentJSString dep;
         if (!dep.init(cx, from))
             return false;
@@ -232,31 +226,31 @@ JavaScriptShared::toVariant(JSContext *c
         return false;
     }
 }
 
 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;
         }
 
         case JSVariant::Tdouble:
           to.set(JS_NumberValue(from.get_double()));
           return true;
 
         case JSVariant::Tbool:
--- a/js/ipc/JavaScriptTypes.ipdlh
+++ b/js/ipc/JavaScriptTypes.ipdlh
@@ -22,21 +22,30 @@ struct JSIID
     uint8_t m3_2;
     uint8_t m3_3;
     uint8_t m3_4;
     uint8_t m3_5;
     uint8_t m3_6;
     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 */
 };
 
 struct ReturnSuccess
 {
 };