|
@@ -50,10 +50,10 @@
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
-// Initialize Node.js cli options to pass to Node.js
|
|
|
+// Preparse Node.js cli options to pass to Node.js
|
|
|
// See https://nodejs.org/api/cli.html#cli_options
|
|
|
-int SetNodeCliFlags() {
|
|
|
- // Options that are unilaterally disallowed
|
|
|
+void ExitIfContainsDisallowedFlags(const std::vector<std::string>& argv) {
|
|
|
+ // Options that are unilaterally disallowed.
|
|
|
static constexpr auto disallowed = base::MakeFixedFlatSet<base::StringPiece>({
|
|
|
"--enable-fips",
|
|
|
"--force-fips",
|
|
@@ -62,40 +62,18 @@ int SetNodeCliFlags() {
|
|
|
"--use-openssl-ca",
|
|
|
});
|
|
|
|
|
|
- const auto argv = base::CommandLine::ForCurrentProcess()->argv();
|
|
|
- std::vector<std::string> args;
|
|
|
-
|
|
|
- // TODO(codebytere): We need to set the first entry in args to the
|
|
|
- // process name owing to src/node_options-inl.h#L286-L290 but this is
|
|
|
- // redundant and so should be refactored upstream.
|
|
|
- args.reserve(argv.size() + 1);
|
|
|
- args.emplace_back("electron");
|
|
|
-
|
|
|
for (const auto& arg : argv) {
|
|
|
-#if BUILDFLAG(IS_WIN)
|
|
|
- const auto& option = base::WideToUTF8(arg);
|
|
|
-#else
|
|
|
- const auto& option = arg;
|
|
|
-#endif
|
|
|
- const auto stripped = base::StringPiece(option).substr(0, option.find('='));
|
|
|
- if (disallowed.contains(stripped)) {
|
|
|
- LOG(ERROR) << "The Node.js cli flag " << stripped
|
|
|
+ const auto key = base::StringPiece(arg).substr(0, arg.find('='));
|
|
|
+ if (disallowed.contains(key)) {
|
|
|
+ LOG(ERROR) << "The Node.js cli flag " << key
|
|
|
<< " is not supported in Electron";
|
|
|
// Node.js returns 9 from ProcessGlobalArgs for any errors encountered
|
|
|
// when setting up cli flags and env vars. Since we're outlawing these
|
|
|
- // flags (making them errors) return 9 here for consistency.
|
|
|
- return 9;
|
|
|
- } else {
|
|
|
- args.push_back(option);
|
|
|
+ // flags (making them errors) exit with the same error code for
|
|
|
+ // consistency.
|
|
|
+ exit(9);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- std::vector<std::string> errors;
|
|
|
-
|
|
|
- // Node.js itself will output parsing errors to
|
|
|
- // console so we don't need to handle that ourselves
|
|
|
- return ProcessGlobalArgs(&args, nullptr, &errors,
|
|
|
- node::kDisallowedInEnvironment);
|
|
|
}
|
|
|
|
|
|
#if IS_MAS_BUILD()
|
|
@@ -116,7 +94,11 @@ v8::Local<v8::Value> GetParameters(v8::Isolate* isolate) {
|
|
|
}
|
|
|
|
|
|
int NodeMain(int argc, char* argv[]) {
|
|
|
- base::CommandLine::Init(argc, argv);
|
|
|
+ bool initialized = base::CommandLine::Init(argc, argv);
|
|
|
+ if (!initialized) {
|
|
|
+ LOG(ERROR) << "Failed to initialize CommandLine";
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
v8_crashpad_support::SetUp();
|
|
@@ -153,15 +135,13 @@ int NodeMain(int argc, char* argv[]) {
|
|
|
// Explicitly register electron's builtin bindings.
|
|
|
NodeBindings::RegisterBuiltinBindings();
|
|
|
|
|
|
- // Parse and set Node.js cli flags.
|
|
|
- int flags_exit_code = SetNodeCliFlags();
|
|
|
- if (flags_exit_code != 0)
|
|
|
- exit(flags_exit_code);
|
|
|
-
|
|
|
// Hack around with the argv pointer. Used for process.title = "blah".
|
|
|
argv = uv_setup_args(argc, argv);
|
|
|
|
|
|
+ // Parse Node.js cli flags and strip out disallowed options.
|
|
|
std::vector<std::string> args(argv, argv + argc);
|
|
|
+ ExitIfContainsDisallowedFlags(args);
|
|
|
+
|
|
|
std::unique_ptr<node::InitializationResult> result =
|
|
|
node::InitializeOncePerProcess(
|
|
|
args,
|