2018-11-05 14:21:02 +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 --allow-natives-syntax
|
|
|
|
|
|
|
|
let cleanup_called = false;
|
|
|
|
let cleanup = function(iter) {
|
|
|
|
assertFalse(cleanup_called);
|
2019-01-30 12:06:32 +00:00
|
|
|
let holdings_list = [];
|
|
|
|
for (holdings of iter) {
|
|
|
|
holdings_list.push(holdings);
|
2018-11-05 14:21:02 +00:00
|
|
|
}
|
2019-01-30 12:06:32 +00:00
|
|
|
assertEquals(1, holdings_list.length);
|
|
|
|
assertEquals("holdings", holdings_list[0]);
|
2018-11-05 14:21:02 +00:00
|
|
|
cleanup_called = true;
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:06:32 +00:00
|
|
|
let fg = new FinalizationGroup(cleanup);
|
2018-11-05 14:21:02 +00:00
|
|
|
let weak_ref;
|
|
|
|
(function() {
|
|
|
|
let o = {};
|
2018-12-17 08:15:02 +00:00
|
|
|
weak_ref = new WeakRef(o);
|
2019-01-30 12:06:32 +00:00
|
|
|
fg.register(o, "holdings");
|
2018-11-05 14:21:02 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
// Since the WeakRef was created during this turn, it is not cleared by GC. The
|
2019-01-30 12:06:32 +00:00
|
|
|
// pointer inside the FinalizationGroup is not cleared either, since the WeakRef
|
|
|
|
// keeps the target object alive.
|
2018-11-05 14:21:02 +00:00
|
|
|
gc();
|
|
|
|
(function() {
|
|
|
|
assertNotEquals(undefined, weak_ref.deref());
|
|
|
|
})();
|
|
|
|
|
2018-12-04 06:12:49 +00:00
|
|
|
%PerformMicrotaskCheckpoint();
|
2018-11-05 14:21:02 +00:00
|
|
|
// Next turn.
|
|
|
|
|
|
|
|
gc();
|
|
|
|
|
2018-12-04 06:12:49 +00:00
|
|
|
%PerformMicrotaskCheckpoint();
|
2018-11-05 14:21:02 +00:00
|
|
|
// Next turn.
|
|
|
|
|
|
|
|
assertTrue(cleanup_called);
|
2018-12-17 08:15:02 +00:00
|
|
|
assertEquals(undefined, weak_ref.deref());
|