@@ -8,6 +8,9 @@ import LiveMeter from "../model/instruments/LiveMeter";
8
8
import EventBus from "@vertx/eventbus-bridge-client.js" ;
9
9
import LiveInstrumentCommand from "../model/command/LiveInstrumentCommand" ;
10
10
import CommandType from "../model/command/CommandType" ;
11
+ import LiveBreakpoint from "../model/instruments/LiveBreakpoint" ;
12
+ import { randomUUID } from "crypto" ;
13
+ import VariableUtil from "../util/VariableUtil" ;
11
14
12
15
export interface VariableInfo {
13
16
block : Runtime . PropertyDescriptor [ ]
@@ -72,23 +75,24 @@ export default class LiveInstrumentRemote {
72
75
let variables = { }
73
76
let promises = [ ] ;
74
77
75
- // Attempt to get variables from the
78
+ // Attempt to get variables from the top call frame
76
79
for ( let scope of frame . scopeChain ) {
80
+ if ( scope . type === 'global' ) {
81
+ continue ; // TODO: Ignore this until we have a better way of filtering out the hundreds of js properties
82
+ }
83
+
77
84
promises . push ( this . getVariable ( scope . object . objectId , 2 )
78
- . then ( res => variables [ scope . type ] = res . result ) ) ;
85
+ . then ( res => {
86
+ if ( scope . type === 'local' || scope . type === 'block' ) {
87
+ variables [ 'local' ] = res
88
+ } else if ( scope . type === 'closure' ) {
89
+ variables [ 'field' ] = res [ 0 ] . value . value ; // TODO: Ensure result[0] is always the class instance
90
+ } else if ( scope . type === 'global' ) {
91
+ // Handle this once we have a better way of filtering out the hundreds of js properties
92
+ }
93
+ } ) ) ;
79
94
}
80
95
81
- this . session . post ( 'Debugger.evaluateOnCallFrame' , {
82
- callFrameId : frame . callFrameId ,
83
- expression : "Object.keys(this).reduce((acc, current, _) => {acc[current] = this[current]; return acc}, {})" ,
84
- } , ( err , res ) => {
85
- if ( err ) {
86
- console . log ( err ) ;
87
- } else {
88
- console . log ( res . result ) ;
89
- }
90
- } )
91
-
92
96
Promise . all ( promises ) . then ( ( ) => {
93
97
// Do stuff
94
98
let instrumentIds = this . breakpointIdToInstrumentIds . get ( message . params . hitBreakpoints [ 0 ] ) ; // TODO: Handle multiple hit breakpoints
@@ -126,6 +130,9 @@ export default class LiveInstrumentRemote {
126
130
variables
127
131
) ;
128
132
}
133
+ if ( instrument . isFinished ( ) ) {
134
+ this . removeBreakpoint ( instrumentId ) ;
135
+ }
129
136
}
130
137
} ) ;
131
138
@@ -152,7 +159,7 @@ export default class LiveInstrumentRemote {
152
159
} ) ;
153
160
}
154
161
155
- private getVariable ( objectId : string , remainingDepth : number ) : Promise < any > {
162
+ private getVariable ( objectId : string , remainingDepth : number ) : Promise < Runtime . PropertyDescriptor [ ] > {
156
163
return new Promise < any > ( ( resolve , reject ) => {
157
164
this . session . post ( "Runtime.getProperties" , {
158
165
objectId : objectId ,
@@ -161,8 +168,23 @@ export default class LiveInstrumentRemote {
161
168
if ( err ) {
162
169
reject ( err ) ;
163
170
} else {
164
- console . log ( res . result ) ;
165
- resolve ( res . result ) ;
171
+ let result : Runtime . PropertyDescriptor [ ] = res . result ;
172
+
173
+ VariableUtil . processVariables ( result )
174
+
175
+ if ( remainingDepth <= 0 )
176
+ return resolve ( result ) ;
177
+
178
+ let newRemainingDepth = remainingDepth - 1 ;
179
+
180
+ let promises = [ ] ;
181
+ for ( let variable of result ) {
182
+ promises . push ( this . getVariable ( variable . value . objectId , newRemainingDepth )
183
+ . then ( res => variable . value . value = res ) ) ;
184
+ }
185
+ Promise . all ( promises ) . then ( ( ) => {
186
+ resolve ( result )
187
+ } ) ;
166
188
}
167
189
} ) ;
168
190
} ) ;
@@ -287,4 +309,16 @@ export default class LiveInstrumentRemote {
287
309
}
288
310
} ) ;
289
311
}
312
+
313
+ test ( ) {
314
+ let instrument = new LiveBreakpoint ( ) ;
315
+ instrument . id = randomUUID ( ) ;
316
+ instrument . location = { source : "test/javascript/test.js" , line : 5 } ;
317
+ instrument . hitLimit = 1 ;
318
+ instrument . applyImmediately = true ;
319
+ instrument . applied = false ;
320
+ instrument . pending = false ;
321
+ instrument . meta = { } ;
322
+ this . addInstrument ( instrument ) ;
323
+ }
290
324
}
0 commit comments