From a1c44a18e2acc1d4e4443ada75eee49ae0dd434f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 12 Sep 2023 05:27:14 -0500 Subject: [PATCH] fix: NodeService order-of-destruction issue (#39783) * refactor: make ElectronRendererClient::node_bindings_ a const ptr refactor: make ElectronRendererClient::electron_bindings_ a const ptr * fix: order-of-destruction bug in NodeService js_env_ depends on the uv_loop from node_bindings_, but is destroyed after node_bindings_ * chore: revert unintentional commit --- shell/services/node/node_service.cc | 8 ++++---- shell/services/node/node_service.h | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/shell/services/node/node_service.cc b/shell/services/node/node_service.cc index ba86b8d27aca..6257f143e976 100644 --- a/shell/services/node/node_service.cc +++ b/shell/services/node/node_service.cc @@ -20,10 +20,10 @@ namespace electron { NodeService::NodeService( mojo::PendingReceiver receiver) - : node_bindings_( - NodeBindings::Create(NodeBindings::BrowserEnvironment::kUtility)), - electron_bindings_( - std::make_unique(node_bindings_->uv_loop())) { + : node_bindings_{NodeBindings::Create( + NodeBindings::BrowserEnvironment::kUtility)}, + electron_bindings_{ + std::make_unique(node_bindings_->uv_loop())} { if (receiver.is_valid()) receiver_.Bind(std::move(receiver)); } diff --git a/shell/services/node/node_service.h b/shell/services/node/node_service.h index ba5e95caf656..03301e95a34e 100644 --- a/shell/services/node/node_service.h +++ b/shell/services/node/node_service.h @@ -37,10 +37,18 @@ class NodeService : public node::mojom::NodeService { private: bool node_env_stopped_ = false; + + const std::unique_ptr node_bindings_; + + // depends-on: node_bindings_'s uv_loop + const std::unique_ptr electron_bindings_; + + // depends-on: node_bindings_'s uv_loop std::unique_ptr js_env_; - std::unique_ptr node_bindings_; - std::unique_ptr electron_bindings_; + + // depends-on: js_env_'s isolate std::shared_ptr node_env_; + mojo::Receiver receiver_{this}; };