Skip to content

Commit

Permalink
fix(debugger): Fix potential debugger lockups
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Aug 26, 2015
1 parent 4a97370 commit f9b0a92
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/debugger/debuggerCommons.js
Expand Up @@ -20,6 +20,7 @@ exports.attachDebugger = function(pid, opt_port) {
target: '.*executors\.js', //jshint ignore:line
line: 37
}, function() {
process.send('ready');
client.reqContinue(function() {
// Intentionally blank.
});
Expand Down
36 changes: 18 additions & 18 deletions lib/debugger/modes/debuggerRepl.js
Expand Up @@ -100,26 +100,26 @@ DebuggerRepl.prototype.printControlFlow_ = function(callback) {
command: 'evaluate',
arguments: {
frame: 0,
maxStringLength: 4000,
expression: 'protractor.promise.controlFlow().getControlFlowText()'
maxStringLength: 1000,
expression: 'command.getName()'
}
}, function(err, controlFlowResponse) {
if (!err) {
self.client.req({
command: 'evaluate',
arguments: {
frame: 0,
maxStringLength: 1000,
expression: 'command.getName()'
}
}, function(err, res) {
if (res.value) {
console.log('-- Next command: ' + res.value);
}
console.log(controlFlowResponse.value);
callback();
});
}, function(err, res) {
if (res.value) {
console.log('-- Next command: ' + res.value);
}
self.client.req({
command: 'evaluate',
arguments: {
frame: 0,
maxStringLength: 4000,
expression: 'protractor.promise.controlFlow().getControlFlowText()'
}
}, function(err, controlFlowResponse) {
if (controlFlowResponse.value) {
console.log(controlFlowResponse.value);
}
callback();
});
});
};
this.client.once('break', onBreak_);
Expand Down
23 changes: 15 additions & 8 deletions lib/protractor.js
Expand Up @@ -821,7 +821,8 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
var sandbox = vm_.createContext(context);

var browserUnderDebug = this;
flow.execute(function() {
var debuggerReadyPromise = webdriver.promise.defer();
flow.execute(function() {
log.puts('Starting WebDriver debugger in a child process. Pause is ' +
'still beta, please report issues at github.com/angular/protractor\n');
process.debugPort = opt_debugPort || process.debugPort;
Expand All @@ -833,15 +834,21 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
var nodedebug = require('child_process').fork(debuggerClientPath, args);
process.on('exit', function() {
nodedebug.kill('SIGTERM');
});
});
nodedebug.on('message', function(m) {
if (m === 'ready') {
debuggerReadyPromise.fulfill();
}
});
});
});

var pausePromise = flow.execute(function() {
return debuggerReadyPromise.then(function() {
// Necessary for backward compatibility with node < 0.12.0
return browserUnderDebug.executeScript_('', 'empty debugger hook');
});
});

var pausePromise = flow.timeout(1000, 'waiting for debugger to attach')
.then(function() {
// Necessary for backward compatibility with node < 0.12.0
browserUnderDebug.executeScript_('', 'empty debugger hook');
});

// Helper used only by debuggers at './debugger/modes/*.js' to insert code
// into the control flow.
Expand Down

0 comments on commit f9b0a92

Please sign in to comment.