From 5e58915bdde5617ddae23de866c358d9ec2ceec8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 21 Jan 2015 14:00:19 -0800 Subject: [PATCH] Separate LoadEnvironment from CreateEnvironment --- atom/browser/atom_browser_main_parts.cc | 3 ++- atom/common/node_bindings.cc | 6 ++++-- atom/common/node_bindings.h | 3 +++ atom/renderer/atom_renderer_client.cc | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index 4233949c9c5..4eae597b8f3 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -63,8 +63,9 @@ void AtomBrowserMainParts::PostEarlyInitialization() { // Support the "--debug" switch. node_debugger_.reset(new NodeDebugger(js_env_->isolate())); - // Create the global environment. + // Create and load the global environment. global_env = node_bindings_->CreateEnvironment(js_env_->context()); + node_bindings_->LoadEnvironment(global_env); // Make sure node can get correct environment when debugging. if (node_debugger_->IsRunning()) diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index e43c4d9625b..1f3180fb895 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -247,11 +247,13 @@ node::Environment* NodeBindings::CreateEnvironment( env->set_process_object(process_object); SetupProcessObject(env, argc, argv, exec_argc, exec_argv); - LoadEnvironment(env); - return env; } +void NodeBindings::LoadEnvironment(node::Environment* env) { + node::LoadEnvironment(env); +} + void NodeBindings::PrepareMessageLoop() { DCHECK(!is_browser_ || BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/atom/common/node_bindings.h b/atom/common/node_bindings.h index 5c3c7783144..908fc89e9ae 100644 --- a/atom/common/node_bindings.h +++ b/atom/common/node_bindings.h @@ -32,6 +32,9 @@ class NodeBindings { // Create the environment and load node.js. virtual node::Environment* CreateEnvironment(v8::Handle context); + // Load node.js in the environment. + void LoadEnvironment(node::Environment* env); + // Prepare for message loop integration. virtual void PrepareMessageLoop(); diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index c910014e19d..e9dc66e96ce 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -148,6 +148,7 @@ void AtomRendererClient::DidCreateScriptContext(blink::WebFrame* frame, // Setup node environment for each window. node::Environment* env = node_bindings_->CreateEnvironment(context); + node_bindings_->LoadEnvironment(env); // Add atom-shell extended APIs. atom_bindings_->BindToFrame(frame);