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
path: root/lib
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-12-30 21:02:42 +0300
committerRyan Dahl <ry@tinyclouds.org>2010-12-30 21:02:42 +0300
commitf484cbf4c7bbbc8549de55984c072cf2f1132c7a (patch)
tree3490d17a6d601b6d8c259d207f6981eb8b89dd27 /lib
parentbb400d5697dd41d50bb7307d8b3478fa8ae1092f (diff)
Debugger: better maintance of script list
Diffstat (limited to 'lib')
-rw-r--r--lib/_debugger.js75
1 files changed, 56 insertions, 19 deletions
diff --git a/lib/_debugger.js b/lib/_debugger.js
index c401066efa5..a3649105978 100644
--- a/lib/_debugger.js
+++ b/lib/_debugger.js
@@ -190,6 +190,8 @@ function Client() {
this.currentFrame = 0;
this.currentSourceLine = -1;
this.currentSource = null;
+ this.handles = {};
+ this.scripts = {};
// Note that 'Protocol' requires strings instead of Buffers.
socket.setEncoding('utf8');
@@ -203,22 +205,53 @@ inherits(Client, net.Stream);
exports.Client = Client;
+Client.prototype._addHandle = function(desc) {
+ if (typeof desc != 'object' || !desc.handle) throw new Error("bad type");
+ this.handles[desc.id] = desc;
+
+ if (desc.type == 'script') {
+ this._addScript(desc);
+ }
+};
+
+
+Client.prototype._addScript = function(desc) {
+ this.scripts[desc.id] = desc;
+};
+
+
+Client.prototype._removeScript = function(desc) {
+ this.scripts[desc.id] = undefined;
+};
+
+
Client.prototype._onResponse = function(res) {
for (var i = 0; i < this._reqCallbacks.length; i++) {
var cb = this._reqCallbacks[i];
if (this._reqCallbacks[i].request_seq == cb.request_seq) break;
}
+ var self = this;
+
if (res.headers.Type == 'connect') {
- // do nothing
- this.emit('ready');
+ // Request a list of scripts for our own storage.
+ self.reqScripts();
+ self.emit('ready');
+
} else if (res.body && res.body.event == 'break') {
this.emit('break', res.body);
+
} else if (res.body && res.body.event == 'afterCompile') {
- this.emit('afterCompile', res.body);
+ this._addHandle(res.body.body.script);
+
+ } else if (res.body && res.body.event == 'scriptCollected') {
+ // ???
+ this._removeScript(res.body.body.script);
+
} else if (cb) {
this._reqCallbacks.splice(i, 1);
cb(res.body);
+
} else {
this.emit('unhandledResponse', res.body);
}
@@ -283,8 +316,12 @@ Client.prototype.reqBacktrace = function(cb) {
// text: 'node.js (lines: 562)' }
//
Client.prototype.reqScripts = function(cb) {
+ var self = this;
this.req({ command: 'scripts' } , function (res) {
- if (cb) cb(res.body);
+ for (var i = 0; i < res.body.length; i++) {
+ self._addHandle(res.body[i]);
+ }
+ if (cb) cb();
});
};
@@ -376,6 +413,18 @@ function restartQuestion (cb) {
});
}
+function printScripts () {
+ var text = '';
+ for (var id in c.scripts) {
+ var script = c.scripts[id];
+ if (typeof script == 'object' && script.name) {
+ text += script.name == c.currentScript ? '* ' : ' ';
+ text += script.name + '\n';
+ }
+ }
+ process.stdout.write(text);
+}
+
function startInterface() {
@@ -397,7 +446,7 @@ function startInterface() {
if (quitTried) return;
quitTried = true;
term.close();
- console.log("debug done\n");
+ console.log("\ndebug done\n");
if (c.writable) {
c.reqContinue(function (res) {
process.exit(0);
@@ -470,20 +519,8 @@ function startInterface() {
});
} else if (cmd == 'scripts' || cmd == 'scripts full') {
- c.reqScripts(function (res) {
- if (/full/.test(cmd)) {
- console.log(res);
- } else {
- var text = '';
- for (var i = 0; i < res.length; i++) {
- text += res[i].name == c.currentScript ? '* ' : ' ';
- text += res[i].name + '\n';
- }
- process.stdout.write(text);
- }
- term.prompt();
- });
-
+ printScripts();
+ term.prompt();
} else if (/^continue/.test(cmd) || /^c/.test(cmd)) {
c.reqContinue(function (res) {