Permalink
Browse files

jslint and renamed --agent-port to --web-port

  • Loading branch information...
dannycoates committed Jul 31, 2010
1 parent dc45824 commit 05c6ebb3755b58dabb3ac571f0642c38b2d4f856
Showing with 141 additions and 123 deletions.
  1. +29 −22 bin/debugger.js
  2. +21 −20 bin/inspector.js
  3. +70 −56 bin/session.js
  4. +18 −15 front-end/node/Debugger.js
  5. +1 −1 front-end/node/InspectorFrontendHostStub.js
  6. +2 −9 readme.md
View
@@ -13,13 +13,16 @@ function makeMessage() {
///////////////////////////////////////////////////////////
// exports
-exports.attachDebugger = function(port) {
- var connected = false;
- var buffer = '';
- var msg = false;
- var conn = net.createConnection(port);
+exports.attachDebugger = function (port) {
+ var connected = false,
+ buffer = '',
+ msg = false,
+ conn = net.createConnection(port),
+ debugr,
+ offset,
+ m;
conn.setEncoding('ascii');
-
+
function parse() {
if (msg && msg.headersDone) {
//parse body
@@ -35,57 +38,61 @@ exports.attachDebugger = function(port) {
}
return;
}
- if (!msg) msg = makeMessage();
+ if (!msg) {
+ msg = makeMessage();
+ }
- var offset = buffer.indexOf('\r\n\r\n');
+ offset = buffer.indexOf('\r\n\r\n');
if (offset > 0) {
msg.headersDone = true;
- msg.headers = buffer.substr(0, offset+4);
- var m = /Content-Length: (\d+)/.exec(msg.headers);
+ msg.headers = buffer.substr(0, offset + 4);
+ m = /Content-Length: (\d+)/.exec(msg.headers);
if (m[1]) {
msg.contentLength = parseInt(m[1], 10);
}
else {
sys.debug('no Content-Length');
}
- buffer = buffer.slice(offset+4);
+ buffer = buffer.slice(offset + 4);
parse();
}
}
- var debugr = Object.create(events.EventEmitter.prototype, {
+ debugr = Object.create(events.EventEmitter.prototype, {
request: {
- value: function(data)
+ value: function (data)
{
if (connected) {
var message = 'Content-Length: ' + data.length + '\r\n\r\n' + data;
conn.write(message);
}
- }},
+ }
+ },
close: {
- value: function()
+ value: function ()
{
conn.end();
- }}
- });
+ }
+ }
+ });
- debugr.__defineGetter__('connected', function() { return connected; });
+ debugr.__defineGetter__('connected', function () { return connected; });
- conn.on('connect', function() {
+ conn.on('connect', function () {
connected = true;
debugr.emit('connect');
});
- conn.on('data', function(data) {
+ conn.on('data', function (data) {
buffer += data;
parse();
});
- conn.on('end', function() {
+ conn.on('end', function () {
debugr.close();
});
- conn.on('close', function() {
+ conn.on('close', function () {
connected = false;
debugr.emit('close');
});
View
@@ -5,27 +5,28 @@ var sys = require('sys'),
var options = {};
-process.argv.forEach(function(arg) {
+process.argv.forEach(function (arg) {
if (arg.indexOf('--') > -1) {
var parts = arg.split('=');
if (parts.length > 1) {
- switch(parts[0]) {
- case '--start':
- options.file = parts[1];
- break;
- case '--start-brk':
- options.file = parts[1];
- options.brk = true;
- break;
- case '--agent-port':
- options.webPort = parseInt(parts[1], 10);
- break;
- case '--debug-port':
- options.debugPort = parseInt(parts[1], 10);
- break;
- default:
- console.log('unknown option: ' + parts[0]);
- break;
+ switch (parts[0]) {
+ case '--start':
+ options.file = parts[1];
+ break;
+ case '--start-brk':
+ options.file = parts[1];
+ options.brk = true;
+ break;
+ case '--web-port':
+ case '--agent-port':
+ options.webPort = parseInt(parts[1], 10);
+ break;
+ case '--debug-port':
+ options.debugPort = parseInt(parts[1], 10);
+ break;
+ default:
+ console.log('unknown option: ' + parts[0]);
+ break;
}
}
else if (parts[0] === '--fwd-io') {
@@ -40,7 +41,7 @@ process.argv.forEach(function(arg) {
console.log('--start=[file] starts [file] in a child process with node_g --debug');
console.log(' [file] path can be absolute or relative to $PWD');
console.log('--start-brk=[file] same as start with --debug-brk');
- console.log('--agent-port=[port] port to host the inspector (default 8080)');
+ console.log('--web-port=[port] port to host the inspector (default 8080)');
console.log('--debug-port=[port] v8 debug port to connect to (default 5858)');
console.log('--fwd-io forward stdout and stderr from the child process to inspector console');
process.exit();
@@ -50,7 +51,7 @@ process.argv.forEach(function(arg) {
var ds = session.createSession(options);
-ds.on('close', function() {
+ds.on('close', function () {
console.log('session closed');
process.exit();
});
View
@@ -12,11 +12,11 @@ var WEBROOT = path.join(path.dirname(__filename), '../front-end');
function staticFile(req, res) {
paperboy
.deliver(WEBROOT, req, res)
- .error(function(statCode,msg) {
+ .error(function (statCode, msg) {
res.writeHead(statCode, {'Content-Type': 'text/plain'});
res.end("Error: " + statCode);
})
- .otherwise(function(err) {
+ .otherwise(function (err) {
var statCode = 404;
res.writeHead(statCode, {'Content-Type': 'text/plain'});
res.end();
@@ -25,7 +25,7 @@ function staticFile(req, res) {
function override(options, defaults) {
var result = {};
- Object.keys(defaults).forEach(function(key) {
+ Object.keys(defaults).forEach(function (key) {
result[key] = options[key] || defaults[key];
});
return result;
@@ -34,50 +34,54 @@ function override(options, defaults) {
///////////////////////////////////////////////////////////
// exports
-exports.createSession = function(options) {
+exports.createSession = function (options) {
var defaults = {
- debugPort: 5858,
- webPort: 8080,
- fwdio: false,
- brk: false,
- file: null
- };
- var settings = override(options || {}, defaults);
- var httpServer = http.createServer(staticFile);
- var wsServer = ws.createServer(null, httpServer);
- var debug = null;
- var breakpoints = {};
- var pending = {};
- var direct = ['scripts',
+ debugPort: 5858,
+ webPort: 8080,
+ fwdio: false,
+ brk: false,
+ file: null
+ },
+ settings = override(options || {}, defaults),
+ httpServer = http.createServer(staticFile),
+ wsServer = ws.createServer(null, httpServer),
+ debug = null,
+ breakpoints = {},
+ pending = {},
+ direct = ['scripts',
'scope',
'lookup',
'evaluate',
'backtrace',
- 'listbreakpoints'];
+ 'listbreakpoints'],
+ flag = '--debug=',
+ proc,
+ sendIo,
+ session;
function breakpointReturnFilter(msg) {
switch (msg.command) {
- case 'setbreakpoint':
- case 'clearbreakpoint':
- case 'changebreakpoint':
- msg.arguments = breakpoints[msg.request_seq];
- delete breakpoints[msg.request_seq];
- break;
- default:
- break;
+ case 'setbreakpoint':
+ case 'clearbreakpoint':
+ case 'changebreakpoint':
+ msg.arguments = breakpoints[msg.request_seq];
+ delete breakpoints[msg.request_seq];
+ break;
+ default:
+ break;
}
return msg;
}
function breakpointRequestFilter(msg) {
switch (msg.command) {
- case 'setbreakpoint':
- case 'clearbreakpoint':
- case 'changebreakpoint':
- breakpoints[msg.seq] = msg.arguments;
- break;
- default:
- break;
+ case 'setbreakpoint':
+ case 'clearbreakpoint':
+ case 'changebreakpoint':
+ breakpoints[msg.seq] = msg.arguments;
+ break;
+ default:
+ break;
}
return msg;
}
@@ -100,8 +104,9 @@ exports.createSession = function(options) {
}
function handleMessage(msg) {
+ var conn, bmsg;
if (msg.type === 'response' && direct.indexOf(msg.command) > -1) {
- var conn = getConnection(msg);
+ conn = getConnection(msg);
if (conn) {
conn.write(JSON.stringify(msg));
}
@@ -110,78 +115,87 @@ exports.createSession = function(options) {
}
}
else {
- var bmsg = breakpointReturnFilter(msg);
+ bmsg = breakpointReturnFilter(msg);
wsServer.broadcast(JSON.stringify(bmsg));
}
}
- wsServer.on('connection', function(conn) {
+ wsServer.on('connection', function (conn) {
if (!debug) {
// first connection
debug = debugr.attachDebugger(settings.debugPort);
- debug.on('data', function(msg) {
+ debug.on('data', function (msg) {
handleMessage(msg);
});
- debug.on('close', function() {
+ debug.on('close', function () {
debug = null;
session.close();
});
}
- conn.on('message', function(data) {
+ conn.on('message', function (data) {
handleRequest(conn, data);
});
session.emit('connection', conn);
});
if (settings.file) {
- var flag = '--debug=';
- if (options.brk) flag = '--debug-brk=';
+ if (options.brk) {
+ flag = '--debug-brk=';
+ }
flag += settings.debugPort;
if (options.profile) {
- var proc = spawn('node_g', [flag, '--prof', '--prof_lazy', settings.file]);
+ proc = spawn('node_g', [flag, '--prof', '--prof_lazy', settings.file]);
}
else {
- var proc = spawn('node_g', [flag, settings.file]);
+ proc = spawn('node_g', [flag, settings.file]);
}
- proc.on('exit', function(code, signal) {
+ proc.on('exit', function (code, signal) {
proc = null;
console.log('proc exited with code: ' + code + ' signal: ' + signal);
});
if (settings.fwdio) {
- function sendIo(event, data) {
+ sendIo = function (event, data) {
wsServer.broadcast(JSON.stringify({
seq: 0,
type: 'event',
event: event,
body: data
}));
- }
+ };
proc.stdout.setEncoding('utf8');
- proc.stdout.on('data', function(data) {
+ proc.stdout.on('data', function (data) {
sys.print(data);
sendIo('stdout', data);
});
proc.stderr.setEncoding('utf8');
- proc.stderr.on('data', function(data) {
+ proc.stderr.on('data', function (data) {
console.error(data);
sendIo('stderr', data);
});
}
}
wsServer.listen(settings.webPort);
- var session = Object.create(events.EventEmitter.prototype, {
+ session = Object.create(events.EventEmitter.prototype, {
close: {
- value: function()
+ value: function ()
{
- if (proc) proc.kill();
- if (debug && debug.connected) debug.close();
- if (wsServer) wsServer.close();
+ if (proc) {
+ proc.kill();
+ }
+ if (debug && debug.connected) {
+ debug.close();
+ }
+ if (wsServer) {
+ wsServer.close();
+ }
session.emit('close');
- }}});
- session.__defineGetter__('webPort', function() { return settings.webPort; });
- session.__defineGetter__('debugPort', function() { return settings.debugPort; });
+ }
+ }
+ });
+ session.__defineGetter__('webPort', function () { return settings.webPort; });
+ session.__defineGetter__('debugPort', function () { return settings.debugPort; });
return session;
};
Oops, something went wrong.

0 comments on commit 05c6ebb

Please sign in to comment.