Skip to content

Commit 2d5017a

Browse files
bcoeCommit Bot
authored andcommitted
[coverage] remove the last continuation range before synthetic return
Rather than only removing the continuation range for the last return statement prior to a synthetic return statement, remove the continuation tracking for whatever statement occurs prior to the synthetic return. Bug: v8:10628 Change-Id: Ieb8e393479c9811cf1b9756840bbfdbe7f44a1b8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2280585 Commit-Queue: Benjamin Coe <[email protected]> Reviewed-by: Toon Verwaest <[email protected]> Reviewed-by: Jakob Gruber <[email protected]> Reviewed-by: Sigurd Schneider <[email protected]> Cr-Commit-Position: refs/heads/master@{#68719}
1 parent 10fdca8 commit 2d5017a

2 files changed

Lines changed: 55 additions & 10 deletions

File tree

src/ast/source-range-ast-visitor.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ void SourceRangeAstVisitor::MaybeRemoveLastContinuationRange(
9999
}
100100

101101
namespace {
102-
Statement* FindLastNonSyntheticReturn(ZonePtrList<Statement>* statements) {
102+
Statement* FindLastNonSyntheticStatement(ZonePtrList<Statement>* statements) {
103103
for (int i = statements->length() - 1; i >= 0; --i) {
104104
Statement* stmt = statements->at(i);
105-
if (!stmt->IsReturnStatement()) break;
106-
if (stmt->AsReturnStatement()->is_synthetic_async_return()) continue;
105+
if (stmt->IsReturnStatement() &&
106+
stmt->AsReturnStatement()->is_synthetic_async_return()) {
107+
continue;
108+
}
107109
return stmt;
108110
}
109111
return nullptr;
@@ -114,11 +116,11 @@ void SourceRangeAstVisitor::MaybeRemoveContinuationRangeOfAsyncReturn(
114116
TryCatchStatement* try_catch_stmt) {
115117
// Detect try-catch inserted by NewTryCatchStatementForAsyncAwait in the
116118
// parser (issued for async functions, including async generators), and
117-
// remove the continuation ranges of return statements corresponding to
118-
// returns at function end in the untransformed source.
119+
// remove the continuation range of the last statement, such that the
120+
// range of the enclosing function body is used.
119121
if (try_catch_stmt->is_try_catch_for_async()) {
120122
Statement* last_non_synthetic =
121-
FindLastNonSyntheticReturn(try_catch_stmt->try_block()->statements());
123+
FindLastNonSyntheticStatement(try_catch_stmt->try_block()->statements());
122124
if (last_non_synthetic) {
123125
MaybeRemoveContinuationRange(last_non_synthetic);
124126
}

test/mjsunit/code-coverage-block-async.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ test().then(r => r.bar()); // 0350
136136
{"start":152,"end":253,"count":1},
137137
{"start":362,"end":374,"count":1}]);
138138

139-
// Documents the open bug that causes trailing space after `finally`
140-
// not to be removed by SourceRangeAstVisitor.
141139
TestCoverage(
142140
"https://crbug.com/v8/10628",
143141
`
@@ -152,7 +150,52 @@ abc(); // 0350
152150
%PerformMicrotaskCheckpoint(); // 0400
153151
`,
154152
[{"start":0,"end":449,"count":1},
155-
{"start":0,"end":301,"count":1},
156-
{"start":252,"end":300,"count":0}]);
153+
{"start":0,"end":301,"count":1}]);
154+
155+
TestCoverage(
156+
"try/catch/finally statements async",
157+
`
158+
!async function() { // 0000
159+
try { nop(); } catch (e) { nop(); } // 0050
160+
try { nop(); } finally { nop(); } // 0100
161+
try { // 0150
162+
try { throw 42; } catch (e) { nop(); }// 0200
163+
} catch (e) { nop(); } // 0250
164+
try { // 0300
165+
try { throw 42; } finally { nop(); } // 0350
166+
} catch (e) { nop(); } // 0400
167+
try { // 0450
168+
throw 42; // 0500
169+
} catch (e) { // 0550
170+
nop(); // 0600
171+
} finally { // 0650
172+
nop(); // 0700
173+
} // 0750
174+
}(); // 0800
175+
`,
176+
[{"start":0,"end":849,"count":1},
177+
{"start":1,"end":801,"count":1},
178+
{"start":67,"end":87,"count":0},
179+
{"start":254,"end":274,"count":0}]
180+
);
181+
182+
TestCoverage("try/catch/finally statements with early return async",
183+
`
184+
!async function() { // 0000
185+
try { throw 42; } catch (e) { return; } // 0050
186+
nop(); // 0100
187+
}(); // 0150
188+
!async function() { // 0200
189+
try { throw 42; } catch (e) {} // 0250
190+
finally { return; } // 0300
191+
nop(); // 0350
192+
}(); // 0400
193+
`,
194+
[{"start":0,"end":449,"count":1},
195+
{"start":1,"end":151,"count":1},
196+
{"start":91,"end":150,"count":0},
197+
{"start":201,"end":401,"count":1},
198+
{"start":321,"end":400,"count":0}]
199+
);
157200

158201
%DebugToggleBlockCoverage(false);

0 commit comments

Comments
 (0)