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

Commit 5d23280

Browse files
committed
fix(debugger): fix issue where output does not display circular dep and functions
1 parent de59047 commit 5d23280

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

lib/debugger/modes/commandRepl.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ var CommandRepl = function(client) {
3030
CommandRepl.prototype.stepEval = function(expression, callback) {
3131
expression = expression.replace(/"/g, '\\\"');
3232
var expr = 'browser.dbgCodeExecutor_.execute("' + expression + '")';
33-
this.evaluate_(expr, callback);
33+
this.evaluate_(expr, function(err, res) {
34+
// Result is a string representation of the evaluation.
35+
if (res !== undefined) {
36+
console.log(res);
37+
}
38+
callback(err, undefined);
39+
});
3440
};
3541

3642
/**
@@ -47,7 +53,11 @@ CommandRepl.prototype.complete = function(line, callback) {
4753
} else {
4854
line = line.replace(/"/g, '\\\"');
4955
var expr = 'browser.dbgCodeExecutor_.complete("' + line + '")';
50-
this.evaluate_(expr, callback);
56+
this.evaluate_(expr, function(err, res) {
57+
// Result is a JSON representation of the autocomplete response.
58+
var result = res === undefined ? undefined : JSON.parse(res);
59+
callback(err, result);
60+
});
5161
}
5262
};
5363

@@ -77,16 +87,14 @@ CommandRepl.prototype.evaluate_ = function(expression, callback) {
7787
command: 'evaluate',
7888
arguments: {
7989
frame: 0,
80-
maxStringLength: 2000,
90+
maxStringLength: -1,
8191
expression: 'browser.dbgCodeExecutor_.getResult()'
8292
}
8393
}, function(err, res) {
8494
try {
85-
var result = res.value === undefined ?
86-
undefined : JSON.parse(res.value);
87-
callback(err, result);
95+
callback(err, res.value);
8896
} catch (e) {
89-
callback(e, null);
97+
callback(e, undefined);
9098
}
9199
self.client.removeListener('break', onbreak_);
92100
});

lib/protractor.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var util = require('util');
12
var url = require('url');
23
var webdriver = require('selenium-webdriver');
34
var helper = require('./util');
@@ -698,14 +699,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
698699
self.execPromiseResult_ = self.execPromiseError_ = undefined;
699700

700701
self.execPromise_ = self.execPromise_.
701-
then(function() {
702-
var result = execFn_();
703-
if (webdriver.promise.isPromise(result)) {
704-
return result.then(function(val) {return val;});
705-
} else {
706-
return result;
707-
}
708-
}).then(function(result) {
702+
then(execFn_).then(function(result) {
709703
self.execPromiseResult_ = result;
710704
}, function(err) {
711705
self.execPromiseError_ = err;
@@ -720,22 +714,42 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
720714
},
721715

722716
// Execute a piece of code.
717+
// Result is a string representation of the evaluation.
723718
execute: function(code) {
724719
var execFn_ = function() {
725720
// Run code through vm so that we can maintain a local scope which is
726721
// isolated from the rest of the execution.
727-
return vm_.runInThisContext(code);
722+
var res = vm_.runInThisContext(code);
723+
if (!webdriver.promise.isPromise(res)) {
724+
res = webdriver.promise.fulfilled(res);
725+
}
726+
727+
return res.then(function(res) {
728+
if (res === undefined) {
729+
return undefined;
730+
} else {
731+
// The '' forces res to be expanded into a string instead of just
732+
// '[Object]'. Then we remove the extra space caused by the '' using
733+
// substring.
734+
return util.format.apply(this, ['', res]).substring(1);
735+
}
736+
});
728737
};
729738
this.execute_(execFn_);
730739
},
731740

732741
// Autocomplete for a line.
742+
// Result is a JSON representation of the autocomplete response.
733743
complete: function(line) {
734744
var self = this;
735745
var execFn_ = function() {
736746
var deferred = webdriver.promise.defer();
737747
self.replServer_.complete(line, function(err, res) {
738-
deferred.fulfill(res, err);
748+
if (err) {
749+
deferred.reject(err);
750+
} else {
751+
deferred.fulfill(JSON.stringify(res));
752+
}
739753
});
740754
return deferred;
741755
};
@@ -756,8 +770,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
756770
if (this.execPromiseError_) {
757771
throw this.execPromiseError_;
758772
}
759-
760-
return JSON.stringify(this.execPromiseResult_);
773+
return this.execPromiseResult_;
761774
}
762775
};
763776

0 commit comments

Comments
 (0)