1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-20 20:44:13 +01:00

Replace expression closures (function expressions).

Expression closures are to be axed. See https://bugzil.la/1083458.
This commit is contained in:
Doug Kearns
2015-05-26 03:38:58 +10:00
parent 34bfc2f50f
commit ce82387cdd
35 changed files with 182 additions and 184 deletions

View File

@@ -483,9 +483,9 @@ var Addons = Module("addons", {
description: "description",
icon: "iconURL"
};
context.generate = function () {
context.generate = () => {
context.incomplete = true;
AddonManager.getAddonsByTypes(types || ["extension"], function (addons) {
AddonManager.getAddonsByTypes(types || ["extension"], addons => {
context.incomplete = false;
context.completions = addons;
});

View File

@@ -899,7 +899,7 @@ function Class(...args) {
return Constructor;
}
Class.objectGlobal = function (object) {
Class.objectGlobal = object => {
try {
return Cu.getGlobalForObject(object);
}
@@ -920,7 +920,7 @@ Class.objectGlobal = function (object) {
*/
Class.Property = function Property(desc) update(
Object.create(Property.prototype), desc || { configurable: true, writable: true });
Class.Property.prototype.init = function () {};
Class.Property.prototype.init = () => {};
/**
* Extends a subclass with a superclass. The subclass's
* prototype is replaced with a new object, which inherits
@@ -1059,7 +1059,7 @@ Class.prototype = {
* @returns {nsITimer} The timer which backs this timeout.
*/
timeout: function timeout(callback, timeout) {
let timeout_notify = (timer) => {
let timeout_notify = timer => {
if (this.stale ||
util.rehashing && !isinstance(Cu.getGlobalForObject(callback), ["BackstagePass"]))
return;
@@ -1095,7 +1095,7 @@ Class.prototype = {
for (let i = 0; i < arguments.length; i++) {
let src = arguments[i];
Object.getOwnPropertyNames(src || {}).forEach((k) => {
Object.getOwnPropertyNames(src || {}).forEach(k => {
if (k.startsWith("@@") && k.slice(2) in Symbol)
k = Symbol[k.slice(2)];

View File

@@ -102,7 +102,7 @@ var Buffer = Module("Buffer", {
if (!found)
resolve(undefined);
},
handleResult: (pref) => {
handleResult: pref => {
found = true;
resolve(pref.value);
},
@@ -1122,7 +1122,7 @@ var Buffer = Module("Buffer", {
let info = template.map(
(sections || options["pageinfo"])
.map((opt) => Buffer.pageInfo[opt].action.call(this)),
.map(opt => Buffer.pageInfo[opt].action.call(this)),
res => (res && iter(res).join(", ") || undefined),
", ").join("");
@@ -1134,7 +1134,7 @@ var Buffer = Module("Buffer", {
return;
}
let list = template.map(sections || options["pageinfo"], (option) => {
let list = template.map(sections || options["pageinfo"], option => {
let { action, title } = Buffer.pageInfo[option];
return template.table(title, action.call(this, true));
}, ["br"]);
@@ -1824,7 +1824,7 @@ var Buffer = Module("Buffer", {
init: function init(dactyl, modules, window) {
init.superapply(this, arguments);
dactyl.commands["buffer.viewSource"] = function (event) {
dactyl.commands["buffer.viewSource"] = event => {
let elem = event.originalTarget;
let obj = { url: elem.getAttribute("href"), line: Number(elem.getAttribute("line")) };
if (elem.hasAttribute("column"))
@@ -2543,7 +2543,7 @@ var Buffer = Module("Buffer", {
},
validator: function validate(values) {
return this.testValues(values, function (value) {
return this.testValues(values, value => {
if (/^func:/.test(value))
return callable(dactyl.userEval("(" + Option.dequote(value.substr(5)) + ")"));
else

View File

@@ -321,7 +321,7 @@ var Command = Class("Command", {
let res = update([], {
command: this,
explicitOpts: Class.Memoize(function () ({})),
explicitOpts: Class.Memoize(() => ({})),
has: function AP_has(opt) hasOwnProperty(this.explicitOpts, opt)
|| typeof opt === "number" && hasOwnProperty(this, opt),
@@ -1738,7 +1738,7 @@ var Commands = Module("commands", {
name: ["listc[ommands]", "lc"],
description: "List all Ex commands along with their short descriptions",
index: "ex-cmd",
iterate: function (args) commands.iterator().map(function (cmd) ({
iterate: function (args) commands.iterator().map(cmd => ({
__proto__: cmd,
columns: [
cmd.hive == commands.builtin ? "" : ["span", { highlight: "Object", style: "padding-right: 1em;" },
@@ -1826,7 +1826,7 @@ Commands.complQuote = {
"": ["", Commands.quoteArg[""], ""]
};
Commands.parseBool = function (arg) {
Commands.parseBool = arg => {
if (/^(true|1|on)$/i.test(arg))
return true;
if (/^(false|0|off)$/i.test(arg))

View File

@@ -134,7 +134,7 @@ var CompletionContext = Class("CompletionContext", {
this.filterFunc = function filterFunc(items) {
return this.filters
.reduce((res, filter) =>
res.filter((item) => filter.call(this, item)),
res.filter(item => filter.call(this, item)),
items);
};
/**
@@ -738,9 +738,9 @@ var CompletionContext = Class("CompletionContext", {
split: function split(name, obj, fn, ...args) {
let context = this.fork(name);
let alias = (prop) => {
let alias = prop => {
context.__defineGetter__(prop, () => this[prop]);
context.__defineSetter__(prop, (val) => this[prop] = val);
context.__defineSetter__(prop, val => this[prop] = val);
};
alias("_cache");
alias("_completions");

View File

@@ -126,7 +126,7 @@ var Contexts = Module("contexts", {
init: function (name) {
this.name = name;
this.type = ArgType("group", function (group) {
this.type = ArgType("group", group => {
return isString(group) ? contexts.getGroup(group, name)
: group[name];
});
@@ -814,7 +814,7 @@ var Contexts = Module("contexts", {
.slice(0, -1);
iter({ Active: true, Inactive: false }).forEach(function ([name, active]) {
context.split(name, null, function (context) {
context.split(name, null, context => {
context.title[0] = name + " Groups";
context.filters.push(({ item }) => !!item.filter(modules.buffer.uri) == active);
});

View File

@@ -88,7 +88,7 @@ var DOM = Class("DOM", {
Empty: function Empty() this.constructor(null, this.document),
nodes: Class.Memoize(function () ({})),
nodes: Class.Memoize(() => ({})),
get items() {
return function* () {
@@ -1567,10 +1567,10 @@ var DOM = Class("DOM", {
if (!isString(name) || args.length == 0 || name === "") {
var frag = doc.createDocumentFragment();
Array.forEach(args, function (arg) {
Array.forEach(args, arg => {
if (!isArray(arg[0]))
arg = [arg];
arg.forEach(function (arg) {
arg.forEach(arg => {
frag.appendChild(tag(arg, namespaces));
});
});
@@ -1710,12 +1710,12 @@ var DOM = Class("DOM", {
if (isFragment(args)) {
let res = [];
let join = isArray(args) && isStrings(args) ? "" : "\n";
Array.forEach(args, function (arg) {
Array.forEach(args, arg => {
if (!isArray(arg[0]))
arg = [arg];
let contents = [];
arg.forEach(function (arg) {
arg.forEach(arg => {
let string = tag(arg, namespaces, indent);
if (string)
contents.push(string);

View File

@@ -57,7 +57,7 @@ var Download = Class("Download", {
this.source.url]]],
this.list.document, this.nodes);
this.nodes.launch.addEventListener("click", (event) => {
this.nodes.launch.addEventListener("click", event => {
if (event.button == 0) {
event.preventDefault();
this.command("launch");
@@ -122,7 +122,7 @@ var Download = Class("Download", {
let file = io.File(this.targetFile);
if (file.isExecutable() && prefs.get("browser.download.manager.alertOnEXEOpen", true))
this.list.modules.commandline.input(_("download.prompt.launchExecutable") + " ",
(resp) => {
resp => {
if (/^a(lways)$/i.test(resp)) {
prefs.set("browser.download.manager.alertOnEXEOpen", false);
resp = "yes";

View File

@@ -103,7 +103,7 @@ var Help = Module("Help", {
cache.register("help.json", HelpBuilder);
cache.register("help/versions.xml", function () {
cache.register("help/versions.xml", () => {
let NEWS = util.httpGet(config.addon.getResourceURI("NEWS").spec,
{ mimeType: "text/plain;charset=UTF-8" })
.responseText;
@@ -223,7 +223,7 @@ var Help = Module("Help", {
Local: function Local(dactyl, modules, window) ({
init: function init() {
dactyl.commands["dactyl.help"] = function (event) {
dactyl.commands["dactyl.help"] = event => {
let elem = event.originalTarget;
modules.help.help(elem.getAttribute("tag") || elem.textContent);
};

View File

@@ -494,7 +494,7 @@ var IO = Module("io", {
}
let timer = services.Timer(
function () {
() => {
if (!process.isRunning) {
timer.cancel();
deferred.resolve(process.exitValue);
@@ -974,7 +974,7 @@ unlet s:cpo_save
completion: function initCompletion(dactyl, modules, window) {
const { completion, io } = modules;
completion.charset = function (context) {
completion.charset = context => {
context.anchored = false;
context.keys = {
text: util.identity,
@@ -1062,7 +1062,7 @@ unlet s:cpo_save
completion.shellCommand = function shellCommand(context) {
context.title = ["Shell Command", "Path"];
context.generate = function () {
context.generate = () => {
let dirNames = services.environment.get("PATH").split(config.OS.pathListSep);
let commands = [];
@@ -1099,7 +1099,7 @@ unlet s:cpo_save
else if (match.scheme === "chrome") {
context.key = match.prefix;
context.advance(match.prefix.length + 1);
context.generate = function () iter({
context.generate = () => iter({
content: /*L*/"Chrome content",
locale: /*L*/"Locale-specific content",
skin: /*L*/"Theme-specific content"

View File

@@ -405,7 +405,7 @@ var JavaScript = Module("javascript", {
// TODO: Make this a generic completion helper function.
objects.forEach(function (obj) {
obj.ctxt_t.split(obj[1] + "/anchored", this, function (context) {
obj.ctxt_t.split(obj[1] + "/anchored", this, context => {
context.anchored = true;
if (compl)
compl(context, obj[0]);
@@ -416,14 +416,14 @@ var JavaScript = Module("javascript", {
return;
objects.forEach(function (obj) {
obj.ctxt_p.split(obj[1] + "/anchored", this, function (context) {
obj.ctxt_p.split(obj[1] + "/anchored", this, context => {
context.anchored = true;
context.title[0] += /*L*/" (prototypes)";
});
});
objects.forEach(function (obj) {
obj.ctxt_t.split(obj[1] + "/unanchored", this, function (context) {
obj.ctxt_t.split(obj[1] + "/unanchored", this, context => {
context.anchored = false;
context.title[0] += /*L*/" (substrings)";
context.filters.push(unanchored);
@@ -431,7 +431,7 @@ var JavaScript = Module("javascript", {
});
objects.forEach(function (obj) {
obj.ctxt_p.split(obj[1] + "/unanchored", this, function (context) {
obj.ctxt_p.split(obj[1] + "/unanchored", this, context => {
context.anchored = false;
context.title[0] += /*L*/" (prototype substrings)";
context.filters.push(unanchored);

View File

@@ -241,7 +241,7 @@ overlay.overlayWindow(Object.keys(config.overlays),
this.initDependencies(className);
}
else
modules.__defineGetter__(className, function () {
modules.__defineGetter__(className, () => {
let module = modules.jsmodules[className];
Class.replaceProperty(modules, className, module);
if (module.reallyInit)
@@ -350,14 +350,14 @@ overlay.overlayWindow(Object.keys(config.overlays),
}
};
INIT[name].require = function (name) { init[name](); };
INIT[name].require = name => { init[name](); };
}
},
scanModules: function scanModules() {
let { Module, modules } = this.modules;
defineModule.modules.forEach((mod) => {
defineModule.modules.forEach(mod => {
let names = new RealSet(Object.keys(mod.INIT));
if ("init" in mod.INIT)
names.add("init");
@@ -366,14 +366,14 @@ overlay.overlayWindow(Object.keys(config.overlays),
this.deferInit(name, mod.INIT, mod);
});
Module.list.forEach((mod) => {
Module.list.forEach(mod => {
if (!mod.frobbed) {
modules.__defineGetter__(mod.className, () => {
delete modules[mod.className];
return this.loadModule(mod.className, null, Components.stack.caller);
});
Object.keys(mod.prototype.INIT)
.forEach((name) => { this.deferInit(name, mod.prototype.INIT, mod); });
.forEach(name => { this.deferInit(name, mod.prototype.INIT, mod); });
}
mod.frobbed = true;
});

View File

@@ -204,9 +204,8 @@ var Messages = Module("messages", {
javascript: function initJavascript(dactyl, modules, window) {
let { JavaScript } = modules;
JavaScript.setCompleter([this._, this.get, this.format], [
context => messages.iterate()
]);
JavaScript.setCompleter([this._, this.get, this.format],
[context => messages.iterate()]);
JavaScript.setCompleter([this.export],
[function (context, obj, args) {

View File

@@ -758,7 +758,7 @@ var Option = Class("Option", {
acceptable = completions.call(this);
if (isArray(acceptable))
acceptable = new RealSet(acceptable.map((v) => v[0]));
acceptable = new RealSet(acceptable.map(v => v[0]));
else
acceptable = new RealSet(this.parseKey(k)
for (k of Object.keys(acceptable)));
@@ -964,7 +964,7 @@ var Options = Module("options", {
let closure = () => this._optionMap[name];
memoize(this._optionMap, name,
function () Option.types[type](modules, names, description, defaultValue, extraInfo));
() => Option.types[type](modules, names, description, defaultValue, extraInfo));
for (let alias of names.slice(1))
memoize(this._optionMap, alias, closure);
@@ -1165,7 +1165,7 @@ var Options = Module("options", {
name = Option.dequote(name);
if (name == "all" && reset)
modules.commandline.input(_("pref.prompt.resetAll", config.host) + " ",
function (resp) {
resp => {
if (resp == "yes")
for (let pref of prefs.getNames())
prefs.reset(pref);
@@ -1299,7 +1299,7 @@ var Options = Module("options", {
return null;
if (!opt.value && !opt.operator && !opt.invert) {
context.fork("default", 0, this, function (context) {
context.fork("default", 0, this, context => {
context.title = ["Extra Completions"];
context.pushProcessor(0, (item, text, next) => next(item, text.substr(0, 100)));
context.completions = [
@@ -1322,7 +1322,7 @@ var Options = Module("options", {
context.filters.push(i => !have.has(i.text));
modules.completion.optionValue(context, opt.name, opt.operator, null,
function (context) {
context => {
context.generate = () => option.value.map(o => [o, ""]);
});
context.title = ["Current values"];
@@ -1539,7 +1539,7 @@ var Options = Module("options", {
}
if (extra.key && extra.value != null) {
context.fork("default", 0, this, function (context) {
context.fork("default", 0, this, context => {
context.completions = [
[val(opt.value), _("option.currentValue")],
[val(opt.defaultValue), _("option.defaultValue")]
@@ -1559,7 +1559,7 @@ var Options = Module("options", {
if (op == "-")
context.filters.push(i => curValues.indexOf(i.text) > -1);
memoize(extra, "values", function () {
memoize(extra, "values", () => {
if (op == "+")
return curValues.concat(newValues);
if (op == "-")

View File

@@ -193,7 +193,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
let branch = Item.PREFIX + Item.SHUTDOWN_BRANCH;
overlay.overlayWindow("chrome://browser/content/preferences/sanitize.xul",
function (win) {
win => {
let items = ourItems(true);
return prefOverlay(branch, true, {
@@ -472,7 +472,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
&& !args["-host"])
modules.commandline.input(_("sanitize.prompt.deleteAll") + " ",
function (resp) {
resp => {
if (resp.match(/^y(es)?$/i)) {
sanitize(items);
dactyl.echomsg(_("command.sanitize.allDeleted"));

View File

@@ -690,7 +690,7 @@ var File = Class("File", {
/**
* @property {string} The current platform's path separator.
*/
PATH_SEP: Class.Memoize(function () /foo(.)bar/.exec(OS.Path.join("foo", "bar"))[1]),
PATH_SEP: Class.Memoize(() => /foo(.)bar/.exec(OS.Path.join("foo", "bar"))[1]),
pathSplit: Class.Memoize(function () util.regexp("[/" + util.regexp.escape(this.PATH_SEP) + "]", "g")),

View File

@@ -394,7 +394,7 @@ var Styles = Module("Styles", {
completeSite: function (context, content, group=styles.user) {
context.anchored = false;
try {
context.fork("current", 0, this, function (context) {
context.fork("current", 0, this, context => {
context.title = ["Current Site"];
context.completions = [
[content.location.host, /*L*/"Current Host"],
@@ -456,7 +456,7 @@ var Styles = Module("Styles", {
splitContext: function splitContext(context, title) {
for (let item of iter({ Active: true, Inactive: false })) {
let [name, active] = item;
context.split(name, null, function (context) {
context.split(name, null, context => {
context.title[0] = /*L*/name + " " + (title || "Sheets");
context.filters.push(item => !!item.active == active);
});
@@ -728,7 +728,7 @@ var Styles = Module("Styles", {
},
completion: function initCompletion(dactyl, modules, window) {
const names = Array.slice(DOM(["div"], window.document).style);
modules.completion.css = function (context) {
modules.completion.css = context => {
context.title = ["CSS Property"];
context.keys = { text: function (p) p + ":",
description: function () "" };
@@ -755,12 +755,12 @@ var Styles = Module("Styles", {
let patterns = Styles.patterns;
template.highlightCSS = function highlightCSS(css) {
return this.highlightRegexp(css, patterns.property, function (match) {
return this.highlightRegexp(css, patterns.property, match => {
if (!match.length)
return [];
return ["", match.preSpace, template.filter(match.name), ": ",
template.highlightRegexp(match.value, patterns.token, function (match) {
template.highlightRegexp(match.value, patterns.token, match => {
if (match.function)
return ["", template.filter(match.word),
template.highlightRegexp(match.function, patterns.string,

View File

@@ -303,8 +303,9 @@ var Template = Module("Template", {
if (processStrings && false)
str = template._highlightFilter(str, "\n",
function () ["span", { highlight: "NonText" },
"^J"]);
() => ["span",
{ highlight: "NonText" },
"^J"]);
return ["span", { highlight: "Object" }, str];
case "xml":
return arg;
@@ -446,7 +447,7 @@ var Template = Module("Template", {
["tr", { highlight: "Title", align: "left" },
this.map(headings, function (h)
["th", {}, h])],
this.map(iter, (row) =>
this.map(iter, row =>
["tr", {},
this.map(Iterator(row), ([i, d]) =>
["td", { style: style[i] || "" }, d])])];
@@ -455,7 +456,7 @@ var Template = Module("Template", {
usage: function usage(iter, format={}) {
let desc = format.description || (item => this.linkifyHelp(item.description));
let help = format.help || (item => item.name);
let sourceLink = (frame) => {
let sourceLink = frame => {
let source = this.sourceLink(frame);
source[1]["dactyl:hint"] = source[2];
return source;
@@ -464,14 +465,14 @@ var Template = Module("Template", {
format.headings ?
["thead", { highlight: "UsageHead" },
["tr", { highlight: "Title", align: "left" },
this.map(format.headings, (h) => ["th", {}, h])]] :
this.map(format.headings, h => ["th", {}, h])]] :
[],
format.columns ?
["colgroup", {},
this.map(format.columns, (c) => ["col", { style: c }])] :
this.map(format.columns, c => ["col", { style: c }])] :
[],
["tbody", { highlight: "UsageBody" },
this.map(iter, (item) => {
this.map(iter, item => {
// Urgh.
let name = item.name || item.names[0];
let frame = item.definedAt;
@@ -484,7 +485,7 @@ var Template = Module("Template", {
["span", { highlight: "LinkInfo" },
_("io.definedAt"), " ",
sourceLink(frame)]]]],
item.columns ? this.map(item.columns, (c) => ["td", {}, c]) : [],
item.columns ? this.map(item.columns, c => ["td", {}, c]) : [],
["td", {}, desc(item)]];
})]];
}

View File

@@ -299,8 +299,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
char = char.toLowerCase();
stack.top.elements.push(update(
function (obj) obj[char] != null ? quote(obj, char)
: "",
obj => obj[char] != null ? quote(obj, char)
: "",
{ test: function test(obj) obj[char] != null }));
for (let elem of stack)
@@ -505,7 +505,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
let patterns = [];
let substrings = split(pattern, /((?:[^\\{]|\\.)*)\{((?:[^\\}]|\\.)*)\}/gy,
function (match) {
match => {
patterns.push(split(match[2], /((?:[^\\,]|\\.)*),/gy,
null, ",{}"));
}, "{}");
@@ -972,7 +972,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
return iter(obj)
.map(([k, v]) => ["<!ENTITY ", k, " '", String.replace(v == null ? "null" : typeof v == "xml" ? v.toXMLString() : v,
typeof v == "xml" ? /['%]/g : /['"%&<>]/g,
function (m) map[m]),
m => map[m]),
"'>"].join(""))
.join("\n");
},
@@ -1590,8 +1590,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
let done = false;
var promise = test,
retVal;
promise.then((arg) => { retVal = arg; done = true; },
(arg) => { retVal = arg; done = true; });
promise.then(arg => { retVal = arg; done = true; },
arg => { retVal = arg; done = true; });
test = () => done;
}