This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.js
86 lines (74 loc) · 2.69 KB
/
client.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* This file is part of Cockpit.
*
* Copyright (C) 2016 Red Hat, Inc.
*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/
angular.module('registryUI.client', [ ])
.factory('WeakMap', function() {
if (typeof window.WeakMap === 'function')
return window.WeakMap;
/*
* A WeakMap implementation
*
* This works on ES5 browsers, with the caveat that the mapped
* items are discoverable with enough work.
*
* To be clear, the principal use of a WeakMap is to associate
* an value with an object, the object is the key. And then have
* that value go away when the object does. This is very, very
* similar to properties.
*
* The main difference is that any assigned values are not
* garbage collected if the *weakmap* itself is collected,
* and of course one can actually access the non-enumerable
* property that makes this work.
*/
var weak_property, local_seed = 1;
function SimpleWeakMap() {
var local_property = "weakmap" + local_seed;
local_seed += 1;
if (!weak_property)
weak_property = Math.random().toString(36).slice(2);
var self = this;
self.delete = function delete_(obj) {
var x, map = obj[weak_property];
if (map)
delete map[local_property];
};
self.has = function has(obj) {
var map = obj[weak_property];
return (map && local_property in map);
};
self.get = function get(obj) {
var map = obj[weak_property];
if (!map)
return undefined;
return map[local_property];
};
self.set = function set(obj, value) {
var map = obj[weak_property];
if (!map) {
map = function WeakMapData() { };
Object.defineProperty(obj, weak_property, {
enumerable: false, configurable: false,
writable: false, value: map,
});
}
map[local_property] = value;
};
}
return SimpleWeakMap;
});