src: fix warnings around node_options

* header explicit usage, order, and reduce use of `*-inl.h`
* pointer -> const reference when possible
* no variable recyclicng
* `std::begin/end` prefered over `instance.begin/end`
* `USE` for explicit unused resaults

PR-URL: https://github.com/nodejs/node/pull/26280
Fixes: https://github.com/nodejs/node/issues/25593
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Refael Ackermann 2019-02-25 15:42:28 -05:00
parent af8b92c073
commit 2c6d94f3db
6 changed files with 18 additions and 16 deletions

View File

@ -1,7 +1,7 @@
#include "env-inl.h" #include "env-inl.h"
#include "node.h" #include "node.h"
#include "node_i18n.h" #include "node_i18n.h"
#include "node_options-inl.h" #include "node_options.h"
#include "util-inl.h" #include "util-inl.h"
namespace node { namespace node {

View File

@ -213,15 +213,15 @@ auto OptionsParser<Options>::Convert(
template <typename Options> template <typename Options>
template <typename ChildOptions> template <typename ChildOptions>
void OptionsParser<Options>::Insert( void OptionsParser<Options>::Insert(
const OptionsParser<ChildOptions>* child_options_parser, const OptionsParser<ChildOptions>& child_options_parser,
ChildOptions* (Options::* get_child)()) { ChildOptions* (Options::* get_child)()) {
aliases_.insert(child_options_parser->aliases_.begin(), aliases_.insert(std::begin(child_options_parser.aliases_),
child_options_parser->aliases_.end()); std::end(child_options_parser.aliases_));
for (const auto& pair : child_options_parser->options_) for (const auto& pair : child_options_parser.options_)
options_.emplace(pair.first, Convert(pair.second, get_child)); options_.emplace(pair.first, Convert(pair.second, get_child));
for (const auto& pair : child_options_parser->implications_) for (const auto& pair : child_options_parser.implications_)
implications_.emplace(pair.first, Convert(pair.second, get_child)); implications_.emplace(pair.first, Convert(pair.second, get_child));
} }

View File

@ -1,8 +1,9 @@
#include <cerrno>
#include "env-inl.h" #include "env-inl.h"
#include "node_binding.h" #include "node_binding.h"
#include "node_options-inl.h" #include "node_options-inl.h"
#include <cstdlib> // strtoul, errno
using v8::Boolean; using v8::Boolean;
using v8::Context; using v8::Context;
using v8::FunctionCallbackInfo; using v8::FunctionCallbackInfo;
@ -123,7 +124,7 @@ class EnvironmentOptionsParser : public OptionsParser<EnvironmentOptions> {
EnvironmentOptionsParser(); EnvironmentOptionsParser();
explicit EnvironmentOptionsParser(const DebugOptionsParser& dop) explicit EnvironmentOptionsParser(const DebugOptionsParser& dop)
: EnvironmentOptionsParser() { : EnvironmentOptionsParser() {
Insert(&dop, &EnvironmentOptions::get_debug_options); Insert(dop, &EnvironmentOptions::get_debug_options);
} }
}; };
@ -391,7 +392,7 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
kAllowedInEnvironment); kAllowedInEnvironment);
#endif // NODE_REPORT #endif // NODE_REPORT
Insert(&eop, &PerIsolateOptions::get_per_env_options); Insert(eop, &PerIsolateOptions::get_per_env_options);
} }
PerProcessOptionsParser::PerProcessOptionsParser( PerProcessOptionsParser::PerProcessOptionsParser(
@ -501,7 +502,7 @@ PerProcessOptionsParser::PerProcessOptionsParser(
#endif #endif
#endif #endif
Insert(&iop, &PerProcessOptions::get_per_isolate_options); Insert(iop, &PerProcessOptions::get_per_isolate_options);
} }
inline std::string RemoveBrackets(const std::string& host) { inline std::string RemoveBrackets(const std::string& host) {
@ -515,7 +516,8 @@ inline int ParseAndValidatePort(const std::string& port,
std::vector<std::string>* errors) { std::vector<std::string>* errors) {
char* endptr; char* endptr;
errno = 0; errno = 0;
const long result = strtol(port.c_str(), &endptr, 10); // NOLINT(runtime/int) const unsigned long result = // NOLINT(runtime/int)
strtoul(port.c_str(), &endptr, 10);
if (errno != 0 || *endptr != '\0'|| if (errno != 0 || *endptr != '\0'||
(result != 0 && result < 1024) || result > 65535) { (result != 0 && result < 1024) || result > 65535) {
errors->push_back(" must be 0 or in range 1024 to 65535."); errors->push_back(" must be 0 or in range 1024 to 65535.");

View File

@ -290,7 +290,7 @@ class OptionsParser {
// a method that yields the target options type from this parser's options // a method that yields the target options type from this parser's options
// type. // type.
template <typename ChildOptions> template <typename ChildOptions>
void Insert(const OptionsParser<ChildOptions>* child_options_parser, void Insert(const OptionsParser<ChildOptions>& child_options_parser,
ChildOptions* (Options::* get_child)()); ChildOptions* (Options::* get_child)());
// Parse a sequence of options into an options struct, a list of // Parse a sequence of options into an options struct, a list of

View File

@ -1,5 +1,3 @@
#include <climits> // PATH_MAX
#include "env-inl.h" #include "env-inl.h"
#include "node_internals.h" #include "node_internals.h"
#include "node_options-inl.h" #include "node_options-inl.h"
@ -8,6 +6,8 @@
#include "node_revert.h" #include "node_revert.h"
#include "util-inl.h" #include "util-inl.h"
#include <climits> // PATH_MAX
namespace node { namespace node {
using v8::Context; using v8::Context;
using v8::DEFAULT; using v8::DEFAULT;

View File

@ -487,13 +487,13 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
// The first argument is program name. // The first argument is program name.
invalid_args.erase(invalid_args.begin()); invalid_args.erase(invalid_args.begin());
if (errors.size() > 0 || invalid_args.size() > 0) { if (errors.size() > 0 || invalid_args.size() > 0) {
v8::Local<v8::Value> value = v8::Local<v8::Value> error =
ToV8Value(env->context(), ToV8Value(env->context(),
errors.size() > 0 ? errors : invalid_args) errors.size() > 0 ? errors : invalid_args)
.ToLocalChecked(); .ToLocalChecked();
Local<String> key = Local<String> key =
FIXED_ONE_BYTE_STRING(env->isolate(), "invalidExecArgv"); FIXED_ONE_BYTE_STRING(env->isolate(), "invalidExecArgv");
args.This()->Set(env->context(), key, value).FromJust(); USE(args.This()->Set(env->context(), key, error).FromJust());
return; return;
} }
} }