summaryrefslogtreecommitdiff
path: root/src/node_options.h
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-02 01:30:30 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-12-09 06:26:53 +0800
commit61a89630ee5664b1f909b310a016b522a6285521 (patch)
tree621fbd9bfd9c25a43c3ff9ae60251e5bfa2d366c /src/node_options.h
parent22564b99cb9dff471f40c1ad0245d99b9224a207 (diff)
downloadandroid-node-v8-61a89630ee5664b1f909b310a016b522a6285521.tar.gz
android-node-v8-61a89630ee5664b1f909b310a016b522a6285521.tar.bz2
android-node-v8-61a89630ee5664b1f909b310a016b522a6285521.zip
inspector: split the HostPort being used and the one parsed from CLI
Instead of using a shared pointer of the entire debug option set, pass the parsed debug option to inspector classes by value because they are set once the CLI argument parsing is done. Add another shared pointer to HostPort being used by the inspector server, which is copied from the one in the debug options initially. The port of the shared HostPort is 9229 by default and can be specified as 0 initially but will be set to the actual port of the server once it starts listening. This makes the shared state clearer and makes it possible to use `require('internal/options')` in JS land to query the CLI options instead of using `process._breakFirstLine` and other underscored properties of `process` since we are now certain that these values should not be altered once the parsing is done and can be passed around in copies without locks. PR-URL: https://github.com/nodejs/node/pull/24772 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_options.h')
-rw-r--r--src/node_options.h63
1 files changed, 46 insertions, 17 deletions
diff --git a/src/node_options.h b/src/node_options.h
index dfe7ff6c5e..17dc708463 100644
--- a/src/node_options.h
+++ b/src/node_options.h
@@ -3,22 +3,44 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+#include <memory>
#include <string>
-#include <vector>
#include <unordered_map>
-#include <memory>
+#include <vector>
#include "node_constants.h"
+#include "util.h"
namespace node {
-struct HostPort {
- std::string host_name;
- int port;
+class HostPort {
+ public:
+ HostPort(const std::string& host_name, int port)
+ : host_name_(host_name), port_(port) {}
+ HostPort(const HostPort&) = default;
+ HostPort& operator=(const HostPort&) = default;
+ HostPort(HostPort&&) = default;
+ HostPort& operator=(HostPort&&) = default;
+
+ void set_host(const std::string& host) { host_name_ = host; }
+
+ void set_port(int port) { port_ = port; }
+
+ const std::string& host() const { return host_name_; }
+
+ int port() const {
+ // TODO(joyeecheung): make port a uint16_t
+ CHECK_GE(port_, 0);
+ return port_;
+ }
void Update(const HostPort& other) {
- if (!other.host_name.empty()) host_name = other.host_name;
- if (other.port >= 0) port = other.port;
+ if (!other.host_name_.empty()) host_name_ = other.host_name_;
+ if (other.port_ >= 0) port_ = other.port_;
}
+
+ private:
+ std::string host_name_;
+ int port_;
};
class Options {
@@ -33,13 +55,25 @@ class Options {
// per-Isolate, rather than per-Environment.
class DebugOptions : public Options {
public:
+ DebugOptions() = default;
+ DebugOptions(const DebugOptions&) = default;
+ DebugOptions& operator=(const DebugOptions&) = default;
+ DebugOptions(DebugOptions&&) = default;
+ DebugOptions& operator=(DebugOptions&&) = default;
+
+ // --inspect
bool inspector_enabled = false;
+ // --debug
bool deprecated_debug = false;
+ // --inspect-brk
bool break_first_line = false;
+ // --inspect-brk-node
bool break_node_first_line = false;
- HostPort host_port = {"127.0.0.1", -1};
+
enum { kDefaultInspectorPort = 9229 };
+ HostPort host_port{"127.0.0.1", kDefaultInspectorPort};
+
bool deprecated_invocation() const {
return deprecated_debug &&
inspector_enabled &&
@@ -53,19 +87,10 @@ class DebugOptions : public Options {
bool wait_for_connect() const {
return break_first_line || break_node_first_line;
}
-
- const std::string& host() {
- return host_port.host_name;
- }
-
- int port() {
- return host_port.port < 0 ? kDefaultInspectorPort : host_port.port;
- }
};
class EnvironmentOptions : public Options {
public:
- std::shared_ptr<DebugOptions> debug_options { new DebugOptions() };
bool abort_on_uncaught_exception = false;
bool experimental_modules = false;
bool experimental_repl_await = false;
@@ -108,7 +133,11 @@ class EnvironmentOptions : public Options {
std::vector<std::string> user_argv;
inline DebugOptions* get_debug_options();
+ inline const DebugOptions& debug_options() const;
void CheckOptions(std::vector<std::string>* errors);
+
+ private:
+ DebugOptions debug_options_;
};
class PerIsolateOptions : public Options {