Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

debugger: full scope evals

  • Loading branch information...
commit 533797a607fabf5d35ae786a1daed4013724c9b2 1 parent d87ab54
@ry ry authored
Showing with 47 additions and 6 deletions.
  1. +47 −6 lib/_debugger.js
View
53 lib/_debugger.js
@@ -235,23 +235,64 @@ Client.prototype.reqLookup = function(refs, cb) {
});
};
-
+// This is like reqEval, except it will look up the expression in each of the
+// scopes associated with the current frame.
Client.prototype.reqEval = function(expression, cb) {
var self = this;
+
+ if (this.currentFrame == NO_FRAME) {
+ // Only need to eval in global scope.
+ this.reqFrameEval(expression, NO_FRAME, cb);
+ return;
+ }
+
+ // Otherwise we need to get the current frame to see which scopes it has.
+ this.reqBacktrace(function (bt) {
+ var frame = bt.frames[self.currentFrame];
+
+ var evalFrames = frame.scopes.map(function(s) {
+ return bt.frames[s.index].index;
+ });
+
+ self._reqFramesEval(expression, evalFrames, cb);
+ });
+};
+
+
+// Finds the first scope in the array in which the epxression evals.
+Client.prototype._reqFramesEval = function(expression, evalFrames, cb) {
+ if (evalFrames.length == 0) {
+ // Just eval in global scope.
+ this.reqFrameEval(expression, NO_FRAME, cb);
+ return;
+ }
+
+ var self = this;
+ var i = evalFrames.shift();
+
+ this.reqFrameEval(expression, i, function(res) {
+ if (res.success) {
+ if (cb) cb(res);
+ } else {
+ self._reqFramesEval(expression, evalFrames, cb);
+ }
+ });
+};
+
+
+Client.prototype.reqFrameEval = function(expression, frame, cb) {
+ var self = this;
var req = {
command: 'evaluate',
arguments: { expression: expression }
};
-
- if (this.currentFrame == NO_FRAME) {
+ if (frame == NO_FRAME) {
req.arguments.global = true;
} else {
- req.arguments.frame = this.currentFrame;
+ req.arguments.frame = frame;
}
- console.error("currentFrame: %d", this.currentFrame);
-
this.req(req, function(res) {
if (res.success) {
self._addHandle(res.body);
Please sign in to comment.
Something went wrong with that request. Please try again.