1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-12 19:55:46 +01:00
This commit is contained in:
Kris Maglione
2011-09-29 17:57:55 -04:00
parent 06e89e84d2
commit acd13342a4
4 changed files with 37 additions and 13 deletions

View File

@@ -145,7 +145,7 @@ function defineModule(name, params, module) {
defineModule.prefix += " "; defineModule.prefix += " ";
for (let [, mod] in Iterator(params.require || [])) for (let [, mod] in Iterator(params.require || []))
require(jsmodules, mod, null, name); require(module, mod, null, name);
module.__proto__ = jsmodules; module.__proto__ = jsmodules;
module._lastModule = currentModule; module._lastModule = currentModule;
@@ -210,6 +210,10 @@ function require(obj, name, from, targetName) {
" into " + (targetName || obj.NAME || caller.filename + ":" + caller.lineNumber)); " into " + (targetName || obj.NAME || caller.filename + ":" + caller.lineNumber));
JSMLoader.load(name + ".jsm", obj); JSMLoader.load(name + ".jsm", obj);
if (!loaded[name] && obj != jsmodules)
JSMLoader.load(name + ".jsm", jsmodules);
return obj; return obj;
} }
catch (e) { catch (e) {
@@ -235,6 +239,7 @@ defineModule("base", {
}, this); }, this);
this.lazyRequire("messages", ["_", "Messages"]); this.lazyRequire("messages", ["_", "Messages"]);
this.lazyRequire("util", ["util"]);
/** /**
* Returns a list of all of the top-level properties of an object, by * Returns a list of all of the top-level properties of an object, by
@@ -627,9 +632,15 @@ function memoize(obj, key, getter) {
configurable: true, configurable: true,
enumerable: true, enumerable: true,
get: function g_replaceProperty() ( get: function g_replaceProperty() {
Class.replaceProperty(this.instance || this, key, null), try {
Class.replaceProperty(this.instance || this, key, getter.call(this, key))), Class.replaceProperty(this.instance || this, key, null);
return Class.replaceProperty(this.instance || this, key, getter.call(this, key));
}
catch (e) {
util.reportError(e);
}
},
set: function s_replaceProperty(val) set: function s_replaceProperty(val)
Class.replaceProperty(this.instance || this, key, val) Class.replaceProperty(this.instance || this, key, val)
@@ -881,8 +892,13 @@ Class.Memoize = function Memoize(getter, wait)
else else
this.get = function replace() { this.get = function replace() {
let obj = this.instance || this; let obj = this.instance || this;
Class.replaceProperty(obj, key, null); try {
return Class.replaceProperty(obj, key, getter.call(this, key)); Class.replaceProperty(obj, key, null);
return Class.replaceProperty(obj, key, getter.call(this, key));
}
catch (e) {
util.reportError(e);
}
}; };
this.set = function replace(val) Class.replaceProperty(this.instance || this, val); this.set = function replace(val) Class.replaceProperty(this.instance || this, val);

View File

@@ -15,6 +15,8 @@ defineModule("io", {
require: ["services"] require: ["services"]
}, this); }, this);
this.lazyRequire("config", ["config"]);
// TODO: why are we passing around strings rather than file objects? // TODO: why are we passing around strings rather than file objects?
/** /**
* Provides a basic interface to common system I/O operations. * Provides a basic interface to common system I/O operations.

View File

@@ -7,9 +7,10 @@
Components.utils.import("resource://dactyl/bootstrap.jsm"); Components.utils.import("resource://dactyl/bootstrap.jsm");
defineModule("storage", { defineModule("storage", {
exports: ["File", "Storage", "storage"], exports: ["File", "Storage", "storage"],
require: ["config", "services", "util"] require: ["services", "util"]
}, this); }, this);
this.lazyRequire("config", ["config"]);
this.lazyRequire("io", ["IO"]); this.lazyRequire("io", ["IO"]);
var win32 = /^win(32|nt)$/i.test(services.runtime.OS); var win32 = /^win(32|nt)$/i.test(services.runtime.OS);
@@ -17,12 +18,17 @@ var myObject = JSON.parse("{}").constructor;
function loadData(name, store, type) { function loadData(name, store, type) {
try { try {
let data = storage.infoPath.child(name).read(); let file = storage.infoPath.child(name);
let result = JSON.parse(data); if (file.exists()) {
if (result instanceof type) let data = file.read();
return result; let result = JSON.parse(data);
if (result instanceof type)
return result;
}
}
catch (e) {
util.reportError(e);
} }
catch (e) {}
} }
function saveData(obj) { function saveData(obj) {

View File

@@ -1476,7 +1476,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
return func.apply(self || this, Array.slice(arguments, 2)); return func.apply(self || this, Array.slice(arguments, 2));
} }
catch (e) { catch (e) {
util.reportError(e); this.reportError(e);
return undefined; return undefined;
} }
}, },