PR-URL: https://github.com/nodejs/node/pull/47251 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
// Copyright 2021 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: --expose-gc --noincremental-marking --no-concurrent-inlining
|
|
|
|
(async function () {
|
|
|
|
let cleanup_called = false;
|
|
function cleanup(holdings) {
|
|
cleanup_called = true;
|
|
};
|
|
|
|
let cleanup_called_2 = false;
|
|
function cleanup2(holdings) {
|
|
cleanup_called_2 = true;
|
|
};
|
|
|
|
const fg = new FinalizationRegistry(cleanup);
|
|
|
|
let task_1_gc = (async function () {
|
|
const fg2 = new FinalizationRegistry(cleanup2);
|
|
|
|
(function () {
|
|
fg.register({}, "holdings1");
|
|
fg2.register({}, "holdings2");
|
|
})();
|
|
|
|
// Schedule fg and fg2 for cleanup.
|
|
await gc({ type: 'major', execution: 'async' });
|
|
assertFalse(cleanup_called);
|
|
assertFalse(cleanup_called_2);
|
|
})();
|
|
|
|
// Schedule a task to collect fg2, but fg is still alive.
|
|
let task_2_gc = (async function () {
|
|
await gc({ type: 'major', execution: 'async' });
|
|
assertFalse(cleanup_called);
|
|
assertFalse(cleanup_called_2);
|
|
})();
|
|
|
|
// Wait for the two GC tasks to be executed.
|
|
await task_1_gc;
|
|
await task_2_gc;
|
|
|
|
// Check that only the cleanup for fg will be called.
|
|
setTimeout(function() {
|
|
assertTrue(cleanup_called);
|
|
assertFalse(cleanup_called_2);
|
|
}, 0);
|
|
|
|
})();
|