Skip to content

Commit e2b1f71

Browse files
committed
Remove nullable stackParser property
1 parent e3d11f3 commit e2b1f71

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

packages/node/src/integrations/localvariables.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ function hashFrames(frames: StackFrame[] | undefined): string | undefined {
130130
return frames.slice(-10).reduce((acc, frame) => `${acc},${frame.function},${frame.lineno},${frame.colno}`, '');
131131
}
132132

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+
133145
export interface FrameVariables {
134146
function: string;
135147
vars?: Record<string, unknown>;
@@ -144,7 +156,6 @@ export class LocalVariables implements Integration {
144156
public readonly name: string = LocalVariables.id;
145157

146158
private readonly _cachedFrames: LRUMap<string, Promise<FrameVariables[]>> = new LRUMap(20);
147-
private _stackParser: StackParser | undefined;
148159

149160
public constructor(private readonly _session: DebugSession = new AsyncSession()) {}
150161

@@ -161,38 +172,27 @@ export class LocalVariables implements Integration {
161172
clientOptions: ClientOptions | undefined,
162173
): void {
163174
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+
);
167178

168179
addGlobalEventProcessor(async event => this._addLocalVariables(event));
169180
}
170181
}
171182

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-
184183
/**
185184
* Handle the pause event
186185
*/
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> {
190190
if (reason !== 'exception' && reason !== 'promiseRejection') {
191191
return;
192192
}
193193

194194
// data.description contains the original error.stack
195-
const exceptionHash = this._hashFromStack(data?.description);
195+
const exceptionHash = hashFromStack(stackParser, data?.description);
196196

197197
if (exceptionHash == undefined) {
198198
return;

0 commit comments

Comments
 (0)