2019-03-12 09:01:49 +01:00
|
|
|
// 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.
|
|
|
|
|
2021-04-17 15:27:24 +02:00
|
|
|
// Flags: --expose-gc --noincremental-marking
|
2019-03-12 09:01:49 +01:00
|
|
|
|
|
|
|
let wr;
|
2023-03-30 12:11:08 +02:00
|
|
|
(function () {
|
2019-03-12 09:01:49 +01:00
|
|
|
let o = {};
|
|
|
|
wr = new WeakRef(o);
|
|
|
|
// Don't deref here, we want to test that the creation is enough to keep the
|
|
|
|
// WeakRef alive until the end of the turn.
|
|
|
|
})();
|
|
|
|
|
2023-03-30 12:11:08 +02:00
|
|
|
// Here we invoke GC synchronously and, with conservative stack scanning,
|
|
|
|
// there is a chance that the object is not reclaimed now. In any case,
|
|
|
|
// the WeakRef should not be cleared.
|
2019-03-12 09:01:49 +01:00
|
|
|
gc();
|
|
|
|
// Since the WeakRef was created during this turn, it is not cleared by GC.
|
2023-03-30 12:11:08 +02:00
|
|
|
assertNotEquals(undefined, wr.deref());
|
2019-03-12 09:01:49 +01:00
|
|
|
|
2019-09-24 11:56:38 -04:00
|
|
|
// Next task.
|
|
|
|
setTimeout(() => {
|
2023-03-30 12:11:08 +02:00
|
|
|
(async function () {
|
|
|
|
// Trigger GC again to make sure the two WeakRefs are cleared.
|
|
|
|
// We need to invoke GC asynchronously and wait for it to finish, so that
|
|
|
|
// it doesn't need to scan the stack. Otherwise, the objects may not be
|
|
|
|
// reclaimed because of conservative stack scanning and the test may not
|
|
|
|
// work as intended.
|
|
|
|
await gc({ type: 'major', execution: 'async' });
|
|
|
|
assertEquals(undefined, wr.deref());
|
|
|
|
})();
|
2019-09-24 11:56:38 -04:00
|
|
|
}, 0);
|