2020-05-05 09:19:02 +02:00
|
|
|
// 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.
|
|
|
|
|
2021-04-17 15:27:24 +02:00
|
|
|
// Flags: --expose-gc --noincremental-marking
|
2020-05-05 09:19:02 +02:00
|
|
|
|
2023-03-30 12:11:08 +02:00
|
|
|
(async function () {
|
2020-05-05 09:19:02 +02:00
|
|
|
|
2023-03-30 12:11:08 +02:00
|
|
|
let call_count = 0;
|
|
|
|
const reentrant_gc = function (holdings) {
|
|
|
|
gc();
|
|
|
|
call_count++;
|
|
|
|
}
|
2020-05-05 09:19:02 +02:00
|
|
|
|
2023-03-30 12:11:08 +02:00
|
|
|
const fg = new FinalizationRegistry(reentrant_gc);
|
2020-05-05 09:19:02 +02:00
|
|
|
|
2023-03-30 12:11:08 +02:00
|
|
|
(function () {
|
|
|
|
fg.register({}, 42);
|
|
|
|
})();
|
2020-05-05 09:19:02 +02:00
|
|
|
|
2023-03-30 12:11:08 +02:00
|
|
|
// We need to invoke GC asynchronously and wait for it to finish, so that
|
|
|
|
// it doesn't need to scan the stack. Otherwise, the objects may not be
|
|
|
|
// reclaimed because of conservative stack scanning and the test may not
|
|
|
|
// work as intended.
|
|
|
|
await gc({ type: 'major', execution: 'async' });
|
|
|
|
assertEquals(0, call_count);
|
|
|
|
|
|
|
|
setTimeout(function () { assertEquals(1, call_count); }, 0);
|
|
|
|
|
|
|
|
})();
|