Browse Source

fix: dangling raw_ptr in ElectronBrowserMainParts dtor (#39591)

* fix: dangling raw_ptr in ElectronBrowserMainParts dtor

Co-authored-by: Charles Kerr <[email protected]>

* fixup! fix: dangling raw_ptr in ElectronBrowserMainParts dtor

Browser::WhenReady() holds a reference to JsEnv isolate so must come after

Co-authored-by: Charles Kerr <[email protected]>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <[email protected]>
trop[bot] 1 year ago
parent
commit
0641a85498

+ 5 - 5
shell/browser/electron_browser_main_parts.cc

@@ -210,11 +210,11 @@ ElectronBrowserMainParts* ElectronBrowserMainParts::self_ = nullptr;
 
 ElectronBrowserMainParts::ElectronBrowserMainParts()
     : fake_browser_process_(std::make_unique<BrowserProcessImpl>()),
-      browser_(std::make_unique<Browser>()),
-      node_bindings_(
-          NodeBindings::Create(NodeBindings::BrowserEnvironment::kBrowser)),
-      electron_bindings_(
-          std::make_unique<ElectronBindings>(node_bindings_->uv_loop())) {
+      node_bindings_{
+          NodeBindings::Create(NodeBindings::BrowserEnvironment::kBrowser)},
+      electron_bindings_{
+          std::make_unique<ElectronBindings>(node_bindings_->uv_loop())},
+      browser_{std::make_unique<Browser>()} {
   DCHECK(!self_) << "Cannot have two ElectronBrowserMainParts";
   self_ = this;
 }

+ 11 - 2
shell/browser/electron_browser_main_parts.h

@@ -165,11 +165,20 @@ class ElectronBrowserMainParts : public content::BrowserMainParts {
   // Before then, we just exit() without any intermediate steps.
   absl::optional<int> exit_code_;
 
-  std::unique_ptr<JavascriptEnvironment> js_env_;
-  std::unique_ptr<Browser> browser_;
   std::unique_ptr<NodeBindings> node_bindings_;
+
+  // depends-on: node_bindings_
   std::unique_ptr<ElectronBindings> electron_bindings_;
+
+  // depends-on: node_bindings_
+  std::unique_ptr<JavascriptEnvironment> js_env_;
+
+  // depends-on: js_env_'s isolate
   std::unique_ptr<NodeEnvironment> node_env_;
+
+  // depends-on: js_env_'s isolate
+  std::unique_ptr<Browser> browser_;
+
   std::unique_ptr<IconManager> icon_manager_;
   std::unique_ptr<base::FieldTrialList> field_trial_list_;