Skip to content
This repository was archived by the owner on Oct 2, 2021. It is now read-only.

Commit fa93a9b

Browse files
author
Diego Geffner
committed
Now we keep a collection to determine if a script needs to be added, removed or changed on the client
1 parent dd26072 commit fa93a9b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/chrome/chromeDebugAdapter.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
156156

157157
public readonly events: StepProgressEventsEmitter;
158158

159+
private _loadedSourcesByScriptId = new Map<Crdp.Runtime.ScriptId, CrdpScript>();
160+
159161
public constructor({ chromeConnection, lineColTransformer, sourceMapTransformer, pathTransformer, targetFilter, enableSourceMapCaching }: IChromeDebugAdapterOpts,
160162
session: ChromeDebugSession) {
161163
telemetry.setupEventHandler(e => session.sendEvent(e));
@@ -599,7 +601,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
599601
* e.g. the target navigated
600602
*/
601603
protected onExecutionContextsCleared(): Promise<void> {
602-
const cachedScriptParsedEvents = Array.from(this._scriptsById.values());
604+
const cachedScriptParsedEvents = Array.from(this._loadedSourcesByScriptId.values());
603605
this.clearTargetContext();
604606
return this.doAfterProcessingSourceEvents(async () => { // This will not execute until all the on-flight 'new' source events have been processed
605607
for (let scriptedParseEvent of cachedScriptParsedEvents) {
@@ -856,7 +858,28 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
856858
}
857859

858860
protected async sendLoadedSourceEvent(script: Crdp.Debugger.ScriptParsedEvent, loadedSourceEventReason: LoadedSourceEventReason = 'new'): Promise<void> {
861+
switch (loadedSourceEventReason) {
862+
case 'new':
863+
case 'changed':
864+
if (this._loadedSourcesByScriptId.get(script.scriptId)) {
865+
loadedSourceEventReason = 'changed';
866+
} else {
867+
loadedSourceEventReason = 'new';
868+
}
869+
this._loadedSourcesByScriptId.set(script.scriptId, script);
870+
break;
871+
case 'removed':
872+
if (!this._loadedSourcesByScriptId.delete(script.scriptId)) {
873+
telemetry.reportEvent('LoadedSourceEventError', { issue: 'Tried to remove non-existent script', scriptId: script.scriptId });
874+
return;
875+
}
876+
break;
877+
default:
878+
telemetry.reportEvent('LoadedSourceEventError', { issue: 'Unknown reason', reason: loadedSourceEventReason });
879+
}
880+
859881
const scriptEvent = await this.scriptToLoadedSourceEvent(loadedSourceEventReason, script);
882+
860883
this._session.sendEvent(scriptEvent);
861884
}
862885

0 commit comments

Comments
 (0)