@@ -194,10 +194,16 @@ Client.prototype._removeScript = function(desc) {
194
194
195
195
196
196
Client . prototype . _onResponse = function ( res ) {
197
- for ( var i = 0 ; i < this . _reqCallbacks . length ; i ++ ) {
198
- var cb = this . _reqCallbacks [ i ] ;
199
- if ( this . _reqCallbacks [ i ] . request_seq == res . body . request_seq ) break ;
200
- }
197
+ var cb ,
198
+ index = - 1 ;
199
+
200
+ this . _reqCallbacks . some ( function ( fn , i ) {
201
+ if ( fn . request_seq == res . body . request_seq ) {
202
+ cb = fn ;
203
+ index = i ;
204
+ return true ;
205
+ }
206
+ } ) ;
201
207
202
208
var self = this ;
203
209
var handled = false ;
@@ -224,7 +230,7 @@ Client.prototype._onResponse = function(res) {
224
230
}
225
231
226
232
if ( cb ) {
227
- this . _reqCallbacks . splice ( i , 1 ) ;
233
+ this . _reqCallbacks . splice ( index , 1 ) ;
228
234
handled = true ;
229
235
cb ( res . body ) ;
230
236
}
@@ -746,6 +752,7 @@ function Interface() {
746
752
debug : [ ] ,
747
753
control : [ ]
748
754
} ;
755
+ this . breakpoints = [ ] ;
749
756
} ;
750
757
751
758
@@ -874,13 +881,13 @@ Interface.prototype.debugEval = function(code, context, filename, callback) {
874
881
function intChars ( n ) {
875
882
// TODO dumb:
876
883
if ( n < 50 ) {
877
- return 2 ;
878
- } else if ( n < 950 ) {
879
884
return 3 ;
880
- } else if ( n < 9950 ) {
885
+ } else if ( n < 950 ) {
881
886
return 4 ;
882
- } else {
887
+ } else if ( n < 9950 ) {
883
888
return 5 ;
889
+ } else {
890
+ return 6 ;
884
891
}
885
892
}
886
893
@@ -914,15 +921,17 @@ Interface.prototype.run = function() {
914
921
915
922
// Restart script
916
923
Interface . prototype . restart = function ( ) {
917
- if ( ! this . child ) return this . error ( 'App isn\'t running... Try `run` instead' ) ;
924
+ if ( ! this . requireConnection ( ) ) return ;
918
925
919
926
var self = this ;
920
927
921
- this . killChild ( ) ;
928
+ self . pause ( ) ;
929
+ self . killChild ( ) ;
922
930
923
931
// XXX need to wait a little bit for the restart to work?
924
932
setTimeout ( function ( ) {
925
933
self . trySpawn ( ) ;
934
+ self . resume ( ) ;
926
935
} , 1000 ) ;
927
936
} ;
928
937
@@ -1093,14 +1102,15 @@ Interface.prototype.out = Interface.stepGenerator('out', 1);
1093
1102
1094
1103
1095
1104
// Add breakpoint
1096
- Interface . prototype . setBreakpoint = function ( script , line , condition ) {
1105
+ Interface . prototype . setBreakpoint = function ( script , line ,
1106
+ condition , silent ) {
1097
1107
if ( ! this . requireConnection ( ) ) return ;
1098
1108
1099
1109
var self = this ,
1100
1110
scriptId ,
1101
1111
ambiguous ;
1102
1112
1103
- if ( ! this . client . scripts [ script ] ) {
1113
+ if ( script != + script && ! this . client . scripts [ script ] ) {
1104
1114
Object . keys ( this . client . scripts ) . forEach ( function ( id ) {
1105
1115
if ( self . client . scripts [ id ] . name . indexOf ( script ) !== - 1 ) {
1106
1116
if ( scriptId ) {
@@ -1127,16 +1137,21 @@ Interface.prototype.setBreakpoint = function(script, line, condition) {
1127
1137
self . pause ( ) ;
1128
1138
self . client . setBreakpoint ( req , function ( res ) {
1129
1139
if ( res . success ) {
1130
- self . list ( 5 ) ;
1140
+ if ( ! silent ) {
1141
+ self . list ( 5 ) ;
1142
+ }
1131
1143
self . client . breakpoints . push ( {
1132
1144
id : res . body . breakpoint ,
1133
1145
scriptId : scriptId ,
1134
- script : self . client . scripts [ scriptId ] . name ,
1135
- line : line
1146
+ script : ( self . client . scripts [ scriptId ] || { } ) . name ,
1147
+ line : line ,
1148
+ condition : condition
1136
1149
} ) ;
1137
1150
1138
1151
} else {
1139
- self . print ( req . message || 'error!' ) ;
1152
+ if ( ! silent ) {
1153
+ self . print ( req . message || 'error!' ) ;
1154
+ }
1140
1155
}
1141
1156
self . resume ( ) ;
1142
1157
} ) ;
@@ -1177,7 +1192,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
1177
1192
self . pause ( ) ;
1178
1193
self . client . clearBreakpoint ( req , function ( res ) {
1179
1194
if ( res . success ) {
1180
- self . client . breakpoints = self . client . breakpoints . splice ( index , - 1 ) ;
1195
+ self . client . breakpoints . splice ( index , 1 ) ;
1181
1196
self . list ( 5 ) ;
1182
1197
} else {
1183
1198
self . print ( req . message || 'error!' ) ;
@@ -1273,16 +1288,18 @@ Interface.prototype.killChild = function() {
1273
1288
}
1274
1289
1275
1290
if ( this . client ) {
1291
+ // Save breakpoints
1292
+ this . breakpoints = this . client . breakpoints ;
1293
+
1276
1294
this . client . destroy ( ) ;
1277
1295
this . client = null ;
1278
1296
}
1279
-
1280
- this . resume ( ) ;
1281
1297
} ;
1282
1298
1283
1299
1284
1300
Interface . prototype . trySpawn = function ( cb ) {
1285
- var self = this ;
1301
+ var self = this ,
1302
+ breakpoints = this . breakpoints || [ ] ;
1286
1303
1287
1304
this . killChild ( ) ;
1288
1305
@@ -1293,17 +1310,23 @@ Interface.prototype.trySpawn = function(cb) {
1293
1310
1294
1311
this . pause ( ) ;
1295
1312
1296
- var client = self . client = new Client ( ) ;
1297
- var connectionAttempts = 0 ;
1313
+ var client = self . client = new Client ( ) ,
1314
+ connectionAttempts = 0 ;
1298
1315
1299
1316
client . once ( 'ready' , function ( ) {
1300
1317
process . stdout . write ( ' ok\n' ) ;
1301
1318
1302
1319
// since we did debug-brk, we're hitting a break point immediately
1303
1320
// continue before anything else.
1304
1321
client . reqContinue ( function ( ) {
1305
- self . resume ( ) ;
1306
1322
if ( cb ) cb ( ) ;
1323
+
1324
+ // Restore breakpoints
1325
+ breakpoints . forEach ( function ( bp ) {
1326
+ self . setBreakpoint ( bp . scriptId , bp . line , bp . condition , true ) ;
1327
+ } ) ;
1328
+
1329
+ self . resume ( ) ;
1307
1330
} ) ;
1308
1331
1309
1332
client . on ( 'close' , function ( ) {
0 commit comments