1ed5214c8c
BUG=v8:8179 Change-Id: I7dc024fe4880a787cadac8b79bca6da87e2d36de Reviewed-on: https://chromium-review.googlesource.com/c/1328926 Commit-Queue: Marja Hölttä <marja@chromium.org> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#57476}
58 lines
1.2 KiB
JavaScript
58 lines
1.2 KiB
JavaScript
// 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_count = 0;
|
|
let cleanup_cells = [];
|
|
let cleanup = function(iter) {
|
|
for (wc of iter) {
|
|
cleanup_cells.push(wc);
|
|
}
|
|
++cleanup_count;
|
|
}
|
|
|
|
let o = {};
|
|
let wf = new WeakFactory(cleanup);
|
|
let weak_ref;
|
|
(function() {
|
|
weak_ref = wf.makeRef(o);
|
|
|
|
// cleanupSome won't do anything since there are no dirty WeakCells.
|
|
wf.cleanupSome();
|
|
assertEquals(0, cleanup_count);
|
|
})();
|
|
|
|
// Clear the KeepDuringJob set.
|
|
%RunMicrotasks();
|
|
|
|
weak_ref.deref();
|
|
o = null;
|
|
|
|
// The WeakRef is not detected as dirty, since the KeepDuringJob set keeps the
|
|
// target object alive.
|
|
gc();
|
|
|
|
wf.cleanupSome();
|
|
assertEquals(0, cleanup_count);
|
|
|
|
%RunMicrotasks();
|
|
// Next turn.
|
|
|
|
// Now the WeakRef can be cleared.
|
|
gc();
|
|
wf.cleanupSome();
|
|
|
|
assertEquals(1, cleanup_count);
|
|
assertEquals(1, cleanup_cells.length);
|
|
assertEquals(weak_ref, cleanup_cells[0]);
|
|
|
|
// The cleanup task is not executed again since all WeakCells have been
|
|
// processed.
|
|
|
|
%RunMicrotasks();
|
|
// Next turn.
|
|
|
|
assertEquals(1, cleanup_count);
|