mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-23 21:05:46 +01:00
Fix config.addon bug and augment Class.memoize somewhat.
This commit is contained in:
@@ -523,9 +523,11 @@ function memoize(obj, key, getter) {
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
obj.__defineGetter__(key, function g_replaceProperty() (
|
||||
Class.replaceProperty(this.instance || this, key, null),
|
||||
Class.replaceProperty(this.instance || this, key, getter.call(this, key))));
|
||||
|
||||
obj.__defineSetter__(key, function s_replaceProperty(val)
|
||||
Class.replaceProperty(this.instance || this, key, val));
|
||||
}
|
||||
@@ -765,14 +767,33 @@ Class.extend = function extend(subclass, superclass, overrides) {
|
||||
* property's value.
|
||||
* @return {Class.Property}
|
||||
*/
|
||||
Class.memoize = function memoize(getter)
|
||||
Class.memoize = function memoize(getter, wait)
|
||||
Class.Property({
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
init: function (key) {
|
||||
this.get = function replace() let (obj = this.instance || this) (
|
||||
Class.replaceProperty(obj, key, null),
|
||||
Class.replaceProperty(obj, key, getter.call(this, key)))
|
||||
let done = false;
|
||||
let prop = { configurable: true, enumerable: true, value: null, writable: true };
|
||||
if (wait)
|
||||
prop = {
|
||||
configurable: true, enumerable: false,
|
||||
get: function get() {
|
||||
util.waitFor(function () done);
|
||||
return this[key];
|
||||
}
|
||||
}
|
||||
|
||||
this.get = function replace() {
|
||||
let obj = this.instance || this;
|
||||
Object.defineProperty(obj, key, prop);
|
||||
try {
|
||||
return Class.replaceProperty(obj, key, getter.call(this, key));
|
||||
}
|
||||
finally {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
this.set = function replace(val) Class.replaceProperty(this.instance || this, val);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -61,13 +61,13 @@ var ConfigBase = Class("ConfigBase", {
|
||||
if (addon && !addon.getResourceURI)
|
||||
util.reportError(Error("Don't have add-on yet"));
|
||||
|
||||
return !addon || addon.getResourceURI();
|
||||
return !addon || addon.getResourceURI;
|
||||
});
|
||||
|
||||
if (!addon)
|
||||
addon = require("addons").AddonManager.getAddonByID(this.addonID);
|
||||
return addon;
|
||||
}),
|
||||
}, true),
|
||||
|
||||
/**
|
||||
* The current application locale.
|
||||
|
||||
Reference in New Issue
Block a user