@@ -130,6 +130,18 @@ function hashFrames(frames: StackFrame[] | undefined): string | undefined {
130
130
return frames . slice ( - 10 ) . reduce ( ( acc , frame ) => `${ acc } ,${ frame . function } ,${ frame . lineno } ,${ frame . colno } ` , '' ) ;
131
131
}
132
132
133
+ /**
134
+ * We use the stack parser to create a unique hash from the exception stack trace
135
+ * This is used to lookup vars when the exception passes through the event processor
136
+ */
137
+ function hashFromStack ( stackParser : StackParser , stack : string | undefined ) : string | undefined {
138
+ if ( stack === undefined ) {
139
+ return undefined ;
140
+ }
141
+
142
+ return hashFrames ( stackParser ( stack , 1 ) ) ;
143
+ }
144
+
133
145
export interface FrameVariables {
134
146
function : string ;
135
147
vars ?: Record < string , unknown > ;
@@ -144,7 +156,6 @@ export class LocalVariables implements Integration {
144
156
public readonly name : string = LocalVariables . id ;
145
157
146
158
private readonly _cachedFrames : LRUMap < string , Promise < FrameVariables [ ] > > = new LRUMap ( 20 ) ;
147
- private _stackParser : StackParser | undefined ;
148
159
149
160
public constructor ( private readonly _session : DebugSession = new AsyncSession ( ) ) { }
150
161
@@ -161,38 +172,27 @@ export class LocalVariables implements Integration {
161
172
clientOptions : ClientOptions | undefined ,
162
173
) : void {
163
174
if ( clientOptions ?. _experiments ?. includeStackLocals ) {
164
- this . _stackParser = clientOptions . stackParser ;
165
-
166
- this . _session . configureAndConnect ( this . _handlePaused . bind ( this ) ) ;
175
+ this . _session . configureAndConnect ( ev =>
176
+ this . _handlePaused ( clientOptions . stackParser , ev as InspectorNotification < PausedExceptionEvent > ) ,
177
+ ) ;
167
178
168
179
addGlobalEventProcessor ( async event => this . _addLocalVariables ( event ) ) ;
169
180
}
170
181
}
171
182
172
- /**
173
- * We use the stack parser to create a unique hash from the exception stack trace
174
- * This is used to lookup vars when the exception passes through the event processor
175
- */
176
- private _hashFromStack ( stack : string | undefined ) : string | undefined {
177
- if ( this . _stackParser === undefined || stack === undefined ) {
178
- return undefined ;
179
- }
180
-
181
- return hashFrames ( this . _stackParser ( stack , 1 ) ) ;
182
- }
183
-
184
183
/**
185
184
* Handle the pause event
186
185
*/
187
- private async _handlePaused ( {
188
- params : { reason, data, callFrames } ,
189
- } : InspectorNotification < PausedExceptionEvent > ) : Promise < void > {
186
+ private async _handlePaused (
187
+ stackParser : StackParser ,
188
+ { params : { reason, data, callFrames } } : InspectorNotification < PausedExceptionEvent > ,
189
+ ) : Promise < void > {
190
190
if ( reason !== 'exception' && reason !== 'promiseRejection' ) {
191
191
return ;
192
192
}
193
193
194
194
// data.description contains the original error.stack
195
- const exceptionHash = this . _hashFromStack ( data ?. description ) ;
195
+ const exceptionHash = hashFromStack ( stackParser , data ?. description ) ;
196
196
197
197
if ( exceptionHash == undefined ) {
198
198
return ;
0 commit comments