Skip to content

Commit 06d695b

Browse files
committed
Merge branch 'comprehensions-review'
2 parents 9599dc9 + 475e02a commit 06d695b

26 files changed

+1033
-218
lines changed

common/content/abbreviations.js

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,23 @@ const Abbreviations = Module("abbreviations", {
130130
*/
131131
get merged() {
132132
let result = [];
133-
let lhses = util.Array.uniq([lhs for ([, mabbrevs] in Iterator(this.abbrevs)) for (lhs of Object.keys(mabbrevs))].sort());
133+
134+
/* assert start */
135+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
136+
//
137+
// let before = util.Array.uniq([lhs for ([, mabbrevs] in Iterator(this.abbrevs)) for (lhs of Object.keys(mabbrevs))].sort());
138+
// let after = util.Array.uniq(
139+
// Array.from(values(this.abbrevs))
140+
// .reduce((abbrevs, mabbrev) => [...abbrevs, ...Object.keys(mabbrev)], [])
141+
// );
142+
//
143+
// assert(JSON.stringify(before) == JSON.stringify(after), '#1 in abbrevations.js');
144+
/* assert end */
145+
146+
let lhses = util.Array.uniq(
147+
Array.from(values(this.abbrevs))
148+
.reduce((abbrevs, mabbrev) => [...abbrevs, ...Object.keys(mabbrev)], [])
149+
);
134150

135151
for (let lhs of lhses) {
136152
let exists = {};
@@ -208,7 +224,17 @@ const Abbreviations = Module("abbreviations", {
208224
completion.abbreviation = function abbreviation(context, args, modes) {
209225
if (args.completeArg == 0) {
210226
let abbrevs = abbreviations.merged.filter(function (abbr) abbr.inModes(modes));
211-
context.completions = [[abbr.lhs, abbr.rhs] for (abbr of abbrevs)];
227+
228+
/* assert start */
229+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
230+
//
231+
// let before = [[abbr.lhs, abbr.rhs] for (abbr of abbrevs)];
232+
// let after = abbrevs.map(abbr => [abbr.lhs, abbr.rhs]);
233+
//
234+
// assert(JSON.stringify(before) == JSON.stringify(after), '#2 in abbreviations.js');
235+
/* assert end */
236+
237+
context.completions = abbrevs.map(abbr => [abbr.lhs, abbr.rhs]);
212238
}
213239
};
214240
},
@@ -249,15 +275,41 @@ const Abbreviations = Module("abbreviations", {
249275
completion.abbreviation(context, args, modes)
250276
},
251277
literal: 0,
252-
serial: function () [ {
278+
serial: function () {
279+
/* assert start */
280+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
281+
//
282+
// let before = [
283+
// {
284+
// command: this.name,
285+
// arguments: [abbr.lhs],
286+
// literalArg: abbr.rhs,
287+
// options: abbr.rhs instanceof Function ? {"-javascript": null} : {}
288+
// }
289+
// for ([, abbr] in Iterator(abbreviations.merged))
290+
// if (abbr.modesEqual(modes))
291+
// ];
292+
// let after = abbreviations.merged
293+
// .filter(abbr => abbr.modesEqual(modes))
294+
// .map(abbr => ({
295+
// command: this.name,
296+
// arguments: [abbr.lhs],
297+
// literalArg: abbr.rhs,
298+
// options: abbr.rhs instanceof Function ? {"-javascript": null} : {}
299+
// }));
300+
//
301+
// assert(JSON.stringify(before) == JSON.stringify(after), '#3 in abbreviations.js');
302+
/* assert end */
303+
304+
return abbreviations.merged
305+
.filter(abbr => abbr.modesEqual(modes))
306+
.map(abbr => ({
253307
command: this.name,
254308
arguments: [abbr.lhs],
255309
literalArg: abbr.rhs,
256310
options: abbr.rhs instanceof Function ? {"-javascript": null} : {}
257-
}
258-
for ([, abbr] in Iterator(abbreviations.merged))
259-
if (abbr.modesEqual(modes))
260-
]
311+
}));
312+
}
261313
});
262314

263315
commands.add([ch ? ch + "una[bbrev]" : "una[bbreviate]"],

common/content/autocommands.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,18 @@ const AutoCommands = Module("autocommands", {
256256

257257
completion.macro = function macro(context) {
258258
context.title = ["Macro", "Keys"];
259-
context.completions = [item for (item in events.getMacros())];
259+
260+
// NOTE: was unable to execute this assert
261+
/* assert start */
262+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
263+
//
264+
// let before = [item for (item in events.getMacros())];
265+
// let after = Array.from(events.getMacros());
266+
//
267+
// assert(JSON.stringify(before) == JSON.stringify(after), '#1 in autocommands.js');
268+
/* assert end */
269+
270+
context.completions = Array.from(events.getMacros());
260271
};
261272
},
262273
options: function () {

common/content/base.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ const Cu = Components.utils;
1010

1111
function array(obj) {
1212
if (isgenerator(obj))
13-
obj = [k for (k in obj)];
13+
/* assert start */
14+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
15+
//
16+
// let original = Array.from(obj);
17+
// obj = iter(original);
18+
// let before = [k for (k in obj)];
19+
// obj = iter(original);
20+
// let after = Array.from(obj);
21+
//
22+
// assert(JSON.stringify(before) == JSON.stringify(after), '#1 in base.js');
23+
/* assert end */
24+
25+
obj = Array.from(obj);
1426
else if (obj.length)
1527
obj = Array.slice(obj);
1628
return util.Array(obj);
@@ -66,13 +78,35 @@ function iter(obj) {
6678
catch (e) {}
6779
})();
6880
if (isinstance(obj, [HTMLCollection, NodeList]))
69-
return (node for (node of obj));
81+
/* assert start */
82+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
83+
//
84+
// let before = (node for (node of obj));
85+
// let after = (function* () {
86+
// for (node of obj) {
87+
// yield node;
88+
// }
89+
// })();
90+
//
91+
// assert(JSON.stringify(Array.from(before)) == JSON.stringify(Array.from(after)), '#2 in base.js');
92+
/* assert end */
93+
94+
return (function* () {
95+
for (node of obj) {
96+
yield node;
97+
}
98+
})();
7099
if ((typeof NamedNodeMap !== "undefined" && obj instanceof NamedNodeMap) ||
71100
(typeof MozNamedAttrMap !== "undefined" && obj instanceof MozNamedAttrMap))
72101
return (function () {
73102
for (let i = 0, len = obj.length; i < len; ++i)
74103
yield [obj[i].name, obj[i]];
75104
})();
105+
if (obj instanceof Array)
106+
return (function () {
107+
for (value of obj)
108+
yield value;
109+
})();
76110
return Iterator(obj);
77111
}
78112

@@ -401,7 +435,17 @@ const StructBase = Class("StructBase", {
401435
// Iterator over our named members
402436
__iterator__: function () {
403437
let self = this;
404-
return ([k, self[i]] for ([i, k] in Iterator(self.members)))
438+
439+
/* assert start */
440+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
441+
//
442+
// let before = ([k, self[i]] for ([i, k] in Iterator(self.members)));
443+
// let after = iter(Object.keys(self.members).map(i => [self.members[i], self[i]]));
444+
//
445+
// assert(JSON.stringify(Array.from(before)) == JSON.stringify(Array.from(after)), '#3 in base.js');
446+
/* assert end */
447+
448+
return iter(Object.keys(self.members).map(i => [self.members[i], self[i]]));
405449
}
406450
}, {
407451
/**

common/content/bookmarks.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ const Bookmarks = Module("bookmarks", {
5959
this.__defineGetter__("store", function () store);
6060
this.__defineGetter__("bookmarks", function () this.load());
6161

62-
this.__defineGetter__("keywords",
63-
function () [Keyword(k.keyword, k.title, k.icon, k.url) for (k of self.bookmarks) if (k.keyword)]);
62+
this.__defineGetter__("keywords", function () {
63+
return self.bookmarks.filter(k => k.keyword)
64+
.map(k => Keyword(k.keyword, k.title, k.icon, k.url));
65+
});
6466

65-
this.__iterator__ = function () (val for (val of self.bookmarks));
67+
this.__iterator__ = function () iter(self.bookmarks);
6668

6769
function loadBookmark(node) {
6870
if (node.uri == null) // How does this happen?
@@ -335,7 +337,8 @@ const Bookmarks = Module("bookmarks", {
335337
let results = [];
336338
try {
337339
results = JSON.parse(resp.responseText)[1];
338-
results = [[item, ""] for ([k, item] in Iterator(results)) if (typeof item == "string")];
340+
results = results.filter((item, k) => typeof item == "string")
341+
.map((item, k) => [item, ""]);
339342
}
340343
catch (e) {}
341344
if (!callback)
@@ -502,11 +505,13 @@ const Bookmarks = Module("bookmarks", {
502505
"Show jumplist",
503506
function () {
504507
let sh = history.session;
505-
let jumps = [[idx == sh.index ? ">" : "",
506-
Math.abs(idx - sh.index),
507-
val.title,
508-
xml`<a highlight="URL" href=${val.URI.spec}>${val.URI.spec}</a>`]
509-
for ([idx, val] in Iterator(sh))];
508+
let jumps = Array.from(iter(sh))
509+
.map(([idx, val]) => [
510+
idx == sh.index ? ">" : "",
511+
Math.abs(idx - sh.index),
512+
val.title,
513+
xml`<a highlight="URL" href=${val.URI.spec}>${val.URI.spec}</a>`
514+
]);
510515
let list = template.tabular([{ header: "Jump", style: "color: red", colspan: 2 },
511516
{ header: "", style: "text-align: right", highlight: "Number" },
512517
{ header: "Title", style: "width: 250px; max-width: 500px; overflow: hidden" },
@@ -525,9 +530,12 @@ const Bookmarks = Module("bookmarks", {
525530
args.completeFilter = have.pop();
526531

527532
let prefix = filter.substr(0, filter.length - args.completeFilter.length);
528-
let tags = util.Array.uniq(util.Array.flatten([b.tags for (b of bookmarks._cache.bookmarks)]));
533+
let tags = util.Array.uniq(
534+
util.Array.flatten(bookmarks._cache.bookmarks.map(b => b.tags))
535+
);
529536

530-
return [[prefix + tag, tag] for (tag of tags) if (have.indexOf(tag) < 0)];
537+
return tags.filter(tag => have.indexOf(tag) < 0)
538+
.map(tag => [prefix + tag, tag]);
531539
}
532540

533541
function title(context, args) {
@@ -539,8 +547,10 @@ const Bookmarks = Module("bookmarks", {
539547
}
540548

541549
function keyword(context, args) {
542-
let keywords = util.Array.uniq(util.Array.flatten([b.keyword for (b of bookmarks._cache.keywords)]));
543-
return [[kw, kw] for (kw of keywords)];
550+
let keywords = util.Array.uniq(
551+
util.Array.flatten(bookmarks._cache.keywords.map(b => b.keyword))
552+
);
553+
return keywords.map(kw => [kw, kw]);
544554
}
545555

546556
commands.add(["bma[rk]"],

common/content/buffer.js

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ const Buffer = Module("buffer", {
314314
* buffer. Only returns style sheets for the 'screen' media type.
315315
*/
316316
get alternateStyleSheets() {
317+
// NOTE: getAllStyleSheets seems to be not supported
317318
let stylesheets = window.getAllStyleSheets(config.browser.contentWindow);
318319

319320
return stylesheets.filter(
@@ -1371,7 +1372,17 @@ const Buffer = Module("buffer", {
13711372
styles[style.title].push(style.href || "inline");
13721373
});
13731374

1374-
context.completions = [[s, styles[s].join(", ")] for (s in styles)];
1375+
// NOTE: was unable to execute this assert
1376+
/* assert start */
1377+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
1378+
//
1379+
// let before = [[s, styles[s].join(", ")] for (s in styles)];
1380+
// let after = Object.keys(styles).map(s => [s, styles[s].join(", ")]);
1381+
//
1382+
// assert(JSON.stringify(before) == JSON.stringify(after), '#1 in buffer.js');
1383+
/* assert end */
1384+
1385+
context.completions = Object.keys(styles).map(s => [s, styles[s].join(", ")]);
13751386
};
13761387

13771388
const UNTITLED_LABEL = "(Untitled)";
@@ -1457,7 +1468,18 @@ const Buffer = Module("buffer", {
14571468

14581469
if (flags & this.buffer.VISIBLE) {
14591470
context.title = ["Buffers"];
1460-
context.completions = [item for (item in generateTabs(tabs || config.tabbrowser.visibleTabs))];
1471+
1472+
/* assert start */
1473+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
1474+
//
1475+
// let before = [item for (item in generateTabs(tabs || config.tabbrowser.visibleTabs))];
1476+
// let after = Array.from(generateTabs(tabs || config.tabbrowser.visibleTabs));
1477+
//
1478+
// dump(JSON.stringify(before));
1479+
// assert(JSON.stringify(before) == JSON.stringify(after), '#2 in buffer.js');
1480+
/* assert end */
1481+
1482+
context.completions = Array.from(generateTabs(tabs || config.tabbrowser.visibleTabs));
14611483
}
14621484

14631485
if (!liberator.has("tabgroup") || !tabGroup.TV)
@@ -1472,7 +1494,7 @@ const Buffer = Module("buffer", {
14721494
let groupName = group.getTitle();
14731495
context.fork("GROUP_" + group.id, 0, this, function (context) {
14741496
context.title = [groupName || UNTITLED_LABEL];
1475-
context.completions = [item for (item in generateGroupList(group, groupName))];
1497+
context.completions = Array.from(generateGroupList(group, groupName));
14761498
});
14771499
}
14781500
}
@@ -1670,9 +1692,29 @@ const Buffer = Module("buffer", {
16701692
"textarea[not(@disabled) and not(@readonly)]",
16711693
"iframe"];
16721694

1673-
let elements = [m for (m in util.evaluateXPath(xpath))
1674-
if(m.getClientRects().length && (!(m instanceof HTMLIFrameElement) || Editor.windowIsEditable(m.contentWindow)))
1675-
];
1695+
/* assert start */
1696+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
1697+
//
1698+
// let after = [];
1699+
// for (m in util.evaluateXPath(xpath)) {
1700+
// if (m.getClientRects().length
1701+
// && (!(m instanceof HTMLIFrameElement) || Editor.windowIsEditable(m.contentWindow)))
1702+
// after.push(m);
1703+
// }
1704+
// let before = [m for (m in util.evaluateXPath(xpath))
1705+
// if(m.getClientRects().length && (!(m instanceof HTMLIFrameElement) || Editor.windowIsEditable(m.contentWindow)))
1706+
// ];
1707+
//
1708+
// assert(JSON.stringify(before) == JSON.stringify(after), '#3 in buffer.js');
1709+
/* assert end */
1710+
1711+
// NOTE: Array.from doesn't work here
1712+
let elements = [];
1713+
for (let m in util.evaluateXPath(xpath)) {
1714+
if (m.getClientRects().length
1715+
&& (!(m instanceof HTMLIFrameElement) || Editor.windowIsEditable(m.contentWindow)))
1716+
elements.push(m);
1717+
}
16761718

16771719
liberator.assert(elements.length > 0);
16781720
buffer.focusElement(elements[util.Math.constrain(count, 1, elements.length) - 1]);
@@ -1795,7 +1837,18 @@ const Buffer = Module("buffer", {
17951837
"Desired info in the :pageinfo output",
17961838
"charlist", "gfm",
17971839
{
1798-
completer: function (context) [[k, v[1]] for ([k, v] in Iterator(buffer.pageInfo))]
1840+
completer: function (context) {
1841+
/* assert start */
1842+
// function assert(condition, bookmark) { dump(bookmark+': '); if (!condition) dump('FAILED\n'); else dump('PASSED\n'); }
1843+
//
1844+
// let before = [[k, v[1]] for ([k, v] in Iterator(buffer.pageInfo))];
1845+
// let after = Object.keys(buffer.pageInfo).map(k => [k, buffer.pageInfo[k][1]]);
1846+
//
1847+
// assert(JSON.stringify(before) == JSON.stringify(after), '#4 in buffer.js');
1848+
/* assert end */
1849+
1850+
return Object.keys(buffer.pageInfo).map(k => [k, buffer.pageInfo[k][1]]);
1851+
}
17991852
});
18001853

18011854
options.add(["scroll", "scr"],

0 commit comments

Comments
 (0)