Commit 76f6495c authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[parser] Force func decl allocation for code coverage

Preserve coverage for unused functions by force marking them used when
code coverage is enabled.

Bug: chromium:927464
Change-Id: Ia973467d06f7268f4e98cc76d0bb98cc591e979c
Reviewed-on: https://chromium-review.googlesource.com/c/1454717
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59373}
parent fb898302
......@@ -1444,6 +1444,11 @@ Statement* Parser::DeclareFunction(const AstRawString* variable_name,
bool was_added;
Declare(declaration, variable_name, kind, mode, kCreatedInitialized, scope(),
&was_added, beg_pos);
if (source_range_map_ != nullptr) {
// Force the function to be allocated when collecting source coverage, so
// that even dead functions get source coverage data.
declaration->var()->set_is_used();
}
if (names) names->Add(variable_name, zone());
if (kind == SLOPPY_BLOCK_FUNCTION_VARIABLE) {
Token::Value init = loop_nesting_depth() > 0 ? Token::ASSIGN : Token::INIT;
......
......@@ -970,6 +970,17 @@ Running test: testPreciseCountCoveragePartial
}
]
}
[6] : {
functionName : nested_4
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 201
startOffset : 179
}
]
}
]
scriptId : <scriptId>
url : testPreciseCountCoveragePartial
......
......@@ -1004,4 +1004,17 @@ c(true); d(true); // 1650
{"start":1403,"end":1503,"count":0}]
);
TestCoverage(
"https://crbug.com/927464",
`
!function f() { // 0000
function unused() { nop(); } // 0100
nop(); // 0150
}(); // 0200
`,
[{"start":0,"end":199,"count":1},
{"start":1,"end":151,"count":1},
{"start":52,"end":80,"count":0}]
);
%DebugToggleBlockCoverage(false);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment