finalizationregistry-independent-lifetime.js 638 Bytes
Newer Older
1 2 3 4
// 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.

5
// Flags: --expose-gc --noincremental-marking --no-concurrent-recompilation
6 7

let cleanup_called = false;
8
function cleanup(holdings) {
9 10 11
  cleanup_called = true;
};
(function() {
12
  let fg = new FinalizationRegistry(cleanup);
13 14 15 16 17 18 19 20 21 22 23 24 25
  (function() {
    let x = {};
    fg.register(x, {});
    x = null;
  })();
  // Schedule fg for cleanup.
  gc();
})();

// Collect fg, which should result in cleanup not called.
gc();

setTimeout(function() { assertFalse(cleanup_called); }, 0);