chrome-devtools-mcp 0.0.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Settings.js +3 -32
- package/build/node_modules/chrome-devtools-frontend/front_end/core/i18n/i18n.js +35 -8
- package/build/node_modules/chrome-devtools-frontend/front_end/core/root/Runtime.js +4 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/InspectorBackendCommands.js +4 -4
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/SupportedCSSProperties.js +12 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js +366 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AICallTree.js +366 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIContext.js +64 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIQueries.js +105 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/CSSWorkspaceBinding.js +243 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/CompilerScriptMapping.js +407 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ContentProviderBasedProject.js +128 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/DebuggerLanguagePlugins.js +992 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/DebuggerWorkspaceBinding.js +574 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/DefaultScriptMapping.js +112 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/FileUtils.js +186 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/LiveLocation.js +60 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/NetworkProject.js +107 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/PresentationConsoleMessageHelper.js +244 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ResourceMapping.js +473 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ResourceScriptMapping.js +399 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ResourceUtils.js +87 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/SASSSourceMapping.js +181 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/StylesSourceMapping.js +268 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/TempFile.js +55 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/bindings.js +20 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/crux-manager/CrUXManager.js +283 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/crux-manager/crux-manager.js +4 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/emulation/DeviceModeModel.js +775 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/emulation/EmulatedDevices.js +1706 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/emulation/emulation.js +6 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/FormatterWorkerPool.js +131 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/ScriptFormatter.js +77 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/formatter.js +6 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/geometry/GeometryImpl.js +347 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/geometry/geometry.js +4 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/NamesResolver.js +626 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/ScopeChainModel.js +59 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/ScopeTreeCache.js +32 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/source_map_scopes.js +7 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/StackTrace.js +4 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/StackTraceImpl.js +67 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/StackTraceModel.js +97 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/Trie.js +113 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/stack_trace.js +5 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/stack_trace_impl.js +7 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/text_utils/TextUtils.js +23 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/Processor.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/Trace.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DocumentLatency.js +5 -4
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace_source_maps_resolver/SourceMapsResolver.js +199 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace_source_maps_resolver/trace_source_maps_resolver.js +4 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/FileManager.js +64 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/IgnoreListManager.js +511 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/SearchConfig.js +113 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/UISourceCode.js +563 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/WorkspaceImpl.js +204 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/workspace.js +9 -0
- package/build/src/McpContext.js +24 -9
- package/build/src/McpResponse.js +3 -3
- package/build/src/browser.js +3 -1
- package/build/src/index.js +1 -1
- package/build/src/tools/input.js +7 -7
- package/build/src/tools/performance.js +29 -2
- package/build/src/tools/screenshot.js +1 -1
- package/build/src/tools/script.js +40 -14
- package/build/src/trace-processing/parse.js +26 -22
- package/package.json +9 -7
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
// Copyright 2014 The Chromium Authors
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import * as Common from '../../core/common/common.js';
|
|
5
|
+
import * as Platform from '../../core/platform/platform.js';
|
|
6
|
+
import * as SDK from '../../core/sdk/sdk.js';
|
|
7
|
+
// eslint-disable-next-line rulesdir/es-modules-import
|
|
8
|
+
import * as StackTraceImpl from '../stack_trace/stack_trace_impl.js';
|
|
9
|
+
import * as Workspace from '../workspace/workspace.js';
|
|
10
|
+
import { CompilerScriptMapping } from './CompilerScriptMapping.js';
|
|
11
|
+
import { DebuggerLanguagePluginManager } from './DebuggerLanguagePlugins.js';
|
|
12
|
+
import { DefaultScriptMapping } from './DefaultScriptMapping.js';
|
|
13
|
+
import { LiveLocationWithPool } from './LiveLocation.js';
|
|
14
|
+
import { NetworkProject } from './NetworkProject.js';
|
|
15
|
+
import { ResourceScriptMapping } from './ResourceScriptMapping.js';
|
|
16
|
+
let debuggerWorkspaceBindingInstance;
|
|
17
|
+
export class DebuggerWorkspaceBinding {
|
|
18
|
+
resourceMapping;
|
|
19
|
+
#debuggerModelToData;
|
|
20
|
+
#liveLocationPromises;
|
|
21
|
+
pluginManager;
|
|
22
|
+
constructor(resourceMapping, targetManager, ignoreListManager) {
|
|
23
|
+
this.resourceMapping = resourceMapping;
|
|
24
|
+
this.#debuggerModelToData = new Map();
|
|
25
|
+
targetManager.addModelListener(SDK.DebuggerModel.DebuggerModel, SDK.DebuggerModel.Events.GlobalObjectCleared, this.globalObjectCleared, this);
|
|
26
|
+
targetManager.addModelListener(SDK.DebuggerModel.DebuggerModel, SDK.DebuggerModel.Events.DebuggerResumed, this.debuggerResumed, this);
|
|
27
|
+
targetManager.observeModels(SDK.DebuggerModel.DebuggerModel, this);
|
|
28
|
+
ignoreListManager.addEventListener("IGNORED_SCRIPT_RANGES_UPDATED" /* Workspace.IgnoreListManager.Events.IGNORED_SCRIPT_RANGES_UPDATED */, event => this.updateLocations(event.data));
|
|
29
|
+
this.#liveLocationPromises = new Set();
|
|
30
|
+
this.pluginManager = new DebuggerLanguagePluginManager(targetManager, resourceMapping.workspace, this);
|
|
31
|
+
}
|
|
32
|
+
setFunctionRanges(uiSourceCode, ranges) {
|
|
33
|
+
for (const modelData of this.#debuggerModelToData.values()) {
|
|
34
|
+
modelData.compilerMapping.setFunctionRanges(uiSourceCode, ranges);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
static instance(opts = { forceNew: null, resourceMapping: null, targetManager: null, ignoreListManager: null }) {
|
|
38
|
+
const { forceNew, resourceMapping, targetManager, ignoreListManager } = opts;
|
|
39
|
+
if (!debuggerWorkspaceBindingInstance || forceNew) {
|
|
40
|
+
if (!resourceMapping || !targetManager || !ignoreListManager) {
|
|
41
|
+
throw new Error(`Unable to create DebuggerWorkspaceBinding: resourceMapping, targetManager and IgnoreLIstManager must be provided: ${new Error().stack}`);
|
|
42
|
+
}
|
|
43
|
+
debuggerWorkspaceBindingInstance =
|
|
44
|
+
new DebuggerWorkspaceBinding(resourceMapping, targetManager, ignoreListManager);
|
|
45
|
+
}
|
|
46
|
+
return debuggerWorkspaceBindingInstance;
|
|
47
|
+
}
|
|
48
|
+
static removeInstance() {
|
|
49
|
+
debuggerWorkspaceBindingInstance = undefined;
|
|
50
|
+
}
|
|
51
|
+
async computeAutoStepRanges(mode, callFrame) {
|
|
52
|
+
function contained(location, range) {
|
|
53
|
+
const { start, end } = range;
|
|
54
|
+
if (start.scriptId !== location.scriptId) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (location.lineNumber < start.lineNumber || location.lineNumber > end.lineNumber) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (location.lineNumber === start.lineNumber && location.columnNumber < start.columnNumber) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (location.lineNumber === end.lineNumber && location.columnNumber >= end.columnNumber) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const rawLocation = callFrame.location();
|
|
69
|
+
if (!rawLocation) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const pluginManager = this.pluginManager;
|
|
73
|
+
let ranges = [];
|
|
74
|
+
if (mode === "StepOut" /* SDK.DebuggerModel.StepMode.STEP_OUT */) {
|
|
75
|
+
// Step out of inline function.
|
|
76
|
+
return await pluginManager.getInlinedFunctionRanges(rawLocation);
|
|
77
|
+
}
|
|
78
|
+
const uiLocation = await pluginManager.rawLocationToUILocation(rawLocation);
|
|
79
|
+
if (uiLocation) {
|
|
80
|
+
ranges = await pluginManager.uiLocationToRawLocationRanges(uiLocation.uiSourceCode, uiLocation.lineNumber, uiLocation.columnNumber) ||
|
|
81
|
+
[];
|
|
82
|
+
// TODO(bmeurer): Remove the {rawLocation} from the {ranges}?
|
|
83
|
+
ranges = ranges.filter(range => contained(rawLocation, range));
|
|
84
|
+
if (mode === "StepOver" /* SDK.DebuggerModel.StepMode.STEP_OVER */) {
|
|
85
|
+
// Step over an inlined function.
|
|
86
|
+
ranges = ranges.concat(await pluginManager.getInlinedCalleesRanges(rawLocation));
|
|
87
|
+
}
|
|
88
|
+
return ranges;
|
|
89
|
+
}
|
|
90
|
+
const compilerMapping = this.#debuggerModelToData.get(rawLocation.debuggerModel)?.compilerMapping;
|
|
91
|
+
if (!compilerMapping) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
ranges = compilerMapping.getLocationRangesForSameSourceLocation(rawLocation);
|
|
95
|
+
ranges = ranges.filter(range => contained(rawLocation, range));
|
|
96
|
+
return ranges;
|
|
97
|
+
}
|
|
98
|
+
modelAdded(debuggerModel) {
|
|
99
|
+
debuggerModel.setBeforePausedCallback(this.shouldPause.bind(this));
|
|
100
|
+
this.#debuggerModelToData.set(debuggerModel, new ModelData(debuggerModel, this));
|
|
101
|
+
debuggerModel.setComputeAutoStepRangesCallback(this.computeAutoStepRanges.bind(this));
|
|
102
|
+
}
|
|
103
|
+
modelRemoved(debuggerModel) {
|
|
104
|
+
debuggerModel.setComputeAutoStepRangesCallback(null);
|
|
105
|
+
const modelData = this.#debuggerModelToData.get(debuggerModel);
|
|
106
|
+
if (modelData) {
|
|
107
|
+
modelData.dispose();
|
|
108
|
+
this.#debuggerModelToData.delete(debuggerModel);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The promise returned by this function is resolved once all *currently*
|
|
113
|
+
* pending LiveLocations are processed.
|
|
114
|
+
*/
|
|
115
|
+
async pendingLiveLocationChangesPromise() {
|
|
116
|
+
await Promise.all(this.#liveLocationPromises);
|
|
117
|
+
}
|
|
118
|
+
recordLiveLocationChange(promise) {
|
|
119
|
+
void promise.then(() => {
|
|
120
|
+
this.#liveLocationPromises.delete(promise);
|
|
121
|
+
});
|
|
122
|
+
this.#liveLocationPromises.add(promise);
|
|
123
|
+
}
|
|
124
|
+
async updateLocations(script) {
|
|
125
|
+
const updatePromises = [script.target()
|
|
126
|
+
.model(StackTraceImpl.StackTraceModel.StackTraceModel)
|
|
127
|
+
?.scriptInfoChanged(script, this.#translateRawFrames.bind(this))];
|
|
128
|
+
const modelData = this.#debuggerModelToData.get(script.debuggerModel);
|
|
129
|
+
if (modelData) {
|
|
130
|
+
const updatePromise = modelData.updateLocations(script);
|
|
131
|
+
this.recordLiveLocationChange(updatePromise);
|
|
132
|
+
updatePromises.push(updatePromise);
|
|
133
|
+
}
|
|
134
|
+
await Promise.all(updatePromises);
|
|
135
|
+
}
|
|
136
|
+
async createStackTraceFromProtocolRuntime(stackTrace, target) {
|
|
137
|
+
const model = target.model(StackTraceImpl.StackTraceModel.StackTraceModel);
|
|
138
|
+
return await model.createFromProtocolRuntime(stackTrace, this.#translateRawFrames.bind(this));
|
|
139
|
+
}
|
|
140
|
+
async createLiveLocation(rawLocation, updateDelegate, locationPool) {
|
|
141
|
+
const modelData = this.#debuggerModelToData.get(rawLocation.debuggerModel);
|
|
142
|
+
if (!modelData) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
const liveLocationPromise = modelData.createLiveLocation(rawLocation, updateDelegate, locationPool);
|
|
146
|
+
this.recordLiveLocationChange(liveLocationPromise);
|
|
147
|
+
return await liveLocationPromise;
|
|
148
|
+
}
|
|
149
|
+
async createStackTraceTopFrameLiveLocation(rawLocations, updateDelegate, locationPool) {
|
|
150
|
+
console.assert(rawLocations.length > 0);
|
|
151
|
+
const locationPromise = StackTraceTopFrameLocation.createStackTraceTopFrameLocation(rawLocations, this, updateDelegate, locationPool);
|
|
152
|
+
this.recordLiveLocationChange(locationPromise);
|
|
153
|
+
return await locationPromise;
|
|
154
|
+
}
|
|
155
|
+
async createCallFrameLiveLocation(location, updateDelegate, locationPool) {
|
|
156
|
+
const script = location.script();
|
|
157
|
+
if (!script) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
const debuggerModel = location.debuggerModel;
|
|
161
|
+
const liveLocationPromise = this.createLiveLocation(location, updateDelegate, locationPool);
|
|
162
|
+
this.recordLiveLocationChange(liveLocationPromise);
|
|
163
|
+
const liveLocation = await liveLocationPromise;
|
|
164
|
+
if (!liveLocation) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
this.registerCallFrameLiveLocation(debuggerModel, liveLocation);
|
|
168
|
+
return liveLocation;
|
|
169
|
+
}
|
|
170
|
+
async rawLocationToUILocation(rawLocation) {
|
|
171
|
+
const uiLocation = await this.pluginManager.rawLocationToUILocation(rawLocation);
|
|
172
|
+
if (uiLocation) {
|
|
173
|
+
return uiLocation;
|
|
174
|
+
}
|
|
175
|
+
const modelData = this.#debuggerModelToData.get(rawLocation.debuggerModel);
|
|
176
|
+
return modelData ? modelData.rawLocationToUILocation(rawLocation) : null;
|
|
177
|
+
}
|
|
178
|
+
uiSourceCodeForSourceMapSourceURL(debuggerModel, url, isContentScript) {
|
|
179
|
+
const modelData = this.#debuggerModelToData.get(debuggerModel);
|
|
180
|
+
if (!modelData) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
return modelData.compilerMapping.uiSourceCodeForURL(url, isContentScript);
|
|
184
|
+
}
|
|
185
|
+
async uiSourceCodeForSourceMapSourceURLPromise(debuggerModel, url, isContentScript) {
|
|
186
|
+
const uiSourceCode = this.uiSourceCodeForSourceMapSourceURL(debuggerModel, url, isContentScript);
|
|
187
|
+
return await (uiSourceCode || this.waitForUISourceCodeAdded(url, debuggerModel.target()));
|
|
188
|
+
}
|
|
189
|
+
async uiSourceCodeForDebuggerLanguagePluginSourceURLPromise(debuggerModel, url) {
|
|
190
|
+
const uiSourceCode = this.pluginManager.uiSourceCodeForURL(debuggerModel, url);
|
|
191
|
+
return await (uiSourceCode || this.waitForUISourceCodeAdded(url, debuggerModel.target()));
|
|
192
|
+
}
|
|
193
|
+
uiSourceCodeForScript(script) {
|
|
194
|
+
const modelData = this.#debuggerModelToData.get(script.debuggerModel);
|
|
195
|
+
if (!modelData) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
return modelData.uiSourceCodeForScript(script);
|
|
199
|
+
}
|
|
200
|
+
waitForUISourceCodeAdded(url, target) {
|
|
201
|
+
return new Promise(resolve => {
|
|
202
|
+
const workspace = Workspace.Workspace.WorkspaceImpl.instance();
|
|
203
|
+
const descriptor = workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, event => {
|
|
204
|
+
const uiSourceCode = event.data;
|
|
205
|
+
if (uiSourceCode.url() === url && NetworkProject.targetForUISourceCode(uiSourceCode) === target) {
|
|
206
|
+
workspace.removeEventListener(Workspace.Workspace.Events.UISourceCodeAdded, descriptor.listener);
|
|
207
|
+
resolve(uiSourceCode);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async uiLocationToRawLocations(uiSourceCode, lineNumber, columnNumber) {
|
|
213
|
+
const locations = await this.pluginManager.uiLocationToRawLocations(uiSourceCode, lineNumber, columnNumber);
|
|
214
|
+
if (locations) {
|
|
215
|
+
return locations;
|
|
216
|
+
}
|
|
217
|
+
for (const modelData of this.#debuggerModelToData.values()) {
|
|
218
|
+
const locations = modelData.uiLocationToRawLocations(uiSourceCode, lineNumber, columnNumber);
|
|
219
|
+
if (locations.length) {
|
|
220
|
+
return locations;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Computes all the raw location ranges that intersect with the {@link textRange} in the given
|
|
227
|
+
* {@link uiSourceCode}. The reverse mappings of the returned ranges must not be fully contained
|
|
228
|
+
* with the {@link textRange} and it's the responsibility of the caller to appropriately filter or
|
|
229
|
+
* clamp if desired.
|
|
230
|
+
*
|
|
231
|
+
* It's important to note that for a contiguous range in the {@link uiSourceCode} there can be a
|
|
232
|
+
* variety of non-contiguous raw location ranges that intersect with the {@link textRange}. A
|
|
233
|
+
* simple example is that of an HTML document with multiple inline `<script>`s in the same line,
|
|
234
|
+
* so just asking for the raw locations in this single line will return a set of location ranges
|
|
235
|
+
* in different scripts.
|
|
236
|
+
*
|
|
237
|
+
* This method returns an empty array if this {@link uiSourceCode} is not provided by any of the
|
|
238
|
+
* mappings for this instance.
|
|
239
|
+
*
|
|
240
|
+
* @param uiSourceCode the {@link UISourceCode} to which the {@link textRange} belongs.
|
|
241
|
+
* @param textRange the text range in terms of the UI.
|
|
242
|
+
* @returns the list of raw location ranges that intersect with the text range or `[]` if
|
|
243
|
+
* the {@link uiSourceCode} does not belong to this instance.
|
|
244
|
+
*/
|
|
245
|
+
async uiLocationRangeToRawLocationRanges(uiSourceCode, textRange) {
|
|
246
|
+
const ranges = await this.pluginManager.uiLocationRangeToRawLocationRanges(uiSourceCode, textRange);
|
|
247
|
+
if (ranges) {
|
|
248
|
+
return ranges;
|
|
249
|
+
}
|
|
250
|
+
for (const modelData of this.#debuggerModelToData.values()) {
|
|
251
|
+
const ranges = modelData.uiLocationRangeToRawLocationRanges(uiSourceCode, textRange);
|
|
252
|
+
if (ranges) {
|
|
253
|
+
return ranges;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
async normalizeUILocation(uiLocation) {
|
|
259
|
+
const rawLocations = await this.uiLocationToRawLocations(uiLocation.uiSourceCode, uiLocation.lineNumber, uiLocation.columnNumber);
|
|
260
|
+
for (const location of rawLocations) {
|
|
261
|
+
const uiLocationCandidate = await this.rawLocationToUILocation(location);
|
|
262
|
+
if (uiLocationCandidate) {
|
|
263
|
+
return uiLocationCandidate;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return uiLocation;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Computes the set of lines in the {@link uiSourceCode} that map to scripts by either looking at
|
|
270
|
+
* the debug info (if any) or checking for inline scripts within documents. If this set cannot be
|
|
271
|
+
* computed or all the lines in the {@link uiSourceCode} correspond to lines in a script, `null`
|
|
272
|
+
* is returned here.
|
|
273
|
+
*
|
|
274
|
+
* @param uiSourceCode the source entity.
|
|
275
|
+
* @returns a set of known mapped lines for {@link uiSourceCode} or `null` if it's impossible to
|
|
276
|
+
* determine the set or the {@link uiSourceCode} does not map to or include any scripts.
|
|
277
|
+
*/
|
|
278
|
+
async getMappedLines(uiSourceCode) {
|
|
279
|
+
for (const modelData of this.#debuggerModelToData.values()) {
|
|
280
|
+
const mappedLines = modelData.getMappedLines(uiSourceCode);
|
|
281
|
+
if (mappedLines !== null) {
|
|
282
|
+
return mappedLines;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return await this.pluginManager.getMappedLines(uiSourceCode);
|
|
286
|
+
}
|
|
287
|
+
scriptFile(uiSourceCode, debuggerModel) {
|
|
288
|
+
const modelData = this.#debuggerModelToData.get(debuggerModel);
|
|
289
|
+
return modelData ? modelData.getResourceScriptMapping().scriptFile(uiSourceCode) : null;
|
|
290
|
+
}
|
|
291
|
+
scriptsForUISourceCode(uiSourceCode) {
|
|
292
|
+
const scripts = new Set();
|
|
293
|
+
this.pluginManager.scriptsForUISourceCode(uiSourceCode).forEach(script => scripts.add(script));
|
|
294
|
+
for (const modelData of this.#debuggerModelToData.values()) {
|
|
295
|
+
const resourceScriptFile = modelData.getResourceScriptMapping().scriptFile(uiSourceCode);
|
|
296
|
+
if (resourceScriptFile?.script) {
|
|
297
|
+
scripts.add(resourceScriptFile.script);
|
|
298
|
+
}
|
|
299
|
+
modelData.compilerMapping.scriptsForUISourceCode(uiSourceCode).forEach(script => scripts.add(script));
|
|
300
|
+
}
|
|
301
|
+
return [...scripts];
|
|
302
|
+
}
|
|
303
|
+
supportsConditionalBreakpoints(uiSourceCode) {
|
|
304
|
+
const scripts = this.pluginManager.scriptsForUISourceCode(uiSourceCode);
|
|
305
|
+
return scripts.every(script => script.isJavaScript());
|
|
306
|
+
}
|
|
307
|
+
globalObjectCleared(event) {
|
|
308
|
+
this.reset(event.data);
|
|
309
|
+
}
|
|
310
|
+
reset(debuggerModel) {
|
|
311
|
+
const modelData = this.#debuggerModelToData.get(debuggerModel);
|
|
312
|
+
if (!modelData) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
for (const location of modelData.callFrameLocations.values()) {
|
|
316
|
+
this.removeLiveLocation(location);
|
|
317
|
+
}
|
|
318
|
+
modelData.callFrameLocations.clear();
|
|
319
|
+
}
|
|
320
|
+
resetForTest(target) {
|
|
321
|
+
const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
|
|
322
|
+
const modelData = this.#debuggerModelToData.get(debuggerModel);
|
|
323
|
+
if (modelData) {
|
|
324
|
+
modelData.getResourceScriptMapping().resetForTest();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
registerCallFrameLiveLocation(debuggerModel, location) {
|
|
328
|
+
const modelData = this.#debuggerModelToData.get(debuggerModel);
|
|
329
|
+
if (modelData) {
|
|
330
|
+
const locations = modelData.callFrameLocations;
|
|
331
|
+
locations.add(location);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
removeLiveLocation(location) {
|
|
335
|
+
const modelData = this.#debuggerModelToData.get(location.rawLocation.debuggerModel);
|
|
336
|
+
if (modelData) {
|
|
337
|
+
modelData.disposeLocation(location);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
debuggerResumed(event) {
|
|
341
|
+
this.reset(event.data);
|
|
342
|
+
}
|
|
343
|
+
async shouldPause(debuggerPausedDetails, autoSteppingContext) {
|
|
344
|
+
// This function returns false if the debugger should continue stepping
|
|
345
|
+
const { callFrames: [frame] } = debuggerPausedDetails;
|
|
346
|
+
if (!frame) {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
const functionLocation = frame.functionLocation();
|
|
350
|
+
if (!autoSteppingContext || debuggerPausedDetails.reason !== "step" /* Protocol.Debugger.PausedEventReason.Step */ ||
|
|
351
|
+
!functionLocation || !frame.script.isWasm() || !Common.Settings.moduleSetting('wasm-auto-stepping').get() ||
|
|
352
|
+
!this.pluginManager.hasPluginForScript(frame.script)) {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
const uiLocation = await this.pluginManager.rawLocationToUILocation(frame.location());
|
|
356
|
+
if (uiLocation) {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
return autoSteppingContext.script() !== functionLocation.script() ||
|
|
360
|
+
autoSteppingContext.columnNumber !== functionLocation.columnNumber ||
|
|
361
|
+
autoSteppingContext.lineNumber !== functionLocation.lineNumber;
|
|
362
|
+
}
|
|
363
|
+
async #translateRawFrames(frames, target) {
|
|
364
|
+
const rawFrames = frames.slice(0);
|
|
365
|
+
const translatedFrames = [];
|
|
366
|
+
while (rawFrames.length) {
|
|
367
|
+
await this.#translateRawFramesStep(rawFrames, translatedFrames, target);
|
|
368
|
+
}
|
|
369
|
+
return translatedFrames;
|
|
370
|
+
}
|
|
371
|
+
async #translateRawFramesStep(rawFrames, translatedFrames, target) {
|
|
372
|
+
if (await this.pluginManager.translateRawFramesStep(rawFrames, translatedFrames, target)) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const modelData = this.#debuggerModelToData.get(target.model(SDK.DebuggerModel.DebuggerModel));
|
|
376
|
+
if (modelData) {
|
|
377
|
+
modelData.translateRawFramesStep(rawFrames, translatedFrames);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const frame = rawFrames.shift();
|
|
381
|
+
const { url, lineNumber, columnNumber, functionName } = frame;
|
|
382
|
+
translatedFrames.push([{ url, line: lineNumber, column: columnNumber, name: functionName }]);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
class ModelData {
|
|
386
|
+
#debuggerModel;
|
|
387
|
+
#debuggerWorkspaceBinding;
|
|
388
|
+
callFrameLocations;
|
|
389
|
+
#defaultMapping;
|
|
390
|
+
#resourceMapping;
|
|
391
|
+
#resourceScriptMapping;
|
|
392
|
+
compilerMapping;
|
|
393
|
+
#locations;
|
|
394
|
+
constructor(debuggerModel, debuggerWorkspaceBinding) {
|
|
395
|
+
this.#debuggerModel = debuggerModel;
|
|
396
|
+
this.#debuggerWorkspaceBinding = debuggerWorkspaceBinding;
|
|
397
|
+
this.callFrameLocations = new Set();
|
|
398
|
+
const { workspace } = debuggerWorkspaceBinding.resourceMapping;
|
|
399
|
+
this.#defaultMapping = new DefaultScriptMapping(debuggerModel, workspace, debuggerWorkspaceBinding);
|
|
400
|
+
this.#resourceMapping = debuggerWorkspaceBinding.resourceMapping;
|
|
401
|
+
this.#resourceScriptMapping = new ResourceScriptMapping(debuggerModel, workspace, debuggerWorkspaceBinding);
|
|
402
|
+
this.compilerMapping = new CompilerScriptMapping(debuggerModel, workspace, debuggerWorkspaceBinding);
|
|
403
|
+
this.#locations = new Platform.MapUtilities.Multimap();
|
|
404
|
+
}
|
|
405
|
+
async createLiveLocation(rawLocation, updateDelegate, locationPool) {
|
|
406
|
+
console.assert(rawLocation.scriptId !== '');
|
|
407
|
+
const scriptId = rawLocation.scriptId;
|
|
408
|
+
const location = new Location(scriptId, rawLocation, this.#debuggerWorkspaceBinding, updateDelegate, locationPool);
|
|
409
|
+
this.#locations.set(scriptId, location);
|
|
410
|
+
await location.update();
|
|
411
|
+
return location;
|
|
412
|
+
}
|
|
413
|
+
disposeLocation(location) {
|
|
414
|
+
this.#locations.delete(location.scriptId, location);
|
|
415
|
+
}
|
|
416
|
+
async updateLocations(script) {
|
|
417
|
+
const promises = [];
|
|
418
|
+
for (const location of this.#locations.get(script.scriptId)) {
|
|
419
|
+
promises.push(location.update());
|
|
420
|
+
}
|
|
421
|
+
await Promise.all(promises);
|
|
422
|
+
}
|
|
423
|
+
rawLocationToUILocation(rawLocation) {
|
|
424
|
+
let uiLocation = this.compilerMapping.rawLocationToUILocation(rawLocation);
|
|
425
|
+
uiLocation = uiLocation || this.#resourceScriptMapping.rawLocationToUILocation(rawLocation);
|
|
426
|
+
uiLocation = uiLocation || this.#resourceMapping.jsLocationToUILocation(rawLocation);
|
|
427
|
+
uiLocation = uiLocation || this.#defaultMapping.rawLocationToUILocation(rawLocation);
|
|
428
|
+
return uiLocation;
|
|
429
|
+
}
|
|
430
|
+
uiSourceCodeForScript(script) {
|
|
431
|
+
let uiSourceCode = null;
|
|
432
|
+
uiSourceCode = uiSourceCode || this.#resourceScriptMapping.uiSourceCodeForScript(script);
|
|
433
|
+
uiSourceCode = uiSourceCode || this.#resourceMapping.uiSourceCodeForScript(script);
|
|
434
|
+
uiSourceCode = uiSourceCode || this.#defaultMapping.uiSourceCodeForScript(script);
|
|
435
|
+
return uiSourceCode;
|
|
436
|
+
}
|
|
437
|
+
uiLocationToRawLocations(uiSourceCode, lineNumber, columnNumber = 0) {
|
|
438
|
+
// TODO(crbug.com/1153123): Revisit the `#columnNumber = 0` and also preserve `undefined` for source maps?
|
|
439
|
+
let locations = this.compilerMapping.uiLocationToRawLocations(uiSourceCode, lineNumber, columnNumber);
|
|
440
|
+
locations = locations.length ?
|
|
441
|
+
locations :
|
|
442
|
+
this.#resourceScriptMapping.uiLocationToRawLocations(uiSourceCode, lineNumber, columnNumber);
|
|
443
|
+
locations = locations.length ?
|
|
444
|
+
locations :
|
|
445
|
+
this.#resourceMapping.uiLocationToJSLocations(uiSourceCode, lineNumber, columnNumber);
|
|
446
|
+
locations = locations.length ?
|
|
447
|
+
locations :
|
|
448
|
+
this.#defaultMapping.uiLocationToRawLocations(uiSourceCode, lineNumber, columnNumber);
|
|
449
|
+
return locations;
|
|
450
|
+
}
|
|
451
|
+
uiLocationRangeToRawLocationRanges(uiSourceCode, textRange) {
|
|
452
|
+
let ranges = this.compilerMapping.uiLocationRangeToRawLocationRanges(uiSourceCode, textRange);
|
|
453
|
+
ranges ??= this.#resourceScriptMapping.uiLocationRangeToRawLocationRanges(uiSourceCode, textRange);
|
|
454
|
+
ranges ??= this.#resourceMapping.uiLocationRangeToJSLocationRanges(uiSourceCode, textRange);
|
|
455
|
+
ranges ??= this.#defaultMapping.uiLocationRangeToRawLocationRanges(uiSourceCode, textRange);
|
|
456
|
+
return ranges;
|
|
457
|
+
}
|
|
458
|
+
translateRawFramesStep(rawFrames, translatedFrames) {
|
|
459
|
+
if (!this.compilerMapping.translateRawFramesStep(rawFrames, translatedFrames)) {
|
|
460
|
+
this.#defaultTranslateRawFramesStep(rawFrames, translatedFrames);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
/** The default implementation translates one frame at a time and only translates the location, but not the function name. */
|
|
464
|
+
#defaultTranslateRawFramesStep(rawFrames, translatedFrames) {
|
|
465
|
+
const frame = rawFrames.shift();
|
|
466
|
+
const { scriptId, url, lineNumber, columnNumber, functionName } = frame;
|
|
467
|
+
const rawLocation = scriptId ? this.#debuggerModel.createRawLocationByScriptId(scriptId, lineNumber, columnNumber) :
|
|
468
|
+
url ? this.#debuggerModel.createRawLocationByURL(url, lineNumber, columnNumber) :
|
|
469
|
+
null;
|
|
470
|
+
if (rawLocation) {
|
|
471
|
+
const uiLocation = this.rawLocationToUILocation(rawLocation);
|
|
472
|
+
if (uiLocation) {
|
|
473
|
+
translatedFrames.push([{
|
|
474
|
+
uiSourceCode: uiLocation.uiSourceCode,
|
|
475
|
+
name: functionName,
|
|
476
|
+
line: uiLocation.lineNumber,
|
|
477
|
+
column: uiLocation.columnNumber ?? -1
|
|
478
|
+
}]);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
translatedFrames.push([{ url, line: lineNumber, column: columnNumber, name: functionName }]);
|
|
483
|
+
}
|
|
484
|
+
getMappedLines(uiSourceCode) {
|
|
485
|
+
const mappedLines = this.compilerMapping.getMappedLines(uiSourceCode);
|
|
486
|
+
// TODO(crbug.com/1411431): The scripts from the ResourceMapping appear over time,
|
|
487
|
+
// and there's currently no way to inform the UI to update.
|
|
488
|
+
// mappedLines = mappedLines ?? this.#resourceMapping.getMappedLines(uiSourceCode);
|
|
489
|
+
return mappedLines;
|
|
490
|
+
}
|
|
491
|
+
dispose() {
|
|
492
|
+
this.#debuggerModel.setBeforePausedCallback(null);
|
|
493
|
+
this.compilerMapping.dispose();
|
|
494
|
+
this.#resourceScriptMapping.dispose();
|
|
495
|
+
this.#defaultMapping.dispose();
|
|
496
|
+
}
|
|
497
|
+
getResourceScriptMapping() {
|
|
498
|
+
return this.#resourceScriptMapping;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
export class Location extends LiveLocationWithPool {
|
|
502
|
+
scriptId;
|
|
503
|
+
rawLocation;
|
|
504
|
+
#binding;
|
|
505
|
+
constructor(scriptId, rawLocation, binding, updateDelegate, locationPool) {
|
|
506
|
+
super(updateDelegate, locationPool);
|
|
507
|
+
this.scriptId = scriptId;
|
|
508
|
+
this.rawLocation = rawLocation;
|
|
509
|
+
this.#binding = binding;
|
|
510
|
+
}
|
|
511
|
+
async uiLocation() {
|
|
512
|
+
const debuggerModelLocation = this.rawLocation;
|
|
513
|
+
return await this.#binding.rawLocationToUILocation(debuggerModelLocation);
|
|
514
|
+
}
|
|
515
|
+
dispose() {
|
|
516
|
+
super.dispose();
|
|
517
|
+
this.#binding.removeLiveLocation(this);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
class StackTraceTopFrameLocation extends LiveLocationWithPool {
|
|
521
|
+
#updateScheduled;
|
|
522
|
+
#current;
|
|
523
|
+
#locations;
|
|
524
|
+
constructor(updateDelegate, locationPool) {
|
|
525
|
+
super(updateDelegate, locationPool);
|
|
526
|
+
this.#updateScheduled = true;
|
|
527
|
+
this.#current = null;
|
|
528
|
+
this.#locations = null;
|
|
529
|
+
}
|
|
530
|
+
static async createStackTraceTopFrameLocation(rawLocations, binding, updateDelegate, locationPool) {
|
|
531
|
+
const location = new StackTraceTopFrameLocation(updateDelegate, locationPool);
|
|
532
|
+
const locationsPromises = rawLocations.map(rawLocation => binding.createLiveLocation(rawLocation, location.scheduleUpdate.bind(location), locationPool));
|
|
533
|
+
location.#locations = ((await Promise.all(locationsPromises)).filter(l => !!l));
|
|
534
|
+
await location.updateLocation();
|
|
535
|
+
return location;
|
|
536
|
+
}
|
|
537
|
+
async uiLocation() {
|
|
538
|
+
return this.#current ? await this.#current.uiLocation() : null;
|
|
539
|
+
}
|
|
540
|
+
dispose() {
|
|
541
|
+
super.dispose();
|
|
542
|
+
if (this.#locations) {
|
|
543
|
+
for (const location of this.#locations) {
|
|
544
|
+
location.dispose();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
this.#locations = null;
|
|
548
|
+
this.#current = null;
|
|
549
|
+
}
|
|
550
|
+
async scheduleUpdate() {
|
|
551
|
+
if (this.#updateScheduled) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
this.#updateScheduled = true;
|
|
555
|
+
queueMicrotask(() => {
|
|
556
|
+
void this.updateLocation();
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
async updateLocation() {
|
|
560
|
+
this.#updateScheduled = false;
|
|
561
|
+
if (!this.#locations || this.#locations.length === 0) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
this.#current = this.#locations[0];
|
|
565
|
+
for (const location of this.#locations) {
|
|
566
|
+
const uiLocation = await location.uiLocation();
|
|
567
|
+
if (!uiLocation?.isIgnoreListed()) {
|
|
568
|
+
this.#current = location;
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
void this.update();
|
|
573
|
+
}
|
|
574
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Copyright 2012 The Chromium Authors
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import * as Common from '../../core/common/common.js';
|
|
5
|
+
import * as SDK from '../../core/sdk/sdk.js';
|
|
6
|
+
import * as Workspace from '../workspace/workspace.js';
|
|
7
|
+
import { ContentProviderBasedProject } from './ContentProviderBasedProject.js';
|
|
8
|
+
export class DefaultScriptMapping {
|
|
9
|
+
#debuggerWorkspaceBinding;
|
|
10
|
+
#project;
|
|
11
|
+
#eventListeners;
|
|
12
|
+
#uiSourceCodeToScript;
|
|
13
|
+
#scriptToUISourceCode;
|
|
14
|
+
constructor(debuggerModel, workspace, debuggerWorkspaceBinding) {
|
|
15
|
+
defaultScriptMappings.add(this);
|
|
16
|
+
this.#debuggerWorkspaceBinding = debuggerWorkspaceBinding;
|
|
17
|
+
this.#project = new ContentProviderBasedProject(workspace, 'debugger:' + debuggerModel.target().id(), Workspace.Workspace.projectTypes.Debugger, '', true /* isServiceProject */);
|
|
18
|
+
this.#eventListeners = [
|
|
19
|
+
debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared, this.globalObjectCleared, this),
|
|
20
|
+
debuggerModel.addEventListener(SDK.DebuggerModel.Events.ParsedScriptSource, this.parsedScriptSource, this),
|
|
21
|
+
debuggerModel.addEventListener(SDK.DebuggerModel.Events.DiscardedAnonymousScriptSource, this.discardedScriptSource, this),
|
|
22
|
+
];
|
|
23
|
+
this.#uiSourceCodeToScript = new Map();
|
|
24
|
+
this.#scriptToUISourceCode = new Map();
|
|
25
|
+
}
|
|
26
|
+
static createV8ScriptURL(script) {
|
|
27
|
+
const name = Common.ParsedURL.ParsedURL.extractName(script.sourceURL);
|
|
28
|
+
const url = 'debugger:///VM' + script.scriptId + (name ? ' ' + name : '');
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
static scriptForUISourceCode(uiSourceCode) {
|
|
32
|
+
for (const defaultScriptMapping of defaultScriptMappings) {
|
|
33
|
+
const script = defaultScriptMapping.#uiSourceCodeToScript.get(uiSourceCode);
|
|
34
|
+
if (script !== undefined) {
|
|
35
|
+
return script;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
uiSourceCodeForScript(script) {
|
|
41
|
+
return this.#scriptToUISourceCode.get(script) ?? null;
|
|
42
|
+
}
|
|
43
|
+
rawLocationToUILocation(rawLocation) {
|
|
44
|
+
const script = rawLocation.script();
|
|
45
|
+
if (!script) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const uiSourceCode = this.#scriptToUISourceCode.get(script);
|
|
49
|
+
if (!uiSourceCode) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const { lineNumber, columnNumber } = script.rawLocationToRelativeLocation(rawLocation);
|
|
53
|
+
return uiSourceCode.uiLocation(lineNumber, columnNumber);
|
|
54
|
+
}
|
|
55
|
+
uiLocationToRawLocations(uiSourceCode, lineNumber, columnNumber) {
|
|
56
|
+
const script = this.#uiSourceCodeToScript.get(uiSourceCode);
|
|
57
|
+
if (!script) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
({ lineNumber, columnNumber } = script.relativeLocationToRawLocation({ lineNumber, columnNumber }));
|
|
61
|
+
return [script.debuggerModel.createRawLocation(script, lineNumber, columnNumber ?? 0)];
|
|
62
|
+
}
|
|
63
|
+
uiLocationRangeToRawLocationRanges(uiSourceCode, { startLine, startColumn, endLine, endColumn }) {
|
|
64
|
+
const script = this.#uiSourceCodeToScript.get(uiSourceCode);
|
|
65
|
+
if (!script) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
({ lineNumber: startLine, columnNumber: startColumn } =
|
|
69
|
+
script.relativeLocationToRawLocation({ lineNumber: startLine, columnNumber: startColumn }));
|
|
70
|
+
({ lineNumber: endLine, columnNumber: endColumn } =
|
|
71
|
+
script.relativeLocationToRawLocation({ lineNumber: endLine, columnNumber: endColumn }));
|
|
72
|
+
const start = script.debuggerModel.createRawLocation(script, startLine, startColumn);
|
|
73
|
+
const end = script.debuggerModel.createRawLocation(script, endLine, endColumn);
|
|
74
|
+
return [{ start, end }];
|
|
75
|
+
}
|
|
76
|
+
parsedScriptSource(event) {
|
|
77
|
+
const script = event.data;
|
|
78
|
+
const url = DefaultScriptMapping.createV8ScriptURL(script);
|
|
79
|
+
const uiSourceCode = this.#project.createUISourceCode(url, Common.ResourceType.resourceTypes.Script);
|
|
80
|
+
if (script.isBreakpointCondition) {
|
|
81
|
+
uiSourceCode.markAsUnconditionallyIgnoreListed();
|
|
82
|
+
}
|
|
83
|
+
this.#uiSourceCodeToScript.set(uiSourceCode, script);
|
|
84
|
+
this.#scriptToUISourceCode.set(script, uiSourceCode);
|
|
85
|
+
this.#project.addUISourceCodeWithProvider(uiSourceCode, script, null, 'text/javascript');
|
|
86
|
+
void this.#debuggerWorkspaceBinding.updateLocations(script);
|
|
87
|
+
}
|
|
88
|
+
discardedScriptSource(event) {
|
|
89
|
+
const script = event.data;
|
|
90
|
+
const uiSourceCode = this.#scriptToUISourceCode.get(script);
|
|
91
|
+
if (uiSourceCode === undefined) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.#scriptToUISourceCode.delete(script);
|
|
95
|
+
this.#uiSourceCodeToScript.delete(uiSourceCode);
|
|
96
|
+
this.#project.removeUISourceCode(uiSourceCode.url());
|
|
97
|
+
}
|
|
98
|
+
globalObjectCleared() {
|
|
99
|
+
this.#scriptToUISourceCode.clear();
|
|
100
|
+
this.#uiSourceCodeToScript.clear();
|
|
101
|
+
this.#project.reset();
|
|
102
|
+
}
|
|
103
|
+
dispose() {
|
|
104
|
+
defaultScriptMappings.delete(this);
|
|
105
|
+
Common.EventTarget.removeEventListeners(this.#eventListeners);
|
|
106
|
+
this.globalObjectCleared();
|
|
107
|
+
this.#project.dispose();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// TODO(bmeurer): Remove the static methods from DefaultScriptMapping
|
|
111
|
+
// and get rid of this global table.
|
|
112
|
+
const defaultScriptMappings = new Set();
|