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>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
// Copyright 2020 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-recompilation
|
|
|
|
(async function () {
|
|
|
|
let cleanup_called = false;
|
|
function cleanup(holdings) {
|
|
cleanup_called = true;
|
|
};
|
|
|
|
let task_1_gc = (async function () {
|
|
const fg = new FinalizationRegistry(cleanup);
|
|
|
|
(function () {
|
|
let x = {};
|
|
fg.register(x, "holdings");
|
|
x = null;
|
|
})();
|
|
|
|
// Schedule fg for cleanup.
|
|
await gc({ type: 'major', execution: 'async' });
|
|
assertFalse(cleanup_called);
|
|
})();
|
|
|
|
// Schedule a task to collect fg, which should result in cleanup not called.
|
|
let task_2_gc = (async function () {
|
|
await gc({ type: 'major', execution: 'async' });
|
|
assertFalse(cleanup_called);
|
|
})();
|
|
|
|
// Wait for the two GC tasks to be executed.
|
|
await task_1_gc;
|
|
await task_2_gc;
|
|
|
|
// Check that the cleanup will not be called.
|
|
setTimeout(function () { assertFalse(cleanup_called); }, 0);
|
|
|
|
})();
|