Bug 987305 - Refactor EnumSerializer - r=nfroyd
authorBenoit Jacob <bjacob@mozilla.com>
Mon, 14 Apr 2014 10:17:40 -0400
changeset 178371 17597c063177b626d27d25b3852d2c21fe68bc5f
parent 178370 ff132397a4b17736c0e0276b18d5c03a2ea8a3d3
child 178372 29442be13b0b853f1691aa65db257fe119bc7e4e
push id6201
push userryanvm@gmail.com
push dateMon, 14 Apr 2014 19:45:21 +0000
treeherderb2g-inbound@5b6e82e7bbbf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs987305
milestone31.0a1
Bug 987305 - Refactor EnumSerializer - r=nfroyd
dom/asmjscache/AsmJSCache.h
dom/bluetooth/ipc/BluetoothMessageUtils.h
dom/indexedDB/ipc/SerializationHelpers.h
dom/ipc/TabMessageUtils.h
dom/mobilemessage/src/Types.h
gfx/ipc/GfxMessageUtils.h
gfx/layers/ipc/ShadowLayerUtils.h
hal/HalSensor.h
hal/HalTypes.h
ipc/glue/IPCMessageUtils.h
layout/ipc/RenderFrameUtils.h
--- a/dom/asmjscache/AsmJSCache.h
+++ b/dom/asmjscache/AsmJSCache.h
@@ -152,19 +152,19 @@ DeallocEntryChild(PAsmJSCacheEntryChild*
 } // namespace asmjscache
 } // namespace dom
 } // namespace mozilla
 
 namespace IPC {
 
 template <>
 struct ParamTraits<mozilla::dom::asmjscache::OpenMode> :
-  public EnumSerializer<mozilla::dom::asmjscache::OpenMode,
-                        mozilla::dom::asmjscache::eOpenForRead,
-                        mozilla::dom::asmjscache::NUM_OPEN_MODES>
+  public ContiguousEnumSerializer<mozilla::dom::asmjscache::OpenMode,
+                                  mozilla::dom::asmjscache::eOpenForRead,
+                                  mozilla::dom::asmjscache::NUM_OPEN_MODES>
 { };
 
 template <>
 struct ParamTraits<mozilla::dom::asmjscache::Metadata>
 {
   typedef mozilla::dom::asmjscache::Metadata paramType;
   static void Write(Message* aMsg, const paramType& aParam);
   static bool Read(const Message* aMsg, void** aIter, paramType* aResult);
--- a/dom/bluetooth/ipc/BluetoothMessageUtils.h
+++ b/dom/bluetooth/ipc/BluetoothMessageUtils.h
@@ -9,16 +9,17 @@
 
 #include "mozilla/dom/bluetooth/BluetoothCommon.h"
 #include "ipc/IPCMessageUtils.h"
 
 namespace IPC {
 
 template <>
 struct ParamTraits<mozilla::dom::bluetooth::BluetoothObjectType>
-  : public EnumSerializer<mozilla::dom::bluetooth::BluetoothObjectType,
-                          mozilla::dom::bluetooth::TYPE_MANAGER,
-                          mozilla::dom::bluetooth::TYPE_INVALID>
+  : public ContiguousEnumSerializer<
+             mozilla::dom::bluetooth::BluetoothObjectType,
+             mozilla::dom::bluetooth::TYPE_MANAGER,
+             mozilla::dom::bluetooth::TYPE_INVALID>
 { };
 
 } // namespace IPC
 
 #endif // mozilla_dom_bluetooth_ipc_bluetoothchild_h__
--- a/dom/indexedDB/ipc/SerializationHelpers.h
+++ b/dom/indexedDB/ipc/SerializationHelpers.h
@@ -12,19 +12,20 @@
 #include "mozilla/dom/indexedDB/KeyPath.h"
 #include "mozilla/dom/indexedDB/IDBCursor.h"
 #include "mozilla/dom/indexedDB/IDBTransaction.h"
 
 namespace IPC {
 
 template <>
 struct ParamTraits<mozilla::dom::quota::PersistenceType> :
-  public EnumSerializer<mozilla::dom::quota::PersistenceType,
-                        mozilla::dom::quota::PERSISTENCE_TYPE_PERSISTENT,
-                        mozilla::dom::quota::PERSISTENCE_TYPE_INVALID>
+  public ContiguousEnumSerializer<
+           mozilla::dom::quota::PersistenceType,
+           mozilla::dom::quota::PERSISTENCE_TYPE_PERSISTENT,
+           mozilla::dom::quota::PERSISTENCE_TYPE_INVALID>
 { };
 
 template <>
 struct ParamTraits<mozilla::dom::indexedDB::Key>
 {
   typedef mozilla::dom::indexedDB::Key paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
@@ -40,19 +41,20 @@ struct ParamTraits<mozilla::dom::indexed
   static void Log(const paramType& aParam, std::wstring* aLog)
   {
     LogParam(aParam.mBuffer, aLog);
   }
 };
 
 template <>
 struct ParamTraits<mozilla::dom::indexedDB::KeyPath::KeyPathType> :
-  public EnumSerializer<mozilla::dom::indexedDB::KeyPath::KeyPathType,
-                        mozilla::dom::indexedDB::KeyPath::NONEXISTENT,
-                        mozilla::dom::indexedDB::KeyPath::ENDGUARD>
+  public ContiguousEnumSerializer<
+           mozilla::dom::indexedDB::KeyPath::KeyPathType,
+           mozilla::dom::indexedDB::KeyPath::NONEXISTENT,
+           mozilla::dom::indexedDB::KeyPath::ENDGUARD>
 { };
 
 template <>
 struct ParamTraits<mozilla::dom::indexedDB::KeyPath>
 {
   typedef mozilla::dom::indexedDB::KeyPath paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
@@ -70,26 +72,28 @@ struct ParamTraits<mozilla::dom::indexed
   static void Log(const paramType& aParam, std::wstring* aLog)
   {
     LogParam(aParam.mStrings, aLog);
   }
 };
 
 template <>
 struct ParamTraits<mozilla::dom::indexedDB::IDBCursor::Direction> :
-  public EnumSerializer<mozilla::dom::indexedDB::IDBCursor::Direction,
-                        mozilla::dom::indexedDB::IDBCursor::NEXT,
-                        mozilla::dom::indexedDB::IDBCursor::DIRECTION_INVALID>
+  public ContiguousEnumSerializer<
+           mozilla::dom::indexedDB::IDBCursor::Direction,
+           mozilla::dom::indexedDB::IDBCursor::NEXT,
+           mozilla::dom::indexedDB::IDBCursor::DIRECTION_INVALID>
 { };
 
 template <>
 struct ParamTraits<mozilla::dom::indexedDB::IDBTransaction::Mode> :
-  public EnumSerializer<mozilla::dom::indexedDB::IDBTransaction::Mode,
-                        mozilla::dom::indexedDB::IDBTransaction::READ_ONLY,
-                        mozilla::dom::indexedDB::IDBTransaction::MODE_INVALID>
+  public ContiguousEnumSerializer<
+           mozilla::dom::indexedDB::IDBTransaction::Mode,
+           mozilla::dom::indexedDB::IDBTransaction::READ_ONLY,
+           mozilla::dom::indexedDB::IDBTransaction::MODE_INVALID>
 { };
 
 template <>
 struct ParamTraits<mozilla::dom::indexedDB::IndexInfo>
 {
   typedef mozilla::dom::indexedDB::IndexInfo paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
--- a/dom/ipc/TabMessageUtils.h
+++ b/dom/ipc/TabMessageUtils.h
@@ -85,17 +85,17 @@ struct ParamTraits<mozilla::dom::AudioCh
 
   static void Log(const paramType& aParam, std::wstring* aLog)
   {
   }
 };
 
 template <>
 struct ParamTraits<mozilla::dom::AudioChannelState>
-  : public EnumSerializer<mozilla::dom::AudioChannelState,
-                          mozilla::dom::AUDIO_CHANNEL_STATE_NORMAL,
-                          mozilla::dom::AUDIO_CHANNEL_STATE_LAST>
+  : public ContiguousEnumSerializer<mozilla::dom::AudioChannelState,
+                                    mozilla::dom::AUDIO_CHANNEL_STATE_NORMAL,
+                                    mozilla::dom::AUDIO_CHANNEL_STATE_LAST>
 { };
 
 }
 
 
 #endif
--- a/dom/mobilemessage/src/Types.h
+++ b/dom/mobilemessage/src/Types.h
@@ -82,66 +82,72 @@ enum MessageType {
 
 namespace IPC {
 
 /**
  * Delivery state serializer.
  */
 template <>
 struct ParamTraits<mozilla::dom::mobilemessage::DeliveryState>
-  : public EnumSerializer<mozilla::dom::mobilemessage::DeliveryState,
-                          mozilla::dom::mobilemessage::eDeliveryState_Sent,
-                          mozilla::dom::mobilemessage::eDeliveryState_EndGuard>
+  : public ContiguousEnumSerializer<
+             mozilla::dom::mobilemessage::DeliveryState,
+             mozilla::dom::mobilemessage::eDeliveryState_Sent,
+             mozilla::dom::mobilemessage::eDeliveryState_EndGuard>
 {};
 
 /**
  * Delivery status serializer.
  */
 template <>
 struct ParamTraits<mozilla::dom::mobilemessage::DeliveryStatus>
-  : public EnumSerializer<mozilla::dom::mobilemessage::DeliveryStatus,
-                          mozilla::dom::mobilemessage::eDeliveryStatus_NotApplicable,
-                          mozilla::dom::mobilemessage::eDeliveryStatus_EndGuard>
+  : public ContiguousEnumSerializer<
+             mozilla::dom::mobilemessage::DeliveryStatus,
+             mozilla::dom::mobilemessage::eDeliveryStatus_NotApplicable,
+             mozilla::dom::mobilemessage::eDeliveryStatus_EndGuard>
 {};
 
 /**
  * Read status serializer.
  */
 template <>
 struct ParamTraits<mozilla::dom::mobilemessage::ReadStatus>
-  : public EnumSerializer<mozilla::dom::mobilemessage::ReadStatus,
-                          mozilla::dom::mobilemessage::eReadStatus_NotApplicable,
-                          mozilla::dom::mobilemessage::eReadStatus_EndGuard>
+  : public ContiguousEnumSerializer<
+             mozilla::dom::mobilemessage::ReadStatus,
+             mozilla::dom::mobilemessage::eReadStatus_NotApplicable,
+             mozilla::dom::mobilemessage::eReadStatus_EndGuard>
 {};
 
 /**
  * Read state serializer.
  */
 template <>
 struct ParamTraits<mozilla::dom::mobilemessage::ReadState>
-  : public EnumSerializer<mozilla::dom::mobilemessage::ReadState,
-                          mozilla::dom::mobilemessage::eReadState_Unknown,
-                          mozilla::dom::mobilemessage::eReadState_EndGuard>
+  : public ContiguousEnumSerializer<
+             mozilla::dom::mobilemessage::ReadState,
+             mozilla::dom::mobilemessage::eReadState_Unknown,
+             mozilla::dom::mobilemessage::eReadState_EndGuard>
 {};
 
 /**
  * Message class serializer.
  */
 template <>
 struct ParamTraits<mozilla::dom::mobilemessage::MessageClass>
-  : public EnumSerializer<mozilla::dom::mobilemessage::MessageClass,
-                          mozilla::dom::mobilemessage::eMessageClass_Normal,
-                          mozilla::dom::mobilemessage::eMessageClass_EndGuard>
+  : public ContiguousEnumSerializer<
+             mozilla::dom::mobilemessage::MessageClass,
+             mozilla::dom::mobilemessage::eMessageClass_Normal,
+             mozilla::dom::mobilemessage::eMessageClass_EndGuard>
 {};
 
 /**
  * MessageType class serializer.
  */
 template <>
 struct ParamTraits<mozilla::dom::mobilemessage::MessageType>
-  : public EnumSerializer<mozilla::dom::mobilemessage::MessageType,
-                          mozilla::dom::mobilemessage::eMessageType_SMS,
-                          mozilla::dom::mobilemessage::eMessageType_EndGuard>
+  : public ContiguousEnumSerializer<
+             mozilla::dom::mobilemessage::MessageType,
+             mozilla::dom::mobilemessage::eMessageType_SMS,
+             mozilla::dom::mobilemessage::eMessageType_EndGuard>
 {};
 
 } // namespace IPC
 
 #endif // mozilla_dom_mobilemessage_Types_h
--- a/gfx/ipc/GfxMessageUtils.h
+++ b/gfx/ipc/GfxMessageUtils.h
@@ -239,82 +239,92 @@ struct ParamTraits<gfx3DMatrix>
             Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) &&
             Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44));
 #undef Rd
   }
 };
 
 template <>
 struct ParamTraits<gfxContentType>
-  : public TypedEnumSerializer<gfxContentType,
-                               gfxContentType::COLOR,
-                               gfxContentType::SENTINEL>
+  : public ContiguousTypedEnumSerializer<
+             gfxContentType,
+             gfxContentType::COLOR,
+             gfxContentType::SENTINEL>
 {};
 
 template <>
 struct ParamTraits<gfxSurfaceType>
-  : public TypedEnumSerializer<gfxSurfaceType,
-                               gfxSurfaceType::Image,
-                               gfxSurfaceType::Max>
+  : public ContiguousTypedEnumSerializer<
+             gfxSurfaceType,
+             gfxSurfaceType::Image,
+             gfxSurfaceType::Max>
 {};
 
 template <>
 struct ParamTraits<mozilla::GraphicsFilterType>
-  : public EnumSerializer<mozilla::GraphicsFilterType,
-                          GraphicsFilter::FILTER_FAST,
-                          GraphicsFilter::FILTER_SENTINEL>
+  : public ContiguousEnumSerializer<
+             mozilla::GraphicsFilterType,
+             GraphicsFilter::FILTER_FAST,
+             GraphicsFilter::FILTER_SENTINEL>
 {};
 
 template <>
 struct ParamTraits<mozilla::layers::LayersBackend>
-  : public TypedEnumSerializer<mozilla::layers::LayersBackend,
-                               mozilla::layers::LayersBackend::LAYERS_NONE,
-                               mozilla::layers::LayersBackend::LAYERS_LAST>
+  : public ContiguousTypedEnumSerializer<
+             mozilla::layers::LayersBackend,
+             mozilla::layers::LayersBackend::LAYERS_NONE,
+             mozilla::layers::LayersBackend::LAYERS_LAST>
 {};
 
 template <>
 struct ParamTraits<mozilla::layers::ScaleMode>
-  : public TypedEnumSerializer<mozilla::layers::ScaleMode,
-                               mozilla::layers::ScaleMode::SCALE_NONE,
-                               mozilla::layers::ScaleMode::SENTINEL>
+  : public ContiguousTypedEnumSerializer<
+             mozilla::layers::ScaleMode,
+             mozilla::layers::ScaleMode::SCALE_NONE,
+             mozilla::layers::ScaleMode::SENTINEL>
 {};
 
 template <>
 struct ParamTraits<gfxImageFormat>
-  : public TypedEnumSerializer<gfxImageFormat,
-                               gfxImageFormat::ARGB32,
-                               gfxImageFormat::Unknown>
+  : public ContiguousTypedEnumSerializer<
+             gfxImageFormat,
+             gfxImageFormat::ARGB32,
+             gfxImageFormat::Unknown>
 {};
 
 template <>
 struct ParamTraits<mozilla::gfx::AttributeName>
-  : public EnumSerializer<mozilla::gfx::AttributeName,
-                          mozilla::gfx::eBlendBlendmode,
-                          mozilla::gfx::eLastAttributeName>
+  : public ContiguousEnumSerializer<
+             mozilla::gfx::AttributeName,
+             mozilla::gfx::eBlendBlendmode,
+             mozilla::gfx::eLastAttributeName>
 {};
 
 template <>
 struct ParamTraits<mozilla::gfx::AttributeType>
-  : public TypedEnumSerializer<mozilla::gfx::AttributeType,
-                               mozilla::gfx::AttributeType::eBool,
-                               mozilla::gfx::AttributeType::Max>
+  : public ContiguousTypedEnumSerializer<
+             mozilla::gfx::AttributeType,
+             mozilla::gfx::AttributeType::eBool,
+             mozilla::gfx::AttributeType::Max>
 {};
 
 template <>
 struct ParamTraits<mozilla::gfx::PrimitiveType>
-  : public TypedEnumSerializer<mozilla::gfx::PrimitiveType,
-                               mozilla::gfx::PrimitiveType::Empty,
-                               mozilla::gfx::PrimitiveType::Max>
+  : public ContiguousTypedEnumSerializer<
+             mozilla::gfx::PrimitiveType,
+             mozilla::gfx::PrimitiveType::Empty,
+             mozilla::gfx::PrimitiveType::Max>
 {};
 
 template <>
 struct ParamTraits<mozilla::gfx::ColorSpace>
-  : public TypedEnumSerializer<mozilla::gfx::ColorSpace,
-                               mozilla::gfx::ColorSpace::SRGB,
-                               mozilla::gfx::ColorSpace::Max>
+  : public ContiguousTypedEnumSerializer<
+             mozilla::gfx::ColorSpace,
+             mozilla::gfx::ColorSpace::SRGB,
+             mozilla::gfx::ColorSpace::Max>
 {};
 
 /*
 template <>
 struct ParamTraits<mozilla::PixelFormat>
   : public EnumSerializer<mozilla::PixelFormat,
                           gfxImageFormat::ARGB32,
                           gfxImageFormat::Unknown>
@@ -793,26 +803,28 @@ struct ParamTraits<mozilla::layers::Text
     return ReadParam(aMsg, aIter, &aResult->mCompositableType) &&
            ReadParam(aMsg, aIter, &aResult->mDeprecatedTextureHostFlags) &&
            ReadParam(aMsg, aIter, &aResult->mTextureFlags);
   }
 };
 
 template <>
 struct ParamTraits<mozilla::layers::CompositableType>
-  : public EnumSerializer<mozilla::layers::CompositableType,
-                          mozilla::layers::BUFFER_UNKNOWN,
-                          mozilla::layers::BUFFER_COUNT>
+  : public ContiguousEnumSerializer<
+             mozilla::layers::CompositableType,
+             mozilla::layers::BUFFER_UNKNOWN,
+             mozilla::layers::BUFFER_COUNT>
 {};
 
 template <>
 struct ParamTraits<mozilla::gfx::SurfaceFormat>
-  : public TypedEnumSerializer<mozilla::gfx::SurfaceFormat,
-                               mozilla::gfx::SurfaceFormat::B8G8R8A8,
-                               mozilla::gfx::SurfaceFormat::UNKNOWN>
+  : public ContiguousTypedEnumSerializer<
+             mozilla::gfx::SurfaceFormat,
+             mozilla::gfx::SurfaceFormat::B8G8R8A8,
+             mozilla::gfx::SurfaceFormat::UNKNOWN>
 {};
 
 template <>
 struct ParamTraits<mozilla::layers::ScrollableLayerGuid>
 {
   typedef mozilla::layers::ScrollableLayerGuid paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
--- a/gfx/layers/ipc/ShadowLayerUtils.h
+++ b/gfx/layers/ipc/ShadowLayerUtils.h
@@ -81,16 +81,17 @@ struct ParamTraits<mozilla::layers::Magi
   typedef mozilla::layers::MagicGrallocBufferHandle paramType;
   static void Write(Message*, const paramType&) {}
   static bool Read(const Message*, void**, paramType*) { return false; }
 };
 #endif  // !defined(MOZ_HAVE_XSURFACEDESCRIPTORGRALLOC)
 
 template <>
 struct ParamTraits<mozilla::ScreenRotation>
-  : public EnumSerializer<mozilla::ScreenRotation,
-                          mozilla::ROTATION_0,
-                          mozilla::ROTATION_COUNT>
+  : public ContiguousEnumSerializer<
+             mozilla::ScreenRotation,
+             mozilla::ROTATION_0,
+             mozilla::ROTATION_COUNT>
 {};
 
 } // namespace IPC
 
 #endif // IPC_ShadowLayerUtils_h
--- a/hal/HalSensor.h
+++ b/hal/HalSensor.h
@@ -53,23 +53,25 @@ typedef Observer<SensorAccuracy> ISensor
 #include "ipc/IPCMessageUtils.h"
 
 namespace IPC {
   /**
    * Serializer for SensorType
    */
   template <>
   struct ParamTraits<mozilla::hal::SensorType>:
-    public EnumSerializer<mozilla::hal::SensorType,
-                          mozilla::hal::SENSOR_UNKNOWN,
-                          mozilla::hal::NUM_SENSOR_TYPE> {
+    public ContiguousEnumSerializer<
+             mozilla::hal::SensorType,
+             mozilla::hal::SENSOR_UNKNOWN,
+             mozilla::hal::NUM_SENSOR_TYPE> {
   };
 
   template <>
   struct ParamTraits<mozilla::hal::SensorAccuracyType>:
-    public EnumSerializer<mozilla::hal::SensorAccuracyType,
-                          mozilla::hal::SENSOR_ACCURACY_UNKNOWN,
-                          mozilla::hal::NUM_SENSOR_ACCURACY_TYPE> {
+    public ContiguousEnumSerializer<
+             mozilla::hal::SensorAccuracyType,
+             mozilla::hal::SENSOR_ACCURACY_UNKNOWN,
+             mozilla::hal::NUM_SENSOR_ACCURACY_TYPE> {
 
   };
 } // namespace IPC
 
 #endif /* __HAL_SENSOR_H_ */
--- a/hal/HalTypes.h
+++ b/hal/HalTypes.h
@@ -207,122 +207,135 @@ typedef Observer<FMRadioOperationInforma
 
 namespace IPC {
 
 /**
  * Light type serializer.
  */
 template <>
 struct ParamTraits<mozilla::hal::LightType>
-  : public EnumSerializer<mozilla::hal::LightType,
-                          mozilla::hal::eHalLightID_Backlight,
-                          mozilla::hal::eHalLightID_Count>
+  : public ContiguousEnumSerializer<
+             mozilla::hal::LightType,
+             mozilla::hal::eHalLightID_Backlight,
+             mozilla::hal::eHalLightID_Count>
 {};
 
 /**
  * Light mode serializer.
  */
 template <>
 struct ParamTraits<mozilla::hal::LightMode>
-  : public EnumSerializer<mozilla::hal::LightMode,
-                          mozilla::hal::eHalLightMode_User,
-                          mozilla::hal::eHalLightMode_Count>
+  : public ContiguousEnumSerializer<
+             mozilla::hal::LightMode,
+             mozilla::hal::eHalLightMode_User,
+             mozilla::hal::eHalLightMode_Count>
 {};
 
 /**
  * Flash mode serializer.
  */
 template <>
 struct ParamTraits<mozilla::hal::FlashMode>
-  : public EnumSerializer<mozilla::hal::FlashMode,
-                          mozilla::hal::eHalLightFlash_None,
-                          mozilla::hal::eHalLightFlash_Count>
+  : public ContiguousEnumSerializer<
+             mozilla::hal::FlashMode,
+             mozilla::hal::eHalLightFlash_None,
+             mozilla::hal::eHalLightFlash_Count>
 {};
 
 /**
  * Serializer for ShutdownMode.
  */
 template <>
 struct ParamTraits<mozilla::hal::ShutdownMode>
-  : public EnumSerializer<mozilla::hal::ShutdownMode,
-                          mozilla::hal::eHalShutdownMode_Unknown,
-                          mozilla::hal::eHalShutdownMode_Count>
+  : public ContiguousEnumSerializer<
+             mozilla::hal::ShutdownMode,
+             mozilla::hal::eHalShutdownMode_Unknown,
+             mozilla::hal::eHalShutdownMode_Count>
 {};
 
 /**
  * WakeLockControl serializer.
  */
 template <>
 struct ParamTraits<mozilla::hal::WakeLockControl>
-  : public EnumSerializer<mozilla::hal::WakeLockControl,
-                          mozilla::hal::WAKE_LOCK_REMOVE_ONE,
-                          mozilla::hal::NUM_WAKE_LOCK>
+  : public ContiguousEnumSerializer<
+             mozilla::hal::WakeLockControl,
+             mozilla::hal::WAKE_LOCK_REMOVE_ONE,
+             mozilla::hal::NUM_WAKE_LOCK>
 {};
 
 /**
  * Serializer for SwitchState
  */
 template <>
 struct ParamTraits<mozilla::hal::SwitchState>:
-  public EnumSerializer<mozilla::hal::SwitchState,
-                        mozilla::hal::SWITCH_STATE_UNKNOWN,
-                        mozilla::hal::NUM_SWITCH_STATE> {
+  public ContiguousEnumSerializer<
+           mozilla::hal::SwitchState,
+           mozilla::hal::SWITCH_STATE_UNKNOWN,
+           mozilla::hal::NUM_SWITCH_STATE> {
 };
 
 /**
  * Serializer for SwitchDevice
  */
 template <>
 struct ParamTraits<mozilla::hal::SwitchDevice>:
-  public EnumSerializer<mozilla::hal::SwitchDevice,
-                        mozilla::hal::SWITCH_DEVICE_UNKNOWN,
-                        mozilla::hal::NUM_SWITCH_DEVICE> {
+  public ContiguousEnumSerializer<
+           mozilla::hal::SwitchDevice,
+           mozilla::hal::SWITCH_DEVICE_UNKNOWN,
+           mozilla::hal::NUM_SWITCH_DEVICE> {
 };
 
 template <>
 struct ParamTraits<mozilla::hal::ProcessPriority>:
-  public EnumSerializer<mozilla::hal::ProcessPriority,
-                        mozilla::hal::PROCESS_PRIORITY_UNKNOWN,
-                        mozilla::hal::NUM_PROCESS_PRIORITY> {
+  public ContiguousEnumSerializer<
+           mozilla::hal::ProcessPriority,
+           mozilla::hal::PROCESS_PRIORITY_UNKNOWN,
+           mozilla::hal::NUM_PROCESS_PRIORITY> {
 };
 
 /**
  * Serializer for FMRadioOperation
  */
 template <>
 struct ParamTraits<mozilla::hal::FMRadioOperation>:
-  public EnumSerializer<mozilla::hal::FMRadioOperation,
-                        mozilla::hal::FM_RADIO_OPERATION_UNKNOWN,
-                        mozilla::hal::NUM_FM_RADIO_OPERATION>
+  public ContiguousEnumSerializer<
+           mozilla::hal::FMRadioOperation,
+           mozilla::hal::FM_RADIO_OPERATION_UNKNOWN,
+           mozilla::hal::NUM_FM_RADIO_OPERATION>
 {};
 
 /**
  * Serializer for FMRadioOperationStatus
  */
 template <>
 struct ParamTraits<mozilla::hal::FMRadioOperationStatus>:
-  public EnumSerializer<mozilla::hal::FMRadioOperationStatus,
-                        mozilla::hal::FM_RADIO_OPERATION_STATUS_UNKNOWN,
-                        mozilla::hal::NUM_FM_RADIO_OPERATION_STATUS>
+  public ContiguousEnumSerializer<
+           mozilla::hal::FMRadioOperationStatus,
+           mozilla::hal::FM_RADIO_OPERATION_STATUS_UNKNOWN,
+           mozilla::hal::NUM_FM_RADIO_OPERATION_STATUS>
 {};
 
 /**
  * Serializer for FMRadioSeekDirection
  */
 template <>
 struct ParamTraits<mozilla::hal::FMRadioSeekDirection>:
-  public EnumSerializer<mozilla::hal::FMRadioSeekDirection,
-                        mozilla::hal::FM_RADIO_SEEK_DIRECTION_UNKNOWN,
-                        mozilla::hal::NUM_FM_RADIO_SEEK_DIRECTION>
+  public ContiguousEnumSerializer<
+           mozilla::hal::FMRadioSeekDirection,
+           mozilla::hal::FM_RADIO_SEEK_DIRECTION_UNKNOWN,
+           mozilla::hal::NUM_FM_RADIO_SEEK_DIRECTION>
 {};
 
 /**
  * Serializer for FMRadioCountry
  **/
 template <>
 struct ParamTraits<mozilla::hal::FMRadioCountry>:
-  public EnumSerializer<mozilla::hal::FMRadioCountry,
-                        mozilla::hal::FM_RADIO_COUNTRY_UNKNOWN,
-                        mozilla::hal::NUM_FM_RADIO_COUNTRY>
+  public ContiguousEnumSerializer<
+           mozilla::hal::FMRadioCountry,
+           mozilla::hal::FM_RADIO_COUNTRY_UNKNOWN,
+           mozilla::hal::NUM_FM_RADIO_COUNTRY>
 {};
+
 } // namespace IPC
 
 #endif // mozilla_hal_Types_h
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -11,16 +11,17 @@
 #include "chrome/common/ipc_message_utils.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/TimeStamp.h"
 #ifdef XP_WIN
 #include "mozilla/TimeStamp_windows.h"
 #endif
 #include "mozilla/TypedEnum.h"
+#include "mozilla/IntegerTypeTraits.h"
 
 #include <stdint.h>
 
 #include "nsID.h"
 #include "nsMemory.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "js/StructuredClone.h"
@@ -86,102 +87,121 @@ struct SerializedStructuredCloneBuffer
 
 } // namespace mozilla
 
 namespace IPC {
 
 /**
  * Generic enum serializer.
  *
+ * Consider using the specializations below, such as ContiguousEnumSerializer.
+ *
  * This is a generic serializer for any enum type used in IPDL.
  * Programmers can define ParamTraits<E> for enum type E by deriving
- * EnumSerializer<E, smallestLegal, highGuard>.
+ * EnumSerializer<E, MyEnumValidator> where MyEnumValidator is a struct
+ * that has to define a static IsLegalValue function returning whether
+ * a given value is a legal value of the enum type at hand.
  *
- * The serializer would check value againts a range specified by
- * smallestLegal and highGuard.  Only values from smallestLegal to
- * highGuard are valid, include smallestLegal but highGuard.
+ * \sa https://developer.mozilla.org/en/IPDL/Type_Serialization
+ */
+template <typename E, typename EnumValidator>
+struct EnumSerializer {
+  typedef E paramType;
+  typedef typename mozilla::UnsignedStdintTypeForSize<sizeof(paramType)>::Type
+          uintParamType;
+
+  static void Write(Message* aMsg, const paramType& aValue) {
+    MOZ_ASSERT(EnumValidator::IsLegalValue(aValue));
+    WriteParam(aMsg, uintParamType(aValue));
+  }
+
+  static bool Read(const Message* aMsg, void** aIter, paramType* aResult) {
+    uintParamType value;
+    if(!ReadParam(aMsg, aIter, &value) ||
+       !EnumValidator::IsLegalValue(paramType(value))) {
+      return false;
+    }
+    *aResult = paramType(value);
+    return true;
+  }
+};
+
+template <typename E,
+          E MinLegal,
+          E HighBound>
+struct ContiguousEnumValidator
+{
+  static bool IsLegalValue(E e)
+  {
+    return MinLegal <= e && e < HighBound;
+  }
+};
+
+template <typename E,
+          MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) MinLegal,
+          MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) HighBound>
+class ContiguousTypedEnumValidator
+{
+  // Silence overzealous -Wtype-limits bug in GCC fixed in GCC 4.8:
+  // "comparison of unsigned expression >= 0 is always true"
+  // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
+  template <typename T>
+  static bool IsLessThanOrEqual(T a, T b) { return a <= b; }
+
+public:
+  static bool IsLegalValue(E e)
+  {
+    typedef MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) ActualEnumType;
+    return IsLessThanOrEqual(MinLegal, ActualEnumType(e)) &&
+           ActualEnumType(e) < HighBound;
+  }
+};
+
+/**
+ * Specialization of EnumSerializer for enums with contiguous enum values.
+ *
+ * Provide two values: MinLegal, HighBound. An enum value x will be
+ * considered legal if MinLegal <= x < HighBound.
  *
  * For example, following is definition of serializer for enum type FOO.
  * \code
  * enum FOO { FOO_FIRST, FOO_SECOND, FOO_LAST, NUM_FOO };
  *
  * template <>
  * struct ParamTraits<FOO>:
- *     public EnumSerializer<FOO, FOO_FIRST, NUM_FOO> {};
+ *     public ContiguousEnumSerializer<FOO, FOO_FIRST, NUM_FOO> {};
  * \endcode
  * FOO_FIRST, FOO_SECOND, and FOO_LAST are valid value.
- *
- * \sa https://developer.mozilla.org/en/IPDL/Type_Serialization
  */
-template <typename E, E smallestLegal, E highBound>
-struct EnumSerializer {
-  typedef E paramType;
-
-  static bool IsLegalValue(const paramType &aValue) {
-    return smallestLegal <= aValue && aValue < highBound;
-  }
-
-  static void Write(Message* aMsg, const paramType& aValue) {
-    MOZ_ASSERT(IsLegalValue(aValue));
-    WriteParam(aMsg, (int32_t)aValue);
-  }
-
-  static bool Read(const Message* aMsg, void** aIter, paramType* aResult) {
-    int32_t value;
-    if(!ReadParam(aMsg, aIter, &value) ||
-       !IsLegalValue(paramType(value))) {
-      return false;
-    }
-    *aResult = paramType(value);
-    return true;
-  }
-};
+template <typename E,
+          E MinLegal,
+          E HighBound>
+struct ContiguousEnumSerializer
+  : EnumSerializer<E,
+                   ContiguousEnumValidator<E, MinLegal, HighBound>>
+{};
 
 /**
- * Variant of EnumSerializer for MFBT's typed enums
- * defined by MOZ_BEGIN_ENUM_CLASS in mfbt/TypedEnum.h
- *
- * This is only needed on non-C++11 compilers such as B2G's GCC 4.4,
- * where MOZ_BEGIN_ENUM_CLASS is implemented using a nested enum, T::Enum,
- * in a wrapper class T. In this case, the "typed enum" type T cannot be
- * used as an integer template parameter type. MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(T)
- * is how we get at the integer enum type.
+ * Similar to ContiguousEnumSerializer, but for MFBT typed enums
+ * as constructed by MOZ_BEGIN_ENUM_CLASS. This can go away when
+ * we drop MOZ_BEGIN_ENUM_CLASS and use C++11 enum classes directly.
  */
 template <typename E,
-          MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) smallestLegal,
-          MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) highBound>
-struct TypedEnumSerializer {
-  typedef E paramType;
-  typedef MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) intParamType;
-
-  static bool IsLegalValue(const paramType &aValue) {
-    return smallestLegal <= intParamType(aValue) && intParamType(aValue) < highBound;
-  }
-
-  static void Write(Message* aMsg, const paramType& aValue) {
-    MOZ_ASSERT(IsLegalValue(aValue));
-    WriteParam(aMsg, int32_t(intParamType(aValue)));
-  }
-
-  static bool Read(const Message* aMsg, void** aIter, paramType* aResult) {
-    int32_t value;
-    if(!ReadParam(aMsg, aIter, &value) ||
-       !IsLegalValue(intParamType(value))) {
-      return false;
-    }
-    *aResult = intParamType(value);
-    return true;
-  }
-};
+          MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) MinLegal,
+          MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) HighBound>
+struct ContiguousTypedEnumSerializer
+  : EnumSerializer<E,
+                   ContiguousTypedEnumValidator<E, MinLegal, HighBound>>
+{};
 
 template <>
 struct ParamTraits<base::ChildPrivileges>
-  : public EnumSerializer<base::ChildPrivileges,
-                          base::PRIVILEGES_DEFAULT,
-                          base::PRIVILEGES_LAST>
+  : public ContiguousEnumSerializer<base::ChildPrivileges,
+                                    base::PRIVILEGES_DEFAULT,
+                                    base::PRIVILEGES_LAST>
 { };
 
 template<>
 struct ParamTraits<int8_t>
 {
   typedef int8_t paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
@@ -472,19 +492,19 @@ struct ParamTraits<float>
   static void Log(const paramType& aParam, std::wstring* aLog)
   {
     aLog->append(StringPrintf(L"%g", aParam));
   }
 };
 
 template <>
 struct ParamTraits<nsCSSProperty>
-  : public EnumSerializer<nsCSSProperty,
-                          eCSSProperty_UNKNOWN,
-                          eCSSProperty_COUNT>
+  : public ContiguousEnumSerializer<nsCSSProperty,
+                                    eCSSProperty_UNKNOWN,
+                                    eCSSProperty_COUNT>
 {};
 
 template<>
 struct ParamTraits<mozilla::void_t>
 {
   typedef mozilla::void_t paramType;
   static void Write(Message* aMsg, const paramType& aParam) { }
   static bool
--- a/layout/ipc/RenderFrameUtils.h
+++ b/layout/ipc/RenderFrameUtils.h
@@ -30,16 +30,17 @@ enum ScrollingBehavior {
 
 } // namespace layout
 } // namespace mozilla
 
 namespace IPC {
 
 template <>
 struct ParamTraits<mozilla::layout::ScrollingBehavior>
-  : public EnumSerializer<mozilla::layout::ScrollingBehavior,
-                          mozilla::layout::DEFAULT_SCROLLING,
-                          mozilla::layout::SCROLLING_BEHAVIOR_SENTINEL>
+  : public ContiguousEnumSerializer<
+             mozilla::layout::ScrollingBehavior,
+             mozilla::layout::DEFAULT_SCROLLING,
+             mozilla::layout::SCROLLING_BEHAVIOR_SENTINEL>
 {};
 
 } // namespace IPC
 
 #endif // mozilla_layer_RenderFrameUtils_h