1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-28 15:02:27 +01:00

Get rid of most remaining comprehensions.

This commit is contained in:
Kris Maglione
2015-12-20 15:53:43 -08:00
parent 0aba8fb619
commit 916ea412a5
34 changed files with 372 additions and 256 deletions

View File

@@ -332,10 +332,16 @@ function* properties(obj, prototypes) {
return false;
};
return Ary.uniq([k for (k in obj)].concat(
Object.getOwnPropertyNames(
XPCNativeWrapper.unwrap(obj))
.filter(filter)));
let keys_ = function* (obj) {
for (let key in object)
yield key;
};
return [...new RealSet(
[...keys_(obj),
...Object.getOwnPropertyNames(Cu.waiveXrays(obj))
.filter(filter)])
];
}
else if (!e.stack) {
throw Error(e);
@@ -417,8 +423,11 @@ function keys(obj) {
if (isinstance(obj, ["Map"]))
return iter(obj.keys());
return iter(k for (k in obj)
if (hasOwnProp(obj, k)));
return iter(function* () {
for (let k in obj)
if (hasOwnProp(obj, k))
yield k;
}());
}
/**
@@ -433,13 +442,16 @@ function values(obj) {
return iter(obj.values());
if (isinstance(obj, ["Generator", "Iterator", Iter]))
return iter(k for (k of obj));
return iter(obj);
if (Symbol.iterator in obj)
return iter(obj[Symbol.iterator]());
return iter(obj[k] for (k in obj)
if (hasOwnProp(obj, k)));
return iter(function* () {
for (let k in obj)
if (hasOwnProp(obj, k))
yield obj[k];
}());
}
var RealSet = Set;
@@ -459,7 +471,7 @@ Object.defineProperty(RealSet.prototype, "difference", {
configurable: true,
writable: true,
value: function RealSet_difference(set) {
return new RealSet(i for (i of this) if (!set.has(i)));
return new RealSet(Array.from(this).filter(i => !set.has(i)));
}
});
@@ -467,7 +479,7 @@ Object.defineProperty(RealSet.prototype, "intersection", {
configurable: true,
writable: true,
value: function RealSet_intersection(set) {
return new RealSet(i for (i of this) if (set.has(i)));
return new RealSet(Array.from(this).filter(i => set.has(i)));
}
});
@@ -1424,7 +1436,7 @@ var StructBase = Class("StructBase", Array, {
},
toObject: function struct_toObject() {
return iter.toObject([k, this[k]] for (k of keys(this.members)));
return Ary.toObject(Object.keys(this.members).map(k => [k, this[k]]));
},
toString: function struct_toString() {
@@ -1670,8 +1682,10 @@ update(iter, {
return obj;
},
compact: function compact(iter) {
return (item for (item of iter) if (item != null));
compact: function* compact(iter) {
for (let item of iter)
if (item != null)
yield item;
},
every: function every(iter, pred, self) {
@@ -1838,7 +1852,7 @@ function arrayWrap(fn) {
var Ary = Class("Ary", Array, {
init: function (ary) {
if (Symbol.iterator in ary && !isArray(ary))
ary = [k for (k of ary)];
ary = Array.from(ary);
return new Proxy(ary, {
get: function array_get(target, prop) {

View File

@@ -1110,10 +1110,10 @@ var Buffer = Module("Buffer", {
let distance = reverse ? rect => -rect.top
: rect => rect.top;
let elems = [[e, distance(e.getBoundingClientRect())]
for (e of path.matcher(this.focusedFrame.document))]
.filter(e => e[1] > FUDGE)
.sort((a, b) => a[1] - b[1]);
let elems = Array.from(path.matcher(this.focusedFrame.document),
elem => [e, distance(e.getBoundingClientRect())])
.filter(([elem, dist]) => dist > FUDGE)
.sort((a, b) => a[1] - b[1]);
if (offScreen && !reverse)
elems = elems.filter(function (e) {
@@ -2156,13 +2156,15 @@ var Buffer = Module("Buffer", {
context.title = ["Stylesheet", "Location"];
// unify split style sheets
let styles = iter([s.title, []] for (s of buffer.alternateStyleSheets)).toObject();
let styles = Ary.toObject(buffer.alternateStyleSheets
.map(sheet => [sheet.title, []]));
buffer.alternateStyleSheets.forEach(function (style) {
styles[style.title].push(style.href || _("style.inline"));
});
context.completions = [[title, href.join(", ")] for ([title, href] of iter(styles))];
context.completions = Object.entries(styles)
.map(([title, href]) => [title, href.join(", ")]);
};
completion.savePage = function savePage(context, node) {

View File

@@ -798,7 +798,7 @@ var Commands = Module("commands", {
let lines = string.split(/\r\n|[\r\n]/);
let startLine = context.line;
for (var i = 0; i < lines.length && !context.finished; i++) {
for (let i = 0; i < lines.length && !context.finished; i++) {
// Deal with editors from Silly OSs.
let line = lines[i].replace(/\r$/, "");
@@ -834,10 +834,13 @@ var Commands = Module("commands", {
list: function list(filter, hives) {
const { commandline, completion } = this.modules;
function completerToString(completer) {
if (completer)
return [k
for ([k, v] of iter(config.completers))
if (completer == completion.bound[v])][0] || "custom";
if (completer) {
for (let [key, val] of Object.entries(config.completers))
if (completion.bound(val) === completer)
return key;
return "custom";
}
return "";
}
@@ -1567,6 +1570,7 @@ var Commands = Module("commands", {
for (var [command, args] of commands.parseCommands(context.filter, context))
if (args.trailing)
context.advance(args.commandString.length + 1);
if (!args)
args = { commandString: context.filter };
@@ -1749,7 +1753,8 @@ var Commands = Module("commands", {
names: ["-complete", "-C"],
description: "The argument completion function",
completer: function (context) {
return [[k, ""] for ([k, v] of iter(config.completers))];
return Object.entries(config.completers)
.map(([k, v]) => [k, ""]);
},
type: CommandOption.STRING,
validator: function (arg) {
@@ -1906,12 +1911,11 @@ var Commands = Module("commands", {
setCompleter([CommandHive.prototype.get,
CommandHive.prototype.remove],
[function () {
return [[c.names, c.description] for (c of this)];
return Array.from(this, cmd => [c.names, c.description]);
}]);
setCompleter([Commands.prototype.get],
[function () {
return [[c.names, c.description]
for (c of this.iterator())];
return Array.from(this.iterator(), cmd => [c.names, c.description]);
}]);
},
mappings: function initMappings(dactyl, modules, window) {

View File

@@ -354,9 +354,11 @@ var CompletionContext = Class("CompletionContext", {
set completions(items) {
if (items && isArray(items.array))
items = items.array;
// Accept a generator
if (!isArray(items))
items = [x for (x of iter(items || []))];
items = Array.from(items || []);
if (this._completions !== items) {
delete this.cache.filtered;
delete this.cache.filter;
@@ -795,7 +797,7 @@ var CompletionContext = Class("CompletionContext", {
let res = completer.apply(self || this, [context].concat(args));
if (res && !isArray(res) && !isArray(res.__proto__))
res = [k for (k of res)];
res = Array.from(res);
if (res)
context.completions = res;
@@ -1073,9 +1075,9 @@ var Completion = Module("completion", {
context.fork("about", 6, this, function fork_(context) {
context.title = ["about:"];
context.generate = function generate_() {
return [[k.substr(services.ABOUT.length), ""]
for (k in Cc)
if (k.startsWith(services.ABOUT))];
return Object.keys(Cc).filter(k => k.startsWith(services.ABOUT))
.map(k => [k.substr(services.ABOUT.length),
""]);
};
});
@@ -1151,10 +1153,11 @@ var Completion = Module("completion", {
running[provider] = null;
context.incomplete = result.searchResult >= result.RESULT_NOMATCH_ONGOING;
context.completions = [
{ url: result.getValueAt(i), title: result.getCommentAt(i), icon: result.getImageAt(i) }
for (i of util.range(0, result.matchCount))
];
context.completions = Array.from(
util.range(0, result.matchCount),
i => ({ url: result.getValueAt(i),
title: result.getCommentAt(i),
icon: result.getImageAt(i) }));
}),
get onUpdateSearchResult() { return this.onSearchResult; }
});
@@ -1255,7 +1258,11 @@ var Completion = Module("completion", {
completer: function (context) {
let PREFIX = "/ex/contexts";
context.fork("ex", 0, completion, "ex");
completion.contextList = [[k.substr(PREFIX.length), v.title[0]] for ([k, v] of iter(context.contexts)) if (k.substr(0, PREFIX.length) == PREFIX)];
completion.contextList = (
Object.entries(context.contexts)
.filter(([k]) => k.substr(0, PREFIX.length) == PREFIX)
.map(([k, v]) => [k.substr(PREFIX.length), v.title[0]]));
},
literal: 0
});

View File

@@ -215,12 +215,11 @@ var Contexts = Module("contexts", {
memoize(contexts.hives, name,
() => Object.create(
Object.create(contexts.hiveProto,
{ _hive: { value: name } })));
{ _hive: { value: name } })));
memoize(contexts.groupsProto, name, function () {
return [group[name]
for (group of values(this.groups))
if (hasOwnProp(group, name))];
return this.groups.filter(group => hasOwnProp(group, name))
.map(group => group[name]);
});
},
@@ -728,24 +727,25 @@ var Contexts = Module("contexts", {
],
serialGroup: 20,
serialize: function () {
return [
{
return contexts.initializedGroups()
.filter(group => !group.builtin && group.persist)
.map(group => ({
command: this.name,
bang: true,
options: iter([v, typeof group[k] == "boolean" ? null : group[k]]
// FIXME: this map is expressed multiple times
for ([k, v] of iter({
args: "-args",
description: "-description",
filter: "-locations"
}))
if (group[k])).toObject(),
options: Ary.toObject(
Object.entries({
args: "-args",
description: "-description",
filter: "-locations"
})
.filter(([k]) => group[k])
.map(([k, v]) => [v,
typeof group[k] == "boolean" ? null : group[k]])
),
arguments: [group.name],
ignoreDefaults: true
}
for (group of contexts.initializedGroups())
if (!group.builtin && group.persist)
].concat([{ command: this.name, arguments: ["user"] }]);
}))
.concat([{ command: this.name, arguments: ["user"] }]);
}
});

View File

@@ -671,9 +671,13 @@ var DOM = Class("DOM", {
["span", { highlight: "HtmlTagEnd" }, "<", namespaced(elem), ">"]]
]);
else {
let tag = "<" + [namespaced(elem)].concat(
[namespaced(a) + '="' + String.replace(a.value, /["<]/, DOM.escapeHTML) + '"'
for (a of elem.attributes)]).join(" ");
let escape = val => val.replace(/["<]/g, DOM.escapeHTML);
let tag = "<" + [
namespaced(elem),
...Array.from(elem.attributes,
attr => `${namespaced(attr)}="${escape(attr.value)}"`),
].join(" ");
res.push(tag + (!hasChildren ? "/>" : ">...</" + namespaced(elem) + ">"));
}
@@ -1076,10 +1080,10 @@ var DOM = Class("DOM", {
let params = DEFAULTS[t || "HTML"];
let args = Object.keys(params);
update(params, this.constructor.defaults[type],
iter.toObject([k, opts[k]]
for (k in opts)
if (k in params)));
Ary.toObject(Object.entries(opts)
.filter(([k]) => k in params)));
apply(evt, "init" + t + "Event", args.map(arg => params[arg]));
return evt;
@@ -1672,7 +1676,7 @@ var DOM = Class("DOM", {
}
// FIXME: Surely we can do better.
for (var key in attr) {
for (let key in attr) {
if (/^xmlns(?:$|:)/.test(key)) {
if (_namespaces === namespaces)
namespaces = Object.create(namespaces);
@@ -1685,7 +1689,7 @@ var DOM = Class("DOM", {
var elem = doc.createElementNS(vals[0] || namespaces[""],
name);
for (var key in attr)
for (let key in attr)
if (!/^xmlns(?:$|:)/.test(key)) {
var val = attr[key];
if (nodes && key == "key")
@@ -1699,6 +1703,7 @@ var DOM = Class("DOM", {
else
elem.setAttributeNS(vals[0] || "", key, val);
}
args.forEach(function (e) {
elem.appendChild(tag(e, namespaces));
});
@@ -1825,7 +1830,7 @@ var DOM = Class("DOM", {
// FIXME: Surely we can do better.
let skipAttr = {};
for (var key in attr) {
for (let key in attr) {
if (/^xmlns(?:$|:)/.test(key)) {
if (_namespaces === namespaces)
namespaces = update({}, namespaces);

View File

@@ -18,10 +18,10 @@ lazyRequire("resource://gre/modules/DownloadUtils.jsm", ["DownloadUtils"]);
var MAX_LOAD_TIME = 10 * 1000;
let prefix = "DOWNLOAD_";
var states = iter([v, k.slice(prefix.length).toLowerCase()]
for ([k, v] of iter(Ci.nsIDownloadManager))
if (k.startsWith(prefix)))
.toObject();
var states = Ary.toObject(
Object.entries(Ci.nsIDownloadManager).filter(([key]) => key.startsWith(prefix))
.map(([key, val]) => [val,
key.slice(prefix.length).toLowerCase()]));
var Download = Class("Download", {
init: function init(download, list) {

View File

@@ -301,21 +301,21 @@ var Help = Module("Help", {
dactyl.initHelp();
if (FILE.isDirectory()) {
var addDataEntry = function addDataEntry(file, data) {
var addDataEntry = (file, data) => {
FILE.child(file).write(data);
};
var addURIEntry = function addURIEntry(file, uri) {
var addURIEntry = (file, uri) => {
addDataEntry(file, util.httpGet(uri).responseText);
};
}
else {
var zip = services.ZipWriter(FILE.file, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
addURIEntry = function addURIEntry(file, uri) {
addURIEntry = (file, uri) => {
zip.addEntryChannel(PATH + file, TIME, 9,
services.io.newChannel(uri, null, null), false);
};
addDataEntry = function addDataEntry(file, data) {// Unideal to an extreme.
addDataEntry = (file, data) => {// Unideal to an extreme.
addURIEntry(file, "data:text/plain;charset=UTF-8," + encodeURI(data));
};
}
@@ -396,12 +396,14 @@ var Help = Module("Help", {
addDataEntry(file + ".xhtml", data.join(""));
}
data = [h for (h of highlight)
if (styles.has(h.class) || /^Help/.test(h.class))]
.map(h => h.selector
.replace(/^\[.*?=(.*?)\]/, ".hl-$1")
.replace(/html\|/g, "") + "\t" + "{" + h.cssText + "}")
.join("\n");
data = Array.from(highlight)
.filter(h => styles.has(h.class) || /^Help/.test(h.class))
.map(h => (h.selector
.replace(/^\[.*?=(.*?)\]/, ".hl-$1")
.replace(/html\|/g, "") +
"\t" + "{" + h.cssText + "}"))
.join("\n");
addDataEntry("help.css", data.replace(/chrome:[^ ")]+\//g, ""));
addDataEntry("tag-map.json", JSON.stringify(help.tags));

View File

@@ -99,8 +99,8 @@ update(Highlight.prototype, {
toString: function () {
return "Highlight(" + this.class + ")\n\t" +
[k + ": " + JSON.stringify(String(v))
for ([k, v] of this)].join("\n\t");
Array.from(this, ([k, v]) => `${k}: ${JSON.stringify(String(v))}`)
.join("\n\t")
}
});
@@ -431,18 +431,16 @@ var Highlights = Module("Highlight", {
}
],
serialize: function () {
return [
{
command: this.name,
arguments: [v.class],
literalArg: v.value,
options: {
"-link": v.extends.length ? v.extends : undefined
}
}
for (v of highlight)
if (v.value != v.defaultValue)
];
return Array.from(highlight)
.filter(v => v.value != v.defaultValue)
.map(v => ({
command: this.name,
arguments: [v.class],
literalArg: v.value,
options: {
"-link": v.extends.length ? v.extends : undefined
}
}));
}
});
},
@@ -468,7 +466,8 @@ var Highlights = Module("Highlight", {
completion.highlightGroup = function highlightGroup(context) {
context.title = ["Highlight Group", "Value"];
context.completions = [[v.class, v.value] for (v of highlight)];
context.completions = Array.from(highlight,
v => [v.class, v.value]);
};
},
javascript: function initJavascript(dactyl, modules, window) {

View File

@@ -221,9 +221,8 @@ var IO = Module("io", {
charsets: Class.Memoize(function () {
const BASE = "@mozilla.org/intl/unicode/decoder;1?charset=";
return [k.slice(BASE.length)
for (k of Object.keys(Cc))
if (k.startsWith(BASE))];
return Object.keys(Cc).filter(k.startsWith(BASE))
.map(k => k.slice(BASE.length));
}),
charsetBundle: Class.Memoize(
@@ -930,13 +929,14 @@ unlet s:cpo_save
commands.add(["scrip[tnames]"],
"List all sourced script names",
function () {
let names = [k for (k of io._scriptNames)];
let names = Array.from(io._scriptNames);
if (!names.length)
dactyl.echomsg(_("command.scriptnames.none"));
else
modules.commandline.commandOutput(
template.tabular(["<SNR>", "Filename"], ["text-align: right; padding-right: 1em;"],
([i + 1, file] for ([i, file] of iter(names)))));
Array.from(names.entries(),
([i, file]) => [i + 1, file])));
},
{ argCount: "0" });

View File

@@ -660,8 +660,8 @@ var JavaScript = Module("javascript", {
"encodeURI", "encodeURIComponent", "escape", "eval", "isFinite", "isNaN",
"isXMLName", "parseFloat", "parseInt", "undefined", "unescape", "uneval",
...interfaces.filter(key => /^nsIDOM/.test(key)).map(key => k.substr(6)),
...interfaces.filter(key => /^nsI/.test(key)).map(key => k.substr(3)),
...interfaces.filter(key => /^nsIDOM/.test(key)).map(key => key.substr(6)),
...interfaces.filter(key => /^nsI/.test(key)).map(key => key.substr(3)),
...this.magicalNames,
]);

View File

@@ -832,8 +832,7 @@ var Option = Class("Option", {
if (isArray(acceptable))
acceptable = new RealSet(acceptable.map(v => v[0]));
else
acceptable = new RealSet(this.parseKey(k)
for (k of Object.keys(acceptable)));
acceptable = new RealSet(Object.keys(acceptable).map(k => this.parseKey(k)));
if (this.type === "regexpmap" || this.type === "sitemap")
return Array.concat(vals).every(re => acceptable.has(re.result));
@@ -1483,15 +1482,16 @@ var Options = Module("options", {
modifiers: {},
extra: {
serialize: function () {
return [
{
return Array.from(modules.options)
.filter(opt => (!opt.getter &&
!opt.isDefault &&
(opt.scope & Option.SCOPE_GLOBAL)))
.map(
opt => ({
command: this.name,
literalArg: [opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name
: opt.name + "=" + opt.stringValue]
}
for (opt of modules.options)
if (!opt.getter && !opt.isDefault && (opt.scope & Option.SCOPE_GLOBAL))
];
}));
}
}
}
@@ -1661,7 +1661,8 @@ var Options = Module("options", {
},
javascript: function initJavascript(dactyl, modules, window) {
const { options, JavaScript } = modules;
JavaScript.setCompleter(Options.prototype.get, [() => ([o.name, o.description] for (o of options))]);
JavaScript.setCompleter(Options.prototype.get, [() => Array.from(options,
opt => [opt.name, opt.description])]);
},
sanitizer: function initSanitizer(dactyl, modules, window) {
const { sanitizer } = modules;

View File

@@ -296,10 +296,8 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
function insert(key, fn) {
if (obj[key]) {
let iterator = iter(obj[key]);
if (isArray(obj[key])) {
iterator = ([elem[1].id, elem.slice(2), elem[1]]
for (elem of obj[key]));
}
if (isArray(obj[key]))
iterator = obj[key].map(elem => [elem[1].id, elem.slice(2), elem[1]]);
for (let [elem, xml, attrs] of iterator) {
if (elem = doc.getElementById(String(elem))) {
@@ -479,7 +477,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
return this.activeWindow && this.activeWindow.dactyl.modules;
},
get modules() { return [w.dactyl.modules for (w of this.windows)]; },
get modules() { return Array.from(this.windows, win => win.dactyl.modules) },
/**
* The most recently active dactyl window.

View File

@@ -186,10 +186,10 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
});
function ourItems(persistent) {
return [
item for (item of values(self.itemMap))
if (!item.builtin && (!persistent || item.persistent) && item.name !== "all")
];
return Object.values(self.itemMap)
.filter(item => (!item.builtin &&
(!persistent || item.persistent) &&
item.name !== "all"));
}
function prefOverlay(branch, persistent, local) {
@@ -261,13 +261,15 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
elem.setAttribute("rows", elem.itemCount);
win.Sanitizer = Class("Sanitizer", win.Sanitizer, {
sanitize: function sanitize() {
self.withSavedValues(["sanitizing"], function () {
self.withSavedValues(["sanitizing"], () => {
self.sanitizing = true;
sanitize.superapply(this, arguments);
sanitizer.sanitizeItems([item.name for (item of values(self.itemMap))
if (item.shouldSanitize(false))],
Range.fromArray(this.range || []));
}, this);
sanitizer.sanitizeItems(
Object.values(self.itemMap)
.filter(item => item.shouldSanitize(false))
.map(item => item.name),
Range.fromArray(this.range || []));
});
}
});
}
@@ -601,13 +603,15 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
modules.commandline.commandOutput(template.tabular(
["Host", "Expiry (UTC)", "Path", "Name", "Value"],
["padding-right: 1em", "padding-right: 1em", "padding-right: 1em", "max-width: 12em; overflow: hidden;", "padding-left: 1ex;"],
([c.host,
c.isSession ? ["span", { highlight: "Enabled" }, "session"]
: (new Date(c.expiry * 1000).toJSON() || "Never").replace(/:\d\d\.000Z/, "").replace("T", " ").replace(/-/g, "/"),
c.path,
c.name,
c.value]
for (c of Sanitizer.iterCookies(host)))));
Array.from(Sanitizer.iterCookies(host),
c => [
c.host,
c.isSession ? ["span", { highlight: "Enabled" }, "session"]
: (new Date(c.expiry * 1000).toJSON() || "Never").replace(/:\d\d\.000Z/, "").replace("T", " ").replace(/-/g, "/"),
c.path,
c.name,
c.value,
])));
return;
default:
util.assert(cmd in Sanitizer.PERMS, _("error.invalidArgument"));
@@ -680,17 +684,16 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
{
initialValue: true,
get values() {
return [i
for (i of values(sanitizer.itemMap))
if (i.persistent || i.builtin)];
return Object.values(sanitizer.itemMap)
.filter(i => i.persistent || i.builtin);
},
getter: function () {
if (!sanitizer.runAtShutdown)
return [];
else
return [item.name
for (item of values(sanitizer.itemMap))
if (item.shouldSanitize(true))];
return Object.values(sanitizer.itemMap)
.filter(item => item.shouldSanitize(true))
.map(item => item.name);
},
setter: function (value) {
if (value.length === 0)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2015 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.
@@ -175,17 +175,23 @@ var Services = Module("Services", {
* @param {string} init Name of a property or method used to initialize the
* class.
*/
addClass: function addClass(name, class_, ifaces, init, quiet) {
this.services[name] = { class: class_, interfaces: Array.concat(ifaces || []), method: "createInstance", init: init, quiet: quiet };
addClass: function addClass(name, class_, ifaces, init = null, quiet = false) {
this.services[name] = { class: class_,
interfaces: Array.concat(ifaces || []),
method: "createInstance",
init: init,
quiet: quiet };
if (init)
memoize(this.services[name], "callable", function () {
return callable(XPCOMShim(this.interfaces)[this.init]);
});
this[name] = (function Create() {
return this._create(name, arguments);
}).bind(this);
update.apply(null, [this[name]].concat([Ci[i] for (i of Array.concat(ifaces))]));
this[name] = (...args) => this._create(name, args);
update(this[name],
...Array.concat(ifaces).map(iface => Ci[iface]));
return this[name];
},

View File

@@ -550,7 +550,7 @@ var File = Class("File", {
if (!this.isDirectory())
throw Error(_("io.eNotDir"));
let array = [e for (e of this.iterDirectory())];
let array = Array.from(this.iterDirectory());
if (sort)
array.sort((a, b) => (b.isDirectory() - a.isDirectory() ||
String.localeCompare(a.path, b.path)));

View File

@@ -196,7 +196,7 @@ var Hive = Class("Hive", {
*/
find: function find(name, filter, css, index) {
// Grossly inefficient.
let matches = [k for ([k, v] of iter(this.sheets))];
let matches = Object.keys(this.sheets);
if (index)
matches = String(index).split(",").filter(i => i in this.sheets);
if (name)

View File

@@ -818,8 +818,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
}
if (isObject(params.params)) {
let data = [encodeURIComponent(k) + "=" + encodeURIComponent(v)
for ([k, v] of iter(params.params))];
let encode = ([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`;
let data = Object.entries(params).map(encode);
let uri = util.newURI(url);
uri.query += (uri.query ? "&" : "") + data.join("&");
@@ -1307,8 +1308,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @returns {RegExp} A custom regexp object.
*/
regexp: update(function (expr, flags, tokens) {
flags = flags || [k for ([k, v] of iter({ g: "global", i: "ignorecase", m: "multiline", y: "sticky" }))
if (expr[v])].join("");
if (!flags)
flags = Object.entries({ g: "global",
i: "ignorecase",
m: "multiline",
y: "sticky" })
.filter(([short, full]) => expr[full])
.map(([short]) => short)
.join("");
if (isinstance(expr, ["RegExp"]))
expr = expr.source;
@@ -1472,7 +1479,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
this.errors.push([new Date, obj + "\n" + obj.stack]);
this.errors = this.errors.slice(-this.maxErrors);
this.errors.toString = function () {
return [k + "\n" + v for ([k, v] of this)].join("\n\n");
return this.map(([name, stack]) => `${name}\n${stack}\n`)
.join("\n");
};
this.dump(String(error));
@@ -1510,9 +1518,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
}
catch (e) {}
let ary = host.split(".");
ary = [ary.slice(i).join(".") for (i of util.range(ary.length, 0, -1))];
return ary.filter(h => h.length >= base.length);
let parts = host.split(".");
return Array.from(util.range(parts.length, 0, -1),
i => parts.slice(i).join("."))
.filter(host => host.length >= base.length);
},
/**