diff options
Diffstat (limited to 'common/modules')
-rw-r--r-- | common/modules/base.jsm | 4 | ||||
-rw-r--r-- | common/modules/services.jsm | 1 | ||||
-rw-r--r-- | common/modules/storage.jsm | 23 | ||||
-rw-r--r-- | common/modules/util.jsm | 4 |
4 files changed, 18 insertions, 14 deletions
diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 7d9e03a6..97076991 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -391,9 +391,7 @@ function iter(obj) { if (obj.constructor instanceof ctypes.StructType) return (function () { for (let prop in values(obj.constructor.fields)) - let ([name, type] = Iterator(prop).next()) { - yield [name, obj[name]]; - } + yield let ([name, type] = Iterator(prop).next()) [name, obj[name]]; })(); obj = {}; } diff --git a/common/modules/services.jsm b/common/modules/services.jsm index 6591e73f..1e72ccfb 100644 --- a/common/modules/services.jsm +++ b/common/modules/services.jsm @@ -39,6 +39,7 @@ const Services = Module("Services", { this.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService); this.add("json", "@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance"); this.add("livemark", "@mozilla.org/browser/livemark-service;2", Ci.nsILivemarkService); + this.add("mime", "@mozilla.org/mime;1", Ci.nsIMIMEService); this.add("observer", "@mozilla.org/observer-service;1", Ci.nsIObserverService); this.add("pref", "@mozilla.org/preferences-service;1", [Ci.nsIPrefBranch2, Ci.nsIPrefService]); this.add("privateBrowsing", "@mozilla.org/privatebrowsing;1", Ci.nsIPrivateBrowsingService); diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 5ebe36e5..c7d6f6d9 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -18,10 +18,8 @@ const win32 = /^win(32|nt)$/i.test(services.runtime.OS); function loadData(name, store, type) { try { - if (storage.infoPath) - var file = storage.infoPath.child(name).read(); - if (file) - var result = services.json.decode(file); + let data = storage.infoPath.child(name).read(); + let result = JSON.parse(data); if (result instanceof type) return result; } @@ -37,8 +35,11 @@ function saveData(obj) { const StoreBase = Class("StoreBase", { OPTIONS: ["privateData", "replacer"], + fireEvent: function (event, arg) { storage.fireEvent(this.name, event, arg); }, + get serial() JSON.stringify(this._object, this.replacer), + init: function (name, store, load, options) { this._load = load; @@ -49,11 +50,14 @@ const StoreBase = Class("StoreBase", { this[k] = v; this.reload(); }, + changed: function () { this.timer.tell() }, + reload: function reload() { this._object = this._load() || this._constructor(); this.fireEvent("change", null); }, + save: function () { saveData(this); }, }); @@ -205,8 +209,8 @@ const Storage = Module("Storage", { fireEvent: function fireEvent(key, event, arg) { this.removeDeadObservers(); - // Safe, since we have our own Array object here. if (key in observers) + // Safe, since we have our own Array object here. for each (let observer in observers[key]) observer.callback.get()(key, event, arg); if (key in keys) @@ -481,12 +485,11 @@ const File = Class("File", { /** * @property {string} The current platform's path separator. */ - get PATH_SEP() { - delete this.PATH_SEP; + PATH_SEP: Class.memoize(function () { let f = services.directory.get("CurProcD", Ci.nsIFile); f.append("foo"); - return this.PATH_SEP = f.path.substr(f.parent.path.length, 1); - }, + return f.path.substr(f.parent.path.length, 1); + }), DoesNotExist: function (error) ({ exists: function () false, @@ -544,7 +547,7 @@ const File = Class("File", { joinPaths: function (head, tail, cwd) { let path = this(head, cwd); try { - // FIXME: should only expand env vars and normalise path separators + // FIXME: should only expand environment vars and normalize path separators path.appendRelativePath(this.expandPath(tail, true)); } catch (e) { diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 9c208074..7f427d21 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -501,7 +501,9 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) /** @property {boolean} True if the OS is Mac OS X. */ get isMacOSX() this._arch == "Darwin", /** @property {boolean} True if the OS is some other *nix variant. */ - get isUnix() !this.isWindows && !this.isMacOSX + get isUnix() !this.isWindows && !this.isMacOSX, + /** @property {RegExp} A RegExp which matches illegal characters in path components. */ + get illegalCharacters() this.isWindows ? /[<>:"/\\|?*\x00-\x1f]/ : /\// }, /** |