Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(debugger): fix issue where output does not display circular dep a…
Browse files Browse the repository at this point in the history
…nd functions
  • Loading branch information
hankduan committed Mar 11, 2015
1 parent de59047 commit 5d23280
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
22 changes: 15 additions & 7 deletions lib/debugger/modes/commandRepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ var CommandRepl = function(client) {
CommandRepl.prototype.stepEval = function(expression, callback) {
expression = expression.replace(/"/g, '\\\"');
var expr = 'browser.dbgCodeExecutor_.execute("' + expression + '")';
this.evaluate_(expr, callback);
this.evaluate_(expr, function(err, res) {
// Result is a string representation of the evaluation.
if (res !== undefined) {
console.log(res);
}
callback(err, undefined);
});
};

/**
Expand All @@ -47,7 +53,11 @@ CommandRepl.prototype.complete = function(line, callback) {
} else {
line = line.replace(/"/g, '\\\"');
var expr = 'browser.dbgCodeExecutor_.complete("' + line + '")';
this.evaluate_(expr, callback);
this.evaluate_(expr, function(err, res) {
// Result is a JSON representation of the autocomplete response.
var result = res === undefined ? undefined : JSON.parse(res);
callback(err, result);
});
}
};

Expand Down Expand Up @@ -77,16 +87,14 @@ CommandRepl.prototype.evaluate_ = function(expression, callback) {
command: 'evaluate',
arguments: {
frame: 0,
maxStringLength: 2000,
maxStringLength: -1,
expression: 'browser.dbgCodeExecutor_.getResult()'
}
}, function(err, res) {
try {
var result = res.value === undefined ?
undefined : JSON.parse(res.value);
callback(err, result);
callback(err, res.value);
} catch (e) {
callback(e, null);
callback(e, undefined);
}
self.client.removeListener('break', onbreak_);
});
Expand Down
37 changes: 25 additions & 12 deletions lib/protractor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var util = require('util');
var url = require('url');
var webdriver = require('selenium-webdriver');
var helper = require('./util');
Expand Down Expand Up @@ -698,14 +699,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
self.execPromiseResult_ = self.execPromiseError_ = undefined;

self.execPromise_ = self.execPromise_.
then(function() {
var result = execFn_();
if (webdriver.promise.isPromise(result)) {
return result.then(function(val) {return val;});
} else {
return result;
}
}).then(function(result) {
then(execFn_).then(function(result) {
self.execPromiseResult_ = result;
}, function(err) {
self.execPromiseError_ = err;
Expand All @@ -720,22 +714,42 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
},

// Execute a piece of code.
// Result is a string representation of the evaluation.
execute: function(code) {
var execFn_ = function() {
// Run code through vm so that we can maintain a local scope which is
// isolated from the rest of the execution.
return vm_.runInThisContext(code);
var res = vm_.runInThisContext(code);
if (!webdriver.promise.isPromise(res)) {
res = webdriver.promise.fulfilled(res);
}

return res.then(function(res) {
if (res === undefined) {
return undefined;
} else {
// The '' forces res to be expanded into a string instead of just
// '[Object]'. Then we remove the extra space caused by the '' using
// substring.
return util.format.apply(this, ['', res]).substring(1);
}
});
};
this.execute_(execFn_);
},

// Autocomplete for a line.
// Result is a JSON representation of the autocomplete response.
complete: function(line) {
var self = this;
var execFn_ = function() {
var deferred = webdriver.promise.defer();
self.replServer_.complete(line, function(err, res) {
deferred.fulfill(res, err);
if (err) {
deferred.reject(err);
} else {
deferred.fulfill(JSON.stringify(res));
}
});
return deferred;
};
Expand All @@ -756,8 +770,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
if (this.execPromiseError_) {
throw this.execPromiseError_;
}

return JSON.stringify(this.execPromiseResult_);
return this.execPromiseResult_;
}
};

Expand Down

0 comments on commit 5d23280

Please sign in to comment.