mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Clean up node environment on exit in main process
This commit is contained in:
@@ -132,6 +132,7 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||
// Create the global environment.
|
||||
node::Environment* env =
|
||||
node_bindings_->CreateEnvironment(js_env_->context());
|
||||
node_env_.reset(new NodeEnvironment(env));
|
||||
|
||||
// Make sure node can get correct environment when debugging.
|
||||
if (node_debugger_->IsRunning())
|
||||
|
||||
@@ -22,6 +22,7 @@ class Browser;
|
||||
class JavascriptEnvironment;
|
||||
class NodeBindings;
|
||||
class NodeDebugger;
|
||||
class NodeEnvironment;
|
||||
class BridgeTaskRunner;
|
||||
|
||||
class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
@@ -79,6 +80,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
|
||||
std::unique_ptr<Browser> browser_;
|
||||
std::unique_ptr<JavascriptEnvironment> js_env_;
|
||||
std::unique_ptr<NodeEnvironment> node_env_;
|
||||
std::unique_ptr<NodeBindings> node_bindings_;
|
||||
std::unique_ptr<AtomBindings> atom_bindings_;
|
||||
std::unique_ptr<NodeDebugger> node_debugger_;
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "gin/array_buffer.h"
|
||||
#include "gin/v8_initializer.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
JavascriptEnvironment::JavascriptEnvironment()
|
||||
@@ -46,4 +48,11 @@ bool JavascriptEnvironment::Initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
NodeEnvironment::NodeEnvironment(node::Environment* env) : env_(env) {
|
||||
}
|
||||
|
||||
NodeEnvironment::~NodeEnvironment() {
|
||||
node::FreeEnvironment(env_);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -8,8 +8,13 @@
|
||||
#include "base/macros.h"
|
||||
#include "gin/public/isolate_holder.h"
|
||||
|
||||
namespace node {
|
||||
class Environment;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
// Manage the V8 isolate and context automatically.
|
||||
class JavascriptEnvironment {
|
||||
public:
|
||||
JavascriptEnvironment();
|
||||
@@ -37,6 +42,18 @@ class JavascriptEnvironment {
|
||||
DISALLOW_COPY_AND_ASSIGN(JavascriptEnvironment);
|
||||
};
|
||||
|
||||
// Manage the Node Environment automatically.
|
||||
class NodeEnvironment {
|
||||
public:
|
||||
NodeEnvironment(node::Environment* env);
|
||||
~NodeEnvironment();
|
||||
|
||||
private:
|
||||
node::Environment* env_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NodeEnvironment);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
|
||||
|
||||
Reference in New Issue
Block a user