From 538b97582a40f2ea55f534b47a34c98b94b110e6 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 13 Jun 2017 00:23:11 +0530 Subject: [PATCH 1/2] app: add support for inspect/inspect-brk in forked node process --- atom/app/node_main.cc | 5 +++++ atom/browser/node_debugger.cc | 2 ++ atom/browser/node_debugger.h | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index 210d71d01e19a..ec167af6ac3d6 100644 --- a/atom/app/node_main.cc +++ b/atom/app/node_main.cc @@ -6,6 +6,7 @@ #include "atom/app/uv_task_runner.h" #include "atom/browser/javascript_environment.h" +#include "atom/browser/node_debugger.h" #include "atom/common/api/atom_bindings.h" #include "atom/common/crash_reporter/crash_reporter.h" #include "atom/common/native_mate_converters/string16_converter.h" @@ -50,6 +51,10 @@ int NodeMain(int argc, char *argv[]) { &isolate_data, gin_env.context(), argc, argv, exec_argc, exec_argv); + // Enable support for v8 inspector. + NodeDebugger node_debugger(env); + node_debugger.Start(); + mate::Dictionary process(gin_env.isolate(), env->process_object()); #if defined(OS_WIN) process.SetMethod("log", &AtomBindings::Log); diff --git a/atom/browser/node_debugger.cc b/atom/browser/node_debugger.cc index 2f17d468011ac..f31848abf9554 100644 --- a/atom/browser/node_debugger.cc +++ b/atom/browser/node_debugger.cc @@ -9,6 +9,8 @@ #include "libplatform/libplatform.h" #include "native_mate/dictionary.h" +#include "atom/common/node_includes.h" + namespace atom { NodeDebugger::NodeDebugger(node::Environment* env) : env_(env) { diff --git a/atom/browser/node_debugger.h b/atom/browser/node_debugger.h index a3553192b4ecb..b4eedbcd340cc 100644 --- a/atom/browser/node_debugger.h +++ b/atom/browser/node_debugger.h @@ -7,7 +7,15 @@ #include -#include "atom/common/node_includes.h" +#include "base/macros.h" + +namespace node { +class Environment; +} + +namespace v8 { +class Platform; +} namespace atom { From fc00bf0cc31efe84de5334ed2b59e79ce8648fcb Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Jun 2017 14:04:57 -0700 Subject: [PATCH 2/2] Add initial spec for ELECTRON_RUN_AS_NODE with --inspect-brk --- spec/node-spec.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/node-spec.js b/spec/node-spec.js index 678b8e9490fdf..886ad3d35bf85 100644 --- a/spec/node-spec.js +++ b/spec/node-spec.js @@ -104,8 +104,16 @@ describe('node feature', function () { }) describe('child_process.spawn', function () { + let child + + afterEach(function () { + if (child != null) { + child.kill() + } + }) + it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', function (done) { - const child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], { + child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], { env: { ELECTRON_RUN_AS_NODE: true } @@ -124,6 +132,27 @@ describe('node feature', function () { done() }) }) + + it('supports starting the v8 inspector with --inspect/--inspect-brk', function (done) { + child = ChildProcess.spawn(process.execPath, ['--inspect-brk', path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], { + env: { + ELECTRON_RUN_AS_NODE: true + } + }) + + let output = '' + child.stderr.on('data', function (data) { + output += data + + if (output.trim().startsWith('Debugger listening on port')) { + done() + } + }) + + child.stdout.on('data', function (data) { + done(new Error(`Unexpected output: ${data.toString()}`)) + }) + }) }) })