Bug 1577819, part 2 - WebIDLProcType should match ProcType. r=Ehsan
authorAndrew McCreight <continuation@gmail.com>
Fri, 30 Aug 2019 21:55:42 +0000
changeset 554723 dd470e3dff60dc0e8e7f874cd95d3580503bb4e0
parent 554722 01e8fd20bdc19218fc076daa79720c55ed3b7f08
child 554724 a9ac86bbe8d0bdec01fecf09827514a780142e57
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1577819
milestone70.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 1577819, part 2 - WebIDLProcType should match ProcType. r=Ehsan ProcType gets turned into WebIDLProcType, so I assume the intention is that they are identical. I changed the definition of WebIDLProcType to match ProcType, and added a static assert to check that they have the same number of cases. I also changed the coercion from a static_cast<> to an explicit switch statement so that it will degrade more gracefully if, say, the enums get reordered, or one enum gets a case added and removed at the same time. Differential Revision: https://phabricator.services.mozilla.com/D44212
dom/base/ChromeUtils.cpp
dom/chrome-webidl/ChromeUtils.webidl
widget/ProcInfo.h
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -662,16 +662,52 @@ void ChromeUtils::GetRecentJSDevError(Gl
 void ChromeUtils::ClearRecentJSDevError(GlobalObject&) {
   auto runtime = CycleCollectedJSRuntime::Get();
   MOZ_ASSERT(runtime);
 
   runtime->ClearRecentDevError();
 }
 #endif  // NIGHTLY_BUILD
 
+#define PROCTYPE_TO_WEBIDL_CASE(_procType, _webidl) \
+  case mozilla::ProcType::_procType:                \
+    return WebIDLProcType::_webidl
+
+static WebIDLProcType ProcTypeToWebIDL(mozilla::ProcType aType) {
+  // |strings| contains an extra non-enum value, so subtract one.
+  // Max is the value of the last enum, not the length, so add one.
+  static_assert(ArrayLength(WebIDLProcTypeValues::strings) - 1 ==
+                    static_cast<size_t>(ProcType::Max) + 1,
+                "In order for this static cast to be okay, "
+                "WebIDLProcType must match ProcType exactly");
+
+  switch (aType) {
+    PROCTYPE_TO_WEBIDL_CASE(Web, Web);
+    PROCTYPE_TO_WEBIDL_CASE(File, File);
+    PROCTYPE_TO_WEBIDL_CASE(Extension, Extension);
+    PROCTYPE_TO_WEBIDL_CASE(PrivilegedAbout, Privilegedabout);
+    PROCTYPE_TO_WEBIDL_CASE(WebLargeAllocation, WebLargeAllocation);
+    PROCTYPE_TO_WEBIDL_CASE(Browser, Browser);
+    PROCTYPE_TO_WEBIDL_CASE(Plugin, Plugin);
+    PROCTYPE_TO_WEBIDL_CASE(IPDLUnitTest, IpdlUnitTest);
+    PROCTYPE_TO_WEBIDL_CASE(GMPlugin, GmpPlugin);
+    PROCTYPE_TO_WEBIDL_CASE(GPU, Gpu);
+    PROCTYPE_TO_WEBIDL_CASE(VR, Vr);
+    PROCTYPE_TO_WEBIDL_CASE(RDD, Rdd);
+    PROCTYPE_TO_WEBIDL_CASE(Socket, Socket);
+    PROCTYPE_TO_WEBIDL_CASE(RemoteSandboxBroker, RemoteSandboxBroker);
+    PROCTYPE_TO_WEBIDL_CASE(Unknown, Unknown);
+  }
+
+  MOZ_ASSERT(false, "Unhandled case in ProcTypeToWebIDL");
+  return WebIDLProcType::Unknown;
+}
+
+#undef PROCTYPE_TO_WEBIDL_CASE
+
 /* static */
 already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
                                                        ErrorResult& aRv) {
   // This function will use IPDL to enable threads info on macOS
   // see https://bugzilla.mozilla.org/show_bug.cgi?id=1529023
   if (!XRE_IsParentProcess()) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
@@ -817,18 +853,17 @@ already_AddRefed<Promise> ChromeUtils::R
                     ChildProcInfoDictionary* childProcInfo =
                         children.AppendElement(fallible);
                     if (NS_WARN_IF(!childProcInfo)) {
                       domPromise->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
                       return;
                     }
                     // Basic info.
                     childProcInfo->mChildID = info.childId;
-                    childProcInfo->mType =
-                        static_cast<WebIDLProcType>(info.type);
+                    childProcInfo->mType = ProcTypeToWebIDL(info.type);
                     childProcInfo->mPid = info.pid;
                     childProcInfo->mFilename.Assign(info.filename);
                     childProcInfo->mVirtualMemorySize = info.virtualMemorySize;
                     childProcInfo->mResidentSetSize = info.residentSetSize;
                     childProcInfo->mCpuUser = info.cpuUser;
                     childProcInfo->mCpuKernel = info.cpuKernel;
 
                     // Threads info.
--- a/dom/chrome-webidl/ChromeUtils.webidl
+++ b/dom/chrome-webidl/ChromeUtils.webidl
@@ -441,21 +441,26 @@ partial namespace ChromeUtils {
  * This type is a WebIDL representation of mozilla::ProcType.
  */
 enum WebIDLProcType {
  "web",
  "file",
  "extension",
  "privilegedabout",
  "webLargeAllocation",
+ "browser",
+ "plugin",
+ "ipdlUnitTest",
+ "gmpPlugin",
  "gpu",
+ "vr",
  "rdd",
  "socket",
- "browser",
- "unknown"
+ "remoteSandboxBroker",
+ "unknown",
 };
 
 /**
  * These dictionaries hold information about Firefox running processes and
  * threads.
  *
  * See widget/ProcInfo.h for fields documentation.
  */
--- a/widget/ProcInfo.h
+++ b/widget/ProcInfo.h
@@ -11,36 +11,38 @@
 #include "mozilla/dom/ipc/IdType.h"
 
 namespace mozilla {
 
 namespace ipc {
 class GeckoChildProcessHost;
 }
 
-// Process types
+// Process types. When updating this enum, please make sure to update
+// WebIDLProcType and ProcTypeToWebIDL to mirror the changes.
 enum class ProcType {
-  // These must match the ones in ContentParent.h and E10SUtils.jsm
+  // These must match the ones in ContentParent.h, and E10SUtils.jsm
   Web,
   File,
   Extension,
   PrivilegedAbout,
   WebLargeAllocation,
   // the rest matches GeckoProcessTypes.h
   Browser,  // Default is named Browser here
   Plugin,
   IPDLUnitTest,
   GMPlugin,
   GPU,
   VR,
   RDD,
   Socket,
   RemoteSandboxBroker,
   // Unknown type of process
-  Unknown
+  Unknown,
+  Max = Unknown,
 };
 
 struct ThreadInfo {
   // Thread Id.
   base::ProcessId tid = 0;
   // Thread name, if any.
   nsString name;
   // User time in ns.