@@ -44,6 +44,11 @@ std::unique_ptr<StringBuffer> ToProtocolString(Isolate* isolate,
44
44
return StringBuffer::create (StringView (*buffer, buffer.length ()));
45
45
}
46
46
47
+ // Called from the main thread.
48
+ void StartInspectorIoThreadAsyncCallback (uv_async_t * handle) {
49
+ static_cast <Agent*>(handle->data )->StartIoThread ();
50
+ }
51
+
47
52
#ifdef __POSIX__
48
53
static void EnableInspectorIOThreadSignalHandler (int signo) {
49
54
uv_sem_post (&inspector_io_thread_semaphore);
@@ -156,61 +161,6 @@ static int RegisterDebugSignalHandler() {
156
161
const int NANOS_PER_MSEC = 1000000 ;
157
162
const int CONTEXT_GROUP_ID = 1 ;
158
163
159
- class NodeInspectorClient ;
160
-
161
- class AgentImpl {
162
- public:
163
- explicit AgentImpl (node::Environment* env);
164
-
165
- bool Start (v8::Platform* platform, const char * path,
166
- const DebugOptions& options);
167
- void Stop ();
168
- bool IsStarted ();
169
- bool IsConnected ();
170
- void WaitForDisconnect ();
171
-
172
- void FatalException (Local<Value> error,
173
- Local<v8::Message> message);
174
-
175
- void SchedulePauseOnNextStatement (const std::string& reason);
176
-
177
- void Connect (InspectorSessionDelegate* session);
178
-
179
- NodeInspectorClient* client () {
180
- return inspector_.get ();
181
- }
182
-
183
- private:
184
- template <typename Action>
185
- using MessageQueue =
186
- std::vector<std::tuple<Action, int , std::unique_ptr<StringBuffer>>>;
187
- enum class State { kNew , kAccepting , kConnected , kDone , kError };
188
-
189
- static void ThreadCbIO (void * agent);
190
- static void WriteCbIO (uv_async_t * async);
191
- static void CallAndPauseOnStart (const v8::FunctionCallbackInfo<v8::Value>&);
192
-
193
- void WorkerRunIO ();
194
- void SetConnected (bool connected);
195
- void WaitForFrontendMessage ();
196
- void NotifyMessageReceived ();
197
- bool StartIoThread ();
198
- static void InspectorWrapConsoleCall (
199
- const v8::FunctionCallbackInfo<Value>& args);
200
- static void InspectorConsoleCall (
201
- const v8::FunctionCallbackInfo<Value>& info);
202
- static void StartInspectorIoThreadAsyncCallback (uv_async_t * handle);
203
- State ToState (State state);
204
-
205
- node::Environment* parent_env_;
206
- std::unique_ptr<NodeInspectorClient> inspector_;
207
- std::unique_ptr<InspectorIo> io_;
208
- v8::Platform* platform_;
209
- bool inspector_console_;
210
- std::string path_;
211
- DebugOptions debug_options_;
212
- };
213
-
214
164
class ChannelImpl final : public v8_inspector::V8Inspector::Channel {
215
165
public:
216
166
explicit ChannelImpl (V8Inspector* inspector,
@@ -367,14 +317,18 @@ class NodeInspectorClient : public v8_inspector::V8InspectorClient {
367
317
std::unique_ptr<ChannelImpl> channel_;
368
318
};
369
319
370
- AgentImpl::AgentImpl (Environment* env) : parent_env_(env),
371
- inspector_(nullptr ),
372
- platform_(nullptr ),
373
- inspector_console_(false ) {}
320
+ Agent::Agent (Environment* env) : parent_env_(env),
321
+ inspector_(nullptr ),
322
+ platform_(nullptr ),
323
+ inspector_console_(false ) {}
324
+
325
+ // Header has unique_ptr to some incomplete types - this definition tells
326
+ // the compiler to figure out destruction here, were those types are complete
327
+ Agent::~Agent () {
328
+ }
374
329
375
330
// static
376
- void AgentImpl::InspectorConsoleCall (
377
- const v8::FunctionCallbackInfo<Value>& info) {
331
+ void Agent::InspectorConsoleCall (const v8::FunctionCallbackInfo<Value>& info) {
378
332
Isolate* isolate = info.GetIsolate ();
379
333
Local<Context> context = isolate->GetCurrentContext ();
380
334
@@ -388,7 +342,7 @@ void AgentImpl::InspectorConsoleCall(
388
342
}
389
343
390
344
Environment* env = Environment::GetCurrent (isolate);
391
- if (env->inspector_agent ()->impl -> inspector_console_ ) {
345
+ if (env->inspector_agent ()->inspector_console_ ) {
392
346
Local<Value> inspector_method = args->Get (context, 0 ).ToLocalChecked ();
393
347
CHECK (inspector_method->IsFunction ());
394
348
Local<Value> config_value = args->Get (context, 2 ).ToLocalChecked ();
@@ -417,33 +371,25 @@ void AgentImpl::InspectorConsoleCall(
417
371
}
418
372
419
373
// static
420
- void AgentImpl::InspectorWrapConsoleCall (
421
- const FunctionCallbackInfo<Value>& args) {
422
- Environment* env = Environment::GetCurrent (args);
423
-
424
- if (args.Length () != 3 || !args[0 ]->IsFunction () ||
425
- !args[1 ]->IsFunction () || !args[2 ]->IsObject ()) {
374
+ void Agent::InspectorWrapConsoleCall (const FunctionCallbackInfo<Value>& info) {
375
+ Environment* env = Environment::GetCurrent (info);
376
+ if (info.Length () != 3 || !info[0 ]->IsFunction () ||
377
+ !info[1 ]->IsFunction () || !info[2 ]->IsObject ()) {
426
378
return env->ThrowError (" inspector.wrapConsoleCall takes exactly 3 "
427
379
" arguments: two functions and an object." );
428
380
}
429
381
430
- Local<v8::Array> array = v8::Array::New (env->isolate (), args .Length ());
431
- CHECK (array->Set (env->context (), 0 , args [0 ]).FromJust ());
432
- CHECK (array->Set (env->context (), 1 , args [1 ]).FromJust ());
433
- CHECK (array->Set (env->context (), 2 , args [2 ]).FromJust ());
434
- args .GetReturnValue ().Set (Function::New (env->context (),
382
+ Local<v8::Array> array = v8::Array::New (env->isolate (), info .Length ());
383
+ CHECK (array->Set (env->context (), 0 , info [0 ]).FromJust ());
384
+ CHECK (array->Set (env->context (), 1 , info [1 ]).FromJust ());
385
+ CHECK (array->Set (env->context (), 2 , info [2 ]).FromJust ());
386
+ info .GetReturnValue ().Set (Function::New (env->context (),
435
387
InspectorConsoleCall,
436
388
array).ToLocalChecked ());
437
389
}
438
390
439
- // Called from the main thread.
440
- // static
441
- void AgentImpl::StartInspectorIoThreadAsyncCallback (uv_async_t * handle) {
442
- reinterpret_cast <AgentImpl*>(handle->data )->StartIoThread ();
443
- }
444
-
445
- bool AgentImpl::Start (v8::Platform* platform, const char * path,
446
- const DebugOptions& options) {
391
+ bool Agent::Start (v8::Platform* platform, const char * path,
392
+ const DebugOptions& options) {
447
393
path_ = path == nullptr ? " " : path;
448
394
debug_options_ = options;
449
395
inspector_console_ = false ;
@@ -479,7 +425,7 @@ bool AgentImpl::Start(v8::Platform* platform, const char* path,
479
425
}
480
426
}
481
427
482
- bool AgentImpl ::StartIoThread () {
428
+ bool Agent ::StartIoThread () {
483
429
if (io_ != nullptr )
484
430
return true ;
485
431
@@ -517,27 +463,27 @@ bool AgentImpl::StartIoThread() {
517
463
return true ;
518
464
}
519
465
520
- void AgentImpl ::Stop () {
466
+ void Agent ::Stop () {
521
467
if (io_ != nullptr )
522
468
io_->Stop ();
523
469
}
524
470
525
- void AgentImpl ::Connect (InspectorSessionDelegate* delegate) {
471
+ void Agent ::Connect (InspectorSessionDelegate* delegate) {
526
472
inspector_console_ = true ;
527
473
inspector_->connectFrontend (delegate);
528
474
}
529
475
530
- bool AgentImpl ::IsConnected () {
476
+ bool Agent ::IsConnected () {
531
477
return io_ && io_->IsConnected ();
532
478
}
533
479
534
- bool AgentImpl ::IsStarted () {
480
+ bool Agent ::IsStarted () {
535
481
return !!inspector_;
536
482
}
537
483
538
484
// static
539
- void AgentImpl ::CallAndPauseOnStart (
540
- const v8::FunctionCallbackInfo<v8::Value>& args) {
485
+ void Agent ::CallAndPauseOnStart (
486
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
541
487
Environment* env = Environment::GetCurrent (args);
542
488
CHECK_GT (args.Length (), 1 );
543
489
CHECK (args[0 ]->IsFunction ());
@@ -546,91 +492,41 @@ void AgentImpl::CallAndPauseOnStart(
546
492
call_args.push_back (args[i]);
547
493
}
548
494
549
- env->inspector_agent ()->SchedulePauseOnNextStatement (" Break on start" );
495
+ Agent* agent = env->inspector_agent ();
496
+ agent->inspector_ ->schedulePauseOnNextStatement (" Break on start" );
550
497
551
498
v8::MaybeLocal<v8::Value> retval =
552
499
args[0 ].As <v8::Function>()->Call (env->context (), args[1 ],
553
500
call_args.size (), call_args.data ());
554
501
args.GetReturnValue ().Set (retval.ToLocalChecked ());
555
502
}
556
503
557
- void AgentImpl ::WaitForDisconnect () {
504
+ void Agent ::WaitForDisconnect () {
558
505
if (io_ != nullptr ) {
559
506
io_->WaitForDisconnect ();
560
507
}
561
508
}
562
509
563
- void AgentImpl::FatalException (Local<Value> error,
564
- Local<v8::Message> message) {
510
+ void Agent::FatalException (Local<Value> error, Local<v8::Message> message) {
565
511
if (!IsStarted ())
566
512
return ;
567
513
inspector_->FatalException (error, message);
568
514
WaitForDisconnect ();
569
515
}
570
516
571
- void AgentImpl::SchedulePauseOnNextStatement (const std::string& reason) {
572
- inspector_->schedulePauseOnNextStatement (reason);
573
- }
574
-
575
- // Exported class Agent
576
- Agent::Agent (node::Environment* env) : impl(new AgentImpl(env)) {}
577
-
578
- Agent::~Agent () {
579
- delete impl;
580
- }
581
-
582
- bool Agent::Start (v8::Platform* platform, const char * path,
583
- const DebugOptions& options) {
584
- return impl->Start (platform, path, options);
585
- }
586
-
587
- void Agent::Stop () {
588
- impl->Stop ();
589
- }
590
-
591
- bool Agent::IsStarted () {
592
- return impl->IsStarted ();
593
- }
594
-
595
- bool Agent::IsConnected () {
596
- return impl->IsConnected ();
597
- }
598
-
599
- void Agent::WaitForDisconnect () {
600
- impl->WaitForDisconnect ();
601
- }
602
-
603
- void Agent::FatalException (Local<Value> error,
604
- Local<v8::Message> message) {
605
- impl->FatalException (error, message);
606
- }
607
-
608
- void Agent::SchedulePauseOnNextStatement (const std::string& reason) {
609
- impl->SchedulePauseOnNextStatement (reason);
610
- }
611
-
612
- void Agent::Connect (InspectorSessionDelegate* delegate) {
613
- impl->Connect (delegate);
614
- }
615
-
616
517
void Agent::Dispatch (const StringView& message) {
617
- CHECK_NE (impl-> client () , nullptr );
618
- impl-> client () ->dispatchMessageFromFrontend (message);
518
+ CHECK_NE (inspector_ , nullptr );
519
+ inspector_ ->dispatchMessageFromFrontend (message);
619
520
}
620
521
621
522
void Agent::Disconnect () {
622
- CHECK_NE (impl->client (), nullptr );
623
- impl->client ()->disconnectFrontend ();
624
- }
625
-
626
- InspectorSessionDelegate* Agent::delegate () {
627
- CHECK_NE (impl->client (), nullptr );
628
- return impl->client ()->delegate ();
523
+ CHECK_NE (inspector_, nullptr );
524
+ inspector_->disconnectFrontend ();
629
525
}
630
526
631
527
void Agent::RunMessageLoop () {
632
- CHECK_NE (impl-> client () , nullptr );
633
- impl-> client () ->runMessageLoopOnPause (CONTEXT_GROUP_ID);
528
+ CHECK_NE (inspector_ , nullptr );
529
+ inspector_ ->runMessageLoopOnPause (CONTEXT_GROUP_ID);
634
530
}
635
531
636
532
} // namespace inspector
0 commit comments