Skip to content

Commit

Permalink
[scopes] Rename isScope to isFunctionScope
Browse files Browse the repository at this point in the history
This CL aligns DevTools with an in-flight (but approved) spec PR:
tc39/ecma426#114. We need the flag to
properly hide stack frames from stack traces that got inserted
by transpilers and don't have a corresponding function in authored
code.

The flag also helps when dealing with inlining.

[email protected]

Bug: 40277685
Change-Id: Iafef35e6ccdb0acf56b2fa91aafbdb44f03c6bce
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5836934
Commit-Queue: Simon Zünd <[email protected]>
Reviewed-by: Kim-Anh Tran <[email protected]>
  • Loading branch information
szuend authored and Devtools-frontend LUCI CQ committed Sep 6, 2024
1 parent 939af1f commit 523ce9b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion front_end/core/sdk/SourceMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ describeWithEnvironment('SourceMap', () => {
const generatedRanges =
new GeneratedRangeBuilder(names)
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 0}})
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 1}, isScope: true})
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 1}, isFunctionScope: true})
.start(0, 5, {definition: {sourceIdx: 0, scopeIdx: 3}, callsite: {sourceIdx: 0, line: 15, column: 0}})
.start(0, 5, {definition: {sourceIdx: 0, scopeIdx: 5}, callsite: {sourceIdx: 0, line: 35, column: 0}})
.end(0, 10)
Expand Down
4 changes: 2 additions & 2 deletions front_end/core/sdk/SourceMapScopeChainEntry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describeWithMockConnection('SourceMapScopeRemoteObject', () => {
const range: SDK.SourceMapScopes.GeneratedRange = {
start: {line: 0, column: 0},
end: {line: 0, column: 200},
isScope: false,
isFunctionScope: false,
values: ['a'],
children: [],
};
Expand Down Expand Up @@ -83,7 +83,7 @@ describeWithMockConnection('SourceMapScopeRemoteObject', () => {
const range: SDK.SourceMapScopes.GeneratedRange = {
start: {line: 0, column: 0},
end: {line: 0, column: 200},
isScope: false,
isFunctionScope: false,
values: [[
{from: {line: 0, column: 0}, to: {line: 0, column: 50}, value: 'a'}, // From 0..50 available as 'a'.
{from: {line: 0, column: 50}, to: {line: 0, column: 150}}, // From 50..150 unavailable.
Expand Down
10 changes: 5 additions & 5 deletions front_end/core/sdk/SourceMapScopes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,19 +422,19 @@ describe('decodeGeneratedRanges', () => {
]);
});

it('decodes the "isScope" flag', () => {
it('decodes the "isFunctionScope" flag', () => {
const range = new GeneratedRangeBuilder([])
.start(0, 0)
.start(5, 0, {isScope: true})
.start(5, 0, {isFunctionScope: true})
.end(10, 0)
.start(20, 4, {isScope: false})
.start(20, 4, {isFunctionScope: false})
.end(30, 0)
.end(40, 0)
.build();

const [generatedRange] = decodeGeneratedRanges(range, [], []);
assert.lengthOf(generatedRange.children, 2);
assert.isTrue(generatedRange.children[0].isScope);
assert.isFalse(generatedRange.children[1].isScope);
assert.isTrue(generatedRange.children[0].isFunctionScope);
assert.isFalse(generatedRange.children[1].isFunctionScope);
});
});
10 changes: 5 additions & 5 deletions front_end/core/sdk/SourceMapScopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export interface GeneratedRange {
originalScope?: OriginalScope;

/**
* Whether this generated range is an actual JavaScript scope in the generated code.
* Whether this generated range is an actual JavaScript function in the generated code.
*/
isScope: boolean;
isFunctionScope: boolean;

/**
* If this `GeneratedRange` is the result of inlining `originalScope`, then `callsite`
Expand Down Expand Up @@ -196,7 +196,7 @@ export function decodeGeneratedRanges(
const rangeStack: GeneratedRange[] = [{
start: {line: 0, column: 0},
end: {line: 0, column: 0},
isScope: false,
isFunctionScope: false,
children: [],
values: [],
}];
Expand All @@ -207,7 +207,7 @@ export function decodeGeneratedRanges(
const range: GeneratedRange = {
start: {line: item.line, column: item.column},
end: {line: item.line, column: item.column},
isScope: Boolean(item.flags & EncodedGeneratedRangeFlag.IS_SCOPE),
isFunctionScope: Boolean(item.flags & EncodedGeneratedRangeFlag.IS_FUNCTION_SCOPE),
values: [],
children: [],
};
Expand Down Expand Up @@ -308,7 +308,7 @@ interface EncodedGeneratedRangeEnd {
export const enum EncodedGeneratedRangeFlag {
HAS_DEFINITION = 0x1,
HAS_CALLSITE = 0x2,
IS_SCOPE = 0x4,
IS_FUNCTION_SCOPE = 0x4,
}

function isRangeStart(item: EncodedGeneratedRangeStart|EncodedGeneratedRangeEnd): item is EncodedGeneratedRangeStart {
Expand Down
10 changes: 5 additions & 5 deletions front_end/core/sdk/SourceMapScopesInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('SourceMapScopesInfo', () => {

const generatedRanges = new GeneratedRangeBuilder(names)
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 0}})
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 1}, isScope: true})
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 1}, isFunctionScope: true})
.end(0, 5)
.end(0, 5)
.build();
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('SourceMapScopesInfo', () => {
const generatedRanges =
new GeneratedRangeBuilder(names)
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 0}})
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 1}, isScope: true})
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 1}, isFunctionScope: true})
.start(0, 5, {definition: {sourceIdx: 0, scopeIdx: 3}, callsite: {sourceIdx: 0, line: 15, column: 0}})
.start(0, 5, {definition: {sourceIdx: 0, scopeIdx: 5}, callsite: {sourceIdx: 0, line: 35, column: 0}})
.end(0, 10)
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('SourceMapScopesInfo', () => {

const generatedRanges = new GeneratedRangeBuilder(names)
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 0}})
.start(0, 10, {definition: {sourceIdx: 0, scopeIdx: 1}, isScope: true})
.start(0, 10, {definition: {sourceIdx: 0, scopeIdx: 1}, isFunctionScope: true})
.end(0, 20)
.end(0, 30)
.build();
Expand All @@ -108,7 +108,7 @@ describe('SourceMapScopesInfo', () => {

const generatedRanges = new GeneratedRangeBuilder(names)
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 0}})
.start(0, 10, {definition: {sourceIdx: 0, scopeIdx: 1}, isScope: true})
.start(0, 10, {definition: {sourceIdx: 0, scopeIdx: 1}, isFunctionScope: true})
.end(0, 20)
.end(0, 30)
.build();
Expand All @@ -131,7 +131,7 @@ describe('SourceMapScopesInfo', () => {
const generatedRanges =
new GeneratedRangeBuilder(names)
.start(0, 0, {definition: {sourceIdx: 0, scopeIdx: 0}})
.start(0, 10, {definition: {sourceIdx: 0, scopeIdx: 1}, isScope: true, bindings: ['a', 'b']})
.start(0, 10, {definition: {sourceIdx: 0, scopeIdx: 1}, isFunctionScope: true, bindings: ['a', 'b']})
.end(0, 20)
.end(0, 30)
.build();
Expand Down
4 changes: 2 additions & 2 deletions front_end/core/sdk/SourceMapScopesInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export class SourceMapScopesInfo {

// Record the name if the range corresponds to a function scope in the authored code. And it's either a scope in the
// generated code as well or it has a callsite info (which indicates inlining).
if (originalScope?.kind === 'function' && (range.isScope || range.callsite)) {
if (originalScope?.kind === 'function' && (range.isFunctionScope || range.callsite)) {
result.push({name: originalScope.name ?? '', callsite: range.callsite});

if (range.isScope) {
if (range.isFunctionScope) {
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions front_end/testing/SourceMapEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class GeneratedRangeBuilder {
}

start(line: number, column: number, options?: {
isScope?: boolean,
isFunctionScope?: boolean,
definition?: {sourceIdx: number, scopeIdx: number},
callsite?: {sourceIdx: number, line: number, column: number},
bindings?: (string|undefined|{line: number, column: number, name: string|undefined}[])[],
Expand All @@ -239,8 +239,8 @@ export class GeneratedRangeBuilder {
if (options?.callsite) {
flags |= SDK.SourceMapScopes.EncodedGeneratedRangeFlag.HAS_CALLSITE;
}
if (options?.isScope) {
flags |= SDK.SourceMapScopes.EncodedGeneratedRangeFlag.IS_SCOPE;
if (options?.isFunctionScope) {
flags |= SDK.SourceMapScopes.EncodedGeneratedRangeFlag.IS_FUNCTION_SCOPE;
}
this.#encodedRange += encodeVlq(flags);

Expand Down

0 comments on commit 523ce9b

Please sign in to comment.