-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (58 loc) · 1.4 KB
/
index.js
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
56
57
58
59
60
61
/*! (c) Andrea Giammarchi - ISC */
var self = this || /* istanbul ignore next */ {};
try {
self.WeakRef = WeakRef;
/* istanbul ignore next */
self.FinalizationGroup = FinalizationGroup;
}
catch (o_O) {
// requires a global WeakMap (IE11+)
(function (WeakMap, defineProperties) {
var wr = new WeakMap;
function WeakRef(value) {
wr.set(this, value);
}
defineProperties(
WeakRef.prototype,
{
deref: {
value: function deref() {
return wr.get(this);
}
}
}
);
var fg = new WeakMap;
function FinalizationGroup(fn) {
fg.set(this, []);
}
defineProperties(
FinalizationGroup.prototype,
{
register: {
value: function register(value, name) {
var names = fg.get(this);
if (names.indexOf(name) < 0)
names.push(name);
}
},
unregister: {
value: function unregister(value, name) {
var names = fg.get(this);
var i = names.indexOf(name);
if (-1 < i)
names.splice(i, 1);
return -1 < i;
}
},
cleanupSome: {
value: function cleanupSome(fn) {
fn(fg.get(this));
}
}
}
);
self.WeakRef = WeakRef;
self.FinalizationGroup = FinalizationGroup;
}(WeakMap, Object.defineProperties));
}