2019-06-12 11:38:35 +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.
|
|
|
|
|
2020-04-08 23:16:14 +00:00
|
|
|
// Flags: --harmony-weak-refs-with-cleanup-some --expose-gc --noincremental-marking --allow-natives-syntax
|
2019-06-12 11:38:35 +00:00
|
|
|
|
|
|
|
let cleanup_count = 0;
|
|
|
|
let cleanup_holdings = [];
|
2020-04-07 22:07:13 +00:00
|
|
|
let cleanup = function(holdings) {
|
|
|
|
cleanup_holdings.push(holdings);
|
2019-06-12 11:38:35 +00:00
|
|
|
++cleanup_count;
|
|
|
|
}
|
|
|
|
|
2020-02-25 01:19:48 +00:00
|
|
|
let fg = new FinalizationRegistry(cleanup);
|
2019-06-12 11:38:35 +00:00
|
|
|
(function() {
|
|
|
|
let o = {};
|
|
|
|
fg.register(o, "holdings");
|
|
|
|
|
|
|
|
assertEquals(0, cleanup_count);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// GC will detect o as dead.
|
|
|
|
gc();
|
|
|
|
|
|
|
|
// passing no callback, should trigger cleanup function
|
|
|
|
fg.cleanupSome();
|
|
|
|
assertEquals(1, cleanup_count);
|
|
|
|
assertEquals(1, cleanup_holdings.length);
|
|
|
|
assertEquals("holdings", cleanup_holdings[0]);
|