mirror of
https://github.com/tc39/test262.git
synced 2025-05-10 18:00:27 +02:00
36 lines
814 B
JavaScript
36 lines
814 B
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
|
|
|
|
let cleanup_count = 0;
|
|
let cleanup_cells = [];
|
|
let cleanup = function(iter) {
|
|
for (wc of iter) {
|
|
cleanup_cells.push(wc);
|
|
}
|
|
++cleanup_count;
|
|
}
|
|
|
|
let wf = new WeakFactory(cleanup);
|
|
let weak_cell;
|
|
(function() {
|
|
let o = {};
|
|
weak_cell = wf.makeCell(o);
|
|
|
|
// cleanupSome won't do anything since there are no dirty WeakCells.
|
|
wf.cleanupSome();
|
|
assertEquals(0, cleanup_count);
|
|
})();
|
|
|
|
// GC will detect the WeakCell as dirty.
|
|
gc();
|
|
|
|
// Clear the WeakCell just before we would've called cleanupSome.
|
|
weak_cell.clear();
|
|
|
|
wf.cleanupSome();
|
|
|
|
assertEquals(0, cleanup_count);
|