Get rid of the global_env
This commit is contained in:
parent
e5886dda9b
commit
e401335ebb
4 changed files with 13 additions and 20 deletions
|
@ -106,17 +106,21 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||||
node_debugger_.reset(new NodeDebugger(js_env_->isolate()));
|
node_debugger_.reset(new NodeDebugger(js_env_->isolate()));
|
||||||
|
|
||||||
// Create the global environment.
|
// 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.
|
// Make sure node can get correct environment when debugging.
|
||||||
if (node_debugger_->IsRunning())
|
if (node_debugger_->IsRunning())
|
||||||
global_env->AssignToContext(v8::Debug::GetDebugContext());
|
env->AssignToContext(v8::Debug::GetDebugContext());
|
||||||
|
|
||||||
// Add atom-shell extended APIs.
|
// 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.
|
// 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() {
|
void AtomBrowserMainParts::PreMainMessageLoopRun() {
|
||||||
|
|
|
@ -106,8 +106,6 @@ base::FilePath GetResourcesPath(bool is_browser) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
node::Environment* global_env = nullptr;
|
|
||||||
|
|
||||||
NodeBindings::NodeBindings(bool is_browser)
|
NodeBindings::NodeBindings(bool is_browser)
|
||||||
: is_browser_(is_browser),
|
: is_browser_(is_browser),
|
||||||
message_loop_(nullptr),
|
message_loop_(nullptr),
|
||||||
|
@ -214,10 +212,8 @@ void NodeBindings::RunMessageLoop() {
|
||||||
void NodeBindings::UvRunOnce() {
|
void NodeBindings::UvRunOnce() {
|
||||||
DCHECK(!is_browser_ || BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(!is_browser_ || BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
|
|
||||||
// By default the global env would be used unless user specified another one
|
node::Environment* env = uv_env();
|
||||||
// (this happens for renderer process, which wraps the uv loop with web page
|
CHECK(env);
|
||||||
// context).
|
|
||||||
node::Environment* env = uv_env() ? uv_env() : global_env;
|
|
||||||
|
|
||||||
// Use Locker in browser process.
|
// Use Locker in browser process.
|
||||||
mate::Locker locker(env->isolate());
|
mate::Locker locker(env->isolate());
|
||||||
|
|
|
@ -28,11 +28,4 @@
|
||||||
#include "vendor/node/src/node_buffer.h"
|
#include "vendor/node/src/node_buffer.h"
|
||||||
#include "vendor/node/src/node_internals.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_
|
#endif // ATOM_COMMON_NODE_INCLUDES_H_
|
||||||
|
|
|
@ -163,6 +163,9 @@ void AtomRendererClient::DidCreateScriptContext(
|
||||||
// Add atom-shell extended APIs.
|
// Add atom-shell extended APIs.
|
||||||
atom_bindings_->BindTo(env->isolate(), env->process_object());
|
atom_bindings_->BindTo(env->isolate(), env->process_object());
|
||||||
|
|
||||||
|
// Load everything.
|
||||||
|
node_bindings_->LoadEnvironment(env);
|
||||||
|
|
||||||
if (first_time) {
|
if (first_time) {
|
||||||
// Make uv loop being wrapped by window context.
|
// Make uv loop being wrapped by window context.
|
||||||
node_bindings_->set_uv_env(env);
|
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.
|
// Give the node loop a run to make sure everything is ready.
|
||||||
node_bindings_->RunMessageLoop();
|
node_bindings_->RunMessageLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load everything.
|
|
||||||
node_bindings_->LoadEnvironment(env);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRendererClient::WillReleaseScriptContext(
|
void AtomRendererClient::WillReleaseScriptContext(
|
||||||
|
|
Loading…
Reference in a new issue