2019-01-30 12:06:32 +00:00
|
|
|
// Copyright 2019 the V8 project authors. All rights reserved.
|
2018-10-23 08:30:25 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-10-30 08:43:08 +00:00
|
|
|
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
|
2018-10-23 08:30:25 +00:00
|
|
|
|
|
|
|
let cleanup_call_count = 0;
|
2019-01-30 12:06:32 +00:00
|
|
|
let cleanup_holdings_count = 0;
|
2018-10-23 08:30:25 +00:00
|
|
|
let cleanup = function(iter) {
|
2019-01-30 12:06:32 +00:00
|
|
|
for (holdings of iter) {
|
|
|
|
assertEquals(holdings, undefined);
|
|
|
|
++cleanup_holdings_count;
|
2018-10-23 08:30:25 +00:00
|
|
|
}
|
|
|
|
++cleanup_call_count;
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
let fg = new FinalizationGroup(cleanup);
|
|
|
|
|
|
|
|
// Create an object and register it in the FinalizationGroup. The object needs to be inside
|
2018-10-23 08:30:25 +00:00
|
|
|
// a closure so that we can reliably kill them!
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
let object = {};
|
2019-01-30 12:06:32 +00:00
|
|
|
fg.register(object);
|
2018-10-23 08:30:25 +00:00
|
|
|
|
|
|
|
// object goes out of scope.
|
|
|
|
})();
|
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
// This GC will reclaim the target object and schedule cleanup.
|
2018-10-23 08:30:25 +00:00
|
|
|
gc();
|
|
|
|
assertEquals(0, cleanup_call_count);
|
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
// Assert that the cleanup function was called and iterated the holdings.
|
2018-10-23 08:30:25 +00:00
|
|
|
let timeout_func = function() {
|
|
|
|
assertEquals(1, cleanup_call_count);
|
2019-01-30 12:06:32 +00:00
|
|
|
assertEquals(1, cleanup_holdings_count);
|
2018-10-23 08:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(timeout_func, 0);
|