From e401335ebb2fed1bd224a4be8f305e593f8a2c8c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Mar 2016 19:21:12 +0900 Subject: [PATCH] Get rid of the global_env --- atom/browser/atom_browser_main_parts.cc | 12 ++++++++---- atom/common/node_bindings.cc | 8 ++------ atom/common/node_includes.h | 7 ------- atom/renderer/atom_renderer_client.cc | 6 +++--- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index a711c1c8d2b6..f45f6492a849 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -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() { diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 950a2cd786a6..b0b4148c7baf 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -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()); diff --git a/atom/common/node_includes.h b/atom/common/node_includes.h index 3876d8622913..bb76afb54db9 100644 --- a/atom/common/node_includes.h +++ b/atom/common/node_includes.h @@ -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_ diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 99696cc8282b..7746ce123e4f 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -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(