@@ -3,6 +3,7 @@ import { Breakpoint } from '../JerryBreakpoints';
3
3
import { JerryDebugProtocolHandler } from '../JerryProtocolHandler' ;
4
4
import * as assert from 'assert' ;
5
5
import * as sinon from 'sinon' ;
6
+ import { stringToCesu8 } from '../JerryUtils' ;
6
7
7
8
// utility function
8
9
function encodeArray ( byte : number , str : string ) {
@@ -14,14 +15,26 @@ function encodeArray(byte: number, str: string) {
14
15
return array ;
15
16
}
16
17
17
- function setupHaltedProtocolHandler ( ) {
18
+ function setupHaltedProtocolHandler ( isThereBreakpointHit : boolean = false ) {
18
19
const debugClient = {
19
20
send : sinon . spy ( ) ,
20
21
} ;
21
22
const handler = new JerryDebugProtocolHandler ( { } ) ;
22
23
handler . debuggerClient = debugClient as any ;
23
24
// For these tests mock the current breakpoint by setting the private lastBreakpointHit member:
24
- ( handler as any ) . lastBreakpointHit = { } as Breakpoint ;
25
+ if ( ! isThereBreakpointHit ) {
26
+ ( handler as any ) . lastBreakpointHit = { } as Breakpoint ;
27
+ } else {
28
+ const bp : any = {
29
+ activeIndex : 4 ,
30
+ func : {
31
+ byteCodeCP : 42 ,
32
+ } ,
33
+ offset : 10 ,
34
+ } ;
35
+
36
+ ( handler as any ) . lastBreakpointHit = bp as Breakpoint ;
37
+ }
25
38
return { handler, debugClient } ;
26
39
}
27
40
@@ -633,19 +646,19 @@ suite('JerryProtocolHandler', () => {
633
646
const bp : any = { activeIndex : 3 } ;
634
647
const handler = new JerryDebugProtocolHandler ( { } ) ;
635
648
await handler . updateBreakpoint ( bp , true )
636
- . catch ( error => {
637
- assert . strictEqual ( ( < Error > error ) . message , 'breakpoint already enabled' ) ;
638
- } ) ;
649
+ . catch ( error => {
650
+ assert . strictEqual ( ( < Error > error ) . message , 'breakpoint already enabled' ) ;
651
+ } ) ;
639
652
} ) ;
640
653
641
654
test ( 'throws on disabling inactive breakpoint' , async ( ) => {
642
655
debugClient . send . resetHistory ( ) ;
643
656
const bp : any = { activeIndex : - 1 } ;
644
657
const handler = new JerryDebugProtocolHandler ( { } ) ;
645
658
await handler . updateBreakpoint ( bp , false )
646
- . catch ( error => {
647
- assert . strictEqual ( ( < Error > error ) . message , 'breakpoint already disabled' ) ;
648
- } ) ;
659
+ . catch ( error => {
660
+ assert . strictEqual ( ( < Error > error ) . message , 'breakpoint already disabled' ) ;
661
+ } ) ;
649
662
} ) ;
650
663
651
664
test ( 'enables inactive breakpoint successfully' , async ( ) => {
@@ -758,5 +771,106 @@ suite('JerryProtocolHandler', () => {
758
771
handler . stepOver ( ) ;
759
772
assert ( debugClient . send . withArgs ( Uint8Array . from ( [ SP . CLIENT . JERRY_DEBUGGER_NEXT ] ) ) ) ;
760
773
} ) ;
774
+
775
+
776
+ test ( 'sends the expected message when calling resume()' , ( ) => {
777
+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
778
+ handler . resume ( ) ;
779
+ assert ( debugClient . send . withArgs ( Uint8Array . from ( [ SP . CLIENT . JERRY_DEBUGGER_CONTINUE ] ) ) ) ;
780
+ } ) ;
781
+
782
+ test ( 'pause() throwing error when pausing at breakpoint' , async ( ) => {
783
+ const { handler } = setupHaltedProtocolHandler ( true ) ;
784
+ await handler . pause ( )
785
+ . catch ( error => {
786
+ assert . strictEqual ( ( < Error > error ) . message , 'attempted pause while at breakpoint' ) ;
787
+ } ) ;
788
+ } ) ;
789
+
790
+ test ( 'pause() sending the expected message' , ( ) => {
791
+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
792
+ handler . pause ( ) ;
793
+ assert ( debugClient . send . withArgs ( Uint8Array . from ( [ SP . CLIENT . JERRY_DEBUGGER_STOP ] ) ) ) ;
794
+ } ) ;
795
+ } ) ;
796
+
797
+ suite ( 'getLastBreakpoint()' , ( ) => {
798
+ test ( 'returns with the correct breakpoint' , ( ) => {
799
+ const { handler } = setupHaltedProtocolHandler ( true ) ;
800
+ const bp : any = {
801
+ activeIndex : 4 ,
802
+ func : {
803
+ byteCodeCP : 42 ,
804
+ } ,
805
+ offset : 10 ,
806
+ } ;
807
+ assert . deepStrictEqual ( handler . getLastBreakpoint ( ) , bp ) ;
808
+ } ) ;
809
+ } ) ;
810
+
811
+ suite ( 'sendClientSourceControl()' , ( ) => {
812
+ test ( 'throws if index is -1' , async ( ) => {
813
+ const handler = new JerryDebugProtocolHandler ( { } ) ;
814
+ await handler . sendClientSourceControl ( - 1 )
815
+ . catch ( error => {
816
+ assert . strictEqual ( ( < Error > error ) . message , 'Invalid source sending control code.' ) ;
817
+ } ) ;
818
+ } ) ;
819
+
820
+ test ( 'sends with correct args' , ( ) => {
821
+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
822
+ const defConfig = {
823
+ cpointerSize : 2 ,
824
+ littleEndian : true ,
825
+ } ;
826
+
827
+ const altConfig = {
828
+ cpointerSize : 4 ,
829
+ littleEndian : true ,
830
+ } ;
831
+ handler . debuggerClient = debugClient as any ;
832
+ handler . sendClientSourceControl ( 10 ) ;
833
+ assert ( debugClient . send . withArgs ( defConfig , 'B' , 10 ) ) ;
834
+ assert ( debugClient . send . withArgs ( altConfig , 'B' , 10 ) ) ;
835
+ } ) ;
836
+
837
+ test ( 'sends with correct args2' , ( ) => {
838
+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
839
+ const defConfig = {
840
+ cpointerSize : 2 ,
841
+ littleEndian : false ,
842
+ } ;
843
+ const altConfig = {
844
+ cpointerSize : 4 ,
845
+ littleEndian : false ,
846
+ } ;
847
+ handler . debuggerClient = debugClient as any ;
848
+ handler . sendClientSourceControl ( 10 ) ;
849
+ assert ( debugClient . send . withArgs ( defConfig , 'B' , 10 ) ) ;
850
+ assert ( debugClient . send . withArgs ( altConfig , 'B' , 10 ) ) ;
851
+ } ) ;
852
+ } ) ;
853
+
854
+ suite ( 'sendClientSource()' , ( ) => {
855
+ test ( 'throws if waitForSource is not enabled' , async ( ) => {
856
+ const handler = new JerryDebugProtocolHandler ( { } ) ;
857
+ await handler . sendClientSource ( 'onelittlekitten' , 'and some more' )
858
+ . catch ( error => {
859
+ assert . strictEqual ( ( < Error > error ) . message , 'wait-for-source not enabled' ) ;
860
+ } ) ;
861
+ } ) ;
862
+
863
+ test ( 'if byteLength is less than maxMessageSize send the array' , ( ) => {
864
+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
865
+ const defConfig = {
866
+ cpointerSize : 2 ,
867
+ littleEndian : false ,
868
+ } ;
869
+ ( handler as any ) . maxMessageSize = 100 ;
870
+ let array = stringToCesu8 ( `onelittlekitten\0and some more` , 5 , defConfig ) ;
871
+ ( handler as any ) . onWaitForSource ( ) ;
872
+ handler . sendClientSource ( 'onelittlekitten' , 'and some more' ) ;
873
+ assert ( debugClient . send . withArgs ( array ) ) ;
874
+ } ) ;
761
875
} ) ;
762
876
} ) ;
0 commit comments