Skip to content

Commit c78788a

Browse files
committed
deps: v8, backport 2d08967
Original commit message: [coverage] Extend SourceRangeAstVisitor for throw statements The SourceRangeAstVisitor has custom logic for blocks ending with a statement that has a continuation range. In these cases, the trailing continuation is removed which makes the reported coverage ranges a bit nicer. throw Error('foo') consists of an ExpressionStatement, with a Throw expression stored within the statement. The source range itself is stored with the Throw, not the statement. We now properly extract the correct AST node for trailing throw statements. [email protected], [email protected], [email protected] Bug: v8:8691 Change-Id: Ibcbab79fbe54719a8993045040349c863b139011 Reviewed-on: https://chromium-review.googlesource.com/c/1480632 Commit-Queue: Georg Neis <[email protected]> Reviewed-by: Georg Neis <[email protected]> Reviewed-by: Jakob Gruber <[email protected]> Cr-Commit-Position: refs/heads/master@{#59936} Refs: v8/v8@2d08967 PR-URL: #26413 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d4fdec6 commit c78788a

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

deps/v8/AUTHORS

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Andrew Paprocki <[email protected]>
5050
Andrei Kashcha <[email protected]>
5151
Anna Henningsen <[email protected]>
5252
Bangfu Tao <[email protected]>
53-
Ben Coe <ben@npmjs.com>
53+
Ben Coe <bencoe@gmail.com>
5454
Ben Newman <[email protected]>
5555
Ben Noordhuis <[email protected]>
5656
Benjamin Tan <[email protected]>

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,18 @@ void SourceRangeAstVisitor::MaybeRemoveLastContinuationRange(
5656
if (statements == nullptr || statements->is_empty()) return;
5757

5858
Statement* last_statement = statements->last();
59-
AstNodeSourceRanges* last_range = source_range_map_->Find(last_statement);
59+
AstNodeSourceRanges* last_range = nullptr;
60+
61+
if (last_statement->IsExpressionStatement() &&
62+
last_statement->AsExpressionStatement()->expression()->IsThrow()) {
63+
// For ThrowStatement, source range is tied to Throw expression not
64+
// ExpressionStatement.
65+
last_range = source_range_map_->Find(
66+
last_statement->AsExpressionStatement()->expression());
67+
} else {
68+
last_range = source_range_map_->Find(last_statement);
69+
}
70+
6071
if (last_range == nullptr) return;
6172

6273
if (last_range->HasRange(SourceRangeKind::kContinuation)) {

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

+44-7
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,11 @@ TestCoverage(
353353
[{"start":0,"end":849,"count":1},
354354
{"start":1,"end":801,"count":1},
355355
{"start":67,"end":87,"count":0},
356-
{"start":219,"end":222,"count":0},
356+
{"start":221,"end":222,"count":0},
357357
{"start":254,"end":274,"count":0},
358-
{"start":369,"end":372,"count":0},
358+
{"start":371,"end":372,"count":0},
359359
{"start":403,"end":404,"count":0},
360-
{"start":513,"end":554,"count":0}]
360+
{"start":553,"end":554,"count":0}]
361361
);
362362

363363
TestCoverage("try/catch/finally statements with early return",
@@ -374,10 +374,10 @@ TestCoverage("try/catch/finally statements with early return",
374374
`,
375375
[{"start":0,"end":449,"count":1},
376376
{"start":1,"end":151,"count":1},
377-
{"start":67,"end":70,"count":0},
377+
{"start":69,"end":70,"count":0},
378378
{"start":91,"end":150,"count":0},
379379
{"start":201,"end":401,"count":1},
380-
{"start":267,"end":270,"count":0},
380+
{"start":269,"end":270,"count":0},
381381
{"start":321,"end":400,"count":0}]
382382
);
383383

@@ -409,15 +409,15 @@ TestCoverage(
409409
`,
410410
[{"start":0,"end":1099,"count":1},
411411
{"start":1,"end":151,"count":1},
412-
{"start":67,"end":70,"count":0},
412+
{"start":69,"end":70,"count":0},
413413
{"start":91,"end":150,"count":0},
414414
{"start":201,"end":351,"count":1},
415415
{"start":286,"end":350,"count":0},
416416
{"start":401,"end":701,"count":1},
417417
{"start":603,"end":700,"count":0},
418418
{"start":561,"end":568,"count":0}, // TODO(jgruber): Sorting.
419419
{"start":751,"end":1051,"count":1},
420-
{"start":817,"end":820,"count":0},
420+
{"start":819,"end":820,"count":0},
421421
{"start":861,"end":1050,"count":0}]
422422
);
423423

@@ -1004,4 +1004,41 @@ c(true); d(true); // 1650
10041004
{"start":1403,"end":1503,"count":0}]
10051005
);
10061006

1007+
TestCoverage(
1008+
"https://crbug.com/927464",
1009+
`
1010+
!function f() { // 0000
1011+
function unused() { nop(); } // 0050
1012+
nop(); // 0100
1013+
}(); // 0150
1014+
`,
1015+
[{"start":0,"end":199,"count":1},
1016+
{"start":1,"end":151,"count":1},
1017+
{"start":52,"end":80,"count":0}]
1018+
);
1019+
1020+
TestCoverage(
1021+
"https://crbug.com/v8/8691",
1022+
`
1023+
function f(shouldThrow) { // 0000
1024+
if (shouldThrow) { // 0050
1025+
throw Error('threw') // 0100
1026+
} // 0150
1027+
} // 0200
1028+
try { // 0250
1029+
f(true) // 0300
1030+
} catch (err) { // 0350
1031+
// 0400
1032+
} // 0450
1033+
try { // 0500
1034+
f(false) // 0550
1035+
} catch (err) {} // 0600
1036+
`,
1037+
[{"start":0,"end":649,"count":1},
1038+
{"start":351,"end":352,"count":0},
1039+
{"start":602,"end":616,"count":0},
1040+
{"start":0,"end":201,"count":2},
1041+
{"start":69,"end":153,"count":1}]
1042+
);
1043+
10071044
%DebugToggleBlockCoverage(false);

0 commit comments

Comments
 (0)