mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
[v8-test262-automation] Changes from https://github.com/v8/v8.git at sha dde25872 on Mon Dec 17 2018 19:18:49 GMT+0000 (Coordinated Universal Time)
This commit is contained in:
parent
e87b5d6dab
commit
227c2e8ffe
implementation-contributed/v8
mjsunit
harmony/weakrefs
basics.jscleanupsome-dereffed-and-cleared-weakref.jscleanupsome-dereffed-weakref.jscleanupsome-weakref.jsclear-after-deref.jstwo-weakrefs.jsweakcell-and-weakref.jsweakref-creation-keeps-alive.jsweakref-deref-keeps-alive.js
unicodelctest-no-optimization.jsunicodelctest.jstest262
@ -151,14 +151,10 @@
|
|||||||
clear.call(wc);
|
clear.call(wc);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function TestMakeRef() {
|
(function TestWeakRefConstructor() {
|
||||||
let wf = new WeakFactory(() => {});
|
let wr = new WeakRef({});
|
||||||
let wr = wf.makeRef({});
|
|
||||||
let wc = wf.makeCell({});
|
|
||||||
assertEquals(wr.toString(), "[object WeakRef]");
|
assertEquals(wr.toString(), "[object WeakRef]");
|
||||||
assertNotSame(wr.__proto__, Object.prototype);
|
assertNotSame(wr.__proto__, Object.prototype);
|
||||||
assertSame(wr.__proto__.__proto__, wc.__proto__);
|
|
||||||
assertEquals(wr.holdings, undefined);
|
|
||||||
|
|
||||||
let deref_desc = Object.getOwnPropertyDescriptor(wr.__proto__, "deref");
|
let deref_desc = Object.getOwnPropertyDescriptor(wr.__proto__, "deref");
|
||||||
assertEquals(true, deref_desc.configurable);
|
assertEquals(true, deref_desc.configurable);
|
||||||
@ -166,70 +162,36 @@
|
|||||||
assertEquals("function", typeof deref_desc.value);
|
assertEquals("function", typeof deref_desc.value);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function TestMakeRefWithHoldings() {
|
(function TestWeakRefConstructorWithNonObject() {
|
||||||
let wf = new WeakFactory(() => {});
|
let message = "WeakRef: target must be an object";
|
||||||
let obj = {a: 1};
|
assertThrows(() => new WeakRef(), TypeError, message);
|
||||||
let holdings = {b: 2};
|
assertThrows(() => new WeakRef(1), TypeError, message);
|
||||||
let wr = wf.makeRef(obj, holdings);
|
assertThrows(() => new WeakRef(false), TypeError, message);
|
||||||
assertSame(wr.holdings, holdings);
|
assertThrows(() => new WeakRef("foo"), TypeError, message);
|
||||||
|
assertThrows(() => new WeakRef(Symbol()), TypeError, message);
|
||||||
|
assertThrows(() => new WeakRef(null), TypeError, message);
|
||||||
|
assertThrows(() => new WeakRef(undefined), TypeError, message);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function TestMakeRefWithHoldingsSetHoldings() {
|
(function TestWeakRefConstructorCallAsFunction() {
|
||||||
let wf = new WeakFactory(() => {});
|
let caught = false;
|
||||||
let obj = {a: 1};
|
let message = "";
|
||||||
let holdings = {b: 2};
|
try {
|
||||||
let wr = wf.makeRef(obj, holdings);
|
let f = WeakRef({});
|
||||||
assertSame(wr.holdings, holdings);
|
} catch (e) {
|
||||||
wr.holdings = 5;
|
message = e.message;
|
||||||
assertSame(wr.holdings, holdings);
|
caught = true;
|
||||||
|
} finally {
|
||||||
|
assertTrue(caught);
|
||||||
|
assertEquals(message, "Constructor WeakRef requires 'new'");
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function TestMakeRefWithHoldingsSetHoldingsStrict() {
|
(function TestWeakRefWithProxy() {
|
||||||
"use strict";
|
|
||||||
let wf = new WeakFactory(() => {});
|
|
||||||
let obj = {a: 1};
|
|
||||||
let holdings = {b: 2};
|
|
||||||
let wr = wf.makeRef(obj, holdings);
|
|
||||||
assertSame(wr.holdings, holdings);
|
|
||||||
assertThrows(() => { wr.holdings = 5; }, TypeError);
|
|
||||||
assertSame(wr.holdings, holdings);
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function TestMakeRefWithNonObject() {
|
|
||||||
let wf = new WeakFactory(() => {});
|
|
||||||
let message = "WeakFactory.prototype.makeRef: target must be an object";
|
|
||||||
assertThrows(() => wf.makeRef(), TypeError, message);
|
|
||||||
assertThrows(() => wf.makeRef(1), TypeError, message);
|
|
||||||
assertThrows(() => wf.makeRef(false), TypeError, message);
|
|
||||||
assertThrows(() => wf.makeRef("foo"), TypeError, message);
|
|
||||||
assertThrows(() => wf.makeRef(Symbol()), TypeError, message);
|
|
||||||
assertThrows(() => wf.makeRef(null), TypeError, message);
|
|
||||||
assertThrows(() => wf.makeRef(undefined), TypeError, message);
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function TestMakeRefWithProxy() {
|
|
||||||
let handler = {};
|
let handler = {};
|
||||||
let obj = {};
|
let obj = {};
|
||||||
let proxy = new Proxy(obj, handler);
|
let proxy = new Proxy(obj, handler);
|
||||||
let wf = new WeakFactory(() => {});
|
let wr = new WeakRef(proxy);
|
||||||
let wr = wf.makeRef(proxy);
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function TestMakeRefTargetAndHoldingsSameValue() {
|
|
||||||
let wf = new WeakFactory(() => {});
|
|
||||||
let obj = {a: 1};
|
|
||||||
// SameValue(target, holdings) not ok
|
|
||||||
assertThrows(() => wf.makeRef(obj, obj), TypeError,
|
|
||||||
"WeakFactory.prototype.makeRef: target and holdings must not be same");
|
|
||||||
let holdings = {a: 1};
|
|
||||||
let wr = wf.makeRef(obj, holdings);
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function TestMakeRefWithoutWeakFactory() {
|
|
||||||
assertThrows(() => WeakFactory.prototype.makeRef.call({}, {}), TypeError);
|
|
||||||
// Does not throw:
|
|
||||||
let wf = new WeakFactory(() => {});
|
|
||||||
WeakFactory.prototype.makeRef.call(wf, {});
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function TestCleanupSomeWithoutWeakFactory() {
|
(function TestCleanupSomeWithoutWeakFactory() {
|
||||||
@ -243,24 +205,10 @@
|
|||||||
(function TestDerefWithoutWeakRef() {
|
(function TestDerefWithoutWeakRef() {
|
||||||
let wf = new WeakFactory(() => {});
|
let wf = new WeakFactory(() => {});
|
||||||
let wc = wf.makeCell({});
|
let wc = wf.makeCell({});
|
||||||
let wr = wf.makeRef({});
|
let wr = new WeakRef({});
|
||||||
let deref = Object.getOwnPropertyDescriptor(wr.__proto__, "deref").value;
|
let deref = Object.getOwnPropertyDescriptor(wr.__proto__, "deref").value;
|
||||||
assertThrows(() => deref.call({}), TypeError);
|
assertThrows(() => deref.call({}), TypeError);
|
||||||
assertThrows(() => deref.call(wc), TypeError);
|
assertThrows(() => deref.call(wc), TypeError);
|
||||||
// Does not throw:
|
// Does not throw:
|
||||||
deref.call(wr);
|
deref.call(wr);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function TestWeakRefClearAfterProtoChange() {
|
|
||||||
let wf = new WeakFactory(() => {});
|
|
||||||
let wc = wf.makeCell({});
|
|
||||||
let wr = wf.makeRef({});
|
|
||||||
// Does not throw:
|
|
||||||
wr.clear();
|
|
||||||
wr.__proto__ = {};
|
|
||||||
assertThrows(() => wr.clear(), TypeError);
|
|
||||||
|
|
||||||
let clear = Object.getOwnPropertyDescriptor(wc.__proto__, "clear").value;
|
|
||||||
// Does not throw:
|
|
||||||
clear.call(wr);
|
|
||||||
})();
|
|
||||||
|
51
implementation-contributed/v8/mjsunit/harmony/weakrefs/cleanupsome-dereffed-and-cleared-weakref.js
51
implementation-contributed/v8/mjsunit/harmony/weakrefs/cleanupsome-dereffed-and-cleared-weakref.js
@ -1,51 +0,0 @@
|
|||||||
// 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.
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
// Next turn.
|
|
||||||
|
|
||||||
// This GC detects the WeakRef as dirty.
|
|
||||||
gc();
|
|
||||||
|
|
||||||
// Clear the WeakRef just before we would've called cleanupSome.
|
|
||||||
weak_ref.clear();
|
|
||||||
|
|
||||||
wf.cleanupSome();
|
|
||||||
|
|
||||||
assertEquals(0, cleanup_count);
|
|
@ -1,57 +0,0 @@
|
|||||||
// 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.
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
// Next turn.
|
|
||||||
|
|
||||||
assertEquals(1, cleanup_count);
|
|
@ -1,43 +0,0 @@
|
|||||||
// 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 wf = new WeakFactory(cleanup);
|
|
||||||
let weak_ref;
|
|
||||||
(function() {
|
|
||||||
let o = {};
|
|
||||||
weak_ref = wf.makeRef(o);
|
|
||||||
|
|
||||||
// cleanupSome won't do anything since there are no dirty WeakCells.
|
|
||||||
wf.cleanupSome();
|
|
||||||
assertEquals(0, cleanup_count);
|
|
||||||
})();
|
|
||||||
|
|
||||||
// The WeakRef is not detected as dirty, since the KeepDuringJob set keeps the
|
|
||||||
// target object alive.
|
|
||||||
gc();
|
|
||||||
|
|
||||||
wf.cleanupSome();
|
|
||||||
assertEquals(0, cleanup_count);
|
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
// 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]);
|
|
@ -1,46 +0,0 @@
|
|||||||
// 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_started = false;
|
|
||||||
let cleanup_succeeded = false;
|
|
||||||
let cleanup = function(iter) {
|
|
||||||
cleanup_start = true;
|
|
||||||
let cells = [];
|
|
||||||
for (wc of iter) {
|
|
||||||
cells.push(wc);
|
|
||||||
}
|
|
||||||
assertEquals(1, cells.length);
|
|
||||||
assertEquals(w1, cells[0]);
|
|
||||||
cleanup_succeeded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let wf = new WeakFactory(cleanup);
|
|
||||||
let wr;
|
|
||||||
(function() {
|
|
||||||
let o = { foo: "bar" };
|
|
||||||
wr = wf.makeRef(o);
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Since the WeakRef was created during this turn, they're not cleared by GC.
|
|
||||||
gc();
|
|
||||||
assertNotEquals(undefined, wr.deref());
|
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
// New turn.
|
|
||||||
|
|
||||||
let o = wr.deref();
|
|
||||||
assertEquals("bar", o.foo);
|
|
||||||
|
|
||||||
wr.clear();
|
|
||||||
assertEquals(undefined, wr.deref());
|
|
||||||
|
|
||||||
let timeout_func1 = function() {
|
|
||||||
assertFalse(cleanup_started);
|
|
||||||
assertFalse(cleanup_succeeded);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert that the cleanup function won't be called.
|
|
||||||
setTimeout(timeout_func1, 0);
|
|
@ -4,35 +4,18 @@
|
|||||||
|
|
||||||
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking --allow-natives-syntax
|
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking --allow-natives-syntax
|
||||||
|
|
||||||
let cleanup_count = 0;
|
|
||||||
let cleared_cells1 = [];
|
|
||||||
let cleared_cells2 = [];
|
|
||||||
let cleanup = function(iter) {
|
|
||||||
if (cleanup_count == 0) {
|
|
||||||
for (wc of iter) {
|
|
||||||
cleared_cells1.push(wc);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
assertEquals(1, cleanup_count);
|
|
||||||
for (wc of iter) {
|
|
||||||
cleared_cells2.push(wc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++cleanup_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
let wf = new WeakFactory(cleanup);
|
|
||||||
let o1 = {};
|
let o1 = {};
|
||||||
let o2 = {};
|
let o2 = {};
|
||||||
let wr1;
|
let wr1;
|
||||||
let wr2;
|
let wr2;
|
||||||
(function() {
|
(function() {
|
||||||
wr1 = wf.makeRef(o1);
|
wr1 = new WeakRef(o1);
|
||||||
wr2 = wf.makeRef(o2);
|
wr2 = new WeakRef(o2);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Since the WeakRefs were created during this turn, they're not cleared by GC.
|
// Since the WeakRefs were created during this turn, they're not cleared by GC.
|
||||||
gc();
|
gc();
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
assertNotEquals(undefined, wr1.deref());
|
assertNotEquals(undefined, wr1.deref());
|
||||||
assertNotEquals(undefined, wr2.deref());
|
assertNotEquals(undefined, wr2.deref());
|
||||||
@ -41,8 +24,6 @@ gc();
|
|||||||
%PerformMicrotaskCheckpoint();
|
%PerformMicrotaskCheckpoint();
|
||||||
// New turn.
|
// New turn.
|
||||||
|
|
||||||
assertEquals(0, cleanup_count);
|
|
||||||
|
|
||||||
wr1.deref();
|
wr1.deref();
|
||||||
o1 = null;
|
o1 = null;
|
||||||
gc(); // deref makes sure we don't clean up wr1
|
gc(); // deref makes sure we don't clean up wr1
|
||||||
@ -50,8 +31,6 @@ gc(); // deref makes sure we don't clean up wr1
|
|||||||
%PerformMicrotaskCheckpoint();
|
%PerformMicrotaskCheckpoint();
|
||||||
// New turn.
|
// New turn.
|
||||||
|
|
||||||
assertEquals(0, cleanup_count);
|
|
||||||
|
|
||||||
wr2.deref();
|
wr2.deref();
|
||||||
o2 = null;
|
o2 = null;
|
||||||
gc(); // deref makes sure we don't clean up wr2
|
gc(); // deref makes sure we don't clean up wr2
|
||||||
@ -59,13 +38,11 @@ gc(); // deref makes sure we don't clean up wr2
|
|||||||
%PerformMicrotaskCheckpoint();
|
%PerformMicrotaskCheckpoint();
|
||||||
// New turn.
|
// New turn.
|
||||||
|
|
||||||
assertEquals(1, cleanup_count);
|
assertEquals(undefined, wr1.deref());
|
||||||
assertEquals(wr1, cleared_cells1[0]);
|
|
||||||
|
|
||||||
gc();
|
gc();
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
%PerformMicrotaskCheckpoint();
|
||||||
// New turn.
|
// New turn.
|
||||||
|
|
||||||
assertEquals(2, cleanup_count);
|
assertEquals(undefined, wr2.deref());
|
||||||
assertEquals(wr2, cleared_cells2[0]);
|
|
||||||
|
@ -11,9 +11,8 @@ let cleanup = function(iter) {
|
|||||||
for (wc of iter) {
|
for (wc of iter) {
|
||||||
cells.push(wc);
|
cells.push(wc);
|
||||||
}
|
}
|
||||||
assertEquals(2, cells.length);
|
assertEquals(1, cells.length);
|
||||||
assertTrue(cells.includes(weak_ref));
|
assertEquals(weak_cell, cells[0]);
|
||||||
assertTrue(cells.includes(weak_cell));
|
|
||||||
cleanup_called = true;
|
cleanup_called = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,8 +21,8 @@ let weak_ref;
|
|||||||
let weak_cell;
|
let weak_cell;
|
||||||
(function() {
|
(function() {
|
||||||
let o = {};
|
let o = {};
|
||||||
weak_ref = wf.makeRef(o);
|
weak_ref = new WeakRef(o);
|
||||||
weak_cell = wf.makeRef(o);
|
weak_cell = wf.makeCell(o);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Since the WeakRef was created during this turn, it is not cleared by GC. The
|
// Since the WeakRef was created during this turn, it is not cleared by GC. The
|
||||||
@ -43,3 +42,4 @@ gc();
|
|||||||
// Next turn.
|
// Next turn.
|
||||||
|
|
||||||
assertTrue(cleanup_called);
|
assertTrue(cleanup_called);
|
||||||
|
assertEquals(undefined, weak_ref.deref());
|
||||||
|
@ -4,24 +4,10 @@
|
|||||||
|
|
||||||
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking --allow-natives-syntax
|
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking --allow-natives-syntax
|
||||||
|
|
||||||
let cleanup_called = false;
|
|
||||||
let cleanup = function(iter) {
|
|
||||||
assertFalse(cleanup_called);
|
|
||||||
let count = 0;
|
|
||||||
for (wc of iter) {
|
|
||||||
++count;
|
|
||||||
assertEquals(wr, wc);
|
|
||||||
assertEquals(undefined, wc.deref());
|
|
||||||
}
|
|
||||||
assertEquals(1, count);
|
|
||||||
cleanup_called = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let wf = new WeakFactory(cleanup);
|
|
||||||
let wr;
|
let wr;
|
||||||
(function() {
|
(function() {
|
||||||
let o = {};
|
let o = {};
|
||||||
wr = wf.makeRef(o);
|
wr = new WeakRef(o);
|
||||||
// Don't deref here, we want to test that the creation is enough to keep the
|
// Don't deref here, we want to test that the creation is enough to keep the
|
||||||
// WeakRef alive until the end of the turn.
|
// WeakRef alive until the end of the turn.
|
||||||
})();
|
})();
|
||||||
@ -36,11 +22,6 @@ gc();
|
|||||||
%PerformMicrotaskCheckpoint();
|
%PerformMicrotaskCheckpoint();
|
||||||
// Next turn.
|
// Next turn.
|
||||||
|
|
||||||
assertFalse(cleanup_called);
|
|
||||||
|
|
||||||
gc();
|
gc();
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
assertEquals(undefined, wr.deref());
|
||||||
// Next turn.
|
|
||||||
|
|
||||||
assertTrue(cleanup_called);
|
|
||||||
|
@ -4,25 +4,13 @@
|
|||||||
|
|
||||||
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking --allow-natives-syntax
|
// 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) {
|
|
||||||
assertEquals(undefined, wc.deref());
|
|
||||||
cleanup_cells.push(wc);
|
|
||||||
}
|
|
||||||
++cleanup_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
let wf = new WeakFactory(cleanup);
|
|
||||||
let wf_control = new WeakFactory(cleanup);
|
|
||||||
let wr;
|
let wr;
|
||||||
let wr_control; // control WeakRef for testing what happens without deref
|
let wr_control; // control WeakRef for testing what happens without deref
|
||||||
(function() {
|
(function() {
|
||||||
let o1 = {};
|
let o1 = {};
|
||||||
wr = wf.makeRef(o1);
|
wr = new WeakRef(o1);
|
||||||
let o2 = {};
|
let o2 = {};
|
||||||
wr_control = wf_control.makeRef(o2);
|
wr_control = new WeakRef(o2);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
let strong = {a: wr.deref(), b: wr_control.deref()};
|
let strong = {a: wr.deref(), b: wr_control.deref()};
|
||||||
@ -32,14 +20,6 @@ gc();
|
|||||||
%PerformMicrotaskCheckpoint();
|
%PerformMicrotaskCheckpoint();
|
||||||
// Next turn.
|
// Next turn.
|
||||||
|
|
||||||
gc();
|
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
// Next turn.
|
|
||||||
|
|
||||||
// We have a strong reference to the objects, so the WeakRefs are not cleared yet.
|
|
||||||
assertEquals(0, cleanup_count);
|
|
||||||
|
|
||||||
// Call deref inside a closure, trying to avoid accidentally storing a strong
|
// Call deref inside a closure, trying to avoid accidentally storing a strong
|
||||||
// reference into the object in the stack frame.
|
// reference into the object in the stack frame.
|
||||||
(function() {
|
(function() {
|
||||||
@ -60,17 +40,6 @@ gc();
|
|||||||
%PerformMicrotaskCheckpoint();
|
%PerformMicrotaskCheckpoint();
|
||||||
// Next turn.
|
// Next turn.
|
||||||
|
|
||||||
assertEquals(1, cleanup_count);
|
|
||||||
assertEquals(1, cleanup_cells.length);
|
|
||||||
assertEquals(wc, cleanup_cells[0]);
|
|
||||||
|
|
||||||
gc();
|
gc();
|
||||||
|
|
||||||
%PerformMicrotaskCheckpoint();
|
|
||||||
// Next turn.
|
|
||||||
|
|
||||||
assertEquals(2, cleanup_count);
|
|
||||||
assertEquals(2, cleanup_cells.length);
|
|
||||||
assertEquals(wr, cleanup_cells[1]);
|
|
||||||
|
|
||||||
assertEquals(undefined, wr.deref());
|
assertEquals(undefined, wr.deref());
|
||||||
|
@ -60,6 +60,7 @@ function rand() {
|
|||||||
// To make the test results predictable, we use a 100% deterministic
|
// To make the test results predictable, we use a 100% deterministic
|
||||||
// alternative.
|
// alternative.
|
||||||
// Robert Jenkins' 32 bit integer hash function.
|
// Robert Jenkins' 32 bit integer hash function.
|
||||||
|
seed = seed & 0xffffffff;
|
||||||
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
|
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
|
||||||
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
|
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
|
||||||
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
|
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
|
||||||
|
@ -59,6 +59,7 @@ function rand() {
|
|||||||
// To make the test results predictable, we use a 100% deterministic
|
// To make the test results predictable, we use a 100% deterministic
|
||||||
// alternative.
|
// alternative.
|
||||||
// Robert Jenkins' 32 bit integer hash function.
|
// Robert Jenkins' 32 bit integer hash function.
|
||||||
|
seed = seed & 0xffffffff;
|
||||||
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
|
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
|
||||||
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
|
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
|
||||||
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
|
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user