mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-16 02:45:46 +01:00
Make .closure a Proxy and rename .bound
This commit is contained in:
@@ -261,11 +261,11 @@ var AddonList = Class("AddonList", {
|
||||
this.addons = {};
|
||||
this.ready = false;
|
||||
|
||||
AddonManager.getAddonsByTypes(types, this.closure(function (addons) {
|
||||
AddonManager.getAddonsByTypes(types, addons => {
|
||||
this._addons = addons;
|
||||
if (this.document)
|
||||
this._init();
|
||||
}));
|
||||
});
|
||||
AddonManager.addAddonListener(this);
|
||||
},
|
||||
cleanup: function cleanup() {
|
||||
@@ -273,7 +273,7 @@ var AddonList = Class("AddonList", {
|
||||
},
|
||||
|
||||
_init: function _init() {
|
||||
this._addons.forEach(this.closure.addAddon);
|
||||
this._addons.forEach(this.bound.addAddon);
|
||||
this.ready = true;
|
||||
this.update();
|
||||
},
|
||||
|
||||
@@ -836,7 +836,10 @@ function Class(...args) {
|
||||
}
|
||||
|
||||
Class.extend(Constructor, superclass, args[0]);
|
||||
memoize(Constructor, "closure", Class.makeClosure);
|
||||
memoize(Constructor, "bound", Class.makeClosure);
|
||||
if (Iter && array) // Hack. :/
|
||||
Object.defineProperty(Constructor, "closure",
|
||||
deprecated("bound", { get: function closure() this.bound }));
|
||||
update(Constructor, args[1]);
|
||||
|
||||
Constructor.__proto__ = superclass;
|
||||
@@ -1086,37 +1089,24 @@ for (let name in properties(Class.prototype)) {
|
||||
Object.defineProperty(Class.prototype, name, desc);
|
||||
}
|
||||
|
||||
Class.makeClosure = function makeClosure() {
|
||||
const self = this;
|
||||
function closure(fn) {
|
||||
function _closure() {
|
||||
try {
|
||||
return fn.apply(self, arguments);
|
||||
}
|
||||
catch (e if !(e instanceof FailedAssertion)) {
|
||||
util.reportError(e);
|
||||
throw e.stack ? e : Error(e);
|
||||
}
|
||||
}
|
||||
_closure.wrapped = fn;
|
||||
return _closure;
|
||||
var closureHooks = {
|
||||
get: function closure_get(target, prop) {
|
||||
if (hasOwnProperty(target._closureCache, prop))
|
||||
return target._closureCache[prop];
|
||||
|
||||
let p = target[prop]
|
||||
if (callable(p))
|
||||
return target._closureCache[prop] = p.bind(target);
|
||||
return p;
|
||||
}
|
||||
|
||||
iter(properties(this), properties(this, true)).forEach(function (k) {
|
||||
if (!__lookupGetter__.call(this, k) && callable(this[k]))
|
||||
closure[k] = closure(this[k]);
|
||||
else if (!(k in closure))
|
||||
Object.defineProperty(closure, k, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function get_proxy() self[k],
|
||||
set: function set_proxy(val) self[k] = val,
|
||||
});
|
||||
}, this);
|
||||
|
||||
return closure;
|
||||
};
|
||||
memoize(Class.prototype, "closure", Class.makeClosure);
|
||||
|
||||
Class.makeClosure = function makeClosure() {
|
||||
this._closureCache = {};
|
||||
|
||||
return new Proxy(this, closureHooks);
|
||||
};
|
||||
memoize(Class.prototype, "bound", Class.makeClosure);
|
||||
|
||||
/**
|
||||
* A base class generator for classes which implement XPCOM interfaces.
|
||||
@@ -1845,6 +1835,9 @@ Object.getOwnPropertyNames(Array.prototype).forEach(function (k) {
|
||||
};
|
||||
});
|
||||
|
||||
Object.defineProperty(Class.prototype, "closure",
|
||||
deprecated("bound", { get: function closure() this.bound }));
|
||||
|
||||
endModule();
|
||||
|
||||
// catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright ©2008-2013 Kris Maglione <maglione.k at Gmail>
|
||||
// Copyright ©2008-2014 Kris Maglione <maglione.k at Gmail>
|
||||
//
|
||||
// This work is licensed for reuse under an MIT license. Details are
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
@@ -160,7 +160,7 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
|
||||
try {
|
||||
return services.bookmarks
|
||||
.getBookmarkIdsForURI(uri, {})
|
||||
.some(this.closure.isRegularBookmark);
|
||||
.some(this.bound.isRegularBookmark);
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
|
||||
@@ -46,7 +46,7 @@ var Buffer = Module("Buffer", {
|
||||
this.win = win;
|
||||
},
|
||||
|
||||
get addPageInfoSection() Buffer.closure.addPageInfoSection,
|
||||
get addPageInfoSection() Buffer.bound.addPageInfoSection,
|
||||
|
||||
get pageInfo() Buffer.pageInfo,
|
||||
|
||||
@@ -2057,7 +2057,7 @@ var Buffer = Module("Buffer", {
|
||||
events: function initEvents(dactyl, modules, window) {
|
||||
let { buffer, config, events } = modules;
|
||||
|
||||
events.listen(config.browser, "scroll", buffer.closure._updateBufferPosition, false);
|
||||
events.listen(config.browser, "scroll", buffer.bound._updateBufferPosition, false);
|
||||
},
|
||||
mappings: function initMappings(dactyl, modules, window) {
|
||||
let { Editor, Events, buffer, editor, events, ex, mappings, modes, options, tabs } = modules;
|
||||
|
||||
@@ -759,7 +759,7 @@ var Commands = Module("commands", {
|
||||
const { commandline, completion } = this.modules;
|
||||
function completerToString(completer) {
|
||||
if (completer)
|
||||
return [k for ([k, v] in Iterator(config.completers)) if (completer == completion.closure[v])][0] || "custom";
|
||||
return [k for ([k, v] in Iterator(config.completers)) if (completer == completion.bound[v])][0] || "custom";
|
||||
return "";
|
||||
}
|
||||
// TODO: allow matching of aliases?
|
||||
@@ -831,9 +831,9 @@ var Commands = Module("commands", {
|
||||
|
||||
return group._add.apply(group, arguments);
|
||||
},
|
||||
addUserCommand: deprecated("group.commands.add", { get: function addUserCommand() this.user.closure._add }),
|
||||
addUserCommand: deprecated("group.commands.add", { get: function addUserCommand() this.user.bound._add }),
|
||||
getUserCommands: deprecated("iter(group.commands)", function getUserCommands() iter(this.user).toArray()),
|
||||
removeUserCommand: deprecated("group.commands.remove", { get: function removeUserCommand() this.user.closure.remove }),
|
||||
removeUserCommand: deprecated("group.commands.remove", { get: function removeUserCommand() this.user.bound.remove }),
|
||||
|
||||
/**
|
||||
* Returns the specified command invocation object serialized to
|
||||
@@ -1546,7 +1546,7 @@ var Commands = Module("commands", {
|
||||
function (args) {
|
||||
let cmd = args[0];
|
||||
|
||||
util.assert(!cmd || cmd.split(",").every(commands.validName.closure.test),
|
||||
util.assert(!cmd || cmd.split(",").every(commands.validName.bound.test),
|
||||
_("command.invalidName", cmd));
|
||||
|
||||
if (args.length <= 1)
|
||||
@@ -1576,7 +1576,7 @@ var Commands = Module("commands", {
|
||||
};
|
||||
}
|
||||
else
|
||||
completerFunc = context => modules.completion.closure[config.completers[completer]](context);
|
||||
completerFunc = context => modules.completion.bound[config.completers[completer]](context);
|
||||
}
|
||||
|
||||
let added = args["-group"].add(cmd.split(","),
|
||||
|
||||
@@ -43,14 +43,14 @@ var Group = Class("Group", {
|
||||
delete this[hive];
|
||||
|
||||
if (reason != "shutdown")
|
||||
this.children.splice(0).forEach(this.contexts.closure.removeGroup);
|
||||
this.children.splice(0).forEach(this.contexts.bound.removeGroup);
|
||||
},
|
||||
destroy: function destroy(reason) {
|
||||
for (let hive in values(this.hives))
|
||||
util.trapErrors("destroy", hive);
|
||||
|
||||
if (reason != "shutdown")
|
||||
this.children.splice(0).forEach(this.contexts.closure.removeGroup);
|
||||
this.children.splice(0).forEach(this.contexts.bound.removeGroup);
|
||||
},
|
||||
|
||||
argsExtra: function argsExtra() ({}),
|
||||
|
||||
@@ -1092,7 +1092,7 @@ var DOM = Class("DOM", {
|
||||
* @returns {string} Canonical form.
|
||||
*/
|
||||
canonicalKeys: function canonicalKeys(keys, unknownOk=true) {
|
||||
return this.parse(keys, unknownOk).map(this.closure.stringify).join("");
|
||||
return this.parse(keys, unknownOk).map(this.bound.stringify).join("");
|
||||
},
|
||||
|
||||
iterKeys: function iterKeys(keys) iter(function () {
|
||||
@@ -1480,7 +1480,7 @@ var DOM = Class("DOM", {
|
||||
* @returns {boolean} True when the patterns are all valid.
|
||||
*/
|
||||
validateMatcher: function validateMatcher(list) {
|
||||
return this.testValues(list, DOM.closure.testMatcher);
|
||||
return this.testValues(list, DOM.bound.testMatcher);
|
||||
},
|
||||
|
||||
testMatcher: function testMatcher(value) {
|
||||
|
||||
@@ -253,10 +253,10 @@ var RangeFinder = Module("rangefinder", {
|
||||
|
||||
get prompt() this.mode === modules.modes.FIND_BACKWARD ? "?" : "/",
|
||||
|
||||
get onCancel() modules.rangefinder.closure.onCancel,
|
||||
get onChange() modules.rangefinder.closure.onChange,
|
||||
get onHistory() modules.rangefinder.closure.onHistory,
|
||||
get onSubmit() modules.rangefinder.closure.onSubmit
|
||||
get onCancel() modules.rangefinder.bound.onCancel,
|
||||
get onChange() modules.rangefinder.bound.onChange,
|
||||
get onHistory() modules.rangefinder.bound.onHistory,
|
||||
get onSubmit() modules.rangefinder.bound.onSubmit
|
||||
});
|
||||
},
|
||||
mappings: function initMappings(dactyl, modules, window) {
|
||||
@@ -707,12 +707,12 @@ var RangeFind = Class("RangeFind", {
|
||||
|
||||
addListeners: function addListeners() {
|
||||
for (let range in array.iterValues(this.ranges))
|
||||
range.window.addEventListener("unload", this.closure.onUnload, true);
|
||||
range.window.addEventListener("unload", this.bound.onUnload, true);
|
||||
},
|
||||
purgeListeners: function purgeListeners() {
|
||||
for (let range in array.iterValues(this.ranges))
|
||||
try {
|
||||
range.window.removeEventListener("unload", this.closure.onUnload, true);
|
||||
range.window.removeEventListener("unload", this.bound.onUnload, true);
|
||||
}
|
||||
catch (e if e.result === Cr.NS_ERROR_FAILURE) {}
|
||||
},
|
||||
|
||||
@@ -489,7 +489,7 @@ var IO = Module("io", {
|
||||
system: function system(command, input, callback) {
|
||||
util.dactyl.echomsg(_("io.callingShell", command), 4);
|
||||
|
||||
let { shellEscape } = util.closure;
|
||||
let { shellEscape } = util.bound;
|
||||
|
||||
return this.withTempFiles(function (stdin, stdout, cmd) {
|
||||
if (input instanceof File)
|
||||
|
||||
@@ -463,7 +463,7 @@ var JavaScript = Module("javascript", {
|
||||
}
|
||||
|
||||
this.context.getCache("evalled", Object);
|
||||
this.context.getCache("evalContext", this.closure.newContext);
|
||||
this.context.getCache("evalContext", this.bound.newContext);
|
||||
|
||||
// Okay, have parse stack. Figure out what we're completing.
|
||||
|
||||
@@ -693,7 +693,7 @@ var JavaScript = Module("javascript", {
|
||||
completion: function (dactyl, modules, window) {
|
||||
const { completion } = modules;
|
||||
update(modules.completion, {
|
||||
get javascript() modules.javascript.closure.complete,
|
||||
get javascript() modules.javascript.bound.complete,
|
||||
javascriptCompleter: JavaScript // Backwards compatibility
|
||||
});
|
||||
},
|
||||
|
||||
@@ -291,7 +291,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
* @param {string} branch The preference name. @optional
|
||||
*/
|
||||
resetBranch: function resetBranch(branch) {
|
||||
this.getNames(branch).forEach(this.closure.reset);
|
||||
this.getNames(branch).forEach(this.bound.reset);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -558,7 +558,7 @@ var Styles = Module("Styles", {
|
||||
let uris = util.visibleURIs(window.content);
|
||||
context.compare = modules.CompletionContext.Sort.number;
|
||||
context.generate = () => args["-group"].sheets;
|
||||
context.keys.active = sheet => uris.some(sheet.closure.match);
|
||||
context.keys.active = sheet => uris.some(sheet.bound.match);
|
||||
context.keys.description = sheet => [sheet.formatSites(uris), ": ", sheet.css.replace("\n", "\\n")];
|
||||
if (filter)
|
||||
context.filters.push(({ item }) => filter(item));
|
||||
|
||||
@@ -144,7 +144,7 @@ var Template = Module("Template", {
|
||||
events["dactyl-input"] = events["input"];
|
||||
|
||||
for (let [event, handler] in Iterator(events))
|
||||
node.addEventListener(event, util.wrapCallback(obj.closure(handler), true), false);
|
||||
node.addEventListener(event, util.wrapCallback(handler.bind(obj), true), false);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@@ -72,8 +72,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
},
|
||||
|
||||
activeWindow: deprecated("overlay.activeWindow", { get: function activeWindow() overlay.activeWindow }),
|
||||
overlayObject: deprecated("overlay.overlayObject", { get: function overlayObject() overlay.closure.overlayObject }),
|
||||
overlayWindow: deprecated("overlay.overlayWindow", { get: function overlayWindow() overlay.closure.overlayWindow }),
|
||||
overlayObject: deprecated("overlay.overlayObject", { get: function overlayObject() overlay.bound.overlayObject }),
|
||||
overlayWindow: deprecated("overlay.overlayWindow", { get: function overlayWindow() overlay.bound.overlayWindow }),
|
||||
|
||||
compileMatcher: deprecated("DOM.compileMatcher", { get: function compileMatcher() DOM.compileMatcher }),
|
||||
computedStyle: deprecated("DOM#style", function computedStyle(elem) DOM(elem).style),
|
||||
@@ -95,7 +95,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
readFromClipboard: deprecated("dactyl.clipboardRead", function readFromClipboard() util.dactyl.clipboardRead(false)),
|
||||
|
||||
chromePackages: deprecated("config.chromePackages", { get: function chromePackages() config.chromePackages }),
|
||||
haveGecko: deprecated("config.haveGecko", { get: function haveGecko() config.closure.haveGecko }),
|
||||
haveGecko: deprecated("config.haveGecko", { get: function haveGecko() config.bound.haveGecko }),
|
||||
OS: deprecated("config.OS", { get: function OS() config.OS }),
|
||||
|
||||
dactyl: update(function dactyl(obj) {
|
||||
@@ -1280,7 +1280,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
}
|
||||
|
||||
let res = update(RegExp(expr, flags.replace("x", "")), {
|
||||
closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "closure")),
|
||||
bound: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "bound")),
|
||||
closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "bound")),
|
||||
dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"],
|
||||
iterate: function iterate(str, idx) util.regexp.iterate(this, str, idx)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user