Skip to content

Commit a48d7b9

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[source-map] Convert pasta scopes to 'scopes' proposal scopes
This CL converts pasta function ranges to 'OriginalScope' trees (on top of the existing 'ScopeTreeEntry's). Follow-up changes will update name resolving to use 'OriginalScope' and remove the 'ScopeTreeEntry' type altogether. The 'SourceMapScopesInfo' class currently has one 'OriginalScope' tree per original source file. This CL also keeps the 'sourcesList' consistent with the OriginalScope[] tree list for index maps. This allows us to use the same index to access both the 'sourcesList' array as well as retrieve the OriginalScope tree for that original source file. We may change this in the future into a Map keyed on sourceURL to be less brittle. [email protected] Bug: 389857436 Change-Id: I9ab3821cf6e1d4e0b629921e61fe87c43a9b6d2f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6189116 Commit-Queue: Simon Zünd <[email protected]> Reviewed-by: Kim-Anh Tran <[email protected]>
1 parent 58681ed commit a48d7b9

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

front_end/core/sdk/SourceMap.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import * as Platform from '../platform/platform.js';
3838
import * as Root from '../root/root.js';
3939

4040
import type {CallFrame, ScopeChainEntry} from './DebuggerModel.js';
41-
import {decodeScopes, type Position as GeneratedPosition} from './SourceMapScopes.js';
41+
import {buildOriginalScopes, type NamedFunctionRange} from './SourceMapFunctionRanges.js';
42+
import {decodeScopes, type OriginalScope, type Position as GeneratedPosition} from './SourceMapScopes.js';
4243
import {SourceMapScopesInfo} from './SourceMapScopesInfo.js';
4344

4445
/**
@@ -568,20 +569,29 @@ export class SourceMap {
568569
const {originalScopes, generatedRanges} = decodeScopes(map, {line: baseLineNumber, column: baseColumnNumber});
569570
this.#scopesInfo.addOriginalScopes(originalScopes);
570571
this.#scopesInfo.addGeneratedRanges(generatedRanges);
572+
} else if (map.x_com_bloomberg_sourcesFunctionMappings) {
573+
const originalScopes = this.parseBloombergScopes(map, baseSourceIndex);
574+
this.#scopesInfo.addOriginalScopes(originalScopes);
575+
} else {
576+
// Keep the OriginalScope[] tree array consistent with sources.
577+
this.#scopesInfo.addOriginalScopes(new Array(map.sources.length));
571578
}
572-
this.parseBloombergScopes(map, baseSourceIndex);
573579
}
574580
}
575581

576-
private parseBloombergScopes(map: SourceMapV3Object, baseSourceIndex: number): void {
577-
if (!map.x_com_bloomberg_sourcesFunctionMappings) {
578-
return;
582+
private parseBloombergScopes(map: SourceMapV3Object, baseSourceIndex: number): (OriginalScope|undefined)[] {
583+
const scopeList = map.x_com_bloomberg_sourcesFunctionMappings;
584+
if (!scopeList) {
585+
throw new Error('Cant decode pasta scopes without x_com_bloomberg_sourcesFunctionMappings field');
586+
} else if (scopeList.length !== map.sources.length) {
587+
throw new Error(`x_com_bloomberg_sourcesFunctionMappings must have ${map.sources.length} scope trees`);
579588
}
580589
const names = map.names ?? [];
581-
const scopeList = map.x_com_bloomberg_sourcesFunctionMappings;
590+
const result: (OriginalScope|undefined)[] = [];
582591

583592
for (let i = 0; i < scopeList.length; i++) {
584593
if (!scopeList[i]) {
594+
result.push(undefined);
585595
continue;
586596
}
587597
const sourceInfo = this.#sourceInfos[baseSourceIndex + i];
@@ -594,27 +604,38 @@ export class SourceMap {
594604
let endColumnNumber = 0;
595605

596606
const tokenIter = new TokenIterator(scopes);
597-
const entries: ScopeTreeEntry[] = [];
607+
const entries: NamedFunctionRange[] = [];
598608
let atStart = true;
599609
while (tokenIter.hasNext()) {
600610
if (atStart) {
601611
atStart = false;
602612
} else if (tokenIter.peek() === ',') {
603613
tokenIter.next();
604614
} else {
605-
// Unexpected character.
606-
return;
615+
// Unexpected character. Record what we have up until now.
616+
break;
607617
}
608618
nameIndex += tokenIter.nextVLQ();
609619
startLineNumber += tokenIter.nextVLQ();
610620
startColumnNumber += tokenIter.nextVLQ();
611621
endLineNumber += tokenIter.nextVLQ();
612622
endColumnNumber += tokenIter.nextVLQ();
613-
entries.push(new ScopeTreeEntry(
614-
startLineNumber, startColumnNumber, endLineNumber, endColumnNumber, names[nameIndex] ?? '<invalid>'));
623+
const name = names[nameIndex];
624+
if (name === undefined) {
625+
// If the range doesn't have a valid name, ignore it.
626+
continue;
627+
}
628+
entries.push({
629+
start: {line: startLineNumber, column: startColumnNumber},
630+
end: {line: endLineNumber, column: endColumnNumber},
631+
name,
632+
});
615633
}
616-
sourceInfo.scopeTree = this.buildScopeTree(entries);
634+
result.push(buildOriginalScopes(entries));
635+
sourceInfo.scopeTree = this.buildScopeTree(
636+
entries.map(e => new ScopeTreeEntry(e.start.line, e.start.column, e.end.line, e.end.column, e.name)));
617637
}
638+
return result;
618639
}
619640

620641
private buildScopeTree(entries: ScopeTreeEntry[]): ScopeTreeEntry[] {

front_end/core/sdk/SourceMapScopesInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class SourceMapScopesInfo {
2222
this.#generatedRanges = generatedRanges;
2323
}
2424

25-
addOriginalScopes(scopes: OriginalScope[]): void {
25+
addOriginalScopes(scopes: (OriginalScope|undefined)[]): void {
2626
for (const scope of scopes) {
2727
this.#originalScopes.push(scope);
2828
}

0 commit comments

Comments
 (0)