code-coverage-ad-hoc.js 1.51 KB
Newer Older
1 2 3 4
// Copyright 2017 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.

5
// Flags: --allow-natives-syntax --no-always-opt --no-stress-flush-code
jgruber's avatar
jgruber committed
6
// Files: test/mjsunit/code-coverage-utils.js
7 8 9

// Test code coverage without explicitly activating it upfront.

jgruber's avatar
jgruber committed
10
TestCoverageNoGC(
11 12 13 14 15 16
"call simple function twice",
`
function f() {}
f();
f();
`,
17
[{"start":0,"end":25,"count":1},
18
 {"start":0,"end":15,"count":1}]
19 20
);

jgruber's avatar
jgruber committed
21
TestCoverageNoGC(
22 23 24 25 26 27
"call arrow function twice",
`
var f = () => 1;
f();
f();
`,
28
[{"start":0,"end":26,"count":1},
29
 {"start":8,"end":15,"count":1}]
30 31
);

jgruber's avatar
jgruber committed
32
TestCoverageNoGC(
33 34 35 36 37 38 39 40 41 42
"call nested function",
`
function f() {
  function g() {}
  g();
  g();
}
f();
f();
`,
43
[{"start":0,"end":58,"count":1},
44 45
 {"start":0,"end":48,"count":1},
 {"start":17,"end":32,"count":1}]
46 47
);

jgruber's avatar
jgruber committed
48
TestCoverageNoGC(
49 50 51 52 53 54 55 56
"call recursive function",
`
function fib(x) {
  if (x < 2) return 1;
  return fib(x-1) + fib(x-2);
}
fib(5);
`,
57
[{"start":0,"end":80,"count":1},
58
 {"start":0,"end":72,"count":1}]
59
);
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

TestCoverageNoGC(
"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}
 // The unused function is unfortunately not marked as unused in best-effort
 // code coverage, as the information about its source range is discarded
 // entirely.
]
);