v8/test/mjsunit/code-coverage-class-fields.js
Nikolaos Papaspyrou 60dfddf03c [heap][test] Fix code coverage tests for conservative stack scanning
Code coverage tests invoke garbage collection, to test that coverage
data is not reclaimed by the garbage collector and that the native
%DebugTogglePreciseCoverage works as intended. One of them tests that
garbage collection indeed reclaims the coverage data, if the above
native is not used. When conservative stack scanning is used, this may
fail.

This CL fixes the tests, ensuring that a precise garbage collection
will be invoked, without scanning the stack. To achieve this, the
garbage collection is invoked not with %CollectGarbage but by using
--expose-gc and the asynchronous execution mode, which ensures that
it will be invoked from the event loop without a stack.

Bug: v8:13257
Change-Id: Id44ef0d442bfd0a8afda282c3345e5ebeb239356
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3968708
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83851}
2022-10-21 13:09:40 +00:00

180 lines
5.5 KiB
JavaScript

// 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.
// Flags: --allow-natives-syntax --no-always-turbofan --harmony-public-fields
// Flags: --harmony-static-fields --no-stress-flush-code
// Flags: --expose-gc
// Files: test/mjsunit/code-coverage-utils.js
(async function () {
%DebugToggleBlockCoverage(true);
await TestCoverage(
"class with no fields",
`
class X { // 000
}; // 050
`,
[ {"start":0,"end":99,"count":1} ]
);
await TestCoverage(
"class that's not created",
`
class X { // 000
x = function() { } // 050
}; // 100
`,
[ {"start":0,"end":149,"count":1},
{"start":0,"end":101,"count":0} ]
);
await TestCoverage(
"class with field thats not called",
`
class X { // 000
x = function() { } // 050
}; // 100
let x = new X(); // 150
`,
[ {"start":0,"end":199,"count":1},
{"start":0,"end":101,"count":1},
{"start":56,"end":70,"count":0} ]
);
await TestCoverage(
"class field",
`
class X { // 000
x = function() { } // 050
}; // 100
let x = new X(); // 150
x.x(); // 200
`,
[ {"start":0,"end":249,"count":1},
{"start":0,"end":101,"count":1},
{"start":56,"end":70,"count":1} ]
);
await TestCoverage(
"non contiguous class field",
`
class X { // 000
x = function() { } // 050
foo() { } // 100
y = function() {} // 150
}; // 200
let x = new X(); // 250
x.x(); // 300
x.y(); // 350
`,
[ {"start":0,"end":399,"count":1},
{"start":0,"end":201,"count":1},
{"start":56,"end":70,"count":1},
{"start":102,"end":111,"count":0},
{"start":156,"end":169,"count":1} ]
);
await TestCoverage(
"non contiguous class field thats called",
`
class X { // 000
x = function() { } // 050
foo() { } // 100
y = function() {} // 150
}; // 200
let x = new X(); // 250
x.x(); // 300
x.y(); // 350
x.foo(); // 400
`,
[ {"start":0,"end":449,"count":1},
{"start":0,"end":201,"count":1},
{"start":56,"end":70,"count":1},
{"start":102,"end":111,"count":1},
{"start":156,"end":169,"count":1} ]
);
await TestCoverage(
"class with initializer iife",
`
class X { // 000
x = (function() { })() // 050
}; // 100
let x = new X(); // 150
`,
[ {"start":0,"end":199,"count":1},
{"start":0,"end":101,"count":1},
{"start":57,"end":71,"count":1} ]
);
await TestCoverage(
"class with computed field",
`
function f() {}; // 000
class X { // 050
[f()] = (function() { })() // 100
}; // 150
let x = new X(); // 200
`,
[ {"start":0,"end":249,"count":1},
{"start":0,"end":15,"count":1},
{"start":50,"end":151,"count":1},
{"start":111,"end":125,"count":1} ]
);
await TestCoverage(
"static class field that's not called",
`
class X { // 000
static x = function() { } // 050
}; // 100
`,
[ {"start":0,"end":149,"count":1},
{"start":52,"end":77,"count":1},
{"start":63,"end":77,"count":0} ]
);
await TestCoverage(
"static class field",
`
class X { // 000
static x = function() { } // 050
}; // 100
X.x(); // 150
`,
[ {"start":0,"end":199,"count":1},
{"start":52,"end":77,"count":1},
{"start":63,"end":77,"count":1} ]
);
await TestCoverage(
"static class field with iife",
`
class X { // 000
static x = (function() { })() // 050
}; // 100
`,
[ {"start":0,"end":149,"count":1},
{"start":52,"end":81,"count":1},
{"start":64,"end":78,"count":1} ]
);
await TestCoverage(
"computed static class field",
`
function f() {} // 000
class X { // 050
static [f()] = (function() { })() // 100
}; // 150
`,
[ {"start":0,"end":199,"count":1},
{"start":0,"end":15,"count":1},
{"start":102,"end":135,"count":1},
{"start":118,"end":132,"count":1} ]
);
})();