Browse Source

fix: call `UnregisterIsolate` consistently (#28556)

* fix: call `UnregisterIsolate` consistently

`JavascriptEnvironment` is the class that calls `RegisterIsolate()`
so it should be the one to call `UnregisterIsolate`, and this can happen
right before disposing the aforementioned `isolate`.

See: https://github.com/electron/electron/pull/28468

* fix

Co-authored-by: Fedor Indutny <[email protected]>
trop[bot] 4 years ago
parent
commit
ce6af063a7
2 changed files with 6 additions and 4 deletions
  1. 0 4
      shell/app/node_main.cc
  2. 6 0
      shell/browser/javascript_environment.cc

+ 0 - 4
shell/app/node_main.cc

@@ -281,10 +281,6 @@ int NodeMain(int argc, char* argv[]) {
     node::Stop(env);
     node::FreeEnvironment(env);
     node::FreeIsolateData(isolate_data);
-
-    gin_env.platform()->DrainTasks(isolate);
-    gin_env.platform()->CancelPendingDelayedTasks(isolate);
-    gin_env.platform()->UnregisterIsolate(isolate);
   }
 
   // According to "src/gin/shell/gin_main.cc":

+ 6 - 0
shell/browser/javascript_environment.cc

@@ -82,6 +82,9 @@ JavascriptEnvironment::JavascriptEnvironment(uv_loop_t* event_loop)
 }
 
 JavascriptEnvironment::~JavascriptEnvironment() {
+  DCHECK_NE(platform_, nullptr);
+  platform_->DrainTasks(isolate_);
+
   {
     v8::Locker locker(isolate_);
     v8::HandleScope scope(isolate_);
@@ -89,6 +92,9 @@ JavascriptEnvironment::~JavascriptEnvironment() {
   }
   isolate_->Exit();
   g_isolate = nullptr;
+
+  platform_->CancelPendingDelayedTasks(isolate_);
+  platform_->UnregisterIsolate(isolate_);
 }
 
 class EnabledStateObserverImpl final