2018-10-18 11:30:16 +00:00
|
|
|
// Copyright 2018 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.
|
|
|
|
|
2021-03-07 15:00:51 +00:00
|
|
|
// Flags: --expose-gc --noincremental-marking
|
2021-08-02 15:10:58 +00:00
|
|
|
// Flags: --no-stress-flush-code
|
2018-10-18 11:30:16 +00:00
|
|
|
|
|
|
|
let cleanup0_call_count = 0;
|
2019-01-30 12:06:32 +00:00
|
|
|
let cleanup0_holdings_count = 0;
|
2018-10-18 11:30:16 +00:00
|
|
|
|
|
|
|
let cleanup1_call_count = 0;
|
2019-01-30 12:06:32 +00:00
|
|
|
let cleanup1_holdings_count = 0;
|
2018-10-18 11:30:16 +00:00
|
|
|
|
2020-04-07 22:07:13 +00:00
|
|
|
let cleanup0 = function(holdings) {
|
|
|
|
++cleanup0_holdings_count;
|
2018-10-18 11:30:16 +00:00
|
|
|
++cleanup0_call_count;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:07:13 +00:00
|
|
|
let cleanup1 = function(holdings) {
|
|
|
|
++cleanup1_holdings_count;
|
2018-10-18 11:30:16 +00:00
|
|
|
++cleanup1_call_count;
|
|
|
|
}
|
|
|
|
|
2020-02-25 01:19:48 +00:00
|
|
|
let fg0 = new FinalizationRegistry(cleanup0);
|
|
|
|
let fg1 = new FinalizationRegistry(cleanup1);
|
2018-10-18 11:30:16 +00:00
|
|
|
|
2020-02-25 01:19:48 +00:00
|
|
|
// Register 1 weak reference for each FinalizationRegistry and kill the objects they point to.
|
2018-10-18 11:30:16 +00:00
|
|
|
(function() {
|
|
|
|
// The objects need to be inside a closure so that we can reliably kill them.
|
|
|
|
let objects = [];
|
|
|
|
objects[0] = {};
|
|
|
|
objects[1] = {};
|
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
fg0.register(objects[0], "holdings0-0");
|
|
|
|
fg1.register(objects[1], "holdings1-0");
|
2018-10-18 11:30:16 +00:00
|
|
|
|
|
|
|
// Drop the references to the objects.
|
|
|
|
objects = [];
|
|
|
|
})();
|
|
|
|
|
2020-02-03 17:34:52 +00:00
|
|
|
// Will schedule both fg0 and fg1 for cleanup.
|
|
|
|
gc();
|
|
|
|
|
2018-10-18 11:30:16 +00:00
|
|
|
// Before the cleanup task has a chance to run, do the same thing again, so both
|
2020-02-25 01:19:48 +00:00
|
|
|
// FinalizationRegistries are (again) scheduled for cleanup. This has to be a IIFE function
|
2018-10-18 11:30:16 +00:00
|
|
|
// (so that we can reliably kill the objects) so we cannot use the same function
|
|
|
|
// as before.
|
|
|
|
(function() {
|
|
|
|
let objects = [];
|
|
|
|
objects[0] = {};
|
|
|
|
objects[1] = {};
|
2019-01-30 12:06:32 +00:00
|
|
|
fg0.register(objects[0], "holdings0-1");
|
|
|
|
fg1.register(objects[1], "holdings1-1");
|
2018-10-18 11:30:16 +00:00
|
|
|
objects = [];
|
|
|
|
})();
|
|
|
|
|
2020-02-03 17:34:52 +00:00
|
|
|
gc();
|
|
|
|
|
2018-10-18 11:30:16 +00:00
|
|
|
let timeout_func = function() {
|
2020-04-07 22:07:13 +00:00
|
|
|
assertEquals(2, cleanup0_call_count);
|
2019-01-30 12:06:32 +00:00
|
|
|
assertEquals(2, cleanup0_holdings_count);
|
2020-04-07 22:07:13 +00:00
|
|
|
assertEquals(2, cleanup1_call_count);
|
2019-01-30 12:06:32 +00:00
|
|
|
assertEquals(2, cleanup1_holdings_count);
|
2018-10-18 11:30:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:07:13 +00:00
|
|
|
// Give the cleanup task a chance to run.
|
2018-10-18 11:30:16 +00:00
|
|
|
setTimeout(timeout_func, 0);
|