1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-04-25 03:21:25 +02:00

Make .closure a Proxy and rename .bound

This commit is contained in:
Kris Maglione
2014-03-16 14:32:04 -07:00
parent 03596bd75d
commit af88d531d0
27 changed files with 113 additions and 119 deletions
+4 -4
View File
@@ -233,10 +233,10 @@ var Abbreviations = Module("abbreviations", {
get userHives() this.allHives.filter(h => h !== this.builtin), get userHives() this.allHives.filter(h => h !== this.builtin),
get: deprecated("group.abbrevs.get", { get: function get() this.user.closure.get }), get: deprecated("group.abbrevs.get", { get: function get() this.user.bound.get }),
set: deprecated("group.abbrevs.set", { get: function set() this.user.closure.set }), set: deprecated("group.abbrevs.set", { get: function set() this.user.bound.set }),
remove: deprecated("group.abbrevs.remove", { get: function remove() this.user.closure.remove }), remove: deprecated("group.abbrevs.remove", { get: function remove() this.user.bound.remove }),
removeAll: deprecated("group.abbrevs.clear", { get: function removeAll() this.user.closure.clear }), removeAll: deprecated("group.abbrevs.clear", { get: function removeAll() this.user.bound.clear }),
/** /**
* Returns the abbreviation for the given *mode* if *text* matches the * Returns the abbreviation for the given *mode* if *text* matches the
+4 -4
View File
@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org> // Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com> // 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 // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // 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), get activeHives() contexts.allGroups.autocmd.filter(h => h._store.length),
add: deprecated("group.autocmd.add", { get: function add() autocommands.user.closure.add }), add: deprecated("group.autocmd.add", { get: function add() autocommands.user.bound.add }),
get: deprecated("group.autocmd.get", { get: function get() autocommands.user.closure.get }), get: deprecated("group.autocmd.get", { get: function get() autocommands.user.bound.get }),
remove: deprecated("group.autocmd.remove", { get: function remove() autocommands.user.closure.remove }), remove: deprecated("group.autocmd.remove", { get: function remove() autocommands.user.bound.remove }),
/** /**
* Lists all autocommands with a matching *event*, *regexp* and optionally * Lists all autocommands with a matching *event*, *regexp* and optionally
+2 -2
View File
@@ -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 * 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); let uri = util.newURI(ids);
ids = services.bookmarks ids = services.bookmarks
.getBookmarkIdsForURI(uri, {}) .getBookmarkIdsForURI(uri, {})
.filter(bookmarkcache.closure.isRegularBookmark); .filter(bookmarkcache.bound.isRegularBookmark);
} }
ids.forEach(function (id) { ids.forEach(function (id) {
let bmark = bookmarkcache.bookmarks[id]; let bmark = bookmarkcache.bookmarks[id];
+8 -8
View File
@@ -341,7 +341,7 @@ var CommandMode = Class("CommandMode", {
false); false);
this.messageCount = commandline.messageCount; 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.active.commandline.collapsed = false;
this.widgets.prompt = this.prompt; this.widgets.prompt = this.prompt;
@@ -791,7 +791,7 @@ var CommandLine = Module("commandline", {
let action = this._echoLine; let action = this._echoLine;
if ((flags & this.FORCE_MULTILINE) || (/\n/.test(data) || !isinstance(data, [_, "String"])) && !(flags & this.FORCE_SINGLELINE)) 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; let checkSingleLine = () => action == this._echoLine;
@@ -803,7 +803,7 @@ var CommandLine = Module("commandline", {
// So complicated... // So complicated...
if (checkSingleLine() && !this.widgets.mowContainer.collapsed) { if (checkSingleLine() && !this.widgets.mowContainer.collapsed) {
highlightGroup += " Message"; highlightGroup += " Message";
action = mow.closure.echo; action = mow.bound.echo;
} }
else if (!checkSingleLine() && this.widgets.mowContainer.collapsed) { else if (!checkSingleLine() && this.widgets.mowContainer.collapsed) {
if (this._lastEcho && this.widgets.message && this.widgets.message[1] == this._lastEcho.msg) { 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 = commandline.completionList;
this.itemList.open(this.context); 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) { this.autocompleteTimer = Timer(200, 500, function autocompleteTell(tabPressed) {
if (events.feedingKeys && !tabPressed) if (events.feedingKeys && !tabPressed)
@@ -1246,7 +1246,7 @@ var CommandLine = Module("commandline", {
* called. * called.
*/ */
cleanup: function cleanup() { cleanup: function cleanup() {
dactyl.unregisterObserver("events.doneFeeding", this.closure.onDoneFeeding); dactyl.unregisterObserver("events.doneFeeding", this.bound.onDoneFeeding);
this.previewClear(); this.previewClear();
this.tabTimer.reset(); this.tabTimer.reset();
@@ -1945,7 +1945,7 @@ var ItemList = Class("ItemList", {
this.resize(flags); this.resize(flags);
}, this); }, this);
DOM(this.win).resize(this._onResize.closure.tell); DOM(this.win).resize(this._onResize.bound.tell);
}, },
get rootXML() get rootXML()
@@ -2397,8 +2397,8 @@ var ItemList = Class("ItemList", {
first = row; first = row;
let container = DOM(this.nodes.items); let container = DOM(this.nodes.items);
let before = first ? DOM(first).closure.before let before = first ? DOM(first).bound.before
: DOM(this.nodes.items).closure.append; : DOM(this.nodes.items).bound.append;
for (let [i, row] in this.context.getRows(range.start, range.end, for (let [i, row] in this.context.getRows(range.start, range.end,
this.doc)) { this.doc)) {
+7 -7
View File
@@ -206,7 +206,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
registerObservers: function registerObservers(obj, prop) { registerObservers: function registerObservers(obj, prop) {
for (let [signal, func] in Iterator(obj[prop || "signals"])) 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) { 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)) let filters = args.map(arg => let (re = util.regexp.escape(arg))
util.regexp("\\b" + re + "\\b|(?:^|[()\\s])" + re + "(?:$|[()\\s])", "i")); util.regexp("\\b" + re + "\\b|(?:^|[()\\s])" + re + "(?:$|[()\\s])", "i"));
if (filters.length) 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( commandline.commandOutput(
template.usage(results, params.format)); template.usage(results, params.format));
@@ -377,9 +377,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
}, },
dump: deprecated("util.dump", dump: deprecated("util.dump",
{ get: function dump() util.closure.dump }), { get: function dump() util.bound.dump }),
dumpStack: deprecated("util.dumpStack", dumpStack: deprecated("util.dumpStack",
{ get: function dumpStack() util.closure.dumpStack }), { get: function dumpStack() util.bound.dumpStack }),
/** /**
* Outputs a plain message to the command line. * 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 }), help: deprecated("help.help", { get: function help() modules.help.bound.help }),
findHelp: deprecated("help.findHelp", { get: function findHelp() help.closure.findHelp }), findHelp: deprecated("help.findHelp", { get: function findHelp() help.bound.findHelp }),
/** /**
* @private * @private
@@ -724,7 +724,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
} }
if (obj.completer && false) 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])); .map(i => [i.text, i.description]));
if (obj.options && obj.options.some(o => o.description) && false) if (obj.options && obj.options.some(o => o.description) && false)
+1 -1
View File
@@ -765,7 +765,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
completion: function initCompletion() { completion: function initCompletion() {
completion.register = function complete_register(context) { completion.register = function complete_register(context) {
context = context.fork("registers"); 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); context.match = function (r) !this.filter || this.filter.contains(r);
+9 -9
View File
@@ -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" }, ["window", { id: document.documentElement.id, xmlns: "xul" },
// http://developer.mozilla.org/en/docs/XUL_Tutorial:Updating_Commands // http://developer.mozilla.org/en/docs/XUL_Tutorial:Updating_Commands
["commandset", { id: "dactyl-onfocus", commandupdater: "true", events: "focus", ["commandset", { id: "dactyl-onfocus", commandupdater: "true", events: "focus",
commandupdate: this.closure.onFocusChange }], commandupdate: this.bound.onFocusChange }],
["commandset", { id: "dactyl-onselect", commandupdater: "true", events: "select", ["commandset", { id: "dactyl-onselect", commandupdater: "true", events: "select",
commandupdate: this.closure.onSelectionChange }]]] commandupdate: this.bound.onSelectionChange }]]]
}); });
this._fullscreen = window.fullScreen; 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 }), addSessionListener: deprecated("events.listen", { get: function addSessionListener() this.listen }),
/** /**
@@ -424,11 +424,11 @@ var Events = Module("events", {
return true; 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)), 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)), 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 }), fromString: deprecated("DOM.Event.parse", { get: function fromString() DOM.Event.bound.parse }),
iterKeys: deprecated("DOM.Event.iterKeys", { get: function iterKeys() DOM.Event.closure.iterKeys }), iterKeys: deprecated("DOM.Event.iterKeys", { get: function iterKeys() DOM.Event.bound.iterKeys }),
toString: function toString() { toString: function toString() {
if (!arguments.length) if (!arguments.length)
@@ -1153,9 +1153,9 @@ var Events = Module("events", {
let value = parse.superapply(this, arguments); let value = parse.superapply(this, arguments);
value.forEach(function (filter) { value.forEach(function (filter) {
let vals = Option.splitList(filter.result); 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]-/)); filter.inputKeys = filter.commandKeys.filter(bind("test", /^<[ACM]-/));
}); });
return value; return value;
+11 -11
View File
@@ -24,7 +24,7 @@ var HintSession = Class("HintSession", CommandMode, {
this.activeTimeout = null; // needed for hinttimeout > 0 this.activeTimeout = null; // needed for hinttimeout > 0
this.continue = Boolean(opts.continue); this.continue = Boolean(opts.continue);
this.docs = []; 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.hintNumber = 0;
this.hintString = opts.filter || ""; this.hintString = opts.filter || "";
this.pageHints = []; this.pageHints = [];
@@ -36,8 +36,8 @@ var HintSession = Class("HintSession", CommandMode, {
this.open(); this.open();
this.top = opts.window || content; this.top = opts.window || content;
this.top.addEventListener("resize", this.closure._onResize, true); this.top.addEventListener("resize", this.bound._onResize, true);
this.top.addEventListener("dactyl-commandupdate", this.closure._onResize, false, true); this.top.addEventListener("dactyl-commandupdate", this.bound._onResize, false, true);
this.generate(); this.generate();
@@ -101,8 +101,8 @@ var HintSession = Class("HintSession", CommandMode, {
if (hints.hintSession == this) if (hints.hintSession == this)
hints.hintSession = null; hints.hintSession = null;
if (this.top) { if (this.top) {
this.top.removeEventListener("resize", this.closure._onResize, true); this.top.removeEventListener("resize", this.bound._onResize, true);
this.top.removeEventListener("dactyl-commandupdate", this.closure._onResize, true); this.top.removeEventListener("dactyl-commandupdate", this.bound._onResize, true);
} }
this.removeHints(0); this.removeHints(0);
@@ -750,19 +750,19 @@ var Hints = Module("hints", {
let appContent = document.getElementById("appcontent"); let appContent = document.getElementById("appcontent");
if (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; const Mode = Hints.Mode;
Mode.prototype.__defineGetter__("matcher", function () Mode.prototype.__defineGetter__("matcher", function ()
options.get("extendedhinttags").getKey(this.name, options.get("hinttags").matcher)); options.get("extendedhinttags").getKey(this.name, options.get("hinttags").matcher));
this.modes = {}; 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)); this.addMode("?", "Show information for hint", elem => buffer.showElementInfo(elem));
// TODO: allow for ! override to overwrite existing paths -- where? --djk // TODO: allow for ! override to overwrite existing paths -- where? --djk
this.addMode("s", "Save hint", elem => buffer.saveLink(elem, false)); 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", 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("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("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)); 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; let indexOf = String.indexOf;
if (options.get("hintmatching").has("transliterated")) if (options.get("hintmatching").has("transliterated"))
indexOf = Hints.closure.indexOf; indexOf = Hints.bound.indexOf;
switch (options["hintmatching"][0]) { switch (options["hintmatching"][0]) {
case "contains" : return containsMatcher(hintString); case "contains" : return containsMatcher(hintString);
@@ -1066,7 +1066,7 @@ var Hints = Module("hints", {
context.compare = () => 0; context.compare = () => 0;
context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))]; context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))];
}, },
onCancel: mappings.closure.popCommand, onCancel: mappings.bound.popCommand,
onSubmit: function (arg) { onSubmit: function (arg) {
if (arg) if (arg)
hints.show(arg, opts); hints.show(arg, opts);
@@ -1342,7 +1342,7 @@ var Hints = Module("hints", {
"asdfg;lkjh": "Home Row" "asdfg;lkjh": "Home Row"
}, },
validator: function (value) { 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, return Option.validIf(array.uniq(values).length === values.length && values.length > 1,
_("option.hintkeys.duplicate")); _("option.hintkeys.duplicate"));
} }
+2 -2
View File
@@ -142,9 +142,9 @@ var ProcessorStack = Class("ProcessorStack", {
let list = this.events.filter(e => e.defaultPrevented && !e.dactylDefaultPrevented); let list = this.events.filter(e => e.defaultPrevented && !e.dactylDefaultPrevented);
if (result === Events.PASS) 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) 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) if (result === Events.PASS)
events.feedevents(null, list.slice(0, length), { skipmap: true, isMacro: true, isReplay: true }); events.feedevents(null, list.slice(0, length), { skipmap: true, isMacro: true, isReplay: true });
+2 -2
View File
@@ -107,7 +107,7 @@ var Map = Class("Map", {
*/ */
hasName: function (name) this.keys.indexOf(name) >= 0, 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. * 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. * @param {[Modes.Mode]} modes The modes for which to return mappings.
*/ */
iterate: function (modes) { 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)) return values(stacks.shift().sort((m1, m2) => String.localeCompare(m1.name, m2.name))
.filter((map) => map.rhs && .filter((map) => map.rhs &&
stacks.every(stack => stack.some(m => m.rhs && m.rhs === map.rhs && m.name === map.name)))); stacks.every(stack => stack.some(m => m.rhs && m.rhs === map.rhs && m.name === map.name))));
+1 -1
View File
@@ -311,7 +311,7 @@ var Marks = Module("marks", {
events: function () { events: function () {
let appContent = document.getElementById("appcontent"); let appContent = document.getElementById("appcontent");
if (appContent) if (appContent)
events.listen(appContent, "load", marks.closure._onPageLoad, true); events.listen(appContent, "load", marks.bound._onPageLoad, true);
}, },
mappings: function () { mappings: function () {
var myModes = config.browserModes; var myModes = config.browserModes;
+3 -3
View File
@@ -90,14 +90,14 @@ var MOW = Module("mow", {
if (modes.main != modes.OUTPUT_MULTILINE) { if (modes.main != modes.OUTPUT_MULTILINE) {
modes.push(modes.OUTPUT_MULTILINE, null, { 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) if (stack.pop)
for (let message in values(this.messages)) for (let message in values(this.messages))
if (message.leave) if (message.leave)
message.leave(stack); message.leave(stack);
}), },
window: this.window window: this.window
}); });
+3 -3
View File
@@ -426,11 +426,11 @@ var Tabs = Module("tabs", {
if (focusLeftTab) if (focusLeftTab)
tabs.slice(Math.max(0, index + 1 - count), tabs.slice(Math.max(0, index + 1 - count),
index + 1) index + 1)
.forEach(config.closure.removeTab); .forEach(config.bound.removeTab);
else else
tabs.slice(index, tabs.slice(index,
index + count) index + count)
.forEach(config.closure.removeTab); .forEach(config.bound.removeTab);
return res; return res;
}, },
@@ -1113,7 +1113,7 @@ var Tabs = Module("tabs", {
} }
for (let event in values(["TabMove", "TabOpen", "TabClose"])) for (let event in values(["TabMove", "TabOpen", "TabClose"]))
events.listen(tabContainer, event, callback, false); 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() { mappings: function initMappings() {
+3 -3
View File
@@ -261,11 +261,11 @@ var AddonList = Class("AddonList", {
this.addons = {}; this.addons = {};
this.ready = false; this.ready = false;
AddonManager.getAddonsByTypes(types, this.closure(function (addons) { AddonManager.getAddonsByTypes(types, addons => {
this._addons = addons; this._addons = addons;
if (this.document) if (this.document)
this._init(); this._init();
})); });
AddonManager.addAddonListener(this); AddonManager.addAddonListener(this);
}, },
cleanup: function cleanup() { cleanup: function cleanup() {
@@ -273,7 +273,7 @@ var AddonList = Class("AddonList", {
}, },
_init: function _init() { _init: function _init() {
this._addons.forEach(this.closure.addAddon); this._addons.forEach(this.bound.addAddon);
this.ready = true; this.ready = true;
this.update(); this.update();
}, },
+23 -30
View File
@@ -836,7 +836,10 @@ function Class(...args) {
} }
Class.extend(Constructor, superclass, args[0]); 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]); update(Constructor, args[1]);
Constructor.__proto__ = superclass; Constructor.__proto__ = superclass;
@@ -1086,37 +1089,24 @@ for (let name in properties(Class.prototype)) {
Object.defineProperty(Class.prototype, name, desc); Object.defineProperty(Class.prototype, name, desc);
} }
Class.makeClosure = function makeClosure() { var closureHooks = {
const self = this; get: function closure_get(target, prop) {
function closure(fn) { if (hasOwnProperty(target._closureCache, prop))
function _closure() { return target._closureCache[prop];
try {
return fn.apply(self, arguments); let p = target[prop]
} if (callable(p))
catch (e if !(e instanceof FailedAssertion)) { return target._closureCache[prop] = p.bind(target);
util.reportError(e); return p;
throw e.stack ? e : Error(e);
}
}
_closure.wrapped = fn;
return _closure;
} }
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. * 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(); endModule();
// catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);} // catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);}
+2 -2
View File
@@ -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 // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
@@ -160,7 +160,7 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
try { try {
return services.bookmarks return services.bookmarks
.getBookmarkIdsForURI(uri, {}) .getBookmarkIdsForURI(uri, {})
.some(this.closure.isRegularBookmark); .some(this.bound.isRegularBookmark);
} }
catch (e) { catch (e) {
return false; return false;
+2 -2
View File
@@ -46,7 +46,7 @@ var Buffer = Module("Buffer", {
this.win = win; this.win = win;
}, },
get addPageInfoSection() Buffer.closure.addPageInfoSection, get addPageInfoSection() Buffer.bound.addPageInfoSection,
get pageInfo() Buffer.pageInfo, get pageInfo() Buffer.pageInfo,
@@ -2057,7 +2057,7 @@ var Buffer = Module("Buffer", {
events: function initEvents(dactyl, modules, window) { events: function initEvents(dactyl, modules, window) {
let { buffer, config, events } = modules; 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) { mappings: function initMappings(dactyl, modules, window) {
let { Editor, Events, buffer, editor, events, ex, mappings, modes, options, tabs } = modules; let { Editor, Events, buffer, editor, events, ex, mappings, modes, options, tabs } = modules;
+5 -5
View File
@@ -759,7 +759,7 @@ var Commands = Module("commands", {
const { commandline, completion } = this.modules; const { commandline, completion } = this.modules;
function completerToString(completer) { function completerToString(completer) {
if (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 ""; return "";
} }
// TODO: allow matching of aliases? // TODO: allow matching of aliases?
@@ -831,9 +831,9 @@ var Commands = Module("commands", {
return group._add.apply(group, arguments); 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()), 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 * Returns the specified command invocation object serialized to
@@ -1546,7 +1546,7 @@ var Commands = Module("commands", {
function (args) { function (args) {
let cmd = args[0]; 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)); _("command.invalidName", cmd));
if (args.length <= 1) if (args.length <= 1)
@@ -1576,7 +1576,7 @@ var Commands = Module("commands", {
}; };
} }
else 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(","), let added = args["-group"].add(cmd.split(","),
+2 -2
View File
@@ -43,14 +43,14 @@ var Group = Class("Group", {
delete this[hive]; delete this[hive];
if (reason != "shutdown") 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) { destroy: function destroy(reason) {
for (let hive in values(this.hives)) for (let hive in values(this.hives))
util.trapErrors("destroy", hive); util.trapErrors("destroy", hive);
if (reason != "shutdown") if (reason != "shutdown")
this.children.splice(0).forEach(this.contexts.closure.removeGroup); this.children.splice(0).forEach(this.contexts.bound.removeGroup);
}, },
argsExtra: function argsExtra() ({}), argsExtra: function argsExtra() ({}),
+2 -2
View File
@@ -1092,7 +1092,7 @@ var DOM = Class("DOM", {
* @returns {string} Canonical form. * @returns {string} Canonical form.
*/ */
canonicalKeys: function canonicalKeys(keys, unknownOk=true) { 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 () { iterKeys: function iterKeys(keys) iter(function () {
@@ -1480,7 +1480,7 @@ var DOM = Class("DOM", {
* @returns {boolean} True when the patterns are all valid. * @returns {boolean} True when the patterns are all valid.
*/ */
validateMatcher: function validateMatcher(list) { validateMatcher: function validateMatcher(list) {
return this.testValues(list, DOM.closure.testMatcher); return this.testValues(list, DOM.bound.testMatcher);
}, },
testMatcher: function testMatcher(value) { testMatcher: function testMatcher(value) {
+6 -6
View File
@@ -253,10 +253,10 @@ var RangeFinder = Module("rangefinder", {
get prompt() this.mode === modules.modes.FIND_BACKWARD ? "?" : "/", get prompt() this.mode === modules.modes.FIND_BACKWARD ? "?" : "/",
get onCancel() modules.rangefinder.closure.onCancel, get onCancel() modules.rangefinder.bound.onCancel,
get onChange() modules.rangefinder.closure.onChange, get onChange() modules.rangefinder.bound.onChange,
get onHistory() modules.rangefinder.closure.onHistory, get onHistory() modules.rangefinder.bound.onHistory,
get onSubmit() modules.rangefinder.closure.onSubmit get onSubmit() modules.rangefinder.bound.onSubmit
}); });
}, },
mappings: function initMappings(dactyl, modules, window) { mappings: function initMappings(dactyl, modules, window) {
@@ -707,12 +707,12 @@ var RangeFind = Class("RangeFind", {
addListeners: function addListeners() { addListeners: function addListeners() {
for (let range in array.iterValues(this.ranges)) 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() { purgeListeners: function purgeListeners() {
for (let range in array.iterValues(this.ranges)) for (let range in array.iterValues(this.ranges))
try { 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) {} catch (e if e.result === Cr.NS_ERROR_FAILURE) {}
}, },
+1 -1
View File
@@ -489,7 +489,7 @@ var IO = Module("io", {
system: function system(command, input, callback) { system: function system(command, input, callback) {
util.dactyl.echomsg(_("io.callingShell", command), 4); util.dactyl.echomsg(_("io.callingShell", command), 4);
let { shellEscape } = util.closure; let { shellEscape } = util.bound;
return this.withTempFiles(function (stdin, stdout, cmd) { return this.withTempFiles(function (stdin, stdout, cmd) {
if (input instanceof File) if (input instanceof File)
+2 -2
View File
@@ -463,7 +463,7 @@ var JavaScript = Module("javascript", {
} }
this.context.getCache("evalled", Object); 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. // Okay, have parse stack. Figure out what we're completing.
@@ -693,7 +693,7 @@ var JavaScript = Module("javascript", {
completion: function (dactyl, modules, window) { completion: function (dactyl, modules, window) {
const { completion } = modules; const { completion } = modules;
update(modules.completion, { update(modules.completion, {
get javascript() modules.javascript.closure.complete, get javascript() modules.javascript.bound.complete,
javascriptCompleter: JavaScript // Backwards compatibility javascriptCompleter: JavaScript // Backwards compatibility
}); });
}, },
+1 -1
View File
@@ -291,7 +291,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @param {string} branch The preference name. @optional * @param {string} branch The preference name. @optional
*/ */
resetBranch: function resetBranch(branch) { resetBranch: function resetBranch(branch) {
this.getNames(branch).forEach(this.closure.reset); this.getNames(branch).forEach(this.bound.reset);
}, },
/** /**
+1 -1
View File
@@ -558,7 +558,7 @@ var Styles = Module("Styles", {
let uris = util.visibleURIs(window.content); let uris = util.visibleURIs(window.content);
context.compare = modules.CompletionContext.Sort.number; context.compare = modules.CompletionContext.Sort.number;
context.generate = () => args["-group"].sheets; 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")]; context.keys.description = sheet => [sheet.formatSites(uris), ": ", sheet.css.replace("\n", "\\n")];
if (filter) if (filter)
context.filters.push(({ item }) => filter(item)); context.filters.push(({ item }) => filter(item));
+1 -1
View File
@@ -144,7 +144,7 @@ var Template = Module("Template", {
events["dactyl-input"] = events["input"]; events["dactyl-input"] = events["input"];
for (let [event, handler] in Iterator(events)) 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);
} }
}) })
}, },
+5 -4
View File
@@ -72,8 +72,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
}, },
activeWindow: deprecated("overlay.activeWindow", { get: function activeWindow() overlay.activeWindow }), activeWindow: deprecated("overlay.activeWindow", { get: function activeWindow() overlay.activeWindow }),
overlayObject: deprecated("overlay.overlayObject", { get: function overlayObject() overlay.closure.overlayObject }), overlayObject: deprecated("overlay.overlayObject", { get: function overlayObject() overlay.bound.overlayObject }),
overlayWindow: deprecated("overlay.overlayWindow", { get: function overlayWindow() overlay.closure.overlayWindow }), overlayWindow: deprecated("overlay.overlayWindow", { get: function overlayWindow() overlay.bound.overlayWindow }),
compileMatcher: deprecated("DOM.compileMatcher", { get: function compileMatcher() DOM.compileMatcher }), compileMatcher: deprecated("DOM.compileMatcher", { get: function compileMatcher() DOM.compileMatcher }),
computedStyle: deprecated("DOM#style", function computedStyle(elem) DOM(elem).style), 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)), readFromClipboard: deprecated("dactyl.clipboardRead", function readFromClipboard() util.dactyl.clipboardRead(false)),
chromePackages: deprecated("config.chromePackages", { get: function chromePackages() config.chromePackages }), 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 }), OS: deprecated("config.OS", { get: function OS() config.OS }),
dactyl: update(function dactyl(obj) { 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", "")), { 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"], dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"],
iterate: function iterate(str, idx) util.regexp.iterate(this, str, idx) iterate: function iterate(str, idx) util.regexp.iterate(this, str, idx)
}); });