electron/patches/node/feat_enable_passing_cli_flags.patch
Shelley Vohr 83124889e5
feat: enable passing Node.js cli flags (#21110)
* feat: enable passing Node.js cli flags

* Allow cli flags in ELECTRON_RUN_AS_NODE mode
2020-02-07 02:59:38 +00:00

108 lines
No EOL
3.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Wed, 13 Nov 2019 15:39:48 +0000
Subject: feat: enable passing cli flags
This patches enables passing safelisted cli flags to Node.js.
Upstreamed in https://github.com/nodejs/node/pull/30466.
diff --git a/src/node.cc b/src/node.cc
index 461f736beacec67b35c89a42319f99178a1e38e9..c00bfb6ccbe603604fca29268d15d67b208b2e6a 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -113,8 +113,6 @@
namespace node {
using native_module::NativeModuleEnv;
-using options_parser::kAllowedInEnvironment;
-using options_parser::kDisallowedInEnvironment;
using v8::Boolean;
using v8::EscapableHandleScope;
@@ -670,7 +668,7 @@ void ResetStdio() {
int ProcessGlobalArgs(std::vector<std::string>* args,
std::vector<std::string>* exec_args,
std::vector<std::string>* errors,
- bool is_env) {
+ OptionEnvvarSettings settings) {
// Parse a few arguments which are specific to Node.
std::vector<std::string> v8_args;
@@ -680,7 +678,7 @@ int ProcessGlobalArgs(std::vector<std::string>* args,
exec_args,
&v8_args,
per_process::cli_options.get(),
- is_env ? kAllowedInEnvironment : kDisallowedInEnvironment,
+ settings,
errors);
if (!errors->empty()) return 9;
@@ -851,7 +849,7 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
return 9;
}
- const int exit_code = ProcessGlobalArgs(&env_argv, nullptr, errors, true);
+ const int exit_code = ProcessGlobalArgs(&env_argv, nullptr, errors, kAllowedInEnvironment);
if (exit_code != 0) return exit_code;
}
#endif
@@ -859,7 +857,7 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
if (g_upstream_node_mode) {
// NOTE(jeremy): indentation is intentionally wrong here, to ease rebasing.
- const int exit_code = ProcessGlobalArgs(argv, exec_argv, errors, false);
+ const int exit_code = ProcessGlobalArgs(argv, exec_argv, errors, kDisallowedInEnvironment);
if (exit_code != 0) return exit_code;
// Set the process.title immediately after processing argv if --title is set.
diff --git a/src/node.h b/src/node.h
index 9c6dcbf7014f7cf87f7f66886cbf255978c244fa..4f2da9a46966199465a33c1fa275d0116d395a56 100644
--- a/src/node.h
+++ b/src/node.h
@@ -223,6 +223,16 @@ NODE_EXTERN void Init(int* argc,
int* exec_argc,
const char*** exec_argv);
+enum OptionEnvvarSettings {
+ kAllowedInEnvironment,
+ kDisallowedInEnvironment
+};
+
+NODE_EXTERN int ProcessGlobalArgs(std::vector<std::string>* args,
+ std::vector<std::string>* exec_args,
+ std::vector<std::string>* errors,
+ OptionEnvvarSettings settings);
+
class NodeArrayBufferAllocator;
// An ArrayBuffer::Allocator class with some Node.js-specific tweaks. If you do
diff --git a/src/node_options.h b/src/node_options.h
index 4ce5551284bb5b1b4194905a9fe619f852933405..404cb72536cdaf8f0320770392e02ac75c303cae 100644
--- a/src/node_options.h
+++ b/src/node_options.h
@@ -248,11 +248,6 @@ HostPort NODE_EXTERN SplitHostPort(const std::string& arg,
std::vector<std::string>* errors);
void GetOptions(const v8::FunctionCallbackInfo<v8::Value>& args);
-enum OptionEnvvarSettings {
- kAllowedInEnvironment,
- kDisallowedInEnvironment
-};
-
enum OptionType {
kNoOp,
kV8Option,
diff --git a/src/node_worker.cc b/src/node_worker.cc
index c8b2e1699f26ac9bfeb373653d35271f9b6c841f..a4db86ad99c75e07960a95247a41ed78e5bf55ca 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -16,7 +16,7 @@
#include <string>
#include <vector>
-using node::options_parser::kDisallowedInEnvironment;
+using node::kDisallowedInEnvironment;
using v8::Array;
using v8::Boolean;
using v8::Context;