Browse Source

debugger: primative object inspection

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
7df8a05129
  1. 91
      lib/_debugger.js
  2. 5
      test/simple/test-debugger-client.js

91
lib/_debugger.js

@ -210,6 +210,22 @@ Client.prototype.reqVersion = function(cb) {
};
Client.prototype.reqLookup = function(refs, cb) {
// TODO: We have a cache of handle's we've already seen in this.handles
// This can be used if we're careful.
var req = {
command: 'lookup',
arguments: {
handles: refs
}
};
this.req(req, function(res) {
if (cb) cb(res);
});
};
Client.prototype.reqEval = function(expression, cb) {
var self = this;
var req = {
@ -225,9 +241,10 @@ Client.prototype.reqEval = function(expression, cb) {
}
this.req(req, function(res) {
console.error('reqEval res ', res.body);
self._addHandle(res.body);
if (cb) cb(res.body);
if (res.success) {
self._addHandle(res.body);
}
if (cb) cb(res);
});
};
@ -307,6 +324,60 @@ Client.prototype.step = function(action, count, cb) {
};
Client.prototype.mirrorObject = function(handle, cb) {
var self = this;
if (handle.type == 'object') {
// The handle looks something like this:
// { handle: 8,
// type: 'object',
// className: 'Object',
// constructorFunction: { ref: 9 },
// protoObject: { ref: 4 },
// prototypeObject: { ref: 2 },
// properties: [ { name: 'hello', propertyType: 1, ref: 10 } ],
// text: '#<an Object>' }
// For now ignore the className and constructor and prototype.
// TJ's method of object inspection would probably be good for this:
// https://groups.google.com/forum/?pli=1#!topic/nodejs-dev/4gkWBOimiOg
var propertyRefs = handle.properties.map(function(p) {
return p.ref;
});
this.reqLookup(propertyRefs, function(res) {
if (!res.success) {
console.error("problem with reqLookup");
if (cb) cb(handle);
return;
}
var mirror = {};
for (var i = 0; i < handle.properties.length; i++) {
var value = res.body[handle.properties[i].ref];
self._addHandle(value);
mirror[handle.properties[i].name] = value.text;
}
if (cb) cb(mirror);
});
} else if (handle.type == 'string') {
process.nextTick(function() {
cb(handle.text);
});
} else {
process.nextTick(function() {
cb(handle);
});
}
};
var commands = [
'backtrace',
'continue',
@ -724,12 +795,16 @@ Interface.prototype.handleCommand = function(cmd) {
} else {
cmd = cmd.slice(i);
client.reqEval(cmd, function(res) {
if (res) {
console.log(res.text);
} else {
console.log(res);
if (!res.success) {
console.log(res.message);
term.prompt();
return;
}
term.prompt();
client.mirrorObject(res.body, function(mirror) {
console.log(mirror);
term.prompt();
});
});
}

5
test/simple/test-debugger-client.js

@ -104,9 +104,10 @@ addTest(function (client, done) {
addTest(function (client, done) {
console.error("eval 2+2");
client.reqEval("2+2", function (res) {
assert.ok(res.success);
console.error(res);
assert.equal('4', res.text);
assert.equal(4, res.value);
assert.equal('4', res.body.text);
assert.equal(4, res.body.value);
done();
});
});

Loading…
Cancel
Save