@@ -271,11 +271,6 @@ class NodeInspectorClient : public v8_inspector::V8InspectorClient {
271
271
terminated_(false ),
272
272
running_nested_loop_(false ) {
273
273
inspector_ = V8Inspector::create (env->isolate (), this );
274
- const uint8_t CONTEXT_NAME[] = " Node.js Main Context" ;
275
- StringView context_name (CONTEXT_NAME, sizeof (CONTEXT_NAME) - 1 );
276
- v8_inspector::V8ContextInfo info (env->context (), CONTEXT_GROUP_ID,
277
- context_name);
278
- inspector_->contextCreated (info);
279
274
}
280
275
281
276
void runMessageLoopOnPause (int context_group_id) override {
@@ -296,6 +291,17 @@ class NodeInspectorClient : public v8_inspector::V8InspectorClient {
296
291
return uv_hrtime () * 1.0 / NANOS_PER_MSEC;
297
292
}
298
293
294
+ void contextCreated (Local<Context> context, const std::string& name) {
295
+ std::unique_ptr<StringBuffer> name_buffer = Utf8ToStringView (name);
296
+ v8_inspector::V8ContextInfo info (context, CONTEXT_GROUP_ID,
297
+ name_buffer->string ());
298
+ inspector_->contextCreated (info);
299
+ }
300
+
301
+ void contextDestroyed (Local<Context> context) {
302
+ inspector_->contextDestroyed (context);
303
+ }
304
+
299
305
void quitMessageLoopOnPause () override {
300
306
terminated_ = true ;
301
307
}
@@ -379,6 +385,7 @@ bool Agent::Start(v8::Platform* platform, const char* path,
379
385
inspector_ =
380
386
std::unique_ptr<NodeInspectorClient>(
381
387
new NodeInspectorClient (parent_env_, platform));
388
+ inspector_->contextCreated (parent_env_->context (), " Node.js Main Context" );
382
389
platform_ = platform;
383
390
if (options.inspector_enabled ()) {
384
391
return StartIoThread ();
@@ -451,6 +458,8 @@ bool Agent::IsStarted() {
451
458
}
452
459
453
460
void Agent::WaitForDisconnect () {
461
+ CHECK_NE (inspector_, nullptr );
462
+ inspector_->contextDestroyed (parent_env_->context ());
454
463
if (io_ != nullptr ) {
455
464
io_->WaitForDisconnect ();
456
465
}
0 commit comments