@@ -11,6 +11,7 @@ import CommandType from "../model/command/CommandType";
11
11
import LiveBreakpoint from "../model/instruments/LiveBreakpoint" ;
12
12
import { randomUUID } from "crypto" ;
13
13
import VariableUtil from "../util/VariableUtil" ;
14
+ import SourcePlusPlus from "../SourcePlusPlus" ;
14
15
15
16
export interface VariableInfo {
16
17
block : Runtime . PropertyDescriptor [ ]
@@ -94,47 +95,73 @@ export default class LiveInstrumentRemote {
94
95
} ) ) ;
95
96
}
96
97
97
- Promise . all ( promises ) . then ( ( ) => {
98
- // Do stuff
99
- let instrumentIds = this . breakpointIdToInstrumentIds . get ( message . params . hitBreakpoints [ 0 ] ) ; // TODO: Handle multiple hit breakpoints
100
- if ( ! instrumentIds ) {
101
- this . removeBreakpoint ( message . params . hitBreakpoints [ 0 ] ) ;
102
- return ;
103
- }
98
+ let instrumentIds = this . breakpointIdToInstrumentIds . get ( message . params . hitBreakpoints [ 0 ] ) ; // TODO: Handle multiple hit breakpoints
99
+ if ( ! instrumentIds ) {
100
+ this . removeBreakpoint ( message . params . hitBreakpoints [ 0 ] ) ;
101
+ return ;
102
+ }
104
103
105
- for ( let instrumentId of instrumentIds ) {
106
- let instrument = this . instruments . get ( instrumentId ) ;
107
- if ( ! instrument ) {
108
- continue ;
109
- }
104
+ let instruments = instrumentIds . map ( id => this . instruments . get ( id ) ) ;
105
+ let conditionsSatisfied = Promise . all ( instruments . map ( instrument => {
106
+ if ( instrument . condition === undefined )
107
+ return true ;
108
+
109
+ return new Promise < boolean > ( ( resolve , reject ) => {
110
+ this . session . post ( "Debugger.evaluateOnCallFrame" , {
111
+ callFrameId : frame . callFrameId ,
112
+ expression : instrument . condition
113
+ } , ( err , res ) => {
114
+ if ( err ) {
115
+ reject ( err ) ;
116
+ } else {
117
+ if ( res . result . type !== 'boolean' ) {
118
+ reject ( "Invalid condition for instrument id: " + instrument . id + ": " + instrument . condition ) ;
119
+ } else {
120
+ resolve ( res . result . value ) ;
121
+ }
122
+ }
123
+ } ) ;
124
+ } ) ;
125
+ } ) ) ;
110
126
111
- if ( instrument . type == LiveInstrumentType . BREAKPOINT ) {
112
- ContextReceiver . applyBreakpoint (
113
- instrumentId ,
114
- instrument . location . source ,
115
- instrument . location . line ,
116
- frame ,
117
- variables
118
- ) ;
119
- } else if ( instrument . type == LiveInstrumentType . LOG ) {
120
- let logInstrument = < LiveLog > instrument ;
121
- ContextReceiver . applyLog (
122
- instrumentId ,
123
- logInstrument . logFormat ,
124
- logInstrument . logArguments ,
125
- variables
126
- ) ;
127
- } else if ( instrument . type == LiveInstrumentType . METER ) {
128
- let meterInstrument = < LiveMeter > instrument ;
129
- ContextReceiver . applyMeter (
130
- instrumentId ,
131
- variables
132
- ) ;
133
- }
134
- if ( instrument . isFinished ( ) ) {
135
- this . removeBreakpoint ( instrumentId ) ;
127
+ Promise . all ( promises ) . then ( ( ) => {
128
+ conditionsSatisfied . then ( conditions => {
129
+ for ( let i = 0 ; i < instruments . length ; i ++ ) {
130
+ if ( conditions [ i ] ) {
131
+ let instrument = instruments [ i ] ;
132
+ if ( ! instrument ) {
133
+ continue ;
134
+ }
135
+
136
+ if ( instrument . type == LiveInstrumentType . BREAKPOINT ) {
137
+ ContextReceiver . applyBreakpoint (
138
+ instrument . id ,
139
+ instrument . location . source ,
140
+ instrument . location . line ,
141
+ frame ,
142
+ variables
143
+ ) ;
144
+ } else if ( instrument . type == LiveInstrumentType . LOG ) {
145
+ let logInstrument = < LiveLog > instrument ;
146
+ ContextReceiver . applyLog (
147
+ instrument . id ,
148
+ logInstrument . logFormat ,
149
+ logInstrument . logArguments ,
150
+ variables
151
+ ) ;
152
+ } else if ( instrument . type == LiveInstrumentType . METER ) {
153
+ let meterInstrument = < LiveMeter > instrument ;
154
+ ContextReceiver . applyMeter (
155
+ instrument . id ,
156
+ variables
157
+ ) ;
158
+ }
159
+ if ( instrument . isFinished ( ) ) {
160
+ this . removeBreakpoint ( instrument . id ) ;
161
+ }
162
+ }
136
163
}
137
- }
164
+ } ) ;
138
165
} ) ;
139
166
140
167
// let frameId = message.params.callFrames[0].callFrameId;
@@ -315,6 +342,7 @@ export default class LiveInstrumentRemote {
315
342
test ( ) {
316
343
let instrument = new LiveBreakpoint ( ) ;
317
344
instrument . id = randomUUID ( ) ;
345
+ instrument . condition = "false" ;
318
346
instrument . location = { source : "test/javascript/test.js" , line : 8 } ;
319
347
instrument . hitLimit = 1 ;
320
348
instrument . applyImmediately = true ;
0 commit comments