Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 23271dd

Browse filesBrowse files
Benjamin CoeMylesBorins
authored andcommitted
deps: V8: cherry-pick deac757
Original commit message: [debugger] Fix code coverage for break/return inside switch-case Case statements have a list of statements associated with them, but are not blocks, and were hence not fixed-up correctly for code coverage. This CL also applies the fix-up to the "body" of case statements, in this way removing ranges reported as uncovered between the final break/return in a case and the next case (or end of function). Drive-by: Add optional pretty printing to code coverage test results. Change-Id: I5f4002d4e17b7253ed516d99f7c389ab2264be10 Bug: v8:9705 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1798426 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Sigurd Schneider <sigurds@chromium.org> Cr-Commit-Position: refs/heads/master@{#63719} Refs: v8/v8@deac757 Backport-PR-URL: #30109 PR-URL: #29626 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 6ae7d30 commit 23271dd
Copy full SHA for 23271dd

File tree

Expand file treeCollapse file tree

5 files changed

+81
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+81
-12
lines changed
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.9',
41+
'v8_embedder_string': '-node.10',
4242

4343
##### V8 defaults for Node.js #####
4444

Collapse file

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

Copy file name to clipboardExpand all lines: deps/v8/src/ast/source-range-ast-visitor.cc
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ void SourceRangeAstVisitor::VisitBlock(Block* stmt) {
2525
}
2626
}
2727

28+
void SourceRangeAstVisitor::VisitSwitchStatement(SwitchStatement* stmt) {
29+
AstTraversalVisitor::VisitSwitchStatement(stmt);
30+
ZonePtrList<CaseClause>* clauses = stmt->cases();
31+
for (CaseClause* clause : *clauses) {
32+
MaybeRemoveLastContinuationRange(clause->statements());
33+
}
34+
}
35+
2836
void SourceRangeAstVisitor::VisitFunctionLiteral(FunctionLiteral* expr) {
2937
AstTraversalVisitor::VisitFunctionLiteral(expr);
3038
ZonePtrList<Statement>* stmts = expr->body();
Collapse file

‎deps/v8/src/ast/source-range-ast-visitor.h‎

Copy file name to clipboardExpand all lines: deps/v8/src/ast/source-range-ast-visitor.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SourceRangeAstVisitor final
3434
friend class AstTraversalVisitor<SourceRangeAstVisitor>;
3535

3636
void VisitBlock(Block* stmt);
37+
void VisitSwitchStatement(SwitchStatement* stmt);
3738
void VisitFunctionLiteral(FunctionLiteral* expr);
3839
bool VisitNode(AstNode* node);
3940

Collapse file

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

Copy file name to clipboardExpand all lines: deps/v8/test/mjsunit/code-coverage-block.js
+49-4Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ TestCoverage(
434434
`,
435435
[{"start":0,"end":399,"count":1},
436436
{"start":1,"end":351,"count":1},
437-
{"start":154,"end":204,"count":0},
438-
{"start":226,"end":350,"count":0}]
437+
{"start":154,"end":176,"count":0},
438+
{"start":254,"end":276,"count":0}]
439439
);
440440

441441
TestCoverage(
@@ -464,8 +464,8 @@ TestCoverage(
464464
`,
465465
[{"start":0,"end":999,"count":1},
466466
{"start":1,"end":951,"count":1},
467-
{"start":152,"end":202,"count":0},
468-
{"start":285,"end":353,"count":0}]
467+
{"start":152,"end":168,"count":0},
468+
{"start":287,"end":310,"count":0}]
469469
);
470470

471471
TestCoverage(
@@ -1052,4 +1052,49 @@ try { // 0500
10521052
{"start":69,"end":153,"count":1}]
10531053
);
10541054

1055+
TestCoverage(
1056+
"https://crbug.com/v8/9705",
1057+
`
1058+
function f(x) { // 0000
1059+
switch (x) { // 0050
1060+
case 40: nop(); // 0100
1061+
case 41: nop(); return 1; // 0150
1062+
case 42: nop(); break; // 0200
1063+
} // 0250
1064+
return 3; // 0300
1065+
}; // 0350
1066+
f(40); // 0400
1067+
f(41); // 0450
1068+
f(42); // 0500
1069+
f(43); // 0550
1070+
`,
1071+
[{"start":0,"end":599,"count":1},
1072+
{"start":0,"end":351,"count":4},
1073+
{"start":104,"end":119,"count":1},
1074+
{"start":154,"end":179,"count":2},
1075+
{"start":204,"end":226,"count":1},
1076+
{"start":253,"end":350,"count":2}]
1077+
);
1078+
1079+
TestCoverage(
1080+
"https://crbug.com/v8/9705",
1081+
`
1082+
function f(x) { // 0000
1083+
switch (x) { // 0050
1084+
case 40: nop(); // 0100
1085+
case 41: nop(); return 1; // 0150
1086+
case 42: nop(); break; // 0200
1087+
} // 0250
1088+
return 3; // 0300
1089+
}; // 0350
1090+
f(42); // 0400
1091+
f(43); // 0450
1092+
`,
1093+
[{"start":0,"end":499,"count":1},
1094+
{"start":0,"end":351,"count":2},
1095+
{"start":104,"end":119,"count":0},
1096+
{"start":154,"end":179,"count":0},
1097+
{"start":204,"end":226,"count":1}]
1098+
);
1099+
10551100
%DebugToggleBlockCoverage(false);
Collapse file

‎deps/v8/test/mjsunit/code-coverage-utils.js‎

Copy file name to clipboardExpand all lines: deps/v8/test/mjsunit/code-coverage-utils.js
+22-7Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,40 @@ let gen;
1818
return undefined;
1919
};
2020

21-
function TestCoverageInternal(name, source, expectation, collect_garbage) {
21+
function TestCoverageInternal(
22+
name, source, expectation, collect_garbage, prettyPrintResults) {
2223
source = source.trim();
2324
eval(source);
2425
if (collect_garbage) %CollectGarbage("collect dead objects");
2526
var covfefe = GetCoverage(source);
2627
var stringified_result = JSON.stringify(covfefe);
2728
var stringified_expectation = JSON.stringify(expectation);
28-
if (stringified_result != stringified_expectation) {
29-
print(stringified_result.replace(/[}],[{]/g, "},\n {"));
29+
const mismatch = stringified_result != stringified_expectation;
30+
if (mismatch) {
31+
console.log(stringified_result.replace(/[}],[{]/g, "},\n {"));
32+
}
33+
if (prettyPrintResults) {
34+
console.log("=== Coverage Expectation ===")
35+
for (const {start,end,count} of expectation) {
36+
console.log(`Range [${start}, ${end}) (count: ${count})`);
37+
console.log(source.substring(start, end));
38+
}
39+
console.log("=== Coverage Results ===")
40+
for (const {start,end,count} of covfefe) {
41+
console.log(`Range [${start}, ${end}) (count: ${count})`);
42+
console.log(source.substring(start, end));
43+
}
44+
console.log("========================")
3045
}
3146
assertEquals(stringified_expectation, stringified_result, name + " failed");
3247
};
3348

34-
TestCoverage = function(name, source, expectation) {
35-
TestCoverageInternal(name, source, expectation, true);
49+
TestCoverage = function(name, source, expectation, prettyPrintResults) {
50+
TestCoverageInternal(name, source, expectation, true, prettyPrintResults);
3651
};
3752

38-
TestCoverageNoGC = function(name, source, expectation) {
39-
TestCoverageInternal(name, source, expectation, false);
53+
TestCoverageNoGC = function(name, source, expectation, prettyPrintResults) {
54+
TestCoverageInternal(name, source, expectation, false, prettyPrintResults);
4055
};
4156

4257
nop = function() {};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.