Bug 1475409 - Part 2: Be more explicit about the type of nsXPTType::Tag(), r=mccr8
☠☠ backed out by 113e9ca0b5bc ☠ ☠
authorNika Layzell <nika@thelayzells.com>
Wed, 11 Jul 2018 11:02:32 -0400
changeset 428505 bddd838d19102d55d131a62158d8cb4b5c637284
parent 428504 850f21ca1f451ff48acb72f79c2c316d90fe9c07
child 428506 9f14f7b8bc3d6354ebd0baa922fdae6152f4df37
push id34337
push userncsoregi@mozilla.com
push dateThu, 26 Jul 2018 21:58:45 +0000
treeherdermozilla-central@8f2f847b2f9d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1475409
milestone63.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 1475409 - Part 2: Be more explicit about the type of nsXPTType::Tag(), r=mccr8 This will get us both more clarity as to what types are, but also will improve switch exhaustiveness checks. Summary: Depends On D2113 Reviewers: mccr8! Tags: #secure-revision Bug #: 1475409 Differential Revision: https://phabricator.services.mozilla.com/D2114
js/xpconnect/src/XPCConvert.cpp
xpcom/reflect/xptinfo/xptinfo.h
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -1623,16 +1623,23 @@ xpc::InnerCleanupValue(const nsXPTType& 
             sequence->Clear();
             break;
         }
 
         // Clear the JS::Value to `undefined`
         case nsXPTType::T_JSVAL:
             ((JS::Value*)aValue)->setUndefined();
             break;
+
+        // Non-arithmetic types requiring no cleanup
+        case nsXPTType::T_VOID:
+            break;
+
+        default:
+            MOZ_CRASH("Unknown Type!");
     }
 
     // Null out the pointer if we have it.
     if (aType.HasPointerRepr()) {
         *(void**)aValue = nullptr;
     }
 }
 
--- a/xpcom/reflect/xptinfo/xptinfo.h
+++ b/xpcom/reflect/xptinfo/xptinfo.h
@@ -193,19 +193,17 @@ enum nsXPTTypeTag : uint8_t
  * A nsXPTType is a union used to identify the type of a method argument or
  * return value. The internal data is stored as an 5-bit tag, and two 8-bit
  * integers, to keep alignment requirements low.
  *
  * nsXPTType contains 3 extra bits, reserved for use by nsXPTParamInfo.
  */
 struct nsXPTType
 {
-  // NOTE: This is uint8_t instead of nsXPTTypeTag so that it can be compared
-  // with the nsXPTType::* re-exports.
-  uint8_t Tag() const { return mTag; }
+  nsXPTTypeTag Tag() const { return static_cast<nsXPTTypeTag>(mTag); }
 
   // The index in the function argument list which should be used when
   // determining the iid_is or size_is properties of this dependent type.
   uint8_t ArgNum() const {
     MOZ_ASSERT(Tag() == TD_INTERFACE_IS_TYPE ||
                Tag() == TD_PSTRING_SIZE_IS ||
                Tag() == TD_PWSTRING_SIZE_IS ||
                Tag() == TD_ARRAY);
@@ -316,52 +314,51 @@ public:
     MOZ_ASSERT(aInner <= Idx::INTERFACE_IS_TYPE);
     return xpt::detail::GetType((uint8_t)aInner);
   }
 
   ///////////////////////////////////////
   // nsXPTType backwards compatibility //
   ///////////////////////////////////////
 
-  nsXPTType& operator=(uint8_t aPrefix) { mTag = aPrefix; return *this; }
-  operator uint8_t() const { return mTag; };
+  nsXPTType& operator=(nsXPTTypeTag aPrefix) { mTag = aPrefix; return *this; }
+  operator nsXPTTypeTag() const { return Tag(); }
 
-  enum // Re-export TD_ interfaces from nsXPTType
-  {
-    T_I8                = TD_INT8             ,
-    T_I16               = TD_INT16            ,
-    T_I32               = TD_INT32            ,
-    T_I64               = TD_INT64            ,
-    T_U8                = TD_UINT8            ,
-    T_U16               = TD_UINT16           ,
-    T_U32               = TD_UINT32           ,
-    T_U64               = TD_UINT64           ,
-    T_FLOAT             = TD_FLOAT            ,
-    T_DOUBLE            = TD_DOUBLE           ,
-    T_BOOL              = TD_BOOL             ,
-    T_CHAR              = TD_CHAR             ,
-    T_WCHAR             = TD_WCHAR            ,
-    T_VOID              = TD_VOID             ,
-    T_IID               = TD_PNSIID           ,
-    T_DOMSTRING         = TD_DOMSTRING        ,
-    T_CHAR_STR          = TD_PSTRING          ,
-    T_WCHAR_STR         = TD_PWSTRING         ,
-    T_INTERFACE         = TD_INTERFACE_TYPE   ,
-    T_INTERFACE_IS      = TD_INTERFACE_IS_TYPE,
-    T_ARRAY             = TD_ARRAY            ,
-    T_PSTRING_SIZE_IS   = TD_PSTRING_SIZE_IS  ,
-    T_PWSTRING_SIZE_IS  = TD_PWSTRING_SIZE_IS ,
-    T_UTF8STRING        = TD_UTF8STRING       ,
-    T_CSTRING           = TD_CSTRING          ,
-    T_ASTRING           = TD_ASTRING          ,
-    T_JSVAL             = TD_JSVAL            ,
-    T_DOMOBJECT         = TD_DOMOBJECT        ,
-    T_PROMISE           = TD_PROMISE          ,
-    T_SEQUENCE          = TD_SEQUENCE
-  };
+#define TD_ALIAS_(name_, value_) static constexpr nsXPTTypeTag name_ = value_
+  TD_ALIAS_(T_I8                , TD_INT8             );
+  TD_ALIAS_(T_I16               , TD_INT16            );
+  TD_ALIAS_(T_I32               , TD_INT32            );
+  TD_ALIAS_(T_I64               , TD_INT64            );
+  TD_ALIAS_(T_U8                , TD_UINT8            );
+  TD_ALIAS_(T_U16               , TD_UINT16           );
+  TD_ALIAS_(T_U32               , TD_UINT32           );
+  TD_ALIAS_(T_U64               , TD_UINT64           );
+  TD_ALIAS_(T_FLOAT             , TD_FLOAT            );
+  TD_ALIAS_(T_DOUBLE            , TD_DOUBLE           );
+  TD_ALIAS_(T_BOOL              , TD_BOOL             );
+  TD_ALIAS_(T_CHAR              , TD_CHAR             );
+  TD_ALIAS_(T_WCHAR             , TD_WCHAR            );
+  TD_ALIAS_(T_VOID              , TD_VOID             );
+  TD_ALIAS_(T_IID               , TD_PNSIID           );
+  TD_ALIAS_(T_DOMSTRING         , TD_DOMSTRING        );
+  TD_ALIAS_(T_CHAR_STR          , TD_PSTRING          );
+  TD_ALIAS_(T_WCHAR_STR         , TD_PWSTRING         );
+  TD_ALIAS_(T_INTERFACE         , TD_INTERFACE_TYPE   );
+  TD_ALIAS_(T_INTERFACE_IS      , TD_INTERFACE_IS_TYPE);
+  TD_ALIAS_(T_ARRAY             , TD_ARRAY            );
+  TD_ALIAS_(T_PSTRING_SIZE_IS   , TD_PSTRING_SIZE_IS  );
+  TD_ALIAS_(T_PWSTRING_SIZE_IS  , TD_PWSTRING_SIZE_IS );
+  TD_ALIAS_(T_UTF8STRING        , TD_UTF8STRING       );
+  TD_ALIAS_(T_CSTRING           , TD_CSTRING          );
+  TD_ALIAS_(T_ASTRING           , TD_ASTRING          );
+  TD_ALIAS_(T_JSVAL             , TD_JSVAL            );
+  TD_ALIAS_(T_DOMOBJECT         , TD_DOMOBJECT        );
+  TD_ALIAS_(T_PROMISE           , TD_PROMISE          );
+  TD_ALIAS_(T_SEQUENCE          , TD_SEQUENCE         );
+#undef TD_ALIAS_
 
   ////////////////////////////////////////////////////////////////
   // Ensure these fields are in the same order as xptcodegen.py //
   ////////////////////////////////////////////////////////////////
 
   uint8_t mTag : 5;
 
   // Parameter bitflags are packed into the XPTTypeDescriptor to save space.
@@ -659,22 +656,17 @@ nsXPTType::HasPointerRepr() const
         return false;
   }
 }
 
 inline size_t
 nsXPTType::Stride() const
 {
   // Compute the stride to use when walking an array of the given type.
-  //
-  // NOTE: We cast to nsXPTTypeTag here so we get a warning if a type is missed
-  // in this switch statement. It's important that this method returns a value
-  // for every possible type.
-
-  switch (static_cast<nsXPTTypeTag>(Tag())) {
+  switch (Tag()) {
     case TD_INT8:              return sizeof(int8_t);
     case TD_INT16:             return sizeof(int16_t);
     case TD_INT32:             return sizeof(int32_t);
     case TD_INT64:             return sizeof(int64_t);
     case TD_UINT8:             return sizeof(uint8_t);
     case TD_UINT16:            return sizeof(uint16_t);
     case TD_UINT32:            return sizeof(uint32_t);
     case TD_UINT64:            return sizeof(uint64_t);