Fix initializing V8 on Windows.

This commit is contained in:
Cheng Zhao 2013-12-17 21:55:56 +08:00
parent 56f709ff1f
commit 75c44ca057
5 changed files with 17 additions and 33 deletions

View file

@ -23,20 +23,6 @@ AtomBrowserBindings::AtomBrowserBindings() {
AtomBrowserBindings::~AtomBrowserBindings() {
}
void AtomBrowserBindings::AfterLoad() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
v8::HandleScope handle_scope(node_isolate);
v8::Handle<v8::Object> global = global_env->context()->Global();
v8::Handle<v8::Object> atom = global->Get(ToV8Value("__atom"))->ToObject();
DCHECK(!atom.IsEmpty());
browser_main_parts_.reset(
atom->Get(ToV8Value("browserMainParts"))->ToObject());
DCHECK(!browser_main_parts_.IsEmpty());
}
void AtomBrowserBindings::OnRendererMessage(int process_id,
int routing_id,
const string16& channel,

View file

@ -26,9 +26,6 @@ class AtomBrowserBindings : public AtomBindings {
AtomBrowserBindings();
virtual ~AtomBrowserBindings();
// Called when the node.js main script has been loaded.
virtual void AfterLoad();
// Called when received a message from renderer.
void OnRendererMessage(int process_id,
int routing_id,

View file

@ -9,6 +9,7 @@
#include "browser/atom_browser_context.h"
#include "browser/browser.h"
#include "common/node_bindings.h"
#include "net/proxy/proxy_resolver_v8.h"
#include "common/v8/node_common.h"
@ -49,32 +50,20 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
v8::HandleScope handle_scope(node_isolate);
v8::Local<v8::Context> context = v8::Context::New(node_isolate);
// Wrap whole process in one global context.
context->Enter();
// Create the global environment.
global_env = node_bindings_->CreateEnvironment(context);
// Wrap whole process in one global context.
context->Enter();
// Add atom-shell extended APIs.
atom_bindings_->BindTo(global_env->process_object());
atom_bindings_->AfterLoad();
}
void AtomBrowserMainParts::PreMainMessageLoopRun() {
node_bindings_->PrepareMessageLoop();
brightray::BrowserMainParts::PreMainMessageLoopRun();
{
v8::HandleScope handle_scope(node_isolate);
v8::Context::Scope context_scope(global_env->context());
v8::Handle<v8::Value> args;
node::MakeCallback(atom_bindings_->browser_main_parts(),
"preMainMessageLoopRun",
0, &args);
}
node_bindings_->PrepareMessageLoop();
node_bindings_->RunMessageLoop();
// Make sure the url request job factory is created before the
@ -89,4 +78,14 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
#endif
}
int AtomBrowserMainParts::PreCreateThreads() {
// Note that we are overriding the PreCreateThreads of brightray, since we
// are integrating node in browser, we can just be sure that an V8 instance
// would be prepared, while the ProxyResolverV8::CreateIsolate() would
// try to create a V8 isolate, which messed everything on Windows, so we
// have to override and call RememberDefaultIsolate on Windows instead.
net::ProxyResolverV8::RememberDefaultIsolate();
return 0;
}
} // namespace atom

View file

@ -30,6 +30,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
// Implementations of content::BrowserMainParts.
virtual void PostEarlyInitialization() OVERRIDE;
virtual void PreMainMessageLoopRun() OVERRIDE;
virtual int PreCreateThreads() OVERRIDE;
#if defined(OS_MACOSX)
virtual void PreMainMessageLoopStart() OVERRIDE;
virtual void PostDestroyThreads() OVERRIDE;

View file

@ -142,6 +142,7 @@ node::Environment* NodeBindings::CreateEnvironment(
// Following code are stripped from node::CreateEnvironment in node.cc:
HandleScope handle_scope(isolate);
Context::Scope context_scope(context);
Environment* env = Environment::New(context);