mirror of https://github.com/nodejs/node.git
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 <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: 2d5017a0fc
PR-URL: https://github.com/nodejs/node/pull/34272
Refs: https://github.com/bcoe/c8/issues/229
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
pull/34294/head
parent
99f0404646
commit
1198aebd2d
|
@ -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.20',
|
||||
'v8_embedder_string': '-node.21',
|
||||
|
||||
##### V8 defaults for Node.js #####
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue