|
| 1 | +// Copyright 2018 the V8 project authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +// Flags: --allow-natives-syntax --no-always-opt |
| 6 | +// Files: test/mjsunit/code-coverage-utils.js |
| 7 | + |
| 8 | +%DebugToggleBlockCoverage(true); |
| 9 | + |
| 10 | +TestCoverage( |
| 11 | +"Repro for the bug", |
| 12 | +` |
| 13 | +function lib (n) { // 0000 |
| 14 | + if (n >= 0) { // 0050 |
| 15 | + if (n < 0) { // 0100 |
| 16 | + return; // 0150 |
| 17 | + } // 0200 |
| 18 | + } else if (foo()) { // 0250 |
| 19 | + } // 0300 |
| 20 | +} // 0350 |
| 21 | +function foo () { // 0400 |
| 22 | + console.log('foo') // 0450 |
| 23 | + return false // 0500 |
| 24 | +} // 0550 |
| 25 | +lib(1) // 0600 |
| 26 | +`, |
| 27 | +[{"start":0,"end":649,"count":1}, |
| 28 | +{"start":0,"end":351,"count":1}, |
| 29 | +{"start":115,"end":205,"count":0}, |
| 30 | +{"start":253,"end":303,"count":0}, |
| 31 | +{"start":400,"end":551,"count":0}] |
| 32 | +); |
| 33 | + |
| 34 | +TestCoverage( |
| 35 | +"Variant with omitted brackets", |
| 36 | +` |
| 37 | +function lib (n) { // 0000 |
| 38 | + if (n >= 0) { // 0050 |
| 39 | + if (n < 0) // 0100 |
| 40 | + return; // 0150 |
| 41 | + } // 0200 |
| 42 | + else if (foo()); // 0250 |
| 43 | +} // 0300 |
| 44 | +function foo () { // 0350 |
| 45 | + console.log('foo') // 0400 |
| 46 | + return false // 0450 |
| 47 | +} // 0500 |
| 48 | +lib(1) // 0550 |
| 49 | +`, |
| 50 | +[{"start":0,"end":599,"count":1}, |
| 51 | +{"start":0,"end":301,"count":1}, |
| 52 | +{"start":156,"end":163,"count":0}, |
| 53 | +{"start":203,"end":268,"count":0}, |
| 54 | +{"start":350,"end":501,"count":0}] |
| 55 | +); |
| 56 | + |
| 57 | +%DebugToggleBlockCoverage(false); |
0 commit comments