Don't delay node module initialization
This commit is contained in:
parent
1043f07b42
commit
1b30cac372
5 changed files with 41 additions and 43 deletions
|
@ -46,7 +46,6 @@ int NodeMain(int argc, char *argv[]) {
|
||||||
base::TaskScheduler::CreateAndStartWithDefaultParams("Electron");
|
base::TaskScheduler::CreateAndStartWithDefaultParams("Electron");
|
||||||
|
|
||||||
// Initialize gin::IsolateHolder.
|
// Initialize gin::IsolateHolder.
|
||||||
JavascriptEnvironment::Initialize();
|
|
||||||
JavascriptEnvironment gin_env;
|
JavascriptEnvironment gin_env;
|
||||||
|
|
||||||
int exec_argc;
|
int exec_argc;
|
||||||
|
|
|
@ -529,8 +529,6 @@ void OnIconDataAvailable(v8::Isolate* isolate,
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
App::App(v8::Isolate* isolate) {
|
App::App(v8::Isolate* isolate) {
|
||||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
||||||
|
|
||||||
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->set_delegate(this);
|
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->set_delegate(this);
|
||||||
Browser::Get()->AddObserver(this);
|
Browser::Get()->AddObserver(this);
|
||||||
content::GpuDataManager::GetInstance()->AddObserver(this);
|
content::GpuDataManager::GetInstance()->AddObserver(this);
|
||||||
|
|
|
@ -130,7 +130,27 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||||
|
|
||||||
// The ProxyResolverV8 has setup a complete V8 environment, in order to
|
// The ProxyResolverV8 has setup a complete V8 environment, in order to
|
||||||
// avoid conflicts we only initialize our V8 environment after that.
|
// avoid conflicts we only initialize our V8 environment after that.
|
||||||
JavascriptEnvironment::Initialize();
|
js_env_.reset(new JavascriptEnvironment);
|
||||||
|
|
||||||
|
node_bindings_->Initialize();
|
||||||
|
|
||||||
|
// Create the global environment.
|
||||||
|
node::Environment* env =
|
||||||
|
node_bindings_->CreateEnvironment(js_env_->context());
|
||||||
|
node_env_.reset(new NodeEnvironment(env));
|
||||||
|
|
||||||
|
// Enable support for v8 inspector
|
||||||
|
node_debugger_.reset(new NodeDebugger(env));
|
||||||
|
node_debugger_->Start();
|
||||||
|
|
||||||
|
// Add Electron extended APIs.
|
||||||
|
atom_bindings_->BindTo(js_env_->isolate(), env->process_object());
|
||||||
|
|
||||||
|
// Load everything.
|
||||||
|
node_bindings_->LoadEnvironment(env);
|
||||||
|
|
||||||
|
// Wrap the uv loop with global env.
|
||||||
|
node_bindings_->set_uv_env(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AtomBrowserMainParts::PreCreateThreads() {
|
int AtomBrowserMainParts::PreCreateThreads() {
|
||||||
|
@ -195,28 +215,6 @@ void AtomBrowserMainParts::PostMainMessageLoopStart() {
|
||||||
base::FilePath user_dir;
|
base::FilePath user_dir;
|
||||||
PathService::Get(brightray::DIR_USER_DATA, &user_dir);
|
PathService::Get(brightray::DIR_USER_DATA, &user_dir);
|
||||||
process_singleton_.reset(new ProcessSingleton(user_dir));
|
process_singleton_.reset(new ProcessSingleton(user_dir));
|
||||||
|
|
||||||
js_env_.reset(new JavascriptEnvironment);
|
|
||||||
|
|
||||||
node_bindings_->Initialize();
|
|
||||||
|
|
||||||
// Create the global environment.
|
|
||||||
node::Environment* env =
|
|
||||||
node_bindings_->CreateEnvironment(js_env_->context());
|
|
||||||
node_env_.reset(new NodeEnvironment(env));
|
|
||||||
|
|
||||||
// Enable support for v8 inspector
|
|
||||||
node_debugger_.reset(new NodeDebugger(env));
|
|
||||||
node_debugger_->Start();
|
|
||||||
|
|
||||||
// Add Electron extended APIs.
|
|
||||||
atom_bindings_->BindTo(js_env_->isolate(), env->process_object());
|
|
||||||
|
|
||||||
// Load everything.
|
|
||||||
node_bindings_->LoadEnvironment(env);
|
|
||||||
|
|
||||||
// Wrap the uv loop with global env.
|
|
||||||
node_bindings_->set_uv_env(env);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomBrowserMainParts::PostMainMessageLoopRun() {
|
void AtomBrowserMainParts::PostMainMessageLoopRun() {
|
||||||
|
|
|
@ -18,22 +18,9 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// static
|
|
||||||
void JavascriptEnvironment::Initialize() {
|
|
||||||
auto cmd = base::CommandLine::ForCurrentProcess();
|
|
||||||
|
|
||||||
// --js-flags.
|
|
||||||
std::string js_flags = cmd->GetSwitchValueASCII(switches::kJavaScriptFlags);
|
|
||||||
if (!js_flags.empty())
|
|
||||||
v8::V8::SetFlagsFromString(js_flags.c_str(), js_flags.size());
|
|
||||||
|
|
||||||
gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
|
|
||||||
gin::IsolateHolder::kStableV8Extras,
|
|
||||||
gin::ArrayBufferAllocator::SharedInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
JavascriptEnvironment::JavascriptEnvironment()
|
JavascriptEnvironment::JavascriptEnvironment()
|
||||||
: isolate_holder_(base::ThreadTaskRunnerHandle::Get()),
|
: initialized_(Initialize()),
|
||||||
|
isolate_holder_(base::ThreadTaskRunnerHandle::Get()),
|
||||||
isolate_(isolate_holder_.isolate()),
|
isolate_(isolate_holder_.isolate()),
|
||||||
isolate_scope_(isolate_),
|
isolate_scope_(isolate_),
|
||||||
locker_(isolate_),
|
locker_(isolate_),
|
||||||
|
@ -49,6 +36,21 @@ void JavascriptEnvironment::OnMessageLoopDestroying() {
|
||||||
isolate_holder_.RemoveRunMicrotasksObserver();
|
isolate_holder_.RemoveRunMicrotasksObserver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool JavascriptEnvironment::Initialize() {
|
||||||
|
auto cmd = base::CommandLine::ForCurrentProcess();
|
||||||
|
|
||||||
|
// --js-flags.
|
||||||
|
std::string js_flags = cmd->GetSwitchValueASCII(switches::kJavaScriptFlags);
|
||||||
|
if (!js_flags.empty())
|
||||||
|
v8::V8::SetFlagsFromString(js_flags.c_str(), js_flags.size());
|
||||||
|
|
||||||
|
gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
|
||||||
|
gin::IsolateHolder::kStableV8Extras,
|
||||||
|
gin::ArrayBufferAllocator::SharedInstance());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
NodeEnvironment::NodeEnvironment(node::Environment* env) : env_(env) {
|
NodeEnvironment::NodeEnvironment(node::Environment* env) : env_(env) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ namespace atom {
|
||||||
// Manage the V8 isolate and context automatically.
|
// Manage the V8 isolate and context automatically.
|
||||||
class JavascriptEnvironment {
|
class JavascriptEnvironment {
|
||||||
public:
|
public:
|
||||||
static void Initialize();
|
|
||||||
|
|
||||||
JavascriptEnvironment();
|
JavascriptEnvironment();
|
||||||
|
|
||||||
void OnMessageLoopCreated();
|
void OnMessageLoopCreated();
|
||||||
|
@ -32,6 +30,9 @@ class JavascriptEnvironment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool Initialize();
|
||||||
|
|
||||||
|
bool initialized_;
|
||||||
gin::IsolateHolder isolate_holder_;
|
gin::IsolateHolder isolate_holder_;
|
||||||
v8::Isolate* isolate_;
|
v8::Isolate* isolate_;
|
||||||
v8::Isolate::Scope isolate_scope_;
|
v8::Isolate::Scope isolate_scope_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue