code-coverage-class-fields.js 4.94 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 6
// Flags: --allow-natives-syntax --no-always-opt --harmony-public-fields
// Flags: --harmony-static-fields --no-stress-flush-bytecode
7 8 9 10 11 12
// Files: test/mjsunit/code-coverage-utils.js

%DebugToggleBlockCoverage(true);

TestCoverage(
"class with no fields",
13 14
`
class X {                                  // 000
15 16
};                                         // 050
`,
17
[{"start":0,"end":99,"count":1}]
18 19 20 21
);

TestCoverage(
"class that's not created",
22 23
`
class X {                                  // 000
24 25 26
  x = function() { }                       // 050
};                                         // 100
`,
27 28
[{"start":0,"end":149,"count":1},
 {"start":52,"end":70,"count":0}]
29 30 31 32
);

TestCoverage(
"class with field thats not called",
33 34
`
class X {                                  // 000
35 36 37 38
  x = function() { }                       // 050
};                                         // 100
let x = new X();                           // 150
`,
39 40 41
[{"start":0,"end":199,"count":1},
 {"start":52,"end":70,"count":1},
 {"start":56,"end":70,"count":0}]
42 43 44 45
);

TestCoverage(
"class field",
46 47
`
class X {                                  // 000
48 49 50 51 52
  x = function() { }                       // 050
};                                         // 100
let x = new X();                           // 150
x.x();                                     // 200
`,
53 54 55
[{"start":0,"end":249,"count":1},
 {"start":52,"end":70,"count":1},
 {"start":56,"end":70,"count":1}]
56 57 58 59
);

TestCoverage(
"non contiguous class field",
60 61
`
class X {                                  // 000
62 63 64 65 66 67 68 69
  x = function() { }                       // 050
  foo() { }                                // 100
  y = function() {}                        // 150
};                                         // 200
let x = new X();                           // 250
x.x();                                     // 300
x.y();                                     // 350
`,
70 71 72 73 74
[{"start":0,"end":399,"count":1},
 {"start":52,"end":169,"count":1},
 {"start":56,"end":70,"count":1},
 {"start":102,"end":111,"count":0},
 {"start":156,"end":169,"count":1}]
75 76 77 78
);

TestCoverage(
"non contiguous class field thats called",
79 80
`
class X {                                  // 000
81 82 83 84 85 86 87 88 89
  x = function() { }                       // 050
  foo() { }                                // 100
  y = function() {}                        // 150
};                                         // 200
let x = new X();                           // 250
x.x();                                     // 300
x.y();                                     // 350
x.foo();                                   // 400
`,
90 91 92 93 94
[{"start":0,"end":449,"count":1},
 {"start":52,"end":169,"count":1},
 {"start":56,"end":70,"count":1},
 {"start":102,"end":111,"count":1},
 {"start":156,"end":169,"count":1}]
95 96 97 98
);

TestCoverage(
"class with initializer iife",
99 100
`
class X {                                  // 000
101 102 103 104
  x = (function() { })()                   // 050
};                                         // 100
let x = new X();                           // 150
`,
105 106 107
[{"start":0,"end":199,"count":1},
 {"start":52,"end":74,"count":1},
 {"start":57,"end":71,"count":1}]
108 109 110 111 112 113 114 115 116 117 118
);

TestCoverage(
"class with computed field",
`
function f() {};                           // 000
class X {                                  // 050
  [f()] = (function() { })()               // 100
};                                         // 150
let x = new X();                           // 200
`,
119 120 121 122
[{"start":0,"end":249,"count":1},
 {"start":0,"end":15,"count":1},
 {"start":102,"end":128,"count":1},
 {"start":111,"end":125,"count":1}]
123 124 125 126
);

TestCoverage(
"static class field that's not called",
127 128
`
class X {                                  // 000
129 130 131
  static x = function() { }                // 050
};                                         // 100
`,
132 133 134
[{"start":0,"end":149,"count":1},
 {"start":52,"end":77,"count":1},
 {"start":63,"end":77,"count":0}]
135 136 137 138
);

TestCoverage(
"static class field",
139 140
`
class X {                                  // 000
141 142 143 144
  static x = function() { }                // 050
};                                         // 100
X.x();                                     // 150
`,
145 146 147
[{"start":0,"end":199,"count":1},
 {"start":52,"end":77,"count":1},
 {"start":63,"end":77,"count":1}]
148 149 150 151
);

TestCoverage(
"static class field with iife",
152 153
`
class X {                                  // 000
154 155 156
  static x = (function() { })()            // 050
};                                         // 100
`,
157 158 159
[{"start":0,"end":149,"count":1},
 {"start":52,"end":81,"count":1},
 {"start":64,"end":78,"count":1}]
160 161 162 163 164 165 166 167 168 169
);

TestCoverage(
"computed static class field",
`
function f() {}                            // 000
class X {                                  // 050
  static [f()] = (function() { })()        // 100
};                                         // 150
`,
170 171 172 173
[{"start":0,"end":199,"count":1},
 {"start":0,"end":15,"count":1},
 {"start":102,"end":135,"count":1},
 {"start":118,"end":132,"count":1}]
174
);