Do not create duplicate V8Platform in NodeDebugger

This commit is contained in:
Cheng Zhao 2017-12-08 09:31:35 +09:00
parent 00afeaba9a
commit c0c2461245
5 changed files with 7 additions and 16 deletions

View file

@ -58,7 +58,7 @@ int NodeMain(int argc, char *argv[]) {
// Enable support for v8 inspector. // Enable support for v8 inspector.
NodeDebugger node_debugger(env); NodeDebugger node_debugger(env);
node_debugger.Start(); node_debugger.Start(gin_env.platform());
mate::Dictionary process(gin_env.isolate(), env->process_object()); mate::Dictionary process(gin_env.isolate(), env->process_object());
#if defined(OS_WIN) #if defined(OS_WIN)

View file

@ -137,7 +137,7 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
// Enable support for v8 inspector // Enable support for v8 inspector
node_debugger_.reset(new NodeDebugger(env)); node_debugger_.reset(new NodeDebugger(env));
node_debugger_->Start(); node_debugger_->Start(js_env_->platform());
// Add Electron extended APIs. // Add Electron extended APIs.
atom_bindings_->BindTo(js_env_->isolate(), env->process_object()); atom_bindings_->BindTo(js_env_->isolate(), env->process_object());

View file

@ -23,6 +23,7 @@ class JavascriptEnvironment {
void OnMessageLoopCreated(); void OnMessageLoopCreated();
void OnMessageLoopDestroying(); void OnMessageLoopDestroying();
node::NodePlatform* platform() const { return platform_; }
v8::Isolate* isolate() const { return isolate_; } v8::Isolate* isolate() const { return isolate_; }
v8::Local<v8::Context> context() const { v8::Local<v8::Context> context() const {
return v8::Local<v8::Context>::New(isolate_, context_); return v8::Local<v8::Context>::New(isolate_, context_);

View file

@ -14,15 +14,13 @@
namespace atom { namespace atom {
NodeDebugger::NodeDebugger(node::Environment* env) NodeDebugger::NodeDebugger(node::Environment* env)
: env_(env), platform_(nullptr) { : env_(env) {
} }
NodeDebugger::~NodeDebugger() { NodeDebugger::~NodeDebugger() {
if (platform_)
FreePlatform(platform_);
} }
void NodeDebugger::Start() { void NodeDebugger::Start(node::NodePlatform* platform) {
auto inspector = env_->inspector_agent(); auto inspector = env_->inspector_agent();
if (inspector == nullptr) if (inspector == nullptr)
return; return;
@ -37,13 +35,6 @@ void NodeDebugger::Start() {
} }
if (options.inspector_enabled()) { if (options.inspector_enabled()) {
// Use custom platform since the gin platform does not work correctly
// with node's inspector agent. We use the default thread pool size
// specified by node.cc
platform_ = node::CreatePlatform(
/* thread_pool_size */ 4, env_->event_loop(),
/* tracing_controller */ nullptr);
// Set process._debugWaitConnect if --inspect-brk was specified to stop // Set process._debugWaitConnect if --inspect-brk was specified to stop
// the debugger on the first line // the debugger on the first line
if (options.wait_for_connect()) { if (options.wait_for_connect()) {
@ -51,7 +42,7 @@ void NodeDebugger::Start() {
process.Set("_breakFirstLine", true); process.Set("_breakFirstLine", true);
} }
inspector->Start(platform_, nullptr, options); inspector->Start(platform, nullptr, options);
} }
} }

View file

@ -20,11 +20,10 @@ class NodeDebugger {
explicit NodeDebugger(node::Environment* env); explicit NodeDebugger(node::Environment* env);
~NodeDebugger(); ~NodeDebugger();
void Start(); void Start(node::NodePlatform* platform);
private: private:
node::Environment* env_; node::Environment* env_;
node::NodePlatform* platform_;
DISALLOW_COPY_AND_ASSIGN(NodeDebugger); DISALLOW_COPY_AND_ASSIGN(NodeDebugger);
}; };