Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app: add support for inspect/inspect-brk in forked node process #9739

Merged
merged 2 commits into from Jun 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions atom/app/node_main.cc
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/node_debugger.cc
Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion atom/browser/node_debugger.h
Expand Up @@ -7,7 +7,15 @@

#include <memory>

#include "atom/common/node_includes.h"
#include "base/macros.h"

namespace node {
class Environment;
}

namespace v8 {
class Platform;
}

namespace atom {

Expand Down
31 changes: 30 additions & 1 deletion spec/node-spec.js
Expand Up @@ -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
}
Expand All @@ -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()}`))
})
})
})
})

Expand Down