devtools-tracing 1.0.1 → 1.1.1

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.
Files changed (132) hide show
  1. package/generate.ts +32 -26
  2. package/index.ts +2 -1
  3. package/lib/extension-api/ExtensionAPI.d.ts +357 -0
  4. package/lib/front_end/models/bindings/CSSWorkspaceBinding.ts +318 -0
  5. package/lib/front_end/models/bindings/CompilerScriptMapping.ts +536 -0
  6. package/lib/front_end/models/bindings/ContentProviderBasedProject.ts +187 -0
  7. package/lib/front_end/models/bindings/DebuggerLanguagePlugins.ts +1197 -0
  8. package/lib/front_end/models/bindings/DebuggerWorkspaceBinding.ts +733 -0
  9. package/lib/front_end/models/bindings/DefaultScriptMapping.ts +141 -0
  10. package/lib/front_end/models/bindings/FileUtils.ts +228 -0
  11. package/lib/front_end/models/bindings/LiveLocation.ts +81 -0
  12. package/lib/front_end/models/bindings/NetworkProject.ts +157 -0
  13. package/lib/front_end/models/bindings/PresentationConsoleMessageHelper.ts +312 -0
  14. package/lib/front_end/models/bindings/ResourceMapping.ts +539 -0
  15. package/lib/front_end/models/bindings/ResourceScriptMapping.ts +491 -0
  16. package/lib/front_end/models/bindings/ResourceUtils.ts +103 -0
  17. package/lib/front_end/models/bindings/SASSSourceMapping.ts +222 -0
  18. package/lib/front_end/models/bindings/StylesSourceMapping.ts +316 -0
  19. package/lib/front_end/models/bindings/TempFile.ts +67 -0
  20. package/lib/front_end/models/bindings/bindings.ts +39 -0
  21. package/lib/front_end/models/source_map_scopes/NamesResolver.ts +765 -0
  22. package/lib/front_end/models/source_map_scopes/ScopeChainModel.ts +84 -0
  23. package/lib/front_end/models/source_map_scopes/source_map_scopes.ts +11 -0
  24. package/lib/front_end/models/stack_trace/StackTrace.ts +53 -0
  25. package/lib/front_end/models/stack_trace/StackTraceImpl.ts +85 -0
  26. package/lib/front_end/models/stack_trace/StackTraceModel.ts +128 -0
  27. package/lib/front_end/models/stack_trace/Trie.ts +163 -0
  28. package/lib/front_end/models/stack_trace/stack_trace.ts +9 -0
  29. package/lib/front_end/models/stack_trace/stack_trace_impl.ts +13 -0
  30. package/lib/front_end/models/trace_source_maps_resolver/SourceMapsResolver.ts +240 -0
  31. package/lib/front_end/models/trace_source_maps_resolver/trace_source_maps_resolver.ts +5 -0
  32. package/lib/front_end/models/workspace/FileManager.ts +97 -0
  33. package/lib/front_end/models/workspace/IgnoreListManager.ts +628 -0
  34. package/lib/front_end/models/workspace/SearchConfig.ts +149 -0
  35. package/lib/front_end/models/workspace/UISourceCode.ts +698 -0
  36. package/lib/front_end/models/workspace/WorkspaceImpl.ts +339 -0
  37. package/lib/front_end/models/workspace/workspace.ts +17 -0
  38. package/lib/front_end/panels/timeline/TimelineUIUtils.ts +1029 -0
  39. package/lib/front_end/panels/timeline/extensions/ExtensionUI.ts +49 -0
  40. package/lib/front_end/panels/timeline/extensions/extensions.ts +9 -0
  41. package/lib/front_end/third_party/codemirror.next/LICENSE +21 -0
  42. package/lib/front_end/third_party/codemirror.next/README.chromium +30 -0
  43. package/lib/front_end/third_party/codemirror.next/bundle-tsconfig.json +24 -0
  44. package/lib/front_end/third_party/codemirror.next/bundle.ts +135 -0
  45. package/lib/front_end/third_party/codemirror.next/chunk/angular.js +2 -0
  46. package/lib/front_end/third_party/codemirror.next/chunk/angular.js.map +1 -0
  47. package/lib/front_end/third_party/codemirror.next/chunk/codemirror.js +2 -0
  48. package/lib/front_end/third_party/codemirror.next/chunk/codemirror.js.map +1 -0
  49. package/lib/front_end/third_party/codemirror.next/chunk/cpp.js +2 -0
  50. package/lib/front_end/third_party/codemirror.next/chunk/cpp.js.map +1 -0
  51. package/lib/front_end/third_party/codemirror.next/chunk/css.js +2 -0
  52. package/lib/front_end/third_party/codemirror.next/chunk/html.js +4 -0
  53. package/lib/front_end/third_party/codemirror.next/chunk/java.js +2 -0
  54. package/lib/front_end/third_party/codemirror.next/chunk/java.js.map +1 -0
  55. package/lib/front_end/third_party/codemirror.next/chunk/javascript.js +2 -0
  56. package/lib/front_end/third_party/codemirror.next/chunk/legacy.js +2 -0
  57. package/lib/front_end/third_party/codemirror.next/chunk/legacy.js.map +1 -0
  58. package/lib/front_end/third_party/codemirror.next/chunk/less.js +2 -0
  59. package/lib/front_end/third_party/codemirror.next/chunk/less.js.map +1 -0
  60. package/lib/front_end/third_party/codemirror.next/chunk/markdown.js +2 -0
  61. package/lib/front_end/third_party/codemirror.next/chunk/markdown.js.map +1 -0
  62. package/lib/front_end/third_party/codemirror.next/chunk/php.js +2 -0
  63. package/lib/front_end/third_party/codemirror.next/chunk/php.js.map +1 -0
  64. package/lib/front_end/third_party/codemirror.next/chunk/python.js +2 -0
  65. package/lib/front_end/third_party/codemirror.next/chunk/python.js.map +1 -0
  66. package/lib/front_end/third_party/codemirror.next/chunk/sass.js +2 -0
  67. package/lib/front_end/third_party/codemirror.next/chunk/sass.js.map +1 -0
  68. package/lib/front_end/third_party/codemirror.next/chunk/svelte.js +2 -0
  69. package/lib/front_end/third_party/codemirror.next/chunk/svelte.js.map +1 -0
  70. package/lib/front_end/third_party/codemirror.next/chunk/vue.js +2 -0
  71. package/lib/front_end/third_party/codemirror.next/chunk/vue.js.map +1 -0
  72. package/lib/front_end/third_party/codemirror.next/chunk/wast.js +2 -0
  73. package/lib/front_end/third_party/codemirror.next/chunk/wast.js.map +1 -0
  74. package/lib/front_end/third_party/codemirror.next/chunk/xml.js +2 -0
  75. package/lib/front_end/third_party/codemirror.next/chunk/xml.js.map +1 -0
  76. package/lib/front_end/third_party/codemirror.next/codemirror.next.d.ts +8057 -0
  77. package/lib/front_end/third_party/codemirror.next/codemirror.next.js +2 -0
  78. package/lib/front_end/third_party/codemirror.next/codemirror.next.js.map +1 -0
  79. package/lib/front_end/third_party/codemirror.next/package.json +43 -0
  80. package/lib/front_end/third_party/codemirror.next/rebuild.sh +6 -0
  81. package/lib/front_end/third_party/codemirror.next/rollup.config.mjs +49 -0
  82. package/lib/front_end/third_party/source-map-scopes-codec/LICENSE +26 -0
  83. package/lib/front_end/third_party/source-map-scopes-codec/README.chromium +31 -0
  84. package/lib/front_end/third_party/source-map-scopes-codec/package/CONTRIBUTING.md +33 -0
  85. package/lib/front_end/third_party/source-map-scopes-codec/package/LICENSE +26 -0
  86. package/lib/front_end/third_party/source-map-scopes-codec/package/README.md +64 -0
  87. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/builder.d.ts +62 -0
  88. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/builder.d.ts.map +1 -0
  89. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/safe_builder.d.ts +37 -0
  90. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/safe_builder.d.ts.map +1 -0
  91. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/decode/decode.d.ts +29 -0
  92. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/decode/decode.d.ts.map +1 -0
  93. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/encode/encode.d.ts +8 -0
  94. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/encode/encode.d.ts.map +1 -0
  95. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/mod.d.ts +6 -0
  96. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/mod.d.ts.map +1 -0
  97. package/lib/front_end/third_party/source-map-scopes-codec/package/deno.json +21 -0
  98. package/lib/front_end/third_party/source-map-scopes-codec/package/package.json +14 -0
  99. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.js +196 -0
  100. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.js.map +1 -0
  101. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.ts +262 -0
  102. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.js +235 -0
  103. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.js.map +1 -0
  104. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.ts +359 -0
  105. package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.js +39 -0
  106. package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.js.map +1 -0
  107. package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.ts +53 -0
  108. package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.js +438 -0
  109. package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.js.map +1 -0
  110. package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.ts +539 -0
  111. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.js +23 -0
  112. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.js.map +1 -0
  113. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.ts +35 -0
  114. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.js +257 -0
  115. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.js.map +1 -0
  116. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.ts +348 -0
  117. package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.js +8 -0
  118. package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.js.map +1 -0
  119. package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.ts +20 -0
  120. package/lib/front_end/third_party/source-map-scopes-codec/package/src/scopes-tsconfig.json +8 -0
  121. package/lib/front_end/third_party/source-map-scopes-codec/package/src/scopes.d.ts +184 -0
  122. package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.js +9 -0
  123. package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.js.map +1 -0
  124. package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.ts +12 -0
  125. package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.js +82 -0
  126. package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.js.map +1 -0
  127. package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.ts +99 -0
  128. package/lib/front_end/third_party/source-map-scopes-codec/source-map-scopes-codec.ts +5 -0
  129. package/lib/front_end/ui/legacy/theme_support/ThemeSupport.ts +222 -0
  130. package/lib/front_end/ui/legacy/theme_support/theme_support.ts +5 -0
  131. package/package.json +5 -5
  132. package/patches/chrome-devtools-frontend+1.0.1533544.patch +1549 -20
@@ -0,0 +1,536 @@
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
+
5
+ import * as Common from '../../core/common/common.js';
6
+ import * as Platform from '../../core/platform/platform.js';
7
+ import * as SDK from '../../core/sdk/sdk.js';
8
+ // eslint-disable-next-line @devtools/es-modules-import
9
+ import * as StackTraceImpl from '../stack_trace/stack_trace_impl.js';
10
+ import * as TextUtils from '../text_utils/text_utils.js';
11
+ import * as Workspace from '../workspace/workspace.js';
12
+
13
+ import {ContentProviderBasedProject} from './ContentProviderBasedProject.js';
14
+ import type {DebuggerSourceMapping, DebuggerWorkspaceBinding} from './DebuggerWorkspaceBinding.js';
15
+ import {NetworkProject} from './NetworkProject.js';
16
+
17
+ /**
18
+ * The `CompilerScriptMapping` maps script entities from source maps to scripts and vice versa.
19
+ * It is part of the {@link DebuggerWorkspaceBinding} and operates on top of the
20
+ * {@link SDK.SourceMapManager.SourceMapManager}.
21
+ *
22
+ * The `CompilerScriptMapping` maintains a list of {@link ContentProviderBasedProject}s, in which it
23
+ * creates the `UISourceCode`s for the source-mapped entities. The mapping is implemented in various
24
+ * layers:
25
+ *
26
+ * - `#sourceMapToProject` holds a mapping of all the attached `SourceMap`s to their respective
27
+ * `ContentBasedProviderBasedProject`s. When resolving raw to UI locations this is the first
28
+ * place to check.
29
+ * - `#uiSourceCodeToSourceMaps` maps every `UISourceCode` created herein to the `SourceMap` that
30
+ * it originated from. This is the authoritative source of information: The `#projects` might
31
+ * contain `UISourceCode` objects that were created from this `CompilerScriptMapping`, but which
32
+ * have become stale, and `#uiSourceCodeToSourceMaps` represents these as having no source maps.
33
+ *
34
+ * @see {@link SDK.SourceMap.SourceMap}
35
+ * @see {@link SDK.SourceMapManager.SourceMapManager}
36
+ */
37
+ export class CompilerScriptMapping implements DebuggerSourceMapping {
38
+ readonly #sourceMapManager: SDK.SourceMapManager.SourceMapManager<SDK.Script.Script>;
39
+ readonly #debuggerWorkspaceBinding: DebuggerWorkspaceBinding;
40
+ readonly #stubUISourceCodes = new Map<SDK.Script.Script, Workspace.UISourceCode.UISourceCode>();
41
+ readonly #stubProject: ContentProviderBasedProject;
42
+ readonly #eventListeners: Common.EventTarget.EventDescriptor[];
43
+ readonly #projects = new Map<string, ContentProviderBasedProject>();
44
+ readonly #sourceMapToProject = new Map<SDK.SourceMap.SourceMap, ContentProviderBasedProject>();
45
+ readonly #uiSourceCodeToSourceMaps =
46
+ new Platform.MapUtilities.Multimap<Workspace.UISourceCode.UISourceCode, SDK.SourceMap.SourceMap>();
47
+ readonly #debuggerModel: SDK.DebuggerModel.DebuggerModel;
48
+
49
+ constructor(
50
+ debuggerModel: SDK.DebuggerModel.DebuggerModel, workspace: Workspace.Workspace.WorkspaceImpl,
51
+ debuggerWorkspaceBinding: DebuggerWorkspaceBinding) {
52
+ this.#sourceMapManager = debuggerModel.sourceMapManager();
53
+ this.#debuggerWorkspaceBinding = debuggerWorkspaceBinding;
54
+ this.#debuggerModel = debuggerModel;
55
+
56
+ this.#stubProject = new ContentProviderBasedProject(
57
+ workspace, 'jsSourceMaps:stub:' + debuggerModel.target().id(), Workspace.Workspace.projectTypes.Service, '',
58
+ true /* isServiceProject */);
59
+ this.#eventListeners = [
60
+ this.#sourceMapManager.addEventListener(
61
+ SDK.SourceMapManager.Events.SourceMapWillAttach, this.sourceMapWillAttach, this),
62
+ this.#sourceMapManager.addEventListener(
63
+ SDK.SourceMapManager.Events.SourceMapFailedToAttach, this.sourceMapFailedToAttach, this),
64
+ this.#sourceMapManager.addEventListener(
65
+ SDK.SourceMapManager.Events.SourceMapAttached, this.sourceMapAttached, this),
66
+ this.#sourceMapManager.addEventListener(
67
+ SDK.SourceMapManager.Events.SourceMapDetached, this.sourceMapDetached, this),
68
+ ];
69
+ }
70
+
71
+ setFunctionRanges(
72
+ uiSourceCode: Workspace.UISourceCode.UISourceCode,
73
+ ranges: SDK.SourceMapFunctionRanges.NamedFunctionRange[]): void {
74
+ for (const sourceMap of this.#uiSourceCodeToSourceMaps.get(uiSourceCode)) {
75
+ sourceMap.augmentWithScopes(uiSourceCode.url(), ranges);
76
+ }
77
+ }
78
+
79
+ private addStubUISourceCode(script: SDK.Script.Script): void {
80
+ const stubUISourceCode = this.#stubProject.addContentProvider(
81
+ Common.ParsedURL.ParsedURL.concatenate(script.sourceURL, ':sourcemap'),
82
+ TextUtils.StaticContentProvider.StaticContentProvider.fromString(
83
+ script.sourceURL, Common.ResourceType.resourceTypes.Script,
84
+ '\n\n\n\n\n// Please wait a bit.\n// Compiled script is not shown while source map is being loaded!'),
85
+ 'text/javascript');
86
+ this.#stubUISourceCodes.set(script, stubUISourceCode);
87
+ }
88
+
89
+ private removeStubUISourceCode(script: SDK.Script.Script): void {
90
+ const uiSourceCode = this.#stubUISourceCodes.get(script);
91
+ this.#stubUISourceCodes.delete(script);
92
+ if (uiSourceCode) {
93
+ this.#stubProject.removeUISourceCode(uiSourceCode.url());
94
+ }
95
+ }
96
+
97
+ getLocationRangesForSameSourceLocation(rawLocation: SDK.DebuggerModel.Location): SDK.DebuggerModel.LocationRange[] {
98
+ const debuggerModel = rawLocation.debuggerModel;
99
+ const script = rawLocation.script();
100
+ if (!script) {
101
+ return [];
102
+ }
103
+ const sourceMap = this.#sourceMapManager.sourceMapForClient(script);
104
+ if (!sourceMap) {
105
+ return [];
106
+ }
107
+
108
+ // Find the source location for the raw location.
109
+ const {lineNumber, columnNumber} = script.rawLocationToRelativeLocation(rawLocation);
110
+ const entry = sourceMap.findEntry(lineNumber, columnNumber);
111
+ if (!entry?.sourceURL) {
112
+ return [];
113
+ }
114
+
115
+ const project = this.#sourceMapToProject.get(sourceMap);
116
+ if (!project) {
117
+ return [];
118
+ }
119
+
120
+ const uiSourceCode = project.uiSourceCodeForURL(entry.sourceURL);
121
+ if (!uiSourceCode) {
122
+ return [];
123
+ }
124
+
125
+ // Check that the reverse is also true and we have a binding for this |uiSourceCode|
126
+ // that is referred to from the |sourceMap| of the |script|.
127
+ if (!this.#uiSourceCodeToSourceMaps.hasValue(uiSourceCode, sourceMap)) {
128
+ return [];
129
+ }
130
+
131
+ // Map the source location back to raw location ranges.
132
+ const ranges = sourceMap.findReverseRanges(entry.sourceURL, entry.sourceLineNumber, entry.sourceColumnNumber);
133
+ return ranges.map(({startLine, startColumn, endLine, endColumn}) => {
134
+ const start = script.relativeLocationToRawLocation({lineNumber: startLine, columnNumber: startColumn});
135
+ const end = script.relativeLocationToRawLocation({lineNumber: endLine, columnNumber: endColumn});
136
+ return {
137
+ start: debuggerModel.createRawLocation(script, start.lineNumber, start.columnNumber),
138
+ end: debuggerModel.createRawLocation(script, end.lineNumber, end.columnNumber),
139
+ };
140
+ });
141
+ }
142
+
143
+ uiSourceCodeForURL(url: Platform.DevToolsPath.UrlString, isContentScript: boolean):
144
+ Workspace.UISourceCode.UISourceCode|null {
145
+ const projectType =
146
+ isContentScript ? Workspace.Workspace.projectTypes.ContentScripts : Workspace.Workspace.projectTypes.Network;
147
+ for (const project of this.#projects.values()) {
148
+ if (project.type() !== projectType) {
149
+ continue;
150
+ }
151
+ const uiSourceCode = project.uiSourceCodeForURL(url);
152
+ if (uiSourceCode) {
153
+ return uiSourceCode;
154
+ }
155
+ }
156
+ return null;
157
+ }
158
+
159
+ /**
160
+ * Resolves the source-mapped entity mapped from the given `rawLocation` if any. If the `rawLocation`
161
+ * does not point into a script with a source map, `null` is returned from here, while if the source
162
+ * map for the script is currently being loaded, a stub `UISourceCode` is returned meanwhile. Otherwise,
163
+ * if the script has a source map entry for the position identified by the `rawLocation`, this method
164
+ * will compute the location in the source-mapped file by a reverse lookup on the source map.
165
+ *
166
+ * If `rawLocation` points to a script with a source map managed by this `CompilerScriptMapping`, which
167
+ * is stale (because it was overridden by a more recent mapping), `null` will be returned.
168
+ *
169
+ * @param rawLocation script location.
170
+ * @returns the {@link Workspace.UISourceCode.UILocation} for the `rawLocation` if any.
171
+ */
172
+ rawLocationToUILocation(rawLocation: SDK.DebuggerModel.Location): Workspace.UISourceCode.UILocation|null {
173
+ const script = rawLocation.script();
174
+ if (!script) {
175
+ return null;
176
+ }
177
+
178
+ const {lineNumber, columnNumber} = script.rawLocationToRelativeLocation(rawLocation);
179
+ const stubUISourceCode = this.#stubUISourceCodes.get(script);
180
+ if (stubUISourceCode) {
181
+ return new Workspace.UISourceCode.UILocation(stubUISourceCode, lineNumber, columnNumber);
182
+ }
183
+
184
+ const sourceMap = this.#sourceMapManager.sourceMapForClient(script);
185
+ if (!sourceMap) {
186
+ return null;
187
+ }
188
+
189
+ const project = this.#sourceMapToProject.get(sourceMap);
190
+ if (!project) {
191
+ return null;
192
+ }
193
+
194
+ const entry = sourceMap.findEntry(lineNumber, columnNumber, rawLocation.inlineFrameIndex);
195
+ if (!entry?.sourceURL) {
196
+ return null;
197
+ }
198
+
199
+ const uiSourceCode = project.uiSourceCodeForURL(entry.sourceURL);
200
+ if (!uiSourceCode) {
201
+ return null;
202
+ }
203
+
204
+ // Check that the reverse is also true and we have a binding for this `uiSourceCode`
205
+ // that is referred to from the `sourceMap` of the `script`.
206
+ if (!this.#uiSourceCodeToSourceMaps.hasValue(uiSourceCode, sourceMap)) {
207
+ return null;
208
+ }
209
+
210
+ return uiSourceCode.uiLocation(entry.sourceLineNumber, entry.sourceColumnNumber);
211
+ }
212
+
213
+ /**
214
+ * Resolves a location within a source mapped entity managed by the `CompilerScriptMapping`
215
+ * to its script locations. If the `uiSourceCode` does not belong to this mapping or if its
216
+ * mapping is stale, an empty list will be returned.
217
+ *
218
+ * A single UI location can map to multiple different {@link SDK.DebuggerModel.RawLocation}s,
219
+ * and these raw locations don't even need to belong to the same script (e.g. multiple bundles
220
+ * can reference the same shared source file in case of code splitting, and locations within
221
+ * this shared source file will then resolve to locations in all the bundles).
222
+ *
223
+ * @param uiSourceCode the source mapped entity.
224
+ * @param lineNumber the line number in terms of the {@link uiSourceCode}.
225
+ * @param columnNumber the column number in terms of the {@link uiSourceCode}.
226
+ * @returns a list of raw locations that correspond to the UI location.
227
+ */
228
+ uiLocationToRawLocations(uiSourceCode: Workspace.UISourceCode.UISourceCode, lineNumber: number, columnNumber: number):
229
+ SDK.DebuggerModel.Location[] {
230
+ const locations = [];
231
+ for (const sourceMap of this.#uiSourceCodeToSourceMaps.get(uiSourceCode)) {
232
+ const entry = sourceMap.sourceLineMapping(uiSourceCode.url(), lineNumber, columnNumber);
233
+ if (!entry) {
234
+ continue;
235
+ }
236
+ const script = this.#sourceMapManager.clientForSourceMap(sourceMap);
237
+ if (!script) {
238
+ continue;
239
+ }
240
+ const location = script.relativeLocationToRawLocation(entry);
241
+ locations.push(script.debuggerModel.createRawLocation(script, location.lineNumber, location.columnNumber));
242
+ }
243
+ return locations;
244
+ }
245
+
246
+ uiLocationRangeToRawLocationRanges(
247
+ uiSourceCode: Workspace.UISourceCode.UISourceCode,
248
+ textRange: TextUtils.TextRange.TextRange): SDK.DebuggerModel.LocationRange[]|null {
249
+ if (!this.#uiSourceCodeToSourceMaps.has(uiSourceCode)) {
250
+ return null;
251
+ }
252
+ const ranges = [];
253
+ for (const sourceMap of this.#uiSourceCodeToSourceMaps.get(uiSourceCode)) {
254
+ const script = this.#sourceMapManager.clientForSourceMap(sourceMap);
255
+ if (!script) {
256
+ continue;
257
+ }
258
+
259
+ for (const scriptTextRange of sourceMap.reverseMapTextRanges(uiSourceCode.url(), textRange)) {
260
+ const startLocation = script.relativeLocationToRawLocation(scriptTextRange.start);
261
+ const endLocation = script.relativeLocationToRawLocation(scriptTextRange.end);
262
+ const start =
263
+ script.debuggerModel.createRawLocation(script, startLocation.lineNumber, startLocation.columnNumber);
264
+ const end = script.debuggerModel.createRawLocation(script, endLocation.lineNumber, endLocation.columnNumber);
265
+ ranges.push({start, end});
266
+ }
267
+ }
268
+ return ranges;
269
+ }
270
+
271
+ translateRawFramesStep(
272
+ rawFrames: StackTraceImpl.Trie.RawFrame[],
273
+ translatedFrames: Awaited<ReturnType<StackTraceImpl.StackTraceModel.TranslateRawFrames>>): boolean {
274
+ const frame = rawFrames[0];
275
+ if (StackTraceImpl.Trie.isBuiltinFrame(frame)) {
276
+ return false;
277
+ }
278
+
279
+ const sourceMapWithScopeInfoForFrame =
280
+ (rawFrame: StackTraceImpl.Trie.RawFrame): {sourceMap: SDK.SourceMap.SourceMap, script: SDK.Script.Script}|
281
+ null => {
282
+ const script = this.#debuggerModel.scriptForId(rawFrame.scriptId ?? '');
283
+ if (!script || this.#stubUISourceCodes.has(script)) {
284
+ // Use fallback while source map is being loaded.
285
+ return null;
286
+ }
287
+
288
+ const sourceMap = script.sourceMap();
289
+ return sourceMap?.hasScopeInfo() ? {sourceMap, script} : null;
290
+ };
291
+
292
+ const sourceMapAndScript = sourceMapWithScopeInfoForFrame(frame);
293
+ if (!sourceMapAndScript) {
294
+ return false;
295
+ }
296
+ const {sourceMap, script} = sourceMapAndScript;
297
+ const {lineNumber, columnNumber} = script.relativeLocationToRawLocation(frame);
298
+
299
+ if (!sourceMap.isOutlinedFrame(lineNumber, columnNumber)) {
300
+ const frames = sourceMap.translateCallSite(lineNumber, columnNumber);
301
+ if (!frames.length) {
302
+ return false;
303
+ }
304
+
305
+ rawFrames.shift();
306
+ const result: typeof translatedFrames[0] = [];
307
+ translatedFrames.push(result);
308
+
309
+ const project = this.#sourceMapToProject.get(sourceMap);
310
+ for (const frame of frames) {
311
+ // Switch out url for UISourceCode where we have it.
312
+ const uiSourceCode = frame.url ? project?.uiSourceCodeForURL(frame.url) : undefined;
313
+ result.push({
314
+ ...frame,
315
+ url: uiSourceCode ? undefined : frame.url,
316
+ uiSourceCode: uiSourceCode ?? undefined,
317
+ });
318
+ }
319
+
320
+ return true;
321
+ }
322
+
323
+ // TODO(crbug.com/433162438): Consolidate outlined frames.
324
+ return false;
325
+ }
326
+
327
+ /**
328
+ * Computes the set of line numbers which are source-mapped to a script within the
329
+ * given {@link uiSourceCode}.
330
+ *
331
+ * @param uiSourceCode the source mapped entity.
332
+ * @returns a set of source-mapped line numbers or `null` if the {@link uiSourceCode}
333
+ * is not provided by this {@link CompilerScriptMapping} instance.
334
+ */
335
+ getMappedLines(uiSourceCode: Workspace.UISourceCode.UISourceCode): Set<number>|null {
336
+ if (!this.#uiSourceCodeToSourceMaps.has(uiSourceCode)) {
337
+ return null;
338
+ }
339
+ const mappedLines = new Set<number>();
340
+ for (const sourceMap of this.#uiSourceCodeToSourceMaps.get(uiSourceCode)) {
341
+ for (const entry of sourceMap.mappings()) {
342
+ if (entry.sourceURL !== uiSourceCode.url()) {
343
+ continue;
344
+ }
345
+ mappedLines.add(entry.sourceLineNumber);
346
+ }
347
+ }
348
+ return mappedLines;
349
+ }
350
+
351
+ /**
352
+ * Invoked by the {@link SDK.SourceMapManager.SourceMapManager} whenever it starts loading the
353
+ * source map for a given {@link SDK.Script.Script}. The `CompilerScriptMapping` will set up a
354
+ * {@link Workspace.UISourceCode.UISourceCode} stub for the time that the source map is being
355
+ * loaded to avoid showing the generated code when the DevTools front-end is stopped early (for
356
+ * example on a breakpoint).
357
+ *
358
+ * @param event holds the {@link SDK.Script.Script} whose source map is being loaded.
359
+ */
360
+ private sourceMapWillAttach(event: Common.EventTarget.EventTargetEvent<{client: SDK.Script.Script}>): void {
361
+ const {client: script} = event.data;
362
+ // Create stub UISourceCode for the time source mapping is being loaded.
363
+ this.addStubUISourceCode(script);
364
+ void this.#debuggerWorkspaceBinding.updateLocations(script);
365
+ if (Workspace.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(
366
+ script.sourceURL, {isContentScript: script.isContentScript()})) {
367
+ this.#sourceMapManager.cancelAttachSourceMap(script);
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Invoked by the {@link SDK.SourceMapManager.SourceMapManager} after an attempt to load the
373
+ * source map for a given {@link SDK.Script.Script} failed. The `CompilerScriptMapping` will
374
+ * remove the {@link Workspace.UISourceCode.UISourceCode} stub, and from this time on won't
375
+ * report any mappings for the `client` script.
376
+ *
377
+ * @param event holds the {@link SDK.Script.Script} whose source map failed to load.
378
+ */
379
+ private sourceMapFailedToAttach(event: Common.EventTarget.EventTargetEvent<{client: SDK.Script.Script}>): void {
380
+ const {client: script} = event.data;
381
+ this.removeStubUISourceCode(script);
382
+ void this.#debuggerWorkspaceBinding.updateLocations(script);
383
+ }
384
+
385
+ /**
386
+ * Invoked by the {@link SDK.SourceMapManager.SourceMapManager} after an attempt to load the
387
+ * source map for a given {@link SDK.Script.Script} succeeded. The `CompilerScriptMapping` will
388
+ * now create {@link Workspace.UISourceCode.UISourceCode}s for all the sources mentioned in the
389
+ * `sourceMap`.
390
+ *
391
+ * In case of a conflict this method creates a new {@link Workspace.UISourceCode.UISourceCode}
392
+ * and copies over all the mappings from the other source maps that were registered for the
393
+ * same URL and which are compatible (agree on the content and ignore-list hint for the given
394
+ * URL). If they are considered incompatible, the original `UISourceCode` will simply be
395
+ * removed and a new mapping will be established.
396
+ *
397
+ * @param event holds the {@link SDK.Script.Script} and its {@link SDK.SourceMap.SourceMap}.
398
+ */
399
+ private sourceMapAttached(event: Common.EventTarget.EventTargetEvent<{
400
+ client: SDK.Script.Script,
401
+ sourceMap: SDK.SourceMap.SourceMap,
402
+ }>): void {
403
+ const {client: script, sourceMap} = event.data;
404
+ const scripts = new Set<SDK.Script.Script>([script]);
405
+ this.removeStubUISourceCode(script);
406
+
407
+ const target = script.target();
408
+ const projectId = `jsSourceMaps:${script.isContentScript() ? 'extensions' : ''}:${target.id()}`;
409
+ let project = this.#projects.get(projectId);
410
+ if (!project) {
411
+ const projectType = script.isContentScript() ? Workspace.Workspace.projectTypes.ContentScripts :
412
+ Workspace.Workspace.projectTypes.Network;
413
+ project = new ContentProviderBasedProject(
414
+ this.#stubProject.workspace(), projectId, projectType, /* displayName */ '', /* isServiceProject */ false);
415
+ NetworkProject.setTargetForProject(project, target);
416
+ this.#projects.set(projectId, project);
417
+ }
418
+ this.#sourceMapToProject.set(sourceMap, project);
419
+
420
+ for (const url of sourceMap.sourceURLs()) {
421
+ const contentType = Common.ResourceType.resourceTypes.SourceMapScript;
422
+ const uiSourceCode = project.createUISourceCode(url, contentType);
423
+ if (sourceMap.hasIgnoreListHint(url)) {
424
+ uiSourceCode.markKnownThirdParty();
425
+ }
426
+ const content = sourceMap.embeddedContentByURL(url);
427
+ const contentProvider = content !== null ?
428
+ TextUtils.StaticContentProvider.StaticContentProvider.fromString(url, contentType, content) :
429
+ new SDK.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(
430
+ url, contentType, script.createPageResourceLoadInitiator());
431
+ let metadata: Workspace.UISourceCode.UISourceCodeMetadata|null = null;
432
+ if (content !== null) {
433
+ const encoder = new TextEncoder();
434
+ metadata = new Workspace.UISourceCode.UISourceCodeMetadata(null, encoder.encode(content).length);
435
+ }
436
+ const mimeType = Common.ResourceType.ResourceType.mimeFromURL(url) ?? contentType.canonicalMimeType();
437
+
438
+ this.#uiSourceCodeToSourceMaps.set(uiSourceCode, sourceMap);
439
+ NetworkProject.setInitialFrameAttribution(uiSourceCode, script.frameId);
440
+
441
+ // Check if there was already an `UISourceCode` for the given `url`, and if so, discard
442
+ // the previous one. While it would be possible to keep the previous one and just add
443
+ // the new mapping (from the `sourceMap`) to it as long as there's no conflict, this
444
+ // doesn't really work with the way the `BreakpointManager` and other parts of the front-end
445
+ // work, which only listen for additions/removals of `UISourceCode`s, since there's no
446
+ // notion of a 'UISourceCodeChanged` event (yet).
447
+ //
448
+ // Therefore, unless we discard any previous `UISourceCode` for the `url` and publish the
449
+ // new `uiSourceCode`, the `BreakpointManager` will not restore / set breakpoints in newly
450
+ // added scripts in case of code-splitting, since it won't find out about these new mappings.
451
+ // By removing and (re)adding a `UISourceCode` for the `url` we effectively force restoration
452
+ // of breakpoints.
453
+ const otherUISourceCode = project.uiSourceCodeForURL(url);
454
+ if (otherUISourceCode !== null) {
455
+ // Copy the existing source mappings from the `otherUISourceCode` over as long as
456
+ // they are compatible with the `sourceMap` wrt. `url`. While doing so, also clean
457
+ // up the `otherUISourceCode` (in particular its frame attributions).
458
+ for (const otherSourceMap of this.#uiSourceCodeToSourceMaps.get(otherUISourceCode)) {
459
+ this.#uiSourceCodeToSourceMaps.delete(otherUISourceCode, otherSourceMap);
460
+ const otherScript = this.#sourceMapManager.clientForSourceMap(otherSourceMap);
461
+ if (!otherScript) {
462
+ continue;
463
+ }
464
+ NetworkProject.removeFrameAttribution(otherUISourceCode, otherScript.frameId);
465
+ if (sourceMap.compatibleForURL(url, otherSourceMap)) {
466
+ this.#uiSourceCodeToSourceMaps.set(uiSourceCode, otherSourceMap);
467
+ NetworkProject.addFrameAttribution(uiSourceCode, otherScript.frameId);
468
+ }
469
+ scripts.add(otherScript);
470
+ }
471
+ project.removeUISourceCode(url);
472
+ }
473
+
474
+ project.addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata, mimeType);
475
+ }
476
+ void Promise.all([...scripts].map(script => this.#debuggerWorkspaceBinding.updateLocations(script)))
477
+ .then(() => this.sourceMapAttachedForTest(sourceMap));
478
+ }
479
+
480
+ /**
481
+ * Invoked by the {@link SDK.SourceMapManager.SourceMapManager} when the source map for a given
482
+ * {@link SDK.Script.Script} is removed, which could be either because the target is execution
483
+ * context was destroyed, or the user manually asked to replace the source map for a given
484
+ * script.
485
+ *
486
+ * @param event holds the {@link SDK.Script.Script} and {@link SDK.SourceMap.SourceMap} that
487
+ * should be detached.
488
+ */
489
+ private sourceMapDetached(event: Common.EventTarget.EventTargetEvent<{
490
+ client: SDK.Script.Script,
491
+ sourceMap: SDK.SourceMap.SourceMap,
492
+ }>): void {
493
+ const {client: script, sourceMap} = event.data;
494
+ const project = this.#sourceMapToProject.get(sourceMap);
495
+ if (!project) {
496
+ return;
497
+ }
498
+
499
+ // Remove all the files in the `project` that (still) belong to the `sourceMap`.
500
+ // In case of conflicts or overrides (for example due to HMR), not all the files
501
+ // that were originally provided by the `sourceMap` might still belong to it.
502
+ for (const uiSourceCode of project.uiSourceCodes()) {
503
+ if (this.#uiSourceCodeToSourceMaps.delete(uiSourceCode, sourceMap)) {
504
+ NetworkProject.removeFrameAttribution(uiSourceCode, script.frameId);
505
+ if (!this.#uiSourceCodeToSourceMaps.has(uiSourceCode)) {
506
+ project.removeUISourceCode(uiSourceCode.url());
507
+ }
508
+ }
509
+ }
510
+
511
+ this.#sourceMapToProject.delete(sourceMap);
512
+ void this.#debuggerWorkspaceBinding.updateLocations(script);
513
+ }
514
+
515
+ scriptsForUISourceCode(uiSourceCode: Workspace.UISourceCode.UISourceCode): SDK.Script.Script[] {
516
+ const scripts = [];
517
+ for (const sourceMap of this.#uiSourceCodeToSourceMaps.get(uiSourceCode)) {
518
+ const script = this.#sourceMapManager.clientForSourceMap(sourceMap);
519
+ if (script) {
520
+ scripts.push(script);
521
+ }
522
+ }
523
+ return scripts;
524
+ }
525
+
526
+ private sourceMapAttachedForTest(_sourceMap: SDK.SourceMap.SourceMap): void {
527
+ }
528
+
529
+ dispose(): void {
530
+ Common.EventTarget.removeEventListeners(this.#eventListeners);
531
+ for (const project of this.#projects.values()) {
532
+ project.dispose();
533
+ }
534
+ this.#stubProject.dispose();
535
+ }
536
+ }