Commit 55b1704b authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[js weak refs] Add tests: WeakFactory keeps WeakCells alive

BUG=v8:8179

Change-Id: I43861e114b9f46847df9b02d0337709a685feb72
Reviewed-on: https://chromium-review.googlesource.com/c/1278810Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56771}
parent 04941522
// 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
let cleanup_called = false;
let cleanup = function(iter) {
assertFalse(cleanup_called);
let cells = [];
for (wc of iter) {
cells.push(wc);
}
assertEquals(cells.length, 1);
assertEquals(cells[0].holdings, "this is my cell");
cleanup_called = true;
}
let wf = new WeakFactory(cleanup);
let o1 = {};
let wc1 = wf.makeCell(o1, "this is my cell");
gc();
assertFalse(cleanup_called);
// Drop the last references to o1.
o1 = null;
// Drop the last reference to the WeakCell. The WeakFactory keeps it alive, so
// the cleanup function will be called as normal.
wc1 = null;
gc();
assertFalse(cleanup_called);
let timeout_func = function() {
assertTrue(cleanup_called);
}
setTimeout(timeout_func, 0);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment