Skip to content

Commit

Permalink
deps: V8: backport 2d5017a0fc02
Browse files Browse the repository at this point in the history
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 <bencoe@google.com>
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Reviewed-by: Jakob Gruber <jgruber@chromium.org>
    Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#68719}

Refs: v8/v8@2d5017a

PR-URL: #34272
Refs: bcoe/c8#229
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
bcoe authored and MylesBorins committed Jul 16, 2020
1 parent 7416028 commit 601ed8e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Expand Up @@ -36,7 +36,7 @@

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

##### V8 defaults for Node.js #####

Expand Down
14 changes: 8 additions & 6 deletions deps/v8/src/ast/source-range-ast-visitor.cc
Expand Up @@ -99,11 +99,13 @@ void SourceRangeAstVisitor::MaybeRemoveLastContinuationRange(
}

namespace {
Statement* FindLastNonSyntheticReturn(ZonePtrList<Statement>* statements) {
Statement* FindLastNonSyntheticStatement(ZonePtrList<Statement>* statements) {
for (int i = statements->length() - 1; i >= 0; --i) {
Statement* stmt = statements->at(i);
if (!stmt->IsReturnStatement()) break;
if (stmt->AsReturnStatement()->is_synthetic_async_return()) continue;
if (stmt->IsReturnStatement() &&
stmt->AsReturnStatement()->is_synthetic_async_return()) {
continue;
}
return stmt;
}
return nullptr;
Expand All @@ -114,11 +116,11 @@ void SourceRangeAstVisitor::MaybeRemoveContinuationRangeOfAsyncReturn(
TryCatchStatement* try_catch_stmt) {
// Detect try-catch inserted by NewTryCatchStatementForAsyncAwait in the
// parser (issued for async functions, including async generators), and
// remove the continuation ranges of return statements corresponding to
// returns at function end in the untransformed source.
// remove the continuation range of the last statement, such that the
// range of the enclosing function body is used.
if (try_catch_stmt->is_try_catch_for_async()) {
Statement* last_non_synthetic =
FindLastNonSyntheticReturn(try_catch_stmt->try_block()->statements());
FindLastNonSyntheticStatement(try_catch_stmt->try_block()->statements());
if (last_non_synthetic) {
MaybeRemoveContinuationRange(last_non_synthetic);
}
Expand Down
62 changes: 62 additions & 0 deletions deps/v8/test/mjsunit/code-coverage-block-async.js
Expand Up @@ -136,4 +136,66 @@ test().then(r => r.bar()); // 0350
{"start":152,"end":253,"count":1},
{"start":362,"end":374,"count":1}]);

TestCoverage(
"https://crbug.com/v8/10628",
`
async function abc() { // 0000
try { // 0050
return 'abc'; // 0100
} finally { // 0150
console.log('in finally'); // 0200
} // 0250
} // 0300
abc(); // 0350
%PerformMicrotaskCheckpoint(); // 0400
`,
[{"start":0,"end":449,"count":1},
{"start":0,"end":301,"count":1}]);

TestCoverage(
"try/catch/finally statements async",
`
!async function() { // 0000
try { nop(); } catch (e) { nop(); } // 0050
try { nop(); } finally { nop(); } // 0100
try { // 0150
try { throw 42; } catch (e) { nop(); }// 0200
} catch (e) { nop(); } // 0250
try { // 0300
try { throw 42; } finally { nop(); } // 0350
} catch (e) { nop(); } // 0400
try { // 0450
throw 42; // 0500
} catch (e) { // 0550
nop(); // 0600
} finally { // 0650
nop(); // 0700
} // 0750
}(); // 0800
`,
[{"start":0,"end":849,"count":1},
{"start":1,"end":801,"count":1},
{"start":67,"end":87,"count":0},
{"start":254,"end":274,"count":0}]
);

TestCoverage("try/catch/finally statements with early return async",
`
!async function() { // 0000
try { throw 42; } catch (e) { return; } // 0050
nop(); // 0100
}(); // 0150
!async function() { // 0200
try { throw 42; } catch (e) {} // 0250
finally { return; } // 0300
nop(); // 0350
}(); // 0400
`,
[{"start":0,"end":449,"count":1},
{"start":1,"end":151,"count":1},
{"start":91,"end":150,"count":0},
{"start":201,"end":401,"count":1},
{"start":321,"end":400,"count":0}]
);

%DebugToggleBlockCoverage(false);

0 comments on commit 601ed8e

Please sign in to comment.