mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-06 22:14:12 +01:00
Replace expression closures (function expressions - named and dynamic this).
Expression closures are to be axed. See https://bugzil.la/1083458. Leaving deprecated() and literal() calls and method shorthand syntax conversions until after the ESR overlap.
This commit is contained in:
@@ -266,8 +266,10 @@ var Abbreviations = Module("abbreviations", {
|
||||
list: function (modes, lhs, hives) {
|
||||
hives = (hives || this.userHives).filter(h => !h.empty);
|
||||
|
||||
function abbrevs(hive)
|
||||
hive.merged.filter(ab => (ab.inModes(modes) && ab.lhs.startsWith(lhs)));
|
||||
function abbrevs(hive) {
|
||||
return hive.merged.filter(a => a.inModes(modes) &&
|
||||
a.lhs.startsWith(lhs));
|
||||
}
|
||||
|
||||
let list = ["table", {},
|
||||
["tr", { highlight: "Title" },
|
||||
|
||||
@@ -10,10 +10,13 @@
|
||||
|
||||
var AutoCommand = Struct("event", "filter", "command");
|
||||
update(AutoCommand.prototype, {
|
||||
eventName: Class.Memoize(function () this.event.toLowerCase()),
|
||||
eventName: Class.Memoize(function () {
|
||||
return this.event.toLowerCase();
|
||||
}),
|
||||
|
||||
match: function (event, pattern) {
|
||||
return (!event || this.eventName == event.toLowerCase()) && (!pattern || String(this.filter) === String(pattern));
|
||||
return (!event || this.eventName == event.toLowerCase()) &&
|
||||
(!pattern || String(this.filter) === String(pattern));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -659,7 +659,10 @@ var Bookmarks = Module("bookmarks", {
|
||||
context.format = bookmarks.format;
|
||||
iter(extra).forEach(function ([k, v]) {
|
||||
if (v != null)
|
||||
context.filters.push(function (item) item.item[k] != null && this.matchString(v, item.item[k]));
|
||||
context.filters.push(function (item) {
|
||||
return item.item[k] != null &&
|
||||
this.matchString(v, item.item[k]);
|
||||
});
|
||||
});
|
||||
context.generate = () => values(bookmarkcache.bookmarks);
|
||||
completion.urls(context, tags);
|
||||
|
||||
@@ -289,7 +289,9 @@ var CommandWidgets = Class("CommandWidgets", {
|
||||
yield elem;
|
||||
},
|
||||
|
||||
completionContainer: Class.Memoize(function () this.completionList.parentNode),
|
||||
completionContainer: Class.Memoize(function () {
|
||||
return this.completionList.parentNode;
|
||||
}),
|
||||
|
||||
contextMenu: Class.Memoize(function () {
|
||||
["copy", "copylink", "selectall"].forEach(function (tail) {
|
||||
@@ -304,10 +306,11 @@ var CommandWidgets = Class("CommandWidgets", {
|
||||
return document.getElementById("dactyl-contextmenu");
|
||||
}),
|
||||
|
||||
multilineOutput: Class.Memoize(function () this._whenReady("dactyl-multiline-output",
|
||||
elem => {
|
||||
highlight.highlightNode(elem.contentDocument.body, "MOW");
|
||||
}), true),
|
||||
multilineOutput: Class.Memoize(function () {
|
||||
return this._whenReady("dactyl-multiline-output", elem => {
|
||||
highlight.highlightNode(elem.contentDocument.body, "MOW");
|
||||
});
|
||||
}, true),
|
||||
|
||||
multilineInput: Class.Memoize(() => document.getElementById("dactyl-multiline-input")),
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
init: function () {
|
||||
window.dactyl = this;
|
||||
// cheap attempt at compatibility
|
||||
let prop = { get: deprecated("dactyl", function liberator() dactyl),
|
||||
configurable: true };
|
||||
let prop = {
|
||||
get: deprecated("dactyl", function liberator() { return dactyl; }),
|
||||
configurable: true
|
||||
};
|
||||
Object.defineProperty(window, "liberator", prop);
|
||||
Object.defineProperty(modules, "liberator", prop);
|
||||
this.commands = {};
|
||||
@@ -255,7 +257,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
argCount: "*",
|
||||
completer: function (context, args) {
|
||||
context.keys.text = util.identity;
|
||||
context.keys.description = function () seen[this.text] + /*L*/" matching items";
|
||||
context.keys.description = function () {
|
||||
return seen[this.text] + /*L*/" matching items";
|
||||
};
|
||||
context.ignoreCase = true;
|
||||
let seen = {};
|
||||
context.completions = Ary(keys(item).join(" ").toLowerCase().split(/[()\s]+/)
|
||||
|
||||
@@ -779,7 +779,9 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
|
||||
context = context.fork("registers");
|
||||
context.keys = { text: util.identity, description: editor.bound.getRegister };
|
||||
|
||||
context.match = function (r) !this.filter || this.filter.contains(r);
|
||||
context.match = function (r) {
|
||||
return !this.filter || this.filter.contains(r);
|
||||
};
|
||||
|
||||
context.fork("clipboard", 0, this, ctxt => {
|
||||
ctxt.match = context.match;
|
||||
@@ -1327,11 +1329,12 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
|
||||
mappings.add([modes.TEXT_EDIT, modes.VISUAL],
|
||||
["~"], "Switch case of the character under the cursor and move the cursor to the right",
|
||||
function ({ count }) {
|
||||
function munger(range)
|
||||
String(range).replace(/./g, c => {
|
||||
function munger(range) {
|
||||
return String(range).replace(/./g, c => {
|
||||
let lc = c.toLocaleLowerCase();
|
||||
return c == lc ? c.toLocaleUpperCase() : lc;
|
||||
});
|
||||
}
|
||||
|
||||
var range = editor.selectedRange;
|
||||
if (range.collapsed) {
|
||||
|
||||
@@ -1154,10 +1154,18 @@ var Events = Module("events", {
|
||||
"Pass certain keys through directly for the given URLs",
|
||||
"sitemap", "", {
|
||||
flush: function flush() {
|
||||
memoize(this, "filters", function () this.value.filter(f => f(buffer.documentURI)));
|
||||
memoize(this, "pass", function () new RealSet(Ary.flatten(this.filters.map(f => f.keys))));
|
||||
memoize(this, "commandHive", function hive() Hive(this.filters, "command"));
|
||||
memoize(this, "inputHive", function hive() Hive(this.filters, "input"));
|
||||
memoize(this, "filters", function () {
|
||||
return this.value.filter(f => f(buffer.documentURI));
|
||||
});
|
||||
memoize(this, "pass", function () {
|
||||
return new RealSet(Ary.flatten(this.filters.map(f => f.keys)));
|
||||
});
|
||||
memoize(this, "commandHive", function hive() {
|
||||
return Hive(this.filters, "command");
|
||||
});
|
||||
memoize(this, "inputHive", function hive() {
|
||||
return Hive(this.filters, "input");
|
||||
});
|
||||
},
|
||||
|
||||
has: function (key) this.pass.has(key) || hasOwnProperty(this.commandHive.stack.mappings, key),
|
||||
|
||||
@@ -759,8 +759,10 @@ var Hints = Module("hints", {
|
||||
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));
|
||||
Mode.prototype.__defineGetter__("matcher", function () {
|
||||
return options.get("extendedhinttags")
|
||||
.getKey(this.name, options.get("hinttags").matcher);
|
||||
});
|
||||
|
||||
function cleanLoc(loc) {
|
||||
try {
|
||||
|
||||
@@ -65,12 +65,16 @@ var History = Module("history", {
|
||||
let obj = [];
|
||||
obj.__defineGetter__("index", () => sh.index);
|
||||
obj.__defineSetter__("index", val => { webNav.gotoIndex(val); });
|
||||
obj[Symbol.iterator] = function () this.entries();
|
||||
obj[Symbol.iterator] = function () { return this.entries(); };
|
||||
|
||||
for (let item of iter(sh.SHistoryEnumerator, Ci.nsISHEntry))
|
||||
obj.push(update(Object.create(item), {
|
||||
index: obj.length,
|
||||
icon: Class.Memoize(function () services.favicon.getFaviconImageForPage(this.URI).spec)
|
||||
icon: Class.Memoize(function () {
|
||||
return services.favicon
|
||||
.getFaviconImageForPage(this.URI)
|
||||
.spec;
|
||||
})
|
||||
}));
|
||||
return obj;
|
||||
},
|
||||
@@ -348,7 +352,9 @@ var History = Module("history", {
|
||||
if (maxItems && context.maxItems == null)
|
||||
context.maxItems = 100;
|
||||
context.regenerate = true;
|
||||
context.generate = function () history.get(context.filter, this.maxItems, sort);
|
||||
context.generate = function () {
|
||||
return history.get(context.filter, this.maxItems, sort);
|
||||
};
|
||||
};
|
||||
|
||||
completion.addUrlCompleter("history", "History", completion.history);
|
||||
|
||||
@@ -46,7 +46,9 @@ var ProcessorStack = Class("ProcessorStack", {
|
||||
this.processors.unshift(KeyProcessor(modes.BASE, hive));
|
||||
},
|
||||
|
||||
passUnknown: Class.Memoize(function () options.get("passunknown").getKey(this.modes)),
|
||||
passUnknown: Class.Memoize(function () {
|
||||
return options.get("passunknown").getKey(this.modes);
|
||||
}),
|
||||
|
||||
notify: function () {
|
||||
events.dbg("NOTIFY()");
|
||||
@@ -107,7 +109,9 @@ var ProcessorStack = Class("ProcessorStack", {
|
||||
}
|
||||
else if (result !== Events.KILL && !this.actions.length &&
|
||||
!(this.events[0].isReplay || this.passUnknown ||
|
||||
this.modes.some(function (m) m.passEvent(this), this.events[0]))) {
|
||||
this.modes.some(function (m) {
|
||||
return m.passEvent(this);
|
||||
}, this.events[0]))) {
|
||||
// No patching processors, this isn't a fake, pass-through
|
||||
// event, we're not in pass-through mode, and we're not
|
||||
// choosing to pass unknown keys. Kill the event and beep.
|
||||
|
||||
@@ -45,10 +45,12 @@ var Map = Class("Map", {
|
||||
}
|
||||
},
|
||||
|
||||
name: Class.Memoize(function () this.names[0]),
|
||||
name: Class.Memoize(function () { return this.names[0]; }),
|
||||
|
||||
/** @property {[string]} All of this mapping's names (key sequences). */
|
||||
names: Class.Memoize(function () this._keys.map(k => DOM.Event.canonicalKeys(k))),
|
||||
names: Class.Memoize(function () {
|
||||
return this._keys.map(k => DOM.Event.canonicalKeys(k));
|
||||
}),
|
||||
|
||||
get toStringParams() {
|
||||
return [this.modes.map(m => m.name),
|
||||
|
||||
@@ -47,10 +47,12 @@ var Marks = Module("marks", {
|
||||
params.offset = buffer.scrollPosition;
|
||||
params.path = DOM(buffer.findScrollable(0, false)).xpath;
|
||||
params.timestamp = Date.now() * 1000;
|
||||
params.equals = function (m) this.location == m.location
|
||||
&& this.offset.x == m.offset.x
|
||||
&& this.offset.y == m.offset.y
|
||||
&& this.path == m.path;
|
||||
params.equals = function (m) {
|
||||
return this.location == m.location &&
|
||||
this.offset.x == m.offset.x &&
|
||||
this.offset.y == m.offset.y &&
|
||||
this.path == m.path;
|
||||
};
|
||||
return params;
|
||||
},
|
||||
|
||||
|
||||
@@ -447,7 +447,9 @@ var Modes = Module("modes", {
|
||||
|
||||
description: Messages.Localized(""),
|
||||
|
||||
displayName: Class.Memoize(function () this.name.split("_").map(util.capitalize).join(" ")),
|
||||
displayName: Class.Memoize(function () {
|
||||
return this.name.split("_").map(util.capitalize).join(" ");
|
||||
}),
|
||||
|
||||
isinstance: function isinstance(obj)
|
||||
this.allBases.indexOf(obj) >= 0 || callable(obj) && this instanceof obj,
|
||||
@@ -468,7 +470,9 @@ var Modes = Module("modes", {
|
||||
|
||||
get count() { return !this.insert; },
|
||||
|
||||
_display: Class.Memoize(function _display() this.name.replace(/_/g, " ")),
|
||||
_display: Class.Memoize(function _display() {
|
||||
return this.name.replace(/_/g, " ");
|
||||
}),
|
||||
|
||||
display: function display() this._display,
|
||||
|
||||
@@ -476,15 +480,27 @@ var Modes = Module("modes", {
|
||||
|
||||
hidden: false,
|
||||
|
||||
input: Class.Memoize(function input() this.insert || this.bases.length && this.bases.some(b => b.input)),
|
||||
input: Class.Memoize(function input() {
|
||||
return this.insert || this.bases.length &&
|
||||
this.bases.some(b => b.input);
|
||||
}),
|
||||
|
||||
insert: Class.Memoize(function insert() this.bases.length && this.bases.some(b => b.insert)),
|
||||
insert: Class.Memoize(function insert() {
|
||||
return this.bases.length && this.bases.some(b => b.insert);
|
||||
}),
|
||||
|
||||
ownsFocus: Class.Memoize(function ownsFocus() this.bases.length && this.bases.some(b => b.ownsFocus)),
|
||||
ownsFocus: Class.Memoize(function ownsFocus() {
|
||||
return this.bases.length && this.bases.some(b => b.ownsFocus);
|
||||
}),
|
||||
|
||||
passEvent: function passEvent(event) this.input && event.charCode && !(event.ctrlKey || event.altKey || event.metaKey),
|
||||
passEvent: function passEvent(event) {
|
||||
return this.input && event.charCode &&
|
||||
!(event.ctrlKey || event.altKey || event.metaKey);
|
||||
},
|
||||
|
||||
passUnknown: Class.Memoize(function () options.get("passunknown").getKey(this.name)),
|
||||
passUnknown: Class.Memoize(function () {
|
||||
return options.get("passunknown").getKey(this.name);
|
||||
}),
|
||||
|
||||
get mask() { return this; },
|
||||
|
||||
@@ -505,7 +521,9 @@ var Modes = Module("modes", {
|
||||
StackElement: (function () {
|
||||
const StackElement = Struct("main", "extended", "params", "saved");
|
||||
StackElement.className = "Modes.StackElement";
|
||||
StackElement.defaultValue("params", function () this.main.params);
|
||||
StackElement.defaultValue("params", function () {
|
||||
return this.main.params;
|
||||
});
|
||||
|
||||
update(StackElement.prototype, {
|
||||
get toStringParams() {
|
||||
|
||||
@@ -70,9 +70,13 @@ var MOW = Module("mow", {
|
||||
|
||||
get widget() { return this.widgets.multilineOutput; },
|
||||
|
||||
widgets: Class.Memoize(function widgets() commandline.widgets),
|
||||
widgets: Class.Memoize(function widgets() {
|
||||
return commandline.widgets;
|
||||
}),
|
||||
|
||||
body: Class.Memoize(function body() this.widget.contentDocument.documentElement),
|
||||
body: Class.Memoize(function body() {
|
||||
return this.widget.contentDocument.documentElement;
|
||||
}),
|
||||
get document() { return this.widget.contentDocument; },
|
||||
get window() { return this.widget.contentWindow; },
|
||||
|
||||
|
||||
@@ -62,7 +62,9 @@ var Tabs = Module("tabs", {
|
||||
|
||||
cleanup: function cleanup() {
|
||||
for (let tab of this.allTabs) {
|
||||
let node = function node(class_) document.getAnonymousElementByAttribute(tab, "class", class_);
|
||||
let node = function node(class_) {
|
||||
return document.getAnonymousElementByAttribute(tab, "class", class_);
|
||||
};
|
||||
for (let elem of ["dactyl-tab-icon-number", "dactyl-tab-number"].map(node))
|
||||
if (elem)
|
||||
elem.parentNode.parentNode.removeChild(elem.parentNode);
|
||||
@@ -74,7 +76,9 @@ var Tabs = Module("tabs", {
|
||||
|
||||
updateTabCount: function updateTabCount() {
|
||||
for (let [i, tab] of iter(this.visibleTabs)) {
|
||||
let node = function node(class_) document.getAnonymousElementByAttribute(tab, "class", class_);
|
||||
let node = function node(class_) {
|
||||
return document.getAnonymousElementByAttribute(tab, "class", class_);
|
||||
};
|
||||
if (!node("dactyl-tab-number")) {
|
||||
let img = node("tab-icon-image");
|
||||
if (img) {
|
||||
|
||||
Reference in New Issue
Block a user