Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2011-09-29 22:18:35 +0400
committerRyan Dahl <ry@tinyclouds.org>2011-10-01 00:22:56 +0400
commit360ce526fd5391a955005b27f327bda83acac6dd (patch)
tree7ddf3dd03873ae0e4b0d9eb7ea18914c116f4583
parent4e43afd9737f6c2f1b51d8dbfbb2bc42fabc4deb (diff)
debugger: watch, unwatch, watchers
Fixes #1800.
-rw-r--r--lib/_debugger.js73
-rw-r--r--test/simple/test-debugger-repl.js25
2 files changed, 94 insertions, 4 deletions
diff --git a/lib/_debugger.js b/lib/_debugger.js
index b90d8fbe9c6..8fa09e779b8 100644
--- a/lib/_debugger.js
+++ b/lib/_debugger.js
@@ -644,6 +644,9 @@ var commands = [
'clearBreakpoint (cb)',
],
[
+ 'watch',
+ 'unwatch',
+ 'watchers',
'repl',
'restart',
'kill',
@@ -784,6 +787,7 @@ function Interface(stdin, stdout, args) {
control: []
};
this.breakpoints = [];
+ this._watchers = [];
// Run script automatically
this.pause();
@@ -863,6 +867,8 @@ Interface.prototype.error = function(text) {
// Debugger's `break` event handler
Interface.prototype.handleBreak = function(r) {
+ var self = this;
+
this.pause();
// Save execution context's data
@@ -875,10 +881,15 @@ Interface.prototype.handleBreak = function(r) {
// Print break data
this.print(SourceInfo(r));
- // And list source
- this.list(2);
+ // Show watchers' values
+ this.watchers(true, function (err) {
+ if (err) return self.error(err);
- this.resume(true);
+ // And list source
+ self.list(2);
+
+ self.resume(true);
+ });
};
@@ -1209,6 +1220,62 @@ Interface.prototype.step = Interface.stepGenerator('in', 1);
Interface.prototype.out = Interface.stepGenerator('out', 1);
+// Watch
+Interface.prototype.watch = function(expr) {
+ this._watchers.push(expr);
+};
+
+// Unwatch
+Interface.prototype.unwatch = function(expr) {
+ var index = this._watchers.indexOf(expr);
+
+ // Unwatch by expression
+ // or
+ // Unwatch by watcher number
+ this._watchers.splice(index !== -1 ? index : +expr, 1);
+};
+
+// List watchers
+Interface.prototype.watchers = function() {
+ var self = this,
+ verbose = arguments[0] || false,
+ callback = arguments[1] || function() {},
+ waiting = this._watchers.length,
+ values = [];
+
+ this.pause();
+
+ if (!waiting) {
+ this.resume();
+
+ return callback();
+ }
+
+ this._watchers.forEach(function(watcher, i) {
+ self.debugEval(watcher, null, null, function(err, value) {
+ values[i] = err ? '<error>' : value;
+ wait();
+ });
+ });
+
+ function wait() {
+ if (--waiting === 0) {
+ if (verbose) self.print('Watchers:');
+
+ self._watchers.forEach(function(watcher, i) {
+ self.print(leftPad(i, ' ') + ': ' + watcher + ' = ' +
+ JSON.stringify(values[i]));
+ });
+
+ if (verbose) self.print('');
+
+ self.resume();
+
+ callback(null);
+ }
+ }
+};
+
// Add breakpoint
Interface.prototype.setBreakpoint = function(script, line,
condition, silent) {
diff --git a/test/simple/test-debugger-repl.js b/test/simple/test-debugger-repl.js
index 25d3ceeda44..6152fd4f47f 100644
--- a/test/simple/test-debugger-repl.js
+++ b/test/simple/test-debugger-repl.js
@@ -46,7 +46,7 @@ child.on('line', function(line) {
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
var expectedLine = expected[0].lines.shift();
- assert.ok(line.match(expectedLine) !== null);
+ assert.ok(line.match(expectedLine) !== null, expectedLine);
if (expected[0].lines.length === 0) {
var callback = expected[0].callback;
@@ -59,6 +59,15 @@ function addTest(input, output) {
function next() {
if (expected.length > 0) {
child.stdin.write(expected[0].input + '\n');
+
+ if (!expected[0].lines) {
+ process.nextTick(function() {
+ var callback = expected[0].callback;
+ expected.shift();
+
+ callback && callback();
+ });
+ }
} else {
finish();
}
@@ -80,12 +89,26 @@ addTest('n', [
/11/, /12/, /13/, /14/, /15/
]);
+// Watch
+addTest('watch("\'x\'")');
+
// Continue
addTest('c', [
/break in .*:7/,
+ /Watchers/,
+ /0:\s+'x' = "x"/,
+ /()/,
/5/, /6/, /7/, /8/, /9/
]);
+// Show watchers
+addTest('watchers', [
+ /0:\s+'x' = "x"/
+]);
+
+// Unwatch
+addTest('unwatch("\'x\'")');
+
// Step out
addTest('o', [
/break in .*:14/,