зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1733821 - [9/9] Drive-by cleanup: add nullptr_t overload for CheckArg r=nika
Since `CheckArg`'s `aParam` is declared as `const CharT **`, it's treated as a deduction parameter. Unfortunately, `nullptr` is of type `nullptr_t`, and it doesn't get coerced before template argument deduction takes place. To allow passing `nullptr`, people have been using unwieldy constructs like `static_cast<const wchar_t**>(nullptr)` when `aParam` isn't needed. Centralize this by adding an overload of `CheckArg` that explicitly takes `nullptr_t` and forwards it on to the primary implementation. Strip out all the now-unnecessary `static_cast`s everywhere else. No functional changes. Differential Revision: https://phabricator.services.mozilla.com/D152327
This commit is contained in:
Родитель
8ae15d70b0
Коммит
bc46f84efa
|
@ -144,9 +144,7 @@ LauncherVoidResult LaunchUnelevated(int aArgc, wchar_t* aArgv[]) {
|
||||||
// This should have already been checked, but just in case...
|
// This should have already been checked, but just in case...
|
||||||
EnsureBrowserCommandlineSafe(aArgc, aArgv);
|
EnsureBrowserCommandlineSafe(aArgc, aArgv);
|
||||||
|
|
||||||
if (mozilla::CheckArg(aArgc, aArgv, "osint",
|
if (mozilla::CheckArg(aArgc, aArgv, "osint", nullptr, CheckArgFlag::None)) {
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
CheckArgFlag::None)) {
|
|
||||||
// If the command line contains -osint, we have to arrange things in a
|
// If the command line contains -osint, we have to arrange things in a
|
||||||
// particular order.
|
// particular order.
|
||||||
//
|
//
|
||||||
|
|
|
@ -146,21 +146,16 @@ static void SetMitigationPolicies(mozilla::ProcThreadAttributes& aAttrs,
|
||||||
static mozilla::LauncherFlags ProcessCmdLine(int& aArgc, wchar_t* aArgv[]) {
|
static mozilla::LauncherFlags ProcessCmdLine(int& aArgc, wchar_t* aArgv[]) {
|
||||||
mozilla::LauncherFlags result = mozilla::LauncherFlags::eNone;
|
mozilla::LauncherFlags result = mozilla::LauncherFlags::eNone;
|
||||||
|
|
||||||
if (mozilla::CheckArg(aArgc, aArgv, "wait-for-browser",
|
if (mozilla::CheckArg(aArgc, aArgv, "wait-for-browser", nullptr,
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
mozilla::CheckArgFlag::RemoveArg) ==
|
mozilla::CheckArgFlag::RemoveArg) ==
|
||||||
mozilla::ARG_FOUND ||
|
mozilla::ARG_FOUND ||
|
||||||
mozilla::CheckArg(aArgc, aArgv, "marionette",
|
mozilla::CheckArg(aArgc, aArgv, "marionette", nullptr,
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND ||
|
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND ||
|
||||||
mozilla::CheckArg(aArgc, aArgv, "backgroundtask",
|
mozilla::CheckArg(aArgc, aArgv, "backgroundtask", nullptr,
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND ||
|
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND ||
|
||||||
mozilla::CheckArg(aArgc, aArgv, "headless",
|
mozilla::CheckArg(aArgc, aArgv, "headless", nullptr,
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND ||
|
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND ||
|
||||||
mozilla::CheckArg(aArgc, aArgv, "remote-debugging-port",
|
mozilla::CheckArg(aArgc, aArgv, "remote-debugging-port", nullptr,
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND ||
|
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND ||
|
||||||
mozilla::EnvHasValue("MOZ_AUTOMATION") ||
|
mozilla::EnvHasValue("MOZ_AUTOMATION") ||
|
||||||
mozilla::EnvHasValue("MOZ_HEADLESS")) {
|
mozilla::EnvHasValue("MOZ_HEADLESS")) {
|
||||||
|
@ -220,9 +215,9 @@ static bool DoLauncherProcessChecks(int& argc, wchar_t** argv) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
result |= mozilla::CheckArg(
|
result |=
|
||||||
argc, argv, "launcher", static_cast<const wchar_t**>(nullptr),
|
mozilla::CheckArg(argc, argv, "launcher", nullptr,
|
||||||
mozilla::CheckArgFlag::RemoveArg) == mozilla::ARG_FOUND;
|
mozilla::CheckArgFlag::RemoveArg) == mozilla::ARG_FOUND;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -238,8 +233,7 @@ static mozilla::Maybe<bool> RunAsLauncherProcess(int& argc, wchar_t** argv) {
|
||||||
#if defined(MOZ_LAUNCHER_PROCESS)
|
#if defined(MOZ_LAUNCHER_PROCESS)
|
||||||
bool forceLauncher =
|
bool forceLauncher =
|
||||||
runAsLauncher &&
|
runAsLauncher &&
|
||||||
mozilla::CheckArg(argc, argv, "force-launcher",
|
mozilla::CheckArg(argc, argv, "force-launcher", nullptr,
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
mozilla::CheckArgFlag::RemoveArg) == mozilla::ARG_FOUND;
|
mozilla::CheckArgFlag::RemoveArg) == mozilla::ARG_FOUND;
|
||||||
|
|
||||||
mozilla::LauncherRegistryInfo::ProcessType desiredType =
|
mozilla::LauncherRegistryInfo::ProcessType desiredType =
|
||||||
|
@ -279,8 +273,7 @@ Maybe<int> LauncherMain(int& argc, wchar_t* argv[],
|
||||||
|
|
||||||
SetLauncherErrorAppData(aAppData);
|
SetLauncherErrorAppData(aAppData);
|
||||||
|
|
||||||
if (CheckArg(argc, argv, "log-launcher-error",
|
if (CheckArg(argc, argv, "log-launcher-error", nullptr,
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
mozilla::CheckArgFlag::RemoveArg) == ARG_FOUND) {
|
mozilla::CheckArgFlag::RemoveArg) == ARG_FOUND) {
|
||||||
SetLauncherErrorForceEventLog();
|
SetLauncherErrorForceEventLog();
|
||||||
}
|
}
|
||||||
|
@ -288,8 +281,7 @@ Maybe<int> LauncherMain(int& argc, wchar_t* argv[],
|
||||||
// return fast when we're a child process.
|
// return fast when we're a child process.
|
||||||
// (The remainder of this function has some side effects that are
|
// (The remainder of this function has some side effects that are
|
||||||
// undesirable for content processes)
|
// undesirable for content processes)
|
||||||
if (mozilla::CheckArg(argc, argv, "contentproc",
|
if (mozilla::CheckArg(argc, argv, "contentproc", nullptr,
|
||||||
static_cast<const wchar_t**>(nullptr),
|
|
||||||
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND) {
|
mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND) {
|
||||||
// A child process should not instantiate LauncherRegistryInfo.
|
// A child process should not instantiate LauncherRegistryInfo.
|
||||||
return Nothing();
|
return Nothing();
|
||||||
|
|
|
@ -212,6 +212,14 @@ inline ArgResult CheckArg(int& aArgc, CharT** aArgv, const char* aArg,
|
||||||
return ar;
|
return ar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
|
inline ArgResult CheckArg(int& aArgc, CharT** aArgv, const char* aArg,
|
||||||
|
std::nullptr_t,
|
||||||
|
CheckArgFlag aFlags = CheckArgFlag::RemoveArg) {
|
||||||
|
return CheckArg<CharT>(aArgc, aArgv, aArg,
|
||||||
|
static_cast<const CharT**>(nullptr), aFlags);
|
||||||
|
}
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
// template <typename T>
|
// template <typename T>
|
||||||
// constexpr bool IsStringRange =
|
// constexpr bool IsStringRange =
|
||||||
|
@ -248,8 +256,8 @@ inline bool EnsureCommandlineSafeImpl(int aArgc, CharT** aArgv,
|
||||||
|
|
||||||
// If "-osint" (or the equivalent) is not present, then this is trivially
|
// If "-osint" (or the equivalent) is not present, then this is trivially
|
||||||
// satisfied.
|
// satisfied.
|
||||||
if (CheckArg(aArgc, aArgv, osintLit, static_cast<const CharT**>(nullptr),
|
if (CheckArg(aArgc, aArgv, osintLit, nullptr, CheckArgFlag::None) !=
|
||||||
CheckArgFlag::None) != ARG_FOUND) {
|
ARG_FOUND) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,7 @@ inline Maybe<bool> IsSafeModeRequested(
|
||||||
checkArgFlags |= CheckArgFlag::RemoveArg;
|
checkArgFlags |= CheckArgFlag::RemoveArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgResult ar = CheckArg(aArgc, aArgv, "safe-mode",
|
ArgResult ar = CheckArg(aArgc, aArgv, "safe-mode", nullptr, checkArgFlags);
|
||||||
static_cast<const CharT**>(nullptr), checkArgFlags);
|
|
||||||
if (ar == ARG_BAD) {
|
if (ar == ARG_BAD) {
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче