@@ -45,6 +45,7 @@ export interface ParserStackFrame {
45
45
export interface JerryDebugProtocolDelegate {
46
46
onBacktrace ?( backtrace : Array < Breakpoint > ) : void ;
47
47
onBreakpointHit ?( message : JerryMessageBreakpointHit ) : void ;
48
+ onExceptionHit ?( message : JerryMessageExceptionHit ) : void ;
48
49
onEvalResult ?( subType : number , result : string ) : void ;
49
50
onError ?( code : number , message : string ) : void ;
50
51
onResume ?( ) : void ;
@@ -68,6 +69,12 @@ export interface JerryMessageBreakpointHit {
68
69
exact : boolean ;
69
70
}
70
71
72
+ export interface JerryMessageExceptionHit {
73
+ breakpoint : Breakpoint ;
74
+ exact : boolean ;
75
+ message : string ;
76
+ }
77
+
71
78
export interface JerryEvalResult {
72
79
subtype : number ;
73
80
value : string ;
@@ -135,6 +142,7 @@ export class JerryDebugProtocolHandler {
135
142
136
143
private nextScriptID : number = 1 ;
137
144
private exceptionData ?: Uint8Array ;
145
+ private exceptionString ?: string ;
138
146
private evalsPending : number = 0 ;
139
147
private lastBreakpointHit ?: Breakpoint ;
140
148
private lastBreakpointExact : boolean = true ;
@@ -169,6 +177,9 @@ export class JerryDebugProtocolHandler {
169
177
[ SP . SERVER . JERRY_DEBUGGER_FUNCTION_NAME_END ] : this . onFunctionName ,
170
178
[ SP . SERVER . JERRY_DEBUGGER_RELEASE_BYTE_CODE_CP ] : this . onReleaseByteCodeCP ,
171
179
[ SP . SERVER . JERRY_DEBUGGER_BREAKPOINT_HIT ] : this . onBreakpointHit ,
180
+ [ SP . SERVER . JERRY_DEBUGGER_EXCEPTION_HIT ] : this . onBreakpointHit ,
181
+ [ SP . SERVER . JERRY_DEBUGGER_EXCEPTION_STR ] : this . onExceptionStr ,
182
+ [ SP . SERVER . JERRY_DEBUGGER_EXCEPTION_STR_END ] : this . onExceptionStr ,
172
183
[ SP . SERVER . JERRY_DEBUGGER_BACKTRACE ] : this . onBacktrace ,
173
184
[ SP . SERVER . JERRY_DEBUGGER_BACKTRACE_END ] : this . onBacktrace ,
174
185
[ SP . SERVER . JERRY_DEBUGGER_EVAL_RESULT ] : this . onEvalResult ,
@@ -476,14 +487,6 @@ export class JerryDebugProtocolHandler {
476
487
const breakpointRef = this . getBreakpoint ( breakpointData ) ;
477
488
const breakpoint = breakpointRef . breakpoint ;
478
489
479
- if ( data [ 0 ] === SP . SERVER . JERRY_DEBUGGER_EXCEPTION_HIT ) {
480
- this . log ( 'Exception throw detected' ) ;
481
- if ( this . exceptionData ) {
482
- this . log ( `Exception hint: ${ cesu8ToString ( this . exceptionData ) } ` ) ;
483
- this . exceptionData = undefined ;
484
- }
485
- }
486
-
487
490
this . lastBreakpointHit = breakpoint ;
488
491
this . lastBreakpointExact = breakpointRef . exact ;
489
492
@@ -495,7 +498,23 @@ export class JerryDebugProtocolHandler {
495
498
const atAround = breakpointRef . exact ? 'at' : 'around' ;
496
499
this . log ( `Stopped ${ atAround } ${ breakpointInfo } ${ breakpoint } ` ) ;
497
500
498
- // TODO: handle exception case differently
501
+ if ( data [ 0 ] === SP . SERVER . JERRY_DEBUGGER_EXCEPTION_HIT ) {
502
+ this . log ( 'Exception throw detected' ) ;
503
+ if ( this . exceptionString ) {
504
+ this . log ( `Exception hint: ${ this . exceptionString } ` ) ;
505
+ }
506
+
507
+ if ( this . delegate . onExceptionHit ) {
508
+ this . delegate . onExceptionHit ( {
509
+ 'breakpoint' : breakpoint ,
510
+ 'exact' : breakpointRef . exact ,
511
+ 'message' : this . exceptionString ,
512
+ } ) ;
513
+ this . exceptionString = undefined ;
514
+ return ;
515
+ }
516
+ }
517
+
499
518
if ( this . delegate . onBreakpointHit ) {
500
519
this . delegate . onBreakpointHit ( breakpointRef ) ;
501
520
}
@@ -775,4 +794,13 @@ export class JerryDebugProtocolHandler {
775
794
if ( ! simple ) this . currentRequest = request ;
776
795
return true ;
777
796
}
797
+
798
+ onExceptionStr ( data : Uint8Array ) {
799
+ this . logPacket ( 'onExceptionStr' ) ;
800
+ this . exceptionData = assembleUint8Arrays ( this . exceptionData , data ) ;
801
+ if ( data [ 0 ] === SP . SERVER . JERRY_DEBUGGER_EXCEPTION_STR_END ) {
802
+ this . exceptionString = cesu8ToString ( this . exceptionData ) ;
803
+ this . exceptionData = undefined ;
804
+ }
805
+ }
778
806
}
0 commit comments