Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 --block-coverage | |
|
Michael Starzinger
2017/06/06 11:49:32
question: Why --no-always-opt here? Do the expecte
jgruber
2017/06/06 14:52:46
--no-always-opt is inherited from the ad-hoc/preci
jgruber
2017/06/06 15:06:33
Brief investigation: The top-level FeedbackVector
| |
| 6 | |
| 7 // Test precise code coverage. | |
| 8 | |
| 9 function GetCoverage(source) { | |
| 10 for (var script of %DebugCollectCoverage()) { | |
| 11 if (script.script.source == source) return script; | |
| 12 } | |
| 13 return undefined; | |
| 14 } | |
| 15 | |
| 16 function TestCoverage(name, source, expectation) { | |
| 17 source = source.trim(); | |
| 18 eval(source); | |
| 19 %CollectGarbage("collect dead objects"); | |
| 20 var coverage = GetCoverage(source); | |
| 21 var result = JSON.stringify(coverage); | |
| 22 print(result); | |
| 23 assertEquals(JSON.stringify(expectation), result, name + " failed"); | |
| 24 } | |
| 25 | |
| 26 %DebugToggleBlockCoverage(true); | |
| 27 | |
| 28 TestCoverage( | |
| 29 "call an IIFE", | |
| 30 ` | |
| 31 (function f() {})(); | |
| 32 `, | |
| 33 [{"start":0,"end":20,"count":1},{"start":1,"end":16,"count":1}] | |
|
jgruber
2017/06/06 14:52:46
With --always-opt, the result is [{"start":1,"end"
| |
| 34 ); | |
| 35 | |
| 36 TestCoverage( | |
| 37 "call locally allocated function", | |
| 38 ` | |
| 39 for (var i = 0; i < 10; i++) { | |
| 40 let f = () => 1; | |
| 41 i += f(); | |
| 42 } | |
| 43 `, | |
| 44 [{"start":0,"end":63,"count":1},{"start":41,"end":48,"count":5}] | |
| 45 ); | |
| 46 | |
| 47 TestCoverage( | |
| 48 "if statements", | |
| 49 ` | |
| 50 function g() {} | |
| 51 function f(x) { | |
| 52 if (x == 42) { | |
| 53 if (x == 43) g(); else g(); | |
| 54 } | |
| 55 if (x == 42) { g(); } else { g(); } | |
| 56 if (x == 42) g(); else g(); | |
| 57 if (false) g(); else g(); | |
| 58 if (false) g(); | |
| 59 if (true) g(); else g(); | |
| 60 if (true) g(); | |
| 61 } | |
| 62 f(42); | |
| 63 f(43); | |
| 64 `, | |
| 65 [{"start":0,"end":258,"count":1}, | |
| 66 {"start":0,"end":15,"count":11}, | |
| 67 {"start":16,"end":244,"count":2}, | |
| 68 {"start":45,"end":83,"count":1}, | |
| 69 {"start":64,"end":69,"count":0}, | |
| 70 {"start":71,"end":79,"count":1}, | |
| 71 {"start":98,"end":107,"count":1}, | |
| 72 {"start":109,"end":121,"count":1}, | |
| 73 {"start":136,"end":141,"count":1}, | |
| 74 {"start":143,"end":151,"count":1}, | |
| 75 {"start":164,"end":169,"count":0}, | |
| 76 {"start":171,"end":179,"count":2}, | |
| 77 {"start":192,"end":197,"count":0}, | |
| 78 {"start":209,"end":214,"count":2}, | |
| 79 {"start":216,"end":224,"count":0}, | |
| 80 {"start":236,"end":241,"count":2}] | |
| 81 ); | |
| 82 | |
| 83 %DebugToggleBlockCoverage(false); | |
| OLD | NEW |