@@ -366,6 +366,40 @@ suite('JerryProtocolHandler', () => {
366366 } ) ;
367367 } ) ;
368368
369+ suite ( 'getSources' , ( ) => {
370+ test ( 'returns a sources array' , ( ) => {
371+ const sources = [ {
372+ // Dummy, because the sources is 1-indexed
373+ } , {
374+ name : 'ble.js' ,
375+ source : 'console.log("This is a module...");'
376+ } , {
377+ name : 'led-stripe.js' ,
378+ source : 'const x = 10;'
379+ } ] ;
380+
381+ const handler = new JerryDebugProtocolHandler ( { } ) ;
382+ ( handler as any ) . sources = sources ;
383+
384+ const result = handler . getSources ( ) ;
385+ assert . strictEqual ( result [ 0 ] . name , 'ble.js' ) ;
386+ assert . strictEqual ( result [ 1 ] . source , 'const x = 10;' ) ;
387+ assert . strictEqual ( result . length , 2 ) ;
388+ } ) ;
389+
390+ test ( 'returns an empty array' , ( ) => {
391+ const sources = [ {
392+ // Dummy, because the sources is 1-indexed
393+ } ] ;
394+
395+ const handler = new JerryDebugProtocolHandler ( { } ) ;
396+ ( handler as any ) . sources = sources ;
397+
398+ const result = handler . getSources ( ) ;
399+ assert . strictEqual ( result . length , 0 ) ;
400+ } ) ;
401+ } ) ;
402+
369403 suite ( 'evaluate' , ( ) => {
370404 test ( 'sends single eval packet for short expressions' , ( ) => {
371405 const debugClient = {
@@ -455,6 +489,140 @@ suite('JerryProtocolHandler', () => {
455489 } ) ;
456490 } ) ;
457491
492+ suite ( 'getActiveFunctionBreakpointsByScriptId' , ( ) => {
493+ test ( 'return a breakpoints array' , ( ) => {
494+ const name = 'crane.js' ;
495+ const scriptId = 11 ;
496+ const func = {
497+ scriptId,
498+ lines : [
499+ {
500+ activeIndex : 3 ,
501+ func : { name }
502+ } ,
503+ {
504+ activeIndex : - 1 ,
505+ func : { name }
506+ } ,
507+ {
508+ activeIndex : - 1 ,
509+ func : { name }
510+ } ,
511+ ] ,
512+ } ;
513+ const handler = new JerryDebugProtocolHandler ( { } ) ;
514+ ( handler as any ) . functions = [ func ] ;
515+ ( handler as any ) . lineLists = {
516+ [ scriptId ] : [ [ func ] , [ 'a' , func ] , [ func , 'b' ] ] ,
517+ } ;
518+ const breakpoints = handler . getActiveFunctionBreakpointsByScriptId ( scriptId ) ;
519+ assert . strictEqual ( breakpoints [ 0 ] . activeIndex , 3 ) ;
520+ assert . strictEqual ( breakpoints [ 0 ] . func . name , name ) ;
521+ assert . strictEqual ( breakpoints . length , 1 ) ;
522+ } ) ;
523+
524+ test ( 'throws error on invalid scriptId (0)' , ( ) => {
525+ const scriptId = 0 ;
526+ const handler = new JerryDebugProtocolHandler ( { } ) ;
527+ assert . throws ( ( ) => handler . getActiveFunctionBreakpointsByScriptId ( scriptId ) , 'invalid script id' ) ;
528+ } ) ;
529+
530+ test ( 'throws error on invalid scriptId (greater than linelist length)' , ( ) => {
531+ const scriptId = 4 ;
532+ const handler = new JerryDebugProtocolHandler ( { } ) ;
533+ assert . throws ( ( ) => handler . getActiveFunctionBreakpointsByScriptId ( scriptId ) , 'invalid script id' ) ;
534+ } ) ;
535+
536+ test ( 'return an empty array in case of no active functionbreakpoints' , ( ) => {
537+ const name = 'lumbermill.js' ;
538+ const scriptId = 1 ;
539+ const func = {
540+ scriptId,
541+ lines : [
542+ {
543+ activeIndex : - 1 ,
544+ func : { name }
545+ } ,
546+ ] ,
547+ } ;
548+ const handler = new JerryDebugProtocolHandler ( { } ) ;
549+ ( handler as any ) . functions = [ func ] ;
550+ ( handler as any ) . lineLists = {
551+ [ scriptId ] : [ [ func ] , [ 'a' , func ] , [ func , 'b' ] ] ,
552+ } ;
553+
554+ const breakpoints = handler . getActiveFunctionBreakpointsByScriptId ( scriptId ) ;
555+ assert . strictEqual ( breakpoints . length , 0 ) ;
556+ } ) ;
557+ } ) ;
558+
559+ suite ( 'getInactiveFunctionBreakpointsByScriptId' , ( ) => {
560+ test ( 'return a breakpoins array' , ( ) => {
561+ const name = 'missing-data.js' ;
562+ const scriptId = 9 ;
563+ const func = {
564+ scriptId,
565+ lines : [
566+ {
567+ activeIndex : - 1 ,
568+ func : { name }
569+ } ,
570+ {
571+ activeIndex : 4 ,
572+ func : { name }
573+ } ,
574+ {
575+ activeIndex : 5 ,
576+ func : { name }
577+ } ,
578+ ] ,
579+ } ;
580+ const handler = new JerryDebugProtocolHandler ( { } ) ;
581+ ( handler as any ) . functions = [ func ] ;
582+ ( handler as any ) . lineLists = {
583+ [ scriptId ] : [ [ func ] , [ 'a' , func ] , [ func , 'b' ] ] ,
584+ } ;
585+ const breakpoints = handler . getInactiveFunctionBreakpointsByScriptId ( scriptId ) ;
586+ assert . strictEqual ( breakpoints [ 0 ] . activeIndex , - 1 ) ;
587+ assert . strictEqual ( breakpoints [ 0 ] . func . name , name ) ;
588+ assert . strictEqual ( breakpoints . length , 1 ) ;
589+ } ) ;
590+
591+ test ( 'throws error on invalid scriptId (0)' , ( ) => {
592+ const scriptId = 0 ;
593+ const handler = new JerryDebugProtocolHandler ( { } ) ;
594+ assert . throws ( ( ) => handler . getInactiveFunctionBreakpointsByScriptId ( scriptId ) , 'invalid script id' ) ;
595+ } ) ;
596+
597+ test ( 'throws error on invalid scriptId (greater than linelist length)' , ( ) => {
598+ const scriptId = 10 ;
599+ const handler = new JerryDebugProtocolHandler ( { } ) ;
600+ assert . throws ( ( ) => handler . getInactiveFunctionBreakpointsByScriptId ( scriptId ) , 'invalid script id' ) ;
601+ } ) ;
602+
603+ test ( 'return an empty array in case of no inactive functionbreakpoints' , ( ) => {
604+ const name = 'dust.js' ;
605+ const scriptId = 7 ;
606+ const func = {
607+ scriptId,
608+ lines : [
609+ {
610+ activeIndex : 4 ,
611+ func : { name }
612+ } ,
613+ ] ,
614+ } ;
615+ const handler = new JerryDebugProtocolHandler ( { } ) ;
616+ ( handler as any ) . functions = [ func ] ;
617+ ( handler as any ) . lineLists = {
618+ [ scriptId ] : [ [ func ] , [ 'a' , func ] , [ func , 'b' ] ] ,
619+ } ;
620+
621+ const breakpoints = handler . getInactiveFunctionBreakpointsByScriptId ( scriptId ) ;
622+ assert . strictEqual ( breakpoints . length , 0 ) ;
623+ } ) ;
624+ } ) ;
625+
458626 suite ( 'updateBreakpoint' , ( ) => {
459627 const debugClient = {
460628 send : sinon . spy ( ) ,
0 commit comments