summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/harmony/weakrefs/weakcell-and-weakref.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/mjsunit/harmony/weakrefs/weakcell-and-weakref.js')
-rw-r--r--deps/v8/test/mjsunit/harmony/weakrefs/weakcell-and-weakref.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/deps/v8/test/mjsunit/harmony/weakrefs/weakcell-and-weakref.js b/deps/v8/test/mjsunit/harmony/weakrefs/weakcell-and-weakref.js
new file mode 100644
index 0000000000..f6627be19e
--- /dev/null
+++ b/deps/v8/test/mjsunit/harmony/weakrefs/weakcell-and-weakref.js
@@ -0,0 +1,45 @@
+// 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);
+ let cells = [];
+ for (wc of iter) {
+ cells.push(wc);
+ }
+ assertEquals(1, cells.length);
+ assertEquals(weak_cell, cells[0]);
+ cleanup_called = true;
+}
+
+let wf = new WeakFactory(cleanup);
+let weak_ref;
+let weak_cell;
+(function() {
+ let o = {};
+ weak_ref = new WeakRef(o);
+ weak_cell = wf.makeCell(o);
+})();
+
+// Since the WeakRef was created during this turn, it is not cleared by GC. The
+// WeakCell is not cleared either, since the WeakRef keeps the target object
+// alive.
+gc();
+(function() {
+ assertNotEquals(undefined, weak_ref.deref());
+})();
+
+%PerformMicrotaskCheckpoint();
+// Next turn.
+
+gc();
+
+%PerformMicrotaskCheckpoint();
+// Next turn.
+
+assertTrue(cleanup_called);
+assertEquals(undefined, weak_ref.deref());