v8/test/mjsunit/harmony/weakrefs/iterating-weak-cells.js
Marja Hölttä b839ed4f24 [js weak refs] Disable incremental marking for harmony/weakrefs tests
These tests rely on dropping references to objects either explicitly ("o =
null;") or implicitly ("o goes out of scope") and then doing gc. It's essential
that we haven't already marked the WeakCell pointing to o and marked it alive
before dropping the reference.

BUG=v8:8179

Change-Id: Ie0b73f05c4baa937cf6f28325454ff9087a71a2c
Reviewed-on: https://chromium-review.googlesource.com/c/1306437
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57115}
2018-10-30 10:03:56 +00:00

50 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
let cleanup_called = false;
let cleanup = function(iter) {
assertFalse(cleanup_called);
let cells = [];
for (wc of iter) {
cells.push(wc);
}
assertEquals(cells.length, 2);
if (cells[0] == wc1) {
assertEquals(cells[0].holdings, 1);
assertEquals(cells[1], wc2);
assertEquals(cells[1].holdings, 2);
} else {
assertEquals(cells[0], wc2);
assertEquals(cells[0].holdings, 2);
assertEquals(cells[1], wc1);
assertEquals(cells[1].holdings, 1);
}
cleanup_called = true;
}
let wf = new WeakFactory(cleanup);
let o1 = {};
let o2 = {};
let wc1 = wf.makeCell(o1, 1);
let wc2 = wf.makeCell(o2, 2);
gc();
assertFalse(cleanup_called);
// Drop the last references to o1 and o2.
o1 = null;
o2 = null;
// GC will clear the WeakCells; the cleanup function will be called the next time
// we enter the event loop.
gc();
assertFalse(cleanup_called);
let timeout_func = function() {
assertTrue(cleanup_called);
}
setTimeout(timeout_func, 0);