@@ -1217,47 +1217,68 @@ Interface.prototype.setBreakpoint = function(script, line,
12171217 line = this . client . currentSourceLine + 1 ;
12181218 }
12191219
1220- if ( script != + script && ! this . client . scripts [ script ] ) {
1221- Object . keys ( this . client . scripts ) . forEach ( function ( id ) {
1222- if ( self . client . scripts [ id ] . name . indexOf ( script ) !== - 1 ) {
1223- if ( scriptId ) {
1224- ambiguous = true ;
1225- }
1226- scriptId = id ;
1227- }
1228- } ) ;
1220+ if ( / \( \) $ / . test ( script ) ) {
1221+ // setBreakpoint('functionname()');
1222+ var req = {
1223+ type : 'function' ,
1224+ target : script . replace ( / \( \) $ / , '' ) ,
1225+ condition : condition
1226+ } ;
12291227 } else {
1230- scriptId = script ;
1231- }
1228+ // setBreakpoint('scriptname')
1229+ if ( script != + script && ! this . client . scripts [ script ] ) {
1230+ var scripts = this . client . scripts ;
1231+ Object . keys ( scripts ) . forEach ( function ( id ) {
1232+ if ( scripts [ id ] && scripts [ id ] . name . indexOf ( script ) !== - 1 ) {
1233+ if ( scriptId ) {
1234+ ambiguous = true ;
1235+ }
1236+ scriptId = id ;
1237+ }
1238+ } ) ;
1239+ } else {
1240+ scriptId = script ;
1241+ }
12321242
1233- if ( ! scriptId ) return this . error ( 'Script : ' + script + ' not found' ) ;
1234- if ( ambiguous ) return this . error ( 'Script name is ambiguous' ) ;
1235- if ( line <= 0 ) return this . error ( 'Line should be a positive value' ) ;
1243+ if ( ! scriptId ) return this . error ( 'Script : ' + script + ' not found' ) ;
1244+ if ( ambiguous ) return this . error ( 'Script name is ambiguous' ) ;
1245+ if ( line <= 0 ) return this . error ( 'Line should be a positive value' ) ;
12361246
1237- var req = {
1238- type : 'scriptId' ,
1239- target : scriptId ,
1240- line : line - 1 ,
1241- condition : condition
1242- } ;
1247+ var req = {
1248+ type : 'scriptId' ,
1249+ target : scriptId ,
1250+ line : line - 1 ,
1251+ condition : condition
1252+ } ;
1253+ }
12431254
12441255 self . pause ( ) ;
12451256 self . client . setBreakpoint ( req , function ( res ) {
12461257 if ( res . success ) {
12471258 if ( ! silent ) {
12481259 self . list ( 5 ) ;
12491260 }
1250- self . client . breakpoints . push ( {
1251- id : res . body . breakpoint ,
1252- scriptId : scriptId ,
1253- script : ( self . client . scripts [ scriptId ] || { } ) . name ,
1254- line : line ,
1255- condition : condition
1256- } ) ;
1261+
1262+ // Try load scriptId and line from response
1263+ if ( ! scriptId ) {
1264+ scriptId = res . body . script_id ;
1265+ line = res . body . line ;
1266+ }
1267+
1268+ // If we finally have one - remember this breakpoint
1269+ if ( scriptId ) {
1270+ self . client . breakpoints . push ( {
1271+ id : res . body . breakpoint ,
1272+ scriptId : scriptId ,
1273+ script : ( self . client . scripts [ scriptId ] || { } ) . name ,
1274+ line : line ,
1275+ condition : condition
1276+ } ) ;
1277+ }
12571278
12581279 } else {
12591280 if ( ! silent ) {
1260- self . print ( req . message || 'error!' ) ;
1281+ self . print ( res . message || 'error!' ) ;
12611282 }
12621283 }
12631284 self . resume ( ) ;
0 commit comments