mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Don't delay node module initialization
This commit is contained in:
@@ -46,7 +46,6 @@ int NodeMain(int argc, char *argv[]) {
|
||||
base::TaskScheduler::CreateAndStartWithDefaultParams("Electron");
|
||||
|
||||
// Initialize gin::IsolateHolder.
|
||||
JavascriptEnvironment::Initialize();
|
||||
JavascriptEnvironment gin_env;
|
||||
|
||||
int exec_argc;
|
||||
|
||||
@@ -529,8 +529,6 @@ void OnIconDataAvailable(v8::Isolate* isolate,
|
||||
} // namespace
|
||||
|
||||
App::App(v8::Isolate* isolate) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->set_delegate(this);
|
||||
Browser::Get()->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
|
||||
// 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() {
|
||||
@@ -195,28 +215,6 @@ void AtomBrowserMainParts::PostMainMessageLoopStart() {
|
||||
base::FilePath user_dir;
|
||||
PathService::Get(brightray::DIR_USER_DATA, &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() {
|
||||
|
||||
@@ -18,22 +18,9 @@
|
||||
|
||||
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()
|
||||
: isolate_holder_(base::ThreadTaskRunnerHandle::Get()),
|
||||
: initialized_(Initialize()),
|
||||
isolate_holder_(base::ThreadTaskRunnerHandle::Get()),
|
||||
isolate_(isolate_holder_.isolate()),
|
||||
isolate_scope_(isolate_),
|
||||
locker_(isolate_),
|
||||
@@ -49,6 +36,21 @@ void JavascriptEnvironment::OnMessageLoopDestroying() {
|
||||
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) {
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ namespace atom {
|
||||
// Manage the V8 isolate and context automatically.
|
||||
class JavascriptEnvironment {
|
||||
public:
|
||||
static void Initialize();
|
||||
|
||||
JavascriptEnvironment();
|
||||
|
||||
void OnMessageLoopCreated();
|
||||
@@ -32,6 +30,9 @@ class JavascriptEnvironment {
|
||||
}
|
||||
|
||||
private:
|
||||
bool Initialize();
|
||||
|
||||
bool initialized_;
|
||||
gin::IsolateHolder isolate_holder_;
|
||||
v8::Isolate* isolate_;
|
||||
v8::Isolate::Scope isolate_scope_;
|
||||
|
||||
Reference in New Issue
Block a user