From 5d232807f1e32a9a3ba5a5e4f07ace5d535fc3cd Mon Sep 17 00:00:00 2001 From: Hank Duan Date: Tue, 3 Mar 2015 12:39:06 -0800 Subject: [PATCH] fix(debugger): fix issue where output does not display circular dep and functions --- lib/debugger/modes/commandRepl.js | 22 ++++++++++++------ lib/protractor.js | 37 +++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/lib/debugger/modes/commandRepl.js b/lib/debugger/modes/commandRepl.js index 9d9e0b30c..275c4c51c 100644 --- a/lib/debugger/modes/commandRepl.js +++ b/lib/debugger/modes/commandRepl.js @@ -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); + }); }; /** @@ -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); + }); } }; @@ -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_); }); diff --git a/lib/protractor.js b/lib/protractor.js index b7c03daff..43d0b7e0d 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -1,3 +1,4 @@ +var util = require('util'); var url = require('url'); var webdriver = require('selenium-webdriver'); var helper = require('./util'); @@ -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; @@ -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; }; @@ -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_; } };