Skip to content

Commit d9fbb8a

Browse files
committed
Expose the V8 debug object process.debug
Add one duplicate test from V8, just to make sure it works.
1 parent 3214116 commit d9fbb8a

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

lib/module.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ Module.prototype._compile = function (content, filename) {
420420
+ "\n});";
421421

422422
var compiledWrapper = process.compile(wrapper, filename);
423-
if (filename === process.argv[1] && global.v8debug) {
424-
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0);
423+
if (filename === process.argv[1] && process._debugWaitConnect) {
424+
process.debug.setBreakPoint(compiledWrapper, 0, 0);
425425
}
426426
compiledWrapper.apply(self.exports, [self.exports, require, self, filename, dirname]);
427427
} else {

src/node.cc

+12-10
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,9 @@ static void Load(int argc, char *argv[]) {
16311631
// who do not like how 'src/node.js' setups the module system but do like
16321632
// Node's I/O bindings may want to replace 'f' with their own function.
16331633

1634+
process->Set(String::NewSymbol("_debugWaitConnect"),
1635+
node::debug_wait_connect ? True() : False());
1636+
16341637
Local<Value> args[1] = { Local<Value>::New(process) };
16351638

16361639
f->Call(global, 1, args);
@@ -1741,16 +1744,15 @@ int main(int argc, char *argv[]) {
17411744
int v8argc = node::option_end_index;
17421745
char **v8argv = argv;
17431746

1744-
if (node::debug_wait_connect) {
1745-
// v8argv is a copy of argv up to the script file argument +2 if --debug-brk
1746-
// to expose the v8 debugger js object so that module.js can set
1747-
// a breakpoint on the first line of the startup script
1748-
v8argc += 2;
1749-
v8argv = new char*[v8argc];
1750-
memcpy(v8argv, argv, sizeof(argv) * node::option_end_index);
1751-
v8argv[node::option_end_index] = const_cast<char*>("--expose_debug_as");
1752-
v8argv[node::option_end_index + 1] = const_cast<char*>("v8debug");
1753-
}
1747+
// v8argv is a copy of argv up to the script file argument +2
1748+
// to expose the v8 debugger js object so that module.js can set
1749+
// a breakpoint on the first line of the startup script
1750+
v8argc += 2;
1751+
v8argv = new char*[v8argc];
1752+
memcpy(v8argv, argv, sizeof(argv) * node::option_end_index);
1753+
v8argv[node::option_end_index] = const_cast<char*>("--expose_debug_as");
1754+
v8argv[node::option_end_index + 1] = const_cast<char*>("v8debug");
1755+
17541756
V8::SetFlagsFromCommandLine(&v8argc, v8argv, false);
17551757

17561758
// Ignore SIGPIPE

src/node.js

+3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ global.console.assert = function(expression){
233233

234234
global.Buffer = module.requireNative('buffer').Buffer;
235235

236+
process.debug = global.v8debug.Debug;
237+
global.v8debug = undefined;
238+
236239
process.exit = function (code) {
237240
process.emit("exit");
238241
process.reallyExit(code);

test/simple/test-liveedit.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
common = require("../common");
2+
assert = require("assert");
3+
4+
5+
// This is a duplicate of deps/v8/test/mjsunit/debug-liveedit-1.js
6+
// Just exercises the process.debug object.
7+
8+
eval("var something1 = 25; "
9+
+ " function ChooseAnimal() { return 'Cat'; } "
10+
+ " ChooseAnimal.Helper = function() { return 'Help!'; }");
11+
12+
assert.equal("Cat", ChooseAnimal());
13+
14+
var script = process.debug.findScript(ChooseAnimal);
15+
16+
var orig_animal = "Cat";
17+
var patch_pos = script.source.indexOf(orig_animal);
18+
var new_animal_patch = "Cap' + 'y' + 'bara";
19+
20+
var change_log = new Array();
21+
process.debug.LiveEdit.TestApi.ApplySingleChunkPatch(script,
22+
patch_pos,
23+
orig_animal.length,
24+
new_animal_patch,
25+
change_log);
26+
27+
assert.equal("Capybara", ChooseAnimal());

0 commit comments

Comments
 (0)