blob: 561bf4f058bdd7b814c5ab4add6ecf1fa5a53eed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// Copyright 2022 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-symbol-as-weakmap-key --expose-gc --noincremental-marking
(function TestWeakRefWithSymbolGC() {
let weakRef;
{
const innerKey = Symbol('123');
weakRef = new WeakRef(innerKey);
}
// Since the WeakRef was created during this turn, it is not cleared by GC.
gc();
assertNotEquals(undefined, weakRef.deref());
// Next task.
setTimeout(() => {
gc();
assertEquals(undefined, weakRef.deref());
}, 0);
})();
(function TestFinalizationRegistryWithSymbolGC() {
let cleanUpCalled = false;
const fg = new FinalizationRegistry((target) => {
assertEquals('123', target);
cleanUpCalled = true;
});
(function () {
const innerKey = Symbol('123');
fg.register(innerKey, '123');
})();
gc();
assertFalse(cleanUpCalled);
// Check that cleanup callback was called in a follow up task.
setTimeout(() => {
assertTrue(cleanUpCalled);
}, 0);
})();
|