summaryrefslogtreecommitdiff
path: root/common/modules/storage.jsm
diff options
context:
space:
mode:
authorKris Maglione <maglione.k@gmail.com>2013-04-26 20:46:14 -0700
committerKris Maglione <maglione.k@gmail.com>2013-04-26 20:46:14 -0700
commita06e8f278de0d8a91e034a0471c1bd5f10c01b2e (patch)
tree61d0b5b61301a54a447cb31b6c8002dfa30e84c8 /common/modules/storage.jsm
parentfc11842f5ded88b210905ee1eae3fad45ae5e6cc (diff)
downloadpentadactyl-a06e8f278de0d8a91e034a0471c1bd5f10c01b2e.tar.gz
[PWPBM] Magic.
Diffstat (limited to 'common/modules/storage.jsm')
-rw-r--r--common/modules/storage.jsm38
1 files changed, 27 insertions, 11 deletions
diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm
index be31428d..f4de771f 100644
--- a/common/modules/storage.jsm
+++ b/common/modules/storage.jsm
@@ -246,19 +246,27 @@ var Storage = Module("Storage", {
if (params == null || !isObject(params))
throw Error("Invalid argument type");
- if (!(key in this.keys) && this.privateMode && key in this.globalInstance.keys) {
- let obj = this.globalInstance.keys[key];
- this.keys[key] = obj.clone ? obj.clone(this) : obj;
+ if (this.isLocalModule) {
+ this.globalInstance.newObject.apply(this.globalInstance, arguments);
+
+ 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]) {
- if (key in this && !(params.reload || this.alwaysReload[key]))
- throw Error("WTF? Hm...");
+ let reload = params.reload || this.alwaysReload[key];
+ if (!(key in this.keys) || reload) {
+ 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);
this.keys[key] = new constructor(key, params.store, load, params);
- this.keys[key].timer = new Timer(1000, 10000, function () storage.save(key));
- this.globalInstance.__defineGetter__(key, function () this.keys[key]);
+ this.keys[key].timer = new Timer(1000, 10000, function () self.save(key));
+ this.__defineGetter__(key, function () this.keys[key]);
}
return this.keys[key];
},
@@ -319,11 +327,13 @@ var Storage = Module("Storage", {
fireEvent: function fireEvent(key, event, arg) {
this.removeDeadObservers();
+
if (key in this.observers)
// Safe, since we have our own Array object here.
for each (let observer in this.observers[key])
observer.callback.get()(key, event, arg);
- if (key in this.keys)
+
+ if (key in this.keys && this.keys[key].timer)
this[key].timer.tell();
},
@@ -356,11 +366,17 @@ var Storage = Module("Storage", {
let { keys } = this;
this.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;
- }
+ },
+
+ _privatize: function privatize(obj) {
+ if (obj.privateData && obj.clone)
+ return obj.clone(this);
+ return obj;
+ },
}, {
Replacer: {
skipXpcom: function skipXpcom(key, val) val instanceof Ci.nsISupports ? null : val