refactor: remove use of Node's DebugOptions (#22083)

This commit is contained in:
Shelley Vohr 2020-02-09 18:42:02 +00:00 committed by GitHub
parent 099246f0e4
commit d5e7904610
6 changed files with 16 additions and 147 deletions

View file

@ -27,34 +27,13 @@ void NodeDebugger::Start() {
if (inspector == nullptr)
return;
std::vector<std::string> args;
for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) {
#if defined(OS_WIN)
args.push_back(base::UTF16ToUTF8(arg));
#else
args.push_back(arg);
#endif
}
node::DebugOptions options;
std::vector<std::string> exec_args;
std::vector<std::string> v8_args;
std::vector<std::string> errors;
// TODO(codebytere): remove this parsing and use ProcessGlobalArgs
node::options_parser::Parse(&args, &exec_args, &v8_args, &options,
node::kDisallowedInEnvironment, &errors);
if (!errors.empty()) {
// TODO(jeremy): what's the appropriate behaviour here?
LOG(ERROR) << "Error parsing node options: "
<< base::JoinString(errors, " ");
}
const char* path = "";
if (inspector->Start(path, options,
std::make_shared<node::HostPort>(options.host_port),
true /* is_main */))
// DebugOptions will already have been set by ProcessGlobalArgs,
// so just pull the ones from there to pass to the InspectorAgent
const auto debug_options = env_->options()->debug_options();
if (inspector->Start(
"" /* path */, debug_options,
std::make_shared<node::HostPort>(debug_options.host_port),
true /* is_main */))
DCHECK(env_->inspector_agent()->IsListening());
}

View file

@ -164,7 +164,9 @@ void SetNodeCliFlags() {
const auto& option = arg;
#endif
const auto stripped = base::StringPiece(option).substr(0, option.find('='));
if (allowed.count(stripped) != 0)
// Only allow in no-op (--) option or DebugOptions
if (allowed.count(stripped) != 0 || stripped == "--")
args.push_back(option);
}
@ -172,13 +174,13 @@ void SetNodeCliFlags() {
const int exit_code = ProcessGlobalArgs(&args, nullptr, &errors,
node::kDisallowedInEnvironment);
const std::string err_str = "Error parsing Node.js cli flags ";
if (exit_code != 0) {
if (!errors.empty())
LOG(INFO) << base::JoinString(errors, " ");
else
LOG(INFO) << "Error parsing Node.js cli flags";
LOG(ERROR) << err_str;
} else if (!errors.empty()) {
LOG(ERROR) << err_str << base::JoinString(errors, " ");
}
}
} // namespace
// Initialize NODE_OPTIONS to pass to Node.js
// See https://nodejs.org/api/cli.html#cli_node_options_options

View file

@ -64,6 +64,7 @@
#include "node.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "node_options-inl.h"
#include "node_options.h"
#include "node_platform.h"