@@ -123,6 +123,18 @@ class PendingRequest {
123
123
}
124
124
}
125
125
126
+ export interface JerryScopeChain {
127
+ name : string ;
128
+ variablesReference : number ;
129
+ expensive : boolean ;
130
+ }
131
+
132
+ export interface JerryScopeVariable {
133
+ name : string ;
134
+ type : string ;
135
+ value : string ;
136
+ }
137
+
126
138
// abstracts away the details of the protocol
127
139
export class JerryDebugProtocolHandler {
128
140
public debuggerClient ?: JerryDebuggerClient ;
@@ -149,6 +161,8 @@ export class JerryDebugProtocolHandler {
149
161
private functions : FunctionMap = { } ;
150
162
private newFunctions : FunctionMap = { } ;
151
163
private backtraceData : JerryBacktraceResult = { totalFrames : 0 , backtrace : [ ] } ;
164
+ private scopeMessage ?: Array < number > = [ ] ;
165
+ private scopeVariableMessage ?: string = '' ;
152
166
153
167
private nextScriptID : number = 1 ;
154
168
private exceptionData ?: Uint8Array ;
@@ -197,7 +211,11 @@ export class JerryDebugProtocolHandler {
197
211
[ SP . SERVER . JERRY_DEBUGGER_BACKTRACE_END ] : this . onBacktrace ,
198
212
[ SP . SERVER . JERRY_DEBUGGER_EVAL_RESULT ] : this . onEvalResult ,
199
213
[ SP . SERVER . JERRY_DEBUGGER_EVAL_RESULT_END ] : this . onEvalResult ,
200
- [ SP . SERVER . JERRY_DEBUGGER_WAIT_FOR_SOURCE ] : this . onWaitForSource
214
+ [ SP . SERVER . JERRY_DEBUGGER_WAIT_FOR_SOURCE ] : this . onWaitForSource ,
215
+ [ SP . SERVER . JERRY_DEBUGGER_SCOPE_CHAIN ] : this . onScopeChain ,
216
+ [ SP . SERVER . JERRY_DEBUGGER_SCOPE_CHAIN_END ] : this . onScopeChainEnd ,
217
+ [ SP . SERVER . JERRY_DEBUGGER_SCOPE_VARIABLES ] : this . onScopeVariables ,
218
+ [ SP . SERVER . JERRY_DEBUGGER_SCOPE_VARIABLES_END ] : this . onScopeVariablesEnd
201
219
} ;
202
220
203
221
this . requestQueue = [ ] ;
@@ -586,6 +604,132 @@ export class JerryDebugProtocolHandler {
586
604
return this . backtraceData ;
587
605
}
588
606
607
+ public onScopeChain ( data : Uint8Array ) : void {
608
+ this . logPacket ( 'ScopeChain' ) ;
609
+
610
+ for ( let i = 1 ; i < data . byteLength ; i ++ ) {
611
+ this . scopeMessage . push ( data [ i ] ) ;
612
+ }
613
+ }
614
+
615
+ public onScopeChainEnd ( data : Uint8Array ) : Array < JerryScopeChain > {
616
+ this . logPacket ( 'ScopeChainEnd' ) ;
617
+
618
+ for ( let i = 1 ; i < data . byteLength ; i ++ ) {
619
+ this . scopeMessage . push ( data [ i ] ) ;
620
+ }
621
+
622
+ const scopes : Array < JerryScopeChain > = [ ] ;
623
+ for ( let i = 0 ; i < this . scopeMessage . length ; i ++ ) {
624
+ switch ( this . scopeMessage [ i ] ) {
625
+ case SP . JERRY_DEBUGGER_SCOPE_TYPE . JERRY_DEBUGGER_SCOPE_WITH : {
626
+ scopes . push ( { name : 'with' , variablesReference : i , expensive : true } ) ;
627
+ break ;
628
+ }
629
+ case SP . JERRY_DEBUGGER_SCOPE_TYPE . JERRY_DEBUGGER_SCOPE_LOCAL : {
630
+ scopes . push ( { name : 'local' , variablesReference : i , expensive : true } ) ;
631
+ break ;
632
+ }
633
+ case SP . JERRY_DEBUGGER_SCOPE_TYPE . JERRY_DEBUGGER_SCOPE_CLOSURE : {
634
+ scopes . push ( { name : 'closure' , variablesReference : i , expensive : true } ) ;
635
+ break ;
636
+ }
637
+ case SP . JERRY_DEBUGGER_SCOPE_TYPE . JERRY_DEBUGGER_SCOPE_GLOBAL : {
638
+ scopes . push ( { name : 'global' , variablesReference : i , expensive : true } ) ;
639
+ break ;
640
+ }
641
+ case SP . JERRY_DEBUGGER_SCOPE_TYPE . JERRY_DEBUGGER_SCOPE_NON_CLOSURE : {
642
+ scopes . push ( { name : 'catch' , variablesReference : i , expensive : true } ) ;
643
+ break ;
644
+ }
645
+ default : {
646
+ throw new Error ( 'Invalid scope chain type!' ) ;
647
+ }
648
+ }
649
+ }
650
+ this . scopeMessage = [ ] ;
651
+
652
+ return scopes ;
653
+ }
654
+
655
+ public onScopeVariables ( data : Uint8Array ) : void {
656
+ this . logPacket ( 'ScopeVariables' ) ;
657
+ for ( let i = 1 ; i < data . byteLength ; i ++ ) {
658
+ this . scopeVariableMessage += String . fromCharCode ( data [ i ] ) ;
659
+ }
660
+ }
661
+
662
+ public onScopeVariablesEnd ( data : Uint8Array ) : Array < JerryScopeVariable > {
663
+ this . logPacket ( 'ScopeVariablesEnd' ) ;
664
+
665
+ for ( let i = 1 ; i < data . byteLength ; i ++ ) {
666
+ this . scopeVariableMessage += String . fromCharCode ( data [ i ] ) ;
667
+ }
668
+
669
+ let buff_pos = 0 ;
670
+ const scopeVariablesArray : Array < JerryScopeVariable > = [ ] ;
671
+
672
+ while ( buff_pos < this . scopeVariableMessage . length ) {
673
+ let scopeVariable : JerryScopeVariable = { name : '' , type : '' , value : '' } ;
674
+
675
+ // Process name.
676
+ const name_length = this . scopeVariableMessage [ buff_pos ++ ] . charCodeAt ( 0 ) ;
677
+ scopeVariable . name = this . scopeVariableMessage . substring ( buff_pos , buff_pos + name_length ) ;
678
+
679
+ buff_pos += name_length ;
680
+
681
+ // Process type
682
+ const value_type : SP . JERRY_DEBUGGER_SCOPE_VARIABLES = this . scopeVariableMessage [ buff_pos ++ ] . charCodeAt ( 0 ) ;
683
+ const value_length = this . scopeVariableMessage [ buff_pos ++ ] . charCodeAt ( 0 ) ;
684
+
685
+ scopeVariable . value = this . scopeVariableMessage . substring ( buff_pos , buff_pos + value_length ) ;
686
+ buff_pos += value_length ;
687
+
688
+ switch ( value_type ) {
689
+ case ( SP . JERRY_DEBUGGER_SCOPE_VARIABLES . JERRY_DEBUGGER_VALUE_UNDEFINED ) : {
690
+ scopeVariable . type = 'undefined' ;
691
+ break ;
692
+ }
693
+ case ( SP . JERRY_DEBUGGER_SCOPE_VARIABLES . JERRY_DEBUGGER_VALUE_NULL ) : {
694
+ scopeVariable . type = 'Null' ;
695
+ break ;
696
+ }
697
+ case ( SP . JERRY_DEBUGGER_SCOPE_VARIABLES . JERRY_DEBUGGER_VALUE_BOOLEAN ) : {
698
+ scopeVariable . type = 'Boolean' ;
699
+ break ;
700
+ }
701
+ case ( SP . JERRY_DEBUGGER_SCOPE_VARIABLES . JERRY_DEBUGGER_VALUE_NUMBER ) : {
702
+ scopeVariable . type = 'Number' ;
703
+ break ;
704
+ }
705
+ case ( SP . JERRY_DEBUGGER_SCOPE_VARIABLES . JERRY_DEBUGGER_VALUE_STRING ) : {
706
+ scopeVariable . type = 'String' ;
707
+ break ;
708
+ }
709
+ case ( SP . JERRY_DEBUGGER_SCOPE_VARIABLES . JERRY_DEBUGGER_VALUE_FUNCTION ) : {
710
+ scopeVariable . type = 'Function' ;
711
+ break ;
712
+ }
713
+ case ( SP . JERRY_DEBUGGER_SCOPE_VARIABLES . JERRY_DEBUGGER_VALUE_ARRAY ) : {
714
+ scopeVariable . type = 'Array' ;
715
+ scopeVariable . value = '[' + scopeVariable . value + ']' ;
716
+ break ;
717
+ }
718
+ case ( SP . JERRY_DEBUGGER_SCOPE_VARIABLES . JERRY_DEBUGGER_VALUE_OBJECT ) : {
719
+ scopeVariable . type = 'Object' ;
720
+ break ;
721
+ }
722
+ default : {
723
+ throw new Error ( 'Invalid scope variable type!' ) ;
724
+ }
725
+ }
726
+ scopeVariablesArray . push ( scopeVariable ) ;
727
+ }
728
+ this . scopeVariableMessage = '' ;
729
+
730
+ return scopeVariablesArray ;
731
+ }
732
+
589
733
public onEvalResult ( data : Uint8Array ) : JerryEvalResult {
590
734
this . logPacket ( 'Eval Result' ) ;
591
735
@@ -776,6 +920,26 @@ export class JerryDebugProtocolHandler {
776
920
1 ] ) ) ;
777
921
}
778
922
923
+ public requestScopes ( ) : Promise < any > {
924
+ if ( ! this . lastBreakpointHit ) {
925
+ return Promise . reject ( new Error ( 'scope chain not allowed while app running' ) ) ;
926
+ }
927
+
928
+ return this . sendRequest ( encodeMessage ( this . byteConfig , 'B' ,
929
+ [ SP . CLIENT . JERRY_DEBUGGER_GET_SCOPE_CHAIN ] ) ) ;
930
+ }
931
+
932
+ public requestVariables ( level ?: number ) : Promise < any > {
933
+ if ( ! this . lastBreakpointHit ) {
934
+ return Promise . reject ( new Error ( 'scope variables not allowed while app running' ) ) ;
935
+ }
936
+
937
+ return this . sendRequest ( encodeMessage ( this . byteConfig , 'BI' ,
938
+ [ SP . CLIENT . JERRY_DEBUGGER_GET_SCOPE_VARIABLES ,
939
+ level ] ) ) ;
940
+
941
+ }
942
+
779
943
logPacket ( description : string , ignorable : boolean = false ) {
780
944
// certain packets are ignored while evals are pending
781
945
const ignored = ( ignorable && this . evalsPending ) ? 'Ignored: ' : '' ;
0 commit comments