1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-01 15:15:52 +01:00

[PWPBM] Magic.

This commit is contained in:
Kris Maglione
2013-04-26 20:46:14 -07:00
parent fc11842f5d
commit a06e8f278d

View File

@@ -246,19 +246,27 @@ var Storage = Module("Storage", {
if (params == null || !isObject(params)) if (params == null || !isObject(params))
throw Error("Invalid argument type"); throw Error("Invalid argument type");
if (!(key in this.keys) && this.privateMode && key in this.globalInstance.keys) { if (this.isLocalModule) {
let obj = this.globalInstance.keys[key]; this.globalInstance.newObject.apply(this.globalInstance, arguments);
this.keys[key] = obj.clone ? obj.clone(this) : obj;
if (!(key in this.keys) && this.privateMode && key in this.globalInstance.keys) {
let obj = this.globalInstance.keys[key];
this.keys[key] = this._privatize(obj);
}
return this.keys[key];
} }
if (!(key in this.keys) || params.reload || this.alwaysReload[key]) { let reload = params.reload || this.alwaysReload[key];
if (key in this && !(params.reload || this.alwaysReload[key])) if (!(key in this.keys) || reload) {
throw Error("WTF? Hm..."); if (key in this && !reload)
throw Error("Cannot add storage key with that name.");
let load = function () self._loadData(key, params.store, params.type || myObject); let load = function () self._loadData(key, params.store, params.type || myObject);
this.keys[key] = new constructor(key, params.store, load, params); this.keys[key] = new constructor(key, params.store, load, params);
this.keys[key].timer = new Timer(1000, 10000, function () storage.save(key)); this.keys[key].timer = new Timer(1000, 10000, function () self.save(key));
this.globalInstance.__defineGetter__(key, function () this.keys[key]); this.__defineGetter__(key, function () this.keys[key]);
} }
return this.keys[key]; return this.keys[key];
}, },
@@ -319,11 +327,13 @@ var Storage = Module("Storage", {
fireEvent: function fireEvent(key, event, arg) { fireEvent: function fireEvent(key, event, arg) {
this.removeDeadObservers(); this.removeDeadObservers();
if (key in this.observers) if (key in this.observers)
// Safe, since we have our own Array object here. // Safe, since we have our own Array object here.
for each (let observer in this.observers[key]) for each (let observer in this.observers[key])
observer.callback.get()(key, event, arg); observer.callback.get()(key, event, arg);
if (key in this.keys)
if (key in this.keys && this.keys[key].timer)
this[key].timer.tell(); this[key].timer.tell();
}, },
@@ -356,11 +366,17 @@ var Storage = Module("Storage", {
let { keys } = this; let { keys } = this;
this.keys = {}; this.keys = {};
for (let [k, v] in Iterator(keys)) for (let [k, v] in Iterator(keys))
this.keys[k] = v.clone ? v.clone(this) : v; this.keys[k] = this._privatize(v);
} }
} }
return this._privateMode; return this._privateMode;
} },
_privatize: function privatize(obj) {
if (obj.privateData && obj.clone)
return obj.clone(this);
return obj;
},
}, { }, {
Replacer: { Replacer: {
skipXpcom: function skipXpcom(key, val) val instanceof Ci.nsISupports ? null : val skipXpcom: function skipXpcom(key, val) val instanceof Ci.nsISupports ? null : val