Skip to content

Commit 601ed8e

Browse files
bcoeMylesBorins
authored andcommitted
deps: V8: backport 2d5017a0fc02
Original commit message: [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} Refs: v8/v8@2d5017a PR-URL: #34272 Refs: bcoe/c8#229 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent 7416028 commit 601ed8e

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.23',
39+
'v8_embedder_string': '-node.24',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/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
}

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

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

139+
TestCoverage(
140+
"https://crbug.com/v8/10628",
141+
`
142+
async function abc() { // 0000
143+
try { // 0050
144+
return 'abc'; // 0100
145+
} finally { // 0150
146+
console.log('in finally'); // 0200
147+
} // 0250
148+
} // 0300
149+
abc(); // 0350
150+
%PerformMicrotaskCheckpoint(); // 0400
151+
`,
152+
[{"start":0,"end":449,"count":1},
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+
);
200+
139201
%DebugToggleBlockCoverage(false);

0 commit comments

Comments
 (0)