0dfd9ea512
In the presence of default arguments, the body of the function gets wrapped into another block. This caused our trailing-range-after-return optimization to not apply, because the wrapper block had no source range assigned. This CL correctly assignes a source range to that block, which allows already present code to handle it correctly. Note that this is not a real coverage bug; we've just been reporting whitespace as uncovered. We're fixing it for consistency. Originally reported on github.com/bcoe/c8/issues/66 Bug: v8:9952 Change-Id: Iab3905f558eb99126e0dad8072d03d0a312fdcd3 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1903430 Commit-Queue: Sigurd Schneider <sigurds@chromium.org> Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#64836}
140 lines
4.7 KiB
JavaScript
140 lines
4.7 KiB
JavaScript
// Copyright 2019 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --allow-natives-syntax --no-always-opt --no-stress-flush-bytecode
|
|
// Flags: --no-stress-incremental-marking
|
|
// Files: test/mjsunit/code-coverage-utils.js
|
|
|
|
%DebugToggleBlockCoverage(true);
|
|
|
|
TestCoverage(
|
|
"await expressions",
|
|
`
|
|
async function f() { // 0000
|
|
await 42; // 0050
|
|
await 42; // 0100
|
|
}; // 0150
|
|
f(); // 0200
|
|
%PerformMicrotaskCheckpoint(); // 0250
|
|
`,
|
|
[{"start":0,"end":299,"count":1},
|
|
{"start":0,"end":151,"count":1}]
|
|
);
|
|
|
|
TestCoverage(
|
|
"for-await-of statements",
|
|
`
|
|
!async function() { // 0000
|
|
for await (var x of [0,1,2,3]) { // 0050
|
|
nop(); // 0100
|
|
} // 0150
|
|
}(); // 0200
|
|
%PerformMicrotaskCheckpoint(); // 0250
|
|
`,
|
|
[{"start":0,"end":299,"count":1},
|
|
{"start":1,"end":201,"count":1},
|
|
{"start":83,"end":153,"count":4}]
|
|
);
|
|
|
|
TestCoverage(
|
|
"https://crbug.com/981313",
|
|
`
|
|
class Foo { // 0000
|
|
async timeout() { // 0000
|
|
return new Promise( // 0100
|
|
(r) => setTimeout(r, 10)); // 0000
|
|
} // 0200
|
|
} // 0000
|
|
new Foo().timeout(); // 0300
|
|
`,
|
|
[ {"start":0, "end":349, "count":1},
|
|
{"start":52, "end":203, "count":1},
|
|
{"start":158,"end":182, "count":1}]);
|
|
|
|
TestCoverage(
|
|
"test async generator coverage",
|
|
`
|
|
class Foo { // 0000
|
|
async *timeout() { // 0000
|
|
return new Promise( // 0100
|
|
(r) => setTimeout(r, 10)); // 0000
|
|
} // 0200
|
|
} // 0000
|
|
new Foo().timeout(); // 0300
|
|
`,
|
|
[ {"start":0, "end":349, "count":1},
|
|
{"start":52, "end":203, "count":1},
|
|
{"start":158,"end":182, "count":0}]);
|
|
|
|
TestCoverage(
|
|
"test async generator coverage with next call",
|
|
`
|
|
class Foo { // 0000
|
|
async *timeout() { // 0000
|
|
return new Promise( // 0100
|
|
(r) => setTimeout(r, 10)); // 0000
|
|
} // 0200
|
|
} // 0000
|
|
new Foo().timeout().next(); // 0300
|
|
`,
|
|
[ {"start":0, "end":349, "count":1},
|
|
{"start":52, "end":203, "count":1},
|
|
{"start":158,"end":182, "count":1}]);
|
|
|
|
TestCoverage(
|
|
"test two consecutive returns",
|
|
`
|
|
class Foo { // 0000
|
|
timeout() { // 0000
|
|
return new Promise( // 0100
|
|
(r) => setTimeout(r, 10)); // 0000
|
|
return new Promise( // 0200
|
|
(r) => setTimeout(r, 10)); // 0000
|
|
} // 0300
|
|
} // 0000
|
|
new Foo().timeout(); // 0400
|
|
`,
|
|
[ {"start":0,"end":449,"count":1},
|
|
{"start":52,"end":303,"count":1},
|
|
{"start":184,"end":302,"count":0},
|
|
{"start":158,"end":182,"count":1}] );
|
|
|
|
|
|
TestCoverage(
|
|
"test async generator with two consecutive returns",
|
|
`
|
|
class Foo { // 0000
|
|
async *timeout() { // 0000
|
|
return new Promise( // 0100
|
|
(r) => setTimeout(r, 10)); // 0000
|
|
return new Promise( // 0200
|
|
(r) => setTimeout(r, 10)); // 0000
|
|
} // 0300
|
|
} // 0000
|
|
new Foo().timeout().next(); // 0400
|
|
`,
|
|
[ {"start":0,"end":449,"count":1},
|
|
{"start":52,"end":303,"count":1},
|
|
{"start":184,"end":302,"count":0},
|
|
{"start":158,"end":182,"count":1}] );
|
|
|
|
TestCoverage(
|
|
"https://crbug.com/v8/9952",
|
|
`
|
|
async function test(foo) { // 0000
|
|
return {bar}; // 0050
|
|
// 0100
|
|
function bar() { // 0150
|
|
console.log("test"); // 0200
|
|
} // 0250
|
|
} // 0300
|
|
test().then(r => r.bar()); // 0350
|
|
%PerformMicrotaskCheckpoint(); // 0400`,
|
|
[{"start":0,"end":449,"count":1},
|
|
{"start":0,"end":301,"count":1},
|
|
{"start":152,"end":253,"count":1},
|
|
{"start":362,"end":374,"count":1}]);
|
|
|
|
%DebugToggleBlockCoverage(false);
|