1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-29 04:42:27 +01:00

WeakMaps ftw.

This commit is contained in:
Kris Maglione
2012-10-21 17:49:24 -07:00
parent 88b3f6c835
commit 7d28f98ade

View File

@@ -48,6 +48,8 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
util.addObserver(this);
this.overlays = {};
this.weakMap = WeakMap();
this.onWindowVisible = [];
},
@@ -153,30 +155,28 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
},
getData: function getData(obj, key, constructor) {
let { id } = this;
if (!(id in obj && obj[id]))
obj[id] = {};
if (!this.weakMap.has(obj))
this.weakMap.set(obj, {});
let data = this.weakMap.get(obj);
if (arguments.length == 1)
return obj[id];
return data;
if (obj[id][key] === undefined)
if (data[key] === undefined)
if (constructor === undefined || callable(constructor))
obj[id][key] = (constructor || Array)();
data[key] = (constructor || Array)();
else
obj[id][key] = constructor;
data[key] = constructor;
return obj[id][key];
return data[key];
},
setData: function setData(obj, key, val) {
let { id } = this;
let data = this.getData(obj);
if (!(id in obj))
obj[id] = {};
return obj[id][key] = val;
return data[key] = val;
},
overlayWindow: function (url, fn) {