mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-10 06:05:54 +01:00
Make .closure a Proxy and rename .bound
This commit is contained in:
@@ -233,10 +233,10 @@ var Abbreviations = Module("abbreviations", {
|
||||
|
||||
get userHives() this.allHives.filter(h => h !== this.builtin),
|
||||
|
||||
get: deprecated("group.abbrevs.get", { get: function get() this.user.closure.get }),
|
||||
set: deprecated("group.abbrevs.set", { get: function set() this.user.closure.set }),
|
||||
remove: deprecated("group.abbrevs.remove", { get: function remove() this.user.closure.remove }),
|
||||
removeAll: deprecated("group.abbrevs.clear", { get: function removeAll() this.user.closure.clear }),
|
||||
get: deprecated("group.abbrevs.get", { get: function get() this.user.bound.get }),
|
||||
set: deprecated("group.abbrevs.set", { get: function set() this.user.bound.set }),
|
||||
remove: deprecated("group.abbrevs.remove", { get: function remove() this.user.bound.remove }),
|
||||
removeAll: deprecated("group.abbrevs.clear", { get: function removeAll() this.user.bound.clear }),
|
||||
|
||||
/**
|
||||
* Returns the abbreviation for the given *mode* if *text* matches the
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
|
||||
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
|
||||
// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
|
||||
// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
|
||||
//
|
||||
// This work is licensed for reuse under an MIT license. Details are
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
@@ -77,9 +77,9 @@ var AutoCommands = Module("autocommands", {
|
||||
|
||||
get activeHives() contexts.allGroups.autocmd.filter(h => h._store.length),
|
||||
|
||||
add: deprecated("group.autocmd.add", { get: function add() autocommands.user.closure.add }),
|
||||
get: deprecated("group.autocmd.get", { get: function get() autocommands.user.closure.get }),
|
||||
remove: deprecated("group.autocmd.remove", { get: function remove() autocommands.user.closure.remove }),
|
||||
add: deprecated("group.autocmd.add", { get: function add() autocommands.user.bound.add }),
|
||||
get: deprecated("group.autocmd.get", { get: function get() autocommands.user.bound.get }),
|
||||
remove: deprecated("group.autocmd.remove", { get: function remove() autocommands.user.bound.remove }),
|
||||
|
||||
/**
|
||||
* Lists all autocommands with a matching *event*, *regexp* and optionally
|
||||
|
||||
@@ -172,7 +172,7 @@ var Bookmarks = Module("bookmarks", {
|
||||
}
|
||||
},
|
||||
|
||||
isBookmarked: deprecated("bookmarkcache.isBookmarked", { get: function isBookmarked() bookmarkcache.closure.isBookmarked }),
|
||||
isBookmarked: deprecated("bookmarkcache.isBookmarked", { get: function isBookmarked() bookmarkcache.bound.isBookmarked }),
|
||||
|
||||
/**
|
||||
* Remove a bookmark or bookmarks. If *ids* is an array, removes the
|
||||
@@ -189,7 +189,7 @@ var Bookmarks = Module("bookmarks", {
|
||||
let uri = util.newURI(ids);
|
||||
ids = services.bookmarks
|
||||
.getBookmarkIdsForURI(uri, {})
|
||||
.filter(bookmarkcache.closure.isRegularBookmark);
|
||||
.filter(bookmarkcache.bound.isRegularBookmark);
|
||||
}
|
||||
ids.forEach(function (id) {
|
||||
let bmark = bookmarkcache.bookmarks[id];
|
||||
|
||||
@@ -341,7 +341,7 @@ var CommandMode = Class("CommandMode", {
|
||||
false);
|
||||
|
||||
this.messageCount = commandline.messageCount;
|
||||
modes.push(this.mode, this.extendedMode, this.closure);
|
||||
modes.push(this.mode, this.extendedMode, this.bound);
|
||||
|
||||
this.widgets.active.commandline.collapsed = false;
|
||||
this.widgets.prompt = this.prompt;
|
||||
@@ -791,7 +791,7 @@ var CommandLine = Module("commandline", {
|
||||
let action = this._echoLine;
|
||||
|
||||
if ((flags & this.FORCE_MULTILINE) || (/\n/.test(data) || !isinstance(data, [_, "String"])) && !(flags & this.FORCE_SINGLELINE))
|
||||
action = mow.closure.echo;
|
||||
action = mow.bound.echo;
|
||||
|
||||
let checkSingleLine = () => action == this._echoLine;
|
||||
|
||||
@@ -803,7 +803,7 @@ var CommandLine = Module("commandline", {
|
||||
// So complicated...
|
||||
if (checkSingleLine() && !this.widgets.mowContainer.collapsed) {
|
||||
highlightGroup += " Message";
|
||||
action = mow.closure.echo;
|
||||
action = mow.bound.echo;
|
||||
}
|
||||
else if (!checkSingleLine() && this.widgets.mowContainer.collapsed) {
|
||||
if (this._lastEcho && this.widgets.message && this.widgets.message[1] == this._lastEcho.msg) {
|
||||
@@ -1113,7 +1113,7 @@ var CommandLine = Module("commandline", {
|
||||
this.itemList = commandline.completionList;
|
||||
this.itemList.open(this.context);
|
||||
|
||||
dactyl.registerObserver("events.doneFeeding", this.closure.onDoneFeeding, true);
|
||||
dactyl.registerObserver("events.doneFeeding", this.bound.onDoneFeeding, true);
|
||||
|
||||
this.autocompleteTimer = Timer(200, 500, function autocompleteTell(tabPressed) {
|
||||
if (events.feedingKeys && !tabPressed)
|
||||
@@ -1246,7 +1246,7 @@ var CommandLine = Module("commandline", {
|
||||
* called.
|
||||
*/
|
||||
cleanup: function cleanup() {
|
||||
dactyl.unregisterObserver("events.doneFeeding", this.closure.onDoneFeeding);
|
||||
dactyl.unregisterObserver("events.doneFeeding", this.bound.onDoneFeeding);
|
||||
this.previewClear();
|
||||
|
||||
this.tabTimer.reset();
|
||||
@@ -1945,7 +1945,7 @@ var ItemList = Class("ItemList", {
|
||||
this.resize(flags);
|
||||
}, this);
|
||||
|
||||
DOM(this.win).resize(this._onResize.closure.tell);
|
||||
DOM(this.win).resize(this._onResize.bound.tell);
|
||||
},
|
||||
|
||||
get rootXML()
|
||||
@@ -2397,8 +2397,8 @@ var ItemList = Class("ItemList", {
|
||||
first = row;
|
||||
|
||||
let container = DOM(this.nodes.items);
|
||||
let before = first ? DOM(first).closure.before
|
||||
: DOM(this.nodes.items).closure.append;
|
||||
let before = first ? DOM(first).bound.before
|
||||
: DOM(this.nodes.items).bound.append;
|
||||
|
||||
for (let [i, row] in this.context.getRows(range.start, range.end,
|
||||
this.doc)) {
|
||||
|
||||
@@ -206,7 +206,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
|
||||
registerObservers: function registerObservers(obj, prop) {
|
||||
for (let [signal, func] in Iterator(obj[prop || "signals"]))
|
||||
this.registerObserver(signal, obj.closure(func), false);
|
||||
this.registerObserver(signal, func.bind(obj), false);
|
||||
},
|
||||
|
||||
unregisterObserver: function unregisterObserver(type, callback) {
|
||||
@@ -241,7 +241,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
let filters = args.map(arg => let (re = util.regexp.escape(arg))
|
||||
util.regexp("\\b" + re + "\\b|(?:^|[()\\s])" + re + "(?:$|[()\\s])", "i"));
|
||||
if (filters.length)
|
||||
results = results.filter(item => filters.every(re => keys(item).some(re.closure.test)));
|
||||
results = results.filter(item => filters.every(re => keys(item).some(re.bound.test)));
|
||||
|
||||
commandline.commandOutput(
|
||||
template.usage(results, params.format));
|
||||
@@ -377,9 +377,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
},
|
||||
|
||||
dump: deprecated("util.dump",
|
||||
{ get: function dump() util.closure.dump }),
|
||||
{ get: function dump() util.bound.dump }),
|
||||
dumpStack: deprecated("util.dumpStack",
|
||||
{ get: function dumpStack() util.closure.dumpStack }),
|
||||
{ get: function dumpStack() util.bound.dumpStack }),
|
||||
|
||||
/**
|
||||
* Outputs a plain message to the command line.
|
||||
@@ -627,8 +627,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
}
|
||||
},
|
||||
|
||||
help: deprecated("help.help", { get: function help() modules.help.closure.help }),
|
||||
findHelp: deprecated("help.findHelp", { get: function findHelp() help.closure.findHelp }),
|
||||
help: deprecated("help.help", { get: function help() modules.help.bound.help }),
|
||||
findHelp: deprecated("help.findHelp", { get: function findHelp() help.bound.findHelp }),
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -724,7 +724,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
}
|
||||
|
||||
if (obj.completer && false)
|
||||
add(completion._runCompleter(obj.closure.completer, "", null, args).items
|
||||
add(completion._runCompleter(obj.bound.completer, "", null, args).items
|
||||
.map(i => [i.text, i.description]));
|
||||
|
||||
if (obj.options && obj.options.some(o => o.description) && false)
|
||||
|
||||
@@ -765,7 +765,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
|
||||
completion: function initCompletion() {
|
||||
completion.register = function complete_register(context) {
|
||||
context = context.fork("registers");
|
||||
context.keys = { text: util.identity, description: editor.closure.getRegister };
|
||||
context.keys = { text: util.identity, description: editor.bound.getRegister };
|
||||
|
||||
context.match = function (r) !this.filter || this.filter.contains(r);
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ var EventHive = Class("EventHive", Contexts.Hive, {
|
||||
});
|
||||
},
|
||||
|
||||
get wrapListener() events.closure.wrapListener
|
||||
get wrapListener() events.bound.wrapListener
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -107,9 +107,9 @@ var Events = Module("events", {
|
||||
["window", { id: document.documentElement.id, xmlns: "xul" },
|
||||
// http://developer.mozilla.org/en/docs/XUL_Tutorial:Updating_Commands
|
||||
["commandset", { id: "dactyl-onfocus", commandupdater: "true", events: "focus",
|
||||
commandupdate: this.closure.onFocusChange }],
|
||||
commandupdate: this.bound.onFocusChange }],
|
||||
["commandset", { id: "dactyl-onselect", commandupdater: "true", events: "select",
|
||||
commandupdate: this.closure.onSelectionChange }]]]
|
||||
commandupdate: this.bound.onSelectionChange }]]]
|
||||
});
|
||||
|
||||
this._fullscreen = window.fullScreen;
|
||||
@@ -211,7 +211,7 @@ var Events = Module("events", {
|
||||
}
|
||||
},
|
||||
|
||||
get listen() this.builtin.closure.listen,
|
||||
get listen() this.builtin.bound.listen,
|
||||
addSessionListener: deprecated("events.listen", { get: function addSessionListener() this.listen }),
|
||||
|
||||
/**
|
||||
@@ -424,11 +424,11 @@ var Events = Module("events", {
|
||||
return true;
|
||||
},
|
||||
|
||||
canonicalKeys: deprecated("DOM.Event.canonicalKeys", { get: function canonicalKeys() DOM.Event.closure.canonicalKeys }),
|
||||
canonicalKeys: deprecated("DOM.Event.canonicalKeys", { get: function canonicalKeys() DOM.Event.bound.canonicalKeys }),
|
||||
create: deprecated("DOM.Event", function create() DOM.Event.apply(null, arguments)),
|
||||
dispatch: deprecated("DOM.Event.dispatch", function dispatch() DOM.Event.dispatch.apply(DOM.Event, arguments)),
|
||||
fromString: deprecated("DOM.Event.parse", { get: function fromString() DOM.Event.closure.parse }),
|
||||
iterKeys: deprecated("DOM.Event.iterKeys", { get: function iterKeys() DOM.Event.closure.iterKeys }),
|
||||
fromString: deprecated("DOM.Event.parse", { get: function fromString() DOM.Event.bound.parse }),
|
||||
iterKeys: deprecated("DOM.Event.iterKeys", { get: function iterKeys() DOM.Event.bound.iterKeys }),
|
||||
|
||||
toString: function toString() {
|
||||
if (!arguments.length)
|
||||
@@ -1153,9 +1153,9 @@ var Events = Module("events", {
|
||||
let value = parse.superapply(this, arguments);
|
||||
value.forEach(function (filter) {
|
||||
let vals = Option.splitList(filter.result);
|
||||
filter.keys = DOM.Event.parse(vals[0]).map(DOM.Event.closure.stringify);
|
||||
filter.keys = DOM.Event.parse(vals[0]).map(DOM.Event.bound.stringify);
|
||||
|
||||
filter.commandKeys = vals.slice(1).map(DOM.Event.closure.canonicalKeys);
|
||||
filter.commandKeys = vals.slice(1).map(DOM.Event.bound.canonicalKeys);
|
||||
filter.inputKeys = filter.commandKeys.filter(bind("test", /^<[ACM]-/));
|
||||
});
|
||||
return value;
|
||||
|
||||
@@ -24,7 +24,7 @@ var HintSession = Class("HintSession", CommandMode, {
|
||||
this.activeTimeout = null; // needed for hinttimeout > 0
|
||||
this.continue = Boolean(opts.continue);
|
||||
this.docs = [];
|
||||
this.hintKeys = DOM.Event.parse(options["hintkeys"]).map(DOM.Event.closure.stringify);
|
||||
this.hintKeys = DOM.Event.parse(options["hintkeys"]).map(DOM.Event.bound.stringify);
|
||||
this.hintNumber = 0;
|
||||
this.hintString = opts.filter || "";
|
||||
this.pageHints = [];
|
||||
@@ -36,8 +36,8 @@ var HintSession = Class("HintSession", CommandMode, {
|
||||
this.open();
|
||||
|
||||
this.top = opts.window || content;
|
||||
this.top.addEventListener("resize", this.closure._onResize, true);
|
||||
this.top.addEventListener("dactyl-commandupdate", this.closure._onResize, false, true);
|
||||
this.top.addEventListener("resize", this.bound._onResize, true);
|
||||
this.top.addEventListener("dactyl-commandupdate", this.bound._onResize, false, true);
|
||||
|
||||
this.generate();
|
||||
|
||||
@@ -101,8 +101,8 @@ var HintSession = Class("HintSession", CommandMode, {
|
||||
if (hints.hintSession == this)
|
||||
hints.hintSession = null;
|
||||
if (this.top) {
|
||||
this.top.removeEventListener("resize", this.closure._onResize, true);
|
||||
this.top.removeEventListener("dactyl-commandupdate", this.closure._onResize, true);
|
||||
this.top.removeEventListener("resize", this.bound._onResize, true);
|
||||
this.top.removeEventListener("dactyl-commandupdate", this.bound._onResize, true);
|
||||
}
|
||||
|
||||
this.removeHints(0);
|
||||
@@ -750,19 +750,19 @@ var Hints = Module("hints", {
|
||||
|
||||
let appContent = document.getElementById("appcontent");
|
||||
if (appContent)
|
||||
events.listen(appContent, "scroll", this.resizeTimer.closure.tell, false);
|
||||
events.listen(appContent, "scroll", this.resizeTimer.bound.tell, false);
|
||||
|
||||
const Mode = Hints.Mode;
|
||||
Mode.prototype.__defineGetter__("matcher", function ()
|
||||
options.get("extendedhinttags").getKey(this.name, options.get("hinttags").matcher));
|
||||
|
||||
this.modes = {};
|
||||
this.addMode(";", "Focus hint", buffer.closure.focusElement);
|
||||
this.addMode(";", "Focus hint", buffer.bound.focusElement);
|
||||
this.addMode("?", "Show information for hint", elem => buffer.showElementInfo(elem));
|
||||
// TODO: allow for ! override to overwrite existing paths -- where? --djk
|
||||
this.addMode("s", "Save hint", elem => buffer.saveLink(elem, false));
|
||||
this.addMode("f", "Focus frame", elem => dactyl.focus(elem.ownerDocument.defaultView));
|
||||
this.addMode("F", "Focus frame or pseudo-frame", buffer.closure.focusElement, isScrollable);
|
||||
this.addMode("F", "Focus frame or pseudo-frame", buffer.bound.focusElement, isScrollable);
|
||||
this.addMode("o", "Follow hint", elem => buffer.followLink(elem, dactyl.CURRENT_TAB));
|
||||
this.addMode("t", "Follow hint in a new tab", elem => buffer.followLink(elem, dactyl.NEW_TAB));
|
||||
this.addMode("b", "Follow hint in a background tab", elem => buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB));
|
||||
@@ -1044,7 +1044,7 @@ var Hints = Module("hints", {
|
||||
|
||||
let indexOf = String.indexOf;
|
||||
if (options.get("hintmatching").has("transliterated"))
|
||||
indexOf = Hints.closure.indexOf;
|
||||
indexOf = Hints.bound.indexOf;
|
||||
|
||||
switch (options["hintmatching"][0]) {
|
||||
case "contains" : return containsMatcher(hintString);
|
||||
@@ -1066,7 +1066,7 @@ var Hints = Module("hints", {
|
||||
context.compare = () => 0;
|
||||
context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))];
|
||||
},
|
||||
onCancel: mappings.closure.popCommand,
|
||||
onCancel: mappings.bound.popCommand,
|
||||
onSubmit: function (arg) {
|
||||
if (arg)
|
||||
hints.show(arg, opts);
|
||||
@@ -1342,7 +1342,7 @@ var Hints = Module("hints", {
|
||||
"asdfg;lkjh": "Home Row"
|
||||
},
|
||||
validator: function (value) {
|
||||
let values = DOM.Event.parse(value).map(DOM.Event.closure.stringify);
|
||||
let values = DOM.Event.parse(value).map(DOM.Event.bound.stringify);
|
||||
return Option.validIf(array.uniq(values).length === values.length && values.length > 1,
|
||||
_("option.hintkeys.duplicate"));
|
||||
}
|
||||
|
||||
@@ -142,9 +142,9 @@ var ProcessorStack = Class("ProcessorStack", {
|
||||
let list = this.events.filter(e => e.defaultPrevented && !e.dactylDefaultPrevented);
|
||||
|
||||
if (result === Events.PASS)
|
||||
events.dbg("PASS THROUGH: " + list.slice(0, length).filter(e => e.type === "keypress").map(DOM.Event.closure.stringify));
|
||||
events.dbg("PASS THROUGH: " + list.slice(0, length).filter(e => e.type === "keypress").map(DOM.Event.bound.stringify));
|
||||
if (list.length > length)
|
||||
events.dbg("REFEED: " + list.slice(length).filter(e => e.type === "keypress").map(DOM.Event.closure.stringify));
|
||||
events.dbg("REFEED: " + list.slice(length).filter(e => e.type === "keypress").map(DOM.Event.bound.stringify));
|
||||
|
||||
if (result === Events.PASS)
|
||||
events.feedevents(null, list.slice(0, length), { skipmap: true, isMacro: true, isReplay: true });
|
||||
|
||||
@@ -107,7 +107,7 @@ var Map = Class("Map", {
|
||||
*/
|
||||
hasName: function (name) this.keys.indexOf(name) >= 0,
|
||||
|
||||
get keys() array.flatten(this.names.map(mappings.closure.expand)),
|
||||
get keys() array.flatten(this.names.map(mappings.bound.expand)),
|
||||
|
||||
/**
|
||||
* Execute the action for this mapping.
|
||||
@@ -171,7 +171,7 @@ var MapHive = Class("MapHive", Contexts.Hive, {
|
||||
* @param {[Modes.Mode]} modes The modes for which to return mappings.
|
||||
*/
|
||||
iterate: function (modes) {
|
||||
let stacks = Array.concat(modes).map(this.closure.getStack);
|
||||
let stacks = Array.concat(modes).map(this.bound.getStack);
|
||||
return values(stacks.shift().sort((m1, m2) => String.localeCompare(m1.name, m2.name))
|
||||
.filter((map) => map.rhs &&
|
||||
stacks.every(stack => stack.some(m => m.rhs && m.rhs === map.rhs && m.name === map.name))));
|
||||
|
||||
@@ -311,7 +311,7 @@ var Marks = Module("marks", {
|
||||
events: function () {
|
||||
let appContent = document.getElementById("appcontent");
|
||||
if (appContent)
|
||||
events.listen(appContent, "load", marks.closure._onPageLoad, true);
|
||||
events.listen(appContent, "load", marks.bound._onPageLoad, true);
|
||||
},
|
||||
mappings: function () {
|
||||
var myModes = config.browserModes;
|
||||
|
||||
@@ -90,14 +90,14 @@ var MOW = Module("mow", {
|
||||
|
||||
if (modes.main != modes.OUTPUT_MULTILINE) {
|
||||
modes.push(modes.OUTPUT_MULTILINE, null, {
|
||||
onKeyPress: this.closure.onKeyPress,
|
||||
onKeyPress: this.bound.onKeyPress,
|
||||
|
||||
leave: this.closure(function leave(stack) {
|
||||
leave: stack => {
|
||||
if (stack.pop)
|
||||
for (let message in values(this.messages))
|
||||
if (message.leave)
|
||||
message.leave(stack);
|
||||
}),
|
||||
},
|
||||
|
||||
window: this.window
|
||||
});
|
||||
|
||||
@@ -426,11 +426,11 @@ var Tabs = Module("tabs", {
|
||||
if (focusLeftTab)
|
||||
tabs.slice(Math.max(0, index + 1 - count),
|
||||
index + 1)
|
||||
.forEach(config.closure.removeTab);
|
||||
.forEach(config.bound.removeTab);
|
||||
else
|
||||
tabs.slice(index,
|
||||
index + count)
|
||||
.forEach(config.closure.removeTab);
|
||||
.forEach(config.bound.removeTab);
|
||||
return res;
|
||||
},
|
||||
|
||||
@@ -1113,7 +1113,7 @@ var Tabs = Module("tabs", {
|
||||
}
|
||||
for (let event in values(["TabMove", "TabOpen", "TabClose"]))
|
||||
events.listen(tabContainer, event, callback, false);
|
||||
events.listen(tabContainer, "TabSelect", tabs.closure._onTabSelect, false);
|
||||
events.listen(tabContainer, "TabSelect", tabs.bound._onTabSelect, false);
|
||||
},
|
||||
mappings: function initMappings() {
|
||||
|
||||
|
||||
@@ -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