2018-11-13 10:42:38 +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.
|
|
|
|
|
|
|
|
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
|
|
|
|
|
|
|
|
let cleanup_count = 0;
|
2019-01-30 12:06:32 +00:00
|
|
|
let cleanup_holdings = [];
|
2018-11-13 10:42:38 +00:00
|
|
|
let cleanup = function(iter) {
|
2019-01-30 12:06:32 +00:00
|
|
|
for (holdings of iter) {
|
|
|
|
cleanup_holdings.push(holdings);
|
2018-11-13 10:42:38 +00:00
|
|
|
}
|
|
|
|
++cleanup_count;
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
let fg = new FinalizationGroup(cleanup);
|
2018-11-13 10:42:38 +00:00
|
|
|
(function() {
|
|
|
|
let o = {};
|
2019-01-30 12:06:32 +00:00
|
|
|
fg.register(o, "holdings");
|
2018-11-13 10:42:38 +00:00
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
// cleanupSome won't do anything since there are no reclaimed targets.
|
|
|
|
fg.cleanupSome();
|
2018-11-13 10:42:38 +00:00
|
|
|
assertEquals(0, cleanup_count);
|
|
|
|
})();
|
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
// GC will detect o as dead.
|
2018-11-13 10:42:38 +00:00
|
|
|
gc();
|
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
fg.cleanupSome();
|
2018-11-13 10:42:38 +00:00
|
|
|
assertEquals(1, cleanup_count);
|
2019-01-30 12:06:32 +00:00
|
|
|
assertEquals(1, cleanup_holdings.length);
|
|
|
|
assertEquals("holdings", cleanup_holdings[0]);
|