debugger: Clean ups, bug fixes
authorRyan Dahl <ry@tinyclouds.org>
Thu, 30 Dec 2010 21:25:49 +0000 (13:25 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 30 Dec 2010 21:25:49 +0000 (13:25 -0800)
lib/_debugger.js

index 6517431..a9818be 100644 (file)
@@ -140,8 +140,10 @@ var natives = process.binding('natives');
 
 Client.prototype._addScript = function(desc) {
   this.scripts[desc.id] = desc;
-  desc.isNative = (desc.name.replace('.js', '') in natives) ||
-                  desc.name == 'node.js';
+  if (desc.name) {
+    desc.isNative = (desc.name.replace('.js', '') in natives) ||
+                    desc.name == 'node.js';
+  }
 };
 
 
@@ -153,33 +155,40 @@ Client.prototype._removeScript = function(desc) {
 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;
+    if (this._reqCallbacks[i].request_seq == res.body.request_seq) break;
   }
 
   var self = this;
+  var handled = false;
 
   if (res.headers.Type == 'connect') {
     // Request a list of scripts for our own storage.
     self.reqScripts();
     self.emit('ready');
+    handled = true;
 
   } else if (res.body && res.body.event == 'break') {
     this.emit('break', res.body);
+    handled = true;
 
   } else if (res.body && res.body.event == 'afterCompile') {
     this._addHandle(res.body.body.script);
+    handled = true;
 
   } else if (res.body && res.body.event == 'scriptCollected') {
     // ???
     this._removeScript(res.body.body.script);
+    handled = true;
+
+  }
 
-  } else if (cb) {
+  if (cb) {
     this._reqCallbacks.splice(i, 1);
+    handled = true;
     cb(res.body);
-
-  } else {
-    this.emit('unhandledResponse', res.body);
   }
+
+  if (!handled) this.emit('unhandledResponse', res.body);
 };
 
 
@@ -418,6 +427,7 @@ Interface.prototype.handleCommand = function(cmd) {
     self.tryQuit();
 
   } else if (/^r(un)?/.test(cmd)) {
+    self._lastCommand = null;
     if (self.child) {
       self.restartQuestion(function (yes) {
         if (!yes) {
@@ -497,6 +507,10 @@ Interface.prototype.handleCommand = function(cmd) {
     client.reqContinue();
 
   } else if (/^k(ill)?/.test(cmd)) {
+    if (!client) {
+      self.printNotConnected();
+      return;
+    }
     // kill
     if (self.child) {
       self.killQuestion(function (yes) {