Skip to content
Browse files

debugger: primative object inspection

  • Loading branch information...
1 parent cb71a7d commit 7df8a05129c230ee0345c20c4416fac0279697a8 @ry ry committed
Showing with 86 additions and 10 deletions.
  1. +83 −8 lib/_debugger.js
  2. +3 −2 test/simple/test-debugger-client.js
View
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();
+ });
});
}
View
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();
});
});

0 comments on commit 7df8a05

Please sign in to comment.
Something went wrong with that request. Please try again.