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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// |reftest| skip-if(!this.hasOwnProperty('FinalizationRegistry')) async -- FinalizationRegistry is not enabled unconditionally
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-finalization-registry.prototype.cleanupSome
description: Cleanup might be prevented with an unregister usage
info: |
FinalizationRegistry.prototype.cleanupSome ( [ callback ] )
1. Let finalizationRegistry be the this value.
2. If Type(finalizationRegistry) is not Object, throw a TypeError exception.
3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception.
4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception.
5. Perform ? CleanupFinalizationRegistry(finalizationRegistry, callback).
6. Return undefined.
FinalizationRegistry.prototype.unregister ( unregisterToken )
1. Let removed be false.
2. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationRegistry.[[Cells]], do
a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
i. Remove cell from finalizationRegistry.[[Cells]].
ii. Set removed to true.
3. Return removed.
features: [FinalizationRegistry.prototype.cleanupSome, FinalizationRegistry, host-gc-required]
includes: [async-gc.js]
flags: [async, non-deterministic]
---*/
var token = {};
var finalizationRegistry = new FinalizationRegistry(function() {});
function emptyCells() {
var target = {};
finalizationRegistry.register(target, 'target!', token);
var prom = asyncGC(target);
target = null;
return prom;
}
emptyCells().then(function() {
var called = 0;
var res = finalizationRegistry.unregister(token);
assert.sameValue(res, true, 'unregister target before iterating over it in cleanup');
finalizationRegistry.cleanupSome(function cb(holding) {
called += 1;
});
assert.sameValue(called, 0, 'callback was not called');
}).then($DONE, resolveAsyncGC);
|