2018-09-05 19:34:25 +00:00
|
|
|
// 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.
|
|
|
|
|
2018-12-12 12:46:44 +00:00
|
|
|
// Flags: --allow-natives-syntax --no-always-opt --harmony-public-fields
|
|
|
|
// Flags: --harmony-static-fields --no-stress-flush-bytecode
|
2018-09-05 19:34:25 +00:00
|
|
|
// Files: test/mjsunit/code-coverage-utils.js
|
|
|
|
|
|
|
|
%DebugToggleBlockCoverage(true);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"class with no fields",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
}; // 050
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":99,"count":1}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"class that's not created",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
x = function() { } // 050
|
|
|
|
}; // 100
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":149,"count":1},
|
|
|
|
{"start":52,"end":70,"count":0}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"class with field thats not called",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
x = function() { } // 050
|
|
|
|
}; // 100
|
|
|
|
let x = new X(); // 150
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":199,"count":1},
|
|
|
|
{"start":52,"end":70,"count":1},
|
|
|
|
{"start":56,"end":70,"count":0}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"class field",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
x = function() { } // 050
|
|
|
|
}; // 100
|
|
|
|
let x = new X(); // 150
|
|
|
|
x.x(); // 200
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":249,"count":1},
|
|
|
|
{"start":52,"end":70,"count":1},
|
|
|
|
{"start":56,"end":70,"count":1}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"non contiguous class field",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
x = function() { } // 050
|
|
|
|
foo() { } // 100
|
|
|
|
y = function() {} // 150
|
|
|
|
}; // 200
|
|
|
|
let x = new X(); // 250
|
|
|
|
x.x(); // 300
|
|
|
|
x.y(); // 350
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"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}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"non contiguous class field thats called",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
x = function() { } // 050
|
|
|
|
foo() { } // 100
|
|
|
|
y = function() {} // 150
|
|
|
|
}; // 200
|
|
|
|
let x = new X(); // 250
|
|
|
|
x.x(); // 300
|
|
|
|
x.y(); // 350
|
|
|
|
x.foo(); // 400
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"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}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"class with initializer iife",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
x = (function() { })() // 050
|
|
|
|
}; // 100
|
|
|
|
let x = new X(); // 150
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":199,"count":1},
|
|
|
|
{"start":52,"end":74,"count":1},
|
|
|
|
{"start":57,"end":71,"count":1}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"class with computed field",
|
|
|
|
`
|
|
|
|
function f() {}; // 000
|
|
|
|
class X { // 050
|
|
|
|
[f()] = (function() { })() // 100
|
|
|
|
}; // 150
|
|
|
|
let x = new X(); // 200
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":249,"count":1},
|
|
|
|
{"start":0,"end":15,"count":1},
|
|
|
|
{"start":102,"end":128,"count":1},
|
|
|
|
{"start":111,"end":125,"count":1}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"static class field that's not called",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
static x = function() { } // 050
|
|
|
|
}; // 100
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":149,"count":1},
|
|
|
|
{"start":52,"end":77,"count":1},
|
|
|
|
{"start":63,"end":77,"count":0}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"static class field",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
static x = function() { } // 050
|
|
|
|
}; // 100
|
|
|
|
X.x(); // 150
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":199,"count":1},
|
|
|
|
{"start":52,"end":77,"count":1},
|
|
|
|
{"start":63,"end":77,"count":1}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"static class field with iife",
|
2019-05-16 11:56:18 +00:00
|
|
|
`
|
|
|
|
class X { // 000
|
2018-09-05 19:34:25 +00:00
|
|
|
static x = (function() { })() // 050
|
|
|
|
}; // 100
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":149,"count":1},
|
|
|
|
{"start":52,"end":81,"count":1},
|
|
|
|
{"start":64,"end":78,"count":1}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TestCoverage(
|
|
|
|
"computed static class field",
|
|
|
|
`
|
|
|
|
function f() {} // 000
|
|
|
|
class X { // 050
|
|
|
|
static [f()] = (function() { })() // 100
|
|
|
|
}; // 150
|
|
|
|
`,
|
2019-05-16 11:56:18 +00:00
|
|
|
[{"start":0,"end":199,"count":1},
|
|
|
|
{"start":0,"end":15,"count":1},
|
|
|
|
{"start":102,"end":135,"count":1},
|
|
|
|
{"start":118,"end":132,"count":1}]
|
2018-09-05 19:34:25 +00:00
|
|
|
);
|