Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e30e307

Browse filesBrowse files
Eugene OstroukhovItalo A. Casas
authored andcommitted
inspector: move options parsing
As inspector functionality expands, more options will need to be added. Currently this requires changing adding function arguments, etc. This change packs the veriables into a single class that can be extended without changing APIs. PR-URL: #9691 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 33af09f commit e30e307
Copy full SHA for e30e307

File tree

Expand file treeCollapse file tree

8 files changed

+260
-154
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+260
-154
lines changed
Open diff view settings
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
'src/node_config.cc',
160160
'src/node_constants.cc',
161161
'src/node_contextify.cc',
162+
'src/node_debug_options.cc',
162163
'src/node_file.cc',
163164
'src/node_http_parser.cc',
164165
'src/node_javascript.cc',
@@ -201,6 +202,7 @@
201202
'src/node.h',
202203
'src/node_buffer.h',
203204
'src/node_constants.h',
205+
'src/node_debug_options.h',
204206
'src/node_file.h',
205207
'src/node_http_parser.h',
206208
'src/node_internals.h',
Collapse file

‎src/debug-agent.cc‎

Copy file name to clipboardExpand all lines: src/debug-agent.cc
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ using v8::Value;
5050

5151

5252
Agent::Agent(Environment* env) : state_(kNone),
53-
port_(5858),
5453
wait_(false),
5554
parent_env_(env),
5655
child_env_(nullptr),
@@ -69,7 +68,7 @@ Agent::~Agent() {
6968
}
7069

7170

72-
bool Agent::Start(const char* host, int port, bool wait) {
71+
bool Agent::Start(const DebugOptions& options) {
7372
int err;
7473

7574
if (state_ == kRunning)
@@ -85,9 +84,8 @@ bool Agent::Start(const char* host, int port, bool wait) {
8584
goto async_init_failed;
8685
uv_unref(reinterpret_cast<uv_handle_t*>(&child_signal_));
8786

88-
host_ = host;
89-
port_ = port;
90-
wait_ = wait;
87+
options_ = options;
88+
wait_ = options_.wait_for_connect();
9189

9290
err = uv_thread_create(&thread_,
9391
reinterpret_cast<uv_thread_cb>(ThreadCb),
@@ -210,9 +208,11 @@ void Agent::InitAdaptor(Environment* env) {
210208

211209
api->Set(String::NewFromUtf8(isolate, "host",
212210
NewStringType::kNormal).ToLocalChecked(),
213-
String::NewFromUtf8(isolate, host_.data(), NewStringType::kNormal,
214-
host_.size()).ToLocalChecked());
215-
api->Set(String::NewFromUtf8(isolate, "port"), Integer::New(isolate, port_));
211+
String::NewFromUtf8(isolate, options_.host_name().data(),
212+
NewStringType::kNormal,
213+
options_.host_name().size()).ToLocalChecked());
214+
api->Set(String::NewFromUtf8(isolate, "port"),
215+
Integer::New(isolate, options_.port()));
216216

217217
env->process_object()->Set(String::NewFromUtf8(isolate, "_debugAPI"), api);
218218
api_.Reset(env->isolate(), api);
Collapse file

‎src/debug-agent.h‎

Copy file name to clipboardExpand all lines: src/debug-agent.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
2626

2727
#include "node_mutex.h"
28+
#include "node_debug_options.h"
2829
#include "util.h"
2930
#include "util-inl.h"
3031
#include "uv.h"
@@ -76,7 +77,7 @@ class Agent {
7677
typedef void (*DispatchHandler)(node::Environment* env);
7778

7879
// Start the debugger agent thread
79-
bool Start(const char* host, int port, bool wait);
80+
bool Start(const DebugOptions& options);
8081
// Listen for debug events
8182
void Enable();
8283
// Stop the debugger agent
@@ -114,9 +115,8 @@ class Agent {
114115
};
115116

116117
State state_;
118+
DebugOptions options_;
117119

118-
std::string host_;
119-
int port_;
120120
bool wait_;
121121

122122
uv_sem_t start_sem_;
Collapse file

‎src/inspector_agent.cc‎

Copy file name to clipboardExpand all lines: src/inspector_agent.cc
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class AgentImpl {
131131
explicit AgentImpl(node::Environment* env);
132132

133133
// Start the inspector agent thread
134-
bool Start(v8::Platform* platform, const char* path, int port, bool wait);
134+
bool Start(v8::Platform* platform, const char* path,
135+
const DebugOptions& options);
135136
// Stop the inspector agent
136137
void Stop();
137138

@@ -168,15 +169,14 @@ class AgentImpl {
168169
void NotifyMessageReceived();
169170
State ToState(State state);
170171

172+
DebugOptions options_;
171173
uv_sem_t start_sem_;
172174
ConditionVariable incoming_message_cond_;
173175
Mutex state_lock_;
174176
uv_thread_t thread_;
175177
uv_loop_t child_loop_;
176178

177179
InspectorAgentDelegate* delegate_;
178-
179-
int port_;
180180
bool wait_;
181181
bool shutting_down_;
182182
State state_;
@@ -192,6 +192,8 @@ class AgentImpl {
192192
InspectorSocketServer* server_;
193193

194194
std::string script_name_;
195+
std::string script_path_;
196+
const std::string id_;
195197

196198
friend class ChannelImpl;
197199
friend class DispatchOnInspectorBackendTask;
@@ -316,7 +318,6 @@ class V8NodeInspector : public v8_inspector::V8InspectorClient {
316318
};
317319

318320
AgentImpl::AgentImpl(Environment* env) : delegate_(nullptr),
319-
port_(0),
320321
wait_(false),
321322
shutting_down_(false),
322323
state_(State::kNew),
@@ -396,7 +397,10 @@ void InspectorWrapConsoleCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
396397
}
397398

398399
bool AgentImpl::Start(v8::Platform* platform, const char* path,
399-
int port, bool wait) {
400+
const DebugOptions& options) {
401+
options_ = options;
402+
wait_ = options.wait_for_connect();
403+
400404
auto env = parent_env_;
401405
inspector_ = new V8NodeInspector(this, env, platform);
402406
platform_ = platform;
@@ -408,9 +412,6 @@ bool AgentImpl::Start(v8::Platform* platform, const char* path,
408412
int err = uv_loop_init(&child_loop_);
409413
CHECK_EQ(err, 0);
410414

411-
port_ = port;
412-
wait_ = wait;
413-
414415
err = uv_thread_create(&thread_, AgentImpl::ThreadCbIO, this);
415416
CHECK_EQ(err, 0);
416417
uv_sem_wait(&start_sem_);
@@ -420,7 +421,7 @@ bool AgentImpl::Start(v8::Platform* platform, const char* path,
420421
return false;
421422
}
422423
state_ = State::kAccepting;
423-
if (wait) {
424+
if (options_.wait_for_connect()) {
424425
DispatchMessages();
425426
}
426427
return true;
@@ -548,7 +549,7 @@ void AgentImpl::WorkerRunIO() {
548549
}
549550
InspectorAgentDelegate delegate(this, script_path, script_name_, wait_);
550551
delegate_ = &delegate;
551-
InspectorSocketServer server(&delegate, port_);
552+
InspectorSocketServer server(&delegate, options_.port());
552553
if (!server.Start(&child_loop_)) {
553554
fprintf(stderr, "Unable to open devtools socket: %s\n", uv_strerror(err));
554555
state_ = State::kError; // Safe, main thread is waiting on semaphore
@@ -666,8 +667,8 @@ Agent::~Agent() {
666667
}
667668

668669
bool Agent::Start(v8::Platform* platform, const char* path,
669-
int port, bool wait) {
670-
return impl->Start(platform, path, port, wait);
670+
const DebugOptions& options) {
671+
return impl->Start(platform, path, options);
671672
}
672673

673674
void Agent::Stop() {
Collapse file

‎src/inspector_agent.h‎

Copy file name to clipboardExpand all lines: src/inspector_agent.h
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#error("This header can only be used when inspector is enabled")
88
#endif
99

10+
#include "node_debug_options.h"
11+
1012
// Forward declaration to break recursive dependency chain with src/env.h.
1113
namespace node {
1214
class Environment;
@@ -31,7 +33,8 @@ class Agent {
3133
~Agent();
3234

3335
// Start the inspector agent thread
34-
bool Start(v8::Platform* platform, const char* path, int port, bool wait);
36+
bool Start(v8::Platform* platform, const char* path,
37+
const DebugOptions& options);
3538
// Stop the inspector agent
3639
void Stop();
3740

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.