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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew McCreight 2019-08-30 21:55:42 +00:00
parent d8dc15b323
commit 9fe0f5c10b
3 changed files with 49 additions and 7 deletions

View File

@ -667,6 +667,42 @@ void ChromeUtils::ClearRecentJSDevError(GlobalObject&) {
}
#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) {
@ -822,8 +858,7 @@ already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
}
// 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;

View File

@ -446,11 +446,16 @@ enum WebIDLProcType {
"extension",
"privilegedabout",
"webLargeAllocation",
"browser",
"plugin",
"ipdlUnitTest",
"gmpPlugin",
"gpu",
"vr",
"rdd",
"socket",
"browser",
"unknown"
"remoteSandboxBroker",
"unknown",
};
/**

View File

@ -16,9 +16,10 @@ 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,
@ -35,7 +36,8 @@ enum class ProcType {
Socket,
RemoteSandboxBroker,
// Unknown type of process
Unknown
Unknown,
Max = Unknown,
};
struct ThreadInfo {