@@ -109,8 +109,12 @@ class IoSessionDelegate : public InspectorSessionDelegate {
109
109
// mostly session start, message received, and session end.
110
110
class InspectorIoDelegate : public node ::inspector::SocketServerDelegate {
111
111
public:
112
- InspectorIoDelegate (InspectorIo* io, const std::string& script_path,
112
+ InspectorIoDelegate (InspectorIo* io, const std::string& target_id,
113
+ const std::string& script_path,
113
114
const std::string& script_name, bool wait);
115
+ ~InspectorIoDelegate () {
116
+ io_->ServerDone ();
117
+ }
114
118
// Calls PostIncomingMessage() with appropriate InspectorAction:
115
119
// kStartSession
116
120
void StartSession (int session_id, const std::string& target_id) override ;
@@ -122,11 +126,8 @@ class InspectorIoDelegate: public node::inspector::SocketServerDelegate {
122
126
std::vector<std::string> GetTargetIds () override ;
123
127
std::string GetTargetTitle (const std::string& id) override ;
124
128
std::string GetTargetUrl (const std::string& id) override ;
125
- void ServerDone () override {
126
- io_->ServerDone ();
127
- }
128
129
129
- void AssignTransport (InspectorSocketServer* server) {
130
+ void AssignServer (InspectorSocketServer* server) override {
130
131
server_ = server;
131
132
}
132
133
@@ -163,11 +164,11 @@ class DispatchMessagesTask : public v8::Task {
163
164
InspectorIo::InspectorIo (Environment* env, v8::Platform* platform,
164
165
const std::string& path, const DebugOptions& options,
165
166
bool wait_for_connect)
166
- : options_(options), thread_(), delegate_(nullptr ),
167
- state_ (State::kNew ), parent_env_(env),
168
- thread_req_(), platform_(platform),
167
+ : options_(options), thread_(), state_(State::kNew ),
168
+ parent_env_ (env), thread_req_(), platform_(platform),
169
169
dispatching_messages_(false ), script_name_(path),
170
- wait_for_connect_(wait_for_connect), port_(-1 ) {
170
+ wait_for_connect_(wait_for_connect), port_(-1 ),
171
+ id_(GenerateID()) {
171
172
main_thread_req_ = new AsyncAndAgent ({uv_async_t (), env->inspector_agent ()});
172
173
CHECK_EQ (0 , uv_async_init (env->event_loop (), &main_thread_req_->first ,
173
174
InspectorIo::MainThreadReqAsyncCb));
@@ -244,7 +245,7 @@ void InspectorIo::IoThreadAsyncCb(uv_async_t* async) {
244
245
transport->TerminateConnections ();
245
246
// Fallthrough
246
247
case TransportAction::kStop :
247
- transport->Stop (nullptr );
248
+ transport->Stop ();
248
249
break ;
249
250
case TransportAction::kSendMessage :
250
251
transport->Send (session_id,
@@ -271,11 +272,11 @@ void InspectorIo::ThreadMain() {
271
272
err = uv_async_init (&loop, &thread_req_, IoThreadAsyncCb<Transport>);
272
273
CHECK_EQ (err, 0 );
273
274
std::string script_path = ScriptPath (&loop, script_name_);
274
- InspectorIoDelegate delegate ( this , script_path, script_name_,
275
- wait_for_connect_);
276
- delegate_ = &delegate ;
277
- Transport server (& delegate, &loop, options_.host_name (), options_. port ());
278
- delegate. AssignTransport (&server );
275
+ auto delegate = std::unique_ptr<InspectorIoDelegate>(
276
+ new InspectorIoDelegate ( this , id_, script_path, script_name_,
277
+ wait_for_connect_)) ;
278
+ Transport server (std::move ( delegate) , &loop, options_.host_name (),
279
+ options_. port () );
279
280
TransportAndIo<Transport> queue_transport (&server, this );
280
281
thread_req_.data = &queue_transport;
281
282
if (!server.Start ()) {
@@ -291,8 +292,6 @@ void InspectorIo::ThreadMain() {
291
292
uv_run (&loop, UV_RUN_DEFAULT);
292
293
thread_req_.data = nullptr ;
293
294
CHECK_EQ (uv_loop_close (&loop), 0 );
294
- delegate.AssignTransport (nullptr );
295
- delegate_ = nullptr ;
296
295
}
297
296
298
297
template <typename ActionType>
@@ -328,7 +327,7 @@ void InspectorIo::PostIncomingMessage(InspectorAction action, int session_id,
328
327
}
329
328
330
329
std::vector<std::string> InspectorIo::GetTargetIds () const {
331
- return delegate_ ? delegate_-> GetTargetIds () : std::vector<std::string>() ;
330
+ return { id_ } ;
332
331
}
333
332
334
333
TransportAction InspectorIo::Attach (int session_id) {
@@ -416,14 +415,15 @@ bool InspectorIo::WaitForFrontendEvent() {
416
415
}
417
416
418
417
InspectorIoDelegate::InspectorIoDelegate (InspectorIo* io,
418
+ const std::string& target_id,
419
419
const std::string& script_path,
420
420
const std::string& script_name,
421
421
bool wait)
422
422
: io_(io),
423
423
session_id_ (0 ),
424
424
script_name_(script_name),
425
425
script_path_(script_path),
426
- target_id_(GenerateID() ),
426
+ target_id_(target_id ),
427
427
waiting_(wait),
428
428
server_(nullptr ) { }
429
429
0 commit comments