Get rid of the global_env

This commit is contained in:
Cheng Zhao 2016-03-27 19:21:12 +09:00
parent e5886dda9b
commit e401335ebb
4 changed files with 13 additions and 20 deletions

View file

@ -106,17 +106,21 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
node_debugger_.reset(new NodeDebugger(js_env_->isolate()));
// Create the global environment.
global_env = node_bindings_->CreateEnvironment(js_env_->context());
node::Environment* env =
node_bindings_->CreateEnvironment(js_env_->context());
// Make sure node can get correct environment when debugging.
if (node_debugger_->IsRunning())
global_env->AssignToContext(v8::Debug::GetDebugContext());
env->AssignToContext(v8::Debug::GetDebugContext());
// Add atom-shell extended APIs.
atom_bindings_->BindTo(js_env_->isolate(), global_env->process_object());
atom_bindings_->BindTo(js_env_->isolate(), env->process_object());
// Load everything.
node_bindings_->LoadEnvironment(global_env);
node_bindings_->LoadEnvironment(env);
// Wrap the uv loop with global env.
node_bindings_->set_uv_env(env);
}
void AtomBrowserMainParts::PreMainMessageLoopRun() {

View file

@ -106,8 +106,6 @@ base::FilePath GetResourcesPath(bool is_browser) {
} // namespace
node::Environment* global_env = nullptr;
NodeBindings::NodeBindings(bool is_browser)
: is_browser_(is_browser),
message_loop_(nullptr),
@ -214,10 +212,8 @@ void NodeBindings::RunMessageLoop() {
void NodeBindings::UvRunOnce() {
DCHECK(!is_browser_ || BrowserThread::CurrentlyOn(BrowserThread::UI));
// By default the global env would be used unless user specified another one
// (this happens for renderer process, which wraps the uv loop with web page
// context).
node::Environment* env = uv_env() ? uv_env() : global_env;
node::Environment* env = uv_env();
CHECK(env);
// Use Locker in browser process.
mate::Locker locker(env->isolate());

View file

@ -28,11 +28,4 @@
#include "vendor/node/src/node_buffer.h"
#include "vendor/node/src/node_internals.h"
namespace atom {
// Defined in node_bindings.cc.
// For renderer it's created in atom_renderer_client.cc.
// For browser it's created in atom_browser_main_parts.cc.
extern node::Environment* global_env;
}
#endif // ATOM_COMMON_NODE_INCLUDES_H_

View file

@ -163,6 +163,9 @@ void AtomRendererClient::DidCreateScriptContext(
// Add atom-shell extended APIs.
atom_bindings_->BindTo(env->isolate(), env->process_object());
// Load everything.
node_bindings_->LoadEnvironment(env);
if (first_time) {
// Make uv loop being wrapped by window context.
node_bindings_->set_uv_env(env);
@ -170,9 +173,6 @@ void AtomRendererClient::DidCreateScriptContext(
// Give the node loop a run to make sure everything is ready.
node_bindings_->RunMessageLoop();
}
// Load everything.
node_bindings_->LoadEnvironment(env);
}
void AtomRendererClient::WillReleaseScriptContext(