diff options
author | Kris Maglione <maglione.k@gmail.com> | 2015-12-20 15:53:43 -0800 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2015-12-20 15:53:43 -0800 |
commit | 916ea412a5c71af378f9ec6bc3834e1a9578d2ad (patch) | |
tree | 1bc7488b7c1fe41b8f2847a530b026de49bfa8bd /common/content | |
parent | 0aba8fb619cf9e0bcef71c6a864cac27e1fcc53b (diff) | |
download | pentadactyl-916ea412a5c71af378f9ec6bc3834e1a9578d2ad.tar.gz |
Get rid of most remaining comprehensions.
Diffstat (limited to 'common/content')
-rw-r--r-- | common/content/bookmarks.js | 22 | ||||
-rw-r--r-- | common/content/commandline.js | 3 | ||||
-rw-r--r-- | common/content/dactyl.js | 55 | ||||
-rw-r--r-- | common/content/editor.js | 8 | ||||
-rw-r--r-- | common/content/events.js | 9 | ||||
-rw-r--r-- | common/content/hints.js | 16 | ||||
-rw-r--r-- | common/content/history.js | 19 | ||||
-rw-r--r-- | common/content/mappings.js | 28 | ||||
-rw-r--r-- | common/content/marks.js | 22 | ||||
-rw-r--r-- | common/content/modes.js | 12 | ||||
-rw-r--r-- | common/content/quickmarks.js | 9 | ||||
-rw-r--r-- | common/content/tabs.js | 9 |
12 files changed, 134 insertions, 78 deletions
diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index ff1768e6..a6d85c1e 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -449,13 +449,17 @@ var Bookmarks = Module("bookmarks", { description: "Bookmark page title or description", completer: function title(context, args) { let frames = buffer.allFrames(); + if (!args.bang) - return [ - [win.document.title, frames.length == 1 ? /*L*/"Current Location" : /*L*/"Frame: " + win.location.href] - for (win of frames)]; + return frames.map(win => [win.document.title, + frames.length == 1 ? /*L*/"Current Location" + : /*L*/"Frame: " + win.location.href]); + context.keys.text = "title"; context.keys.description = "url"; - return bookmarks.get(args.join(" "), args["-tags"], null, { keyword: args["-keyword"], title: context.filter }); + return bookmarks.get(args.join(" "), args["-tags"], null, + { keyword: args["-keyword"], + title: context.filter }); }, type: CommandOption.STRING }; @@ -514,12 +518,14 @@ var Bookmarks = Module("bookmarks", { if (!args.bang) { context.title = ["Page URL"]; let frames = buffer.allFrames(); - context.completions = [ - [win.document.documentURI, frames.length == 1 ? /*L*/"Current Location" : /*L*/"Frame: " + win.document.title] - for (win of frames)]; + context.completions = frames.map(win => [win.document.documentURI, + frames.length == 1 ? /*L*/"Current Location" + : /*L*/"Frame: " + win.document.title]); } else - completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] }); + completion.bookmark(context, args["-tags"], + { keyword: args["-keyword"], + title: args["-title"] }); }, options: [keyword, title, tags, post, { diff --git a/common/content/commandline.js b/common/content/commandline.js index def05642..bb1d12c9 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -525,7 +525,8 @@ var CommandLine = Module("commandline", { if (storage.exists("history-" + name)) { let ary = storage.newArray("history-" + name, { store: true, privateData: true }); - this._store.set(name, [v for ([k, v] of ary)]); + this._store.set(name, Array.from(ary, ([key, val]) => val)); + ary.delete(); this._store.changed(); } diff --git a/common/content/dactyl.js b/common/content/dactyl.js index fefb8109..cb088ea5 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -775,19 +775,34 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { let loadplugins = options.get("loadplugins"); if (args) - loadplugins = { __proto__: loadplugins, value: args.map(Option.parseRegexp) }; + loadplugins = { __proto__: loadplugins, + value: args.map(Option.parseRegexp) }; - dir.readDirectory(true).forEach(function (file) { - if (file.leafName[0] == ".") + let shouldSource = file => { + if (!loadplugins.getKey(file.path)) + return false; + + if (force) + return true; + + if (file.path in dactyl.pluginFiles) + return dactyl.pluginFiles[file.path] < file.lastModifiedTime; + + return true; + }; + + dir.readDirectory(true).forEach(file => { + if (file.leafName.startsWith(".")) ; - else if (file.isFile() && loadplugins.getKey(file.path) - && !(!force && file.path in dactyl.pluginFiles && dactyl.pluginFiles[file.path] >= file.lastModifiedTime)) { - try { - io.source(file.path); - dactyl.pluginFiles[file.path] = file.lastModifiedTime; - } - catch (e) { - dactyl.reportError(e); + else if (file.isFile()) { + if (shouldSource(file)) { + try { + io.source(file.path); + dactyl.pluginFiles[file.path] = file.lastModifiedTime; + } + catch (e) { + dactyl.reportError(e); + } } } else if (file.isDirectory()) @@ -804,10 +819,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { dactyl.echomsg( _("plugin.searchingForIn", - JSON.stringify("plugins/**/*.{js," + config.fileExtension + "}"), - JSON.stringify([dir.path.replace(/.plugins$/, "") - for (dir of dirs)] - .join(","))), + JSON.stringify("plugins/**/*.{js," + config.fileExtension + "}"), + JSON.stringify(dirs.map(dir => dir.path.replace(/.plugins$/, "")) + .join(","))), 2); dirs.forEach(function (dir) { @@ -1226,7 +1240,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @property {[Window]} Returns an array of all the host application's * open windows. */ - get windows() { return [w for (w of overlay.windows)]; } + get windows() { return Array.from(overlay.windows); } }, { isToolbarHidden: function isToolbarHidden(toolbar) { @@ -1399,7 +1413,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { N: ["Tab number over icon", highlight.selector("TabIconNumber")] }, setter: function (opts) { - let classes = [v[1] for ([k, v] of iter(this.opts)) if (opts.indexOf(k) < 0)]; + let classes = Object.entries(this.opts) + .filter(([name]) => !opts.includes(name)) + .map(([name, data]) => data[1]); styles.system.add("taboptions", "chrome://*", classes.length ? classes.join(",") + "{ display: none; }" : ""); @@ -1876,7 +1892,10 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { completion.dialog = function dialog(context) { context.title = ["Dialog"]; context.filters.push(({ item }) => !item[2] || item[2]()); - context.completions = [[k, v[0], v[2]] for ([k, v] of iter(config.dialogs))]; + + context.completions = ( + Object.entries(config.dialogs) + .map(([key, val]) => [k, v[0], v[2]])); }; completion.menuItem = function menuItem(context) { diff --git a/common/content/editor.js b/common/content/editor.js index e7750476..27c0c444 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail> +// Copyright (c) 2008-2015 Kris Maglione <maglione.k at Gmail> // Copyright (c) 2006-2009 by Martin Stubenschrott <stubenschrott@vimperator.org> // // This work is licensed for reuse under an MIT license. Details are @@ -1399,9 +1399,11 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { }, validator: function (value) { this.format({}, value); + let allowed = new RealSet(["column", "file", "line"]); - return [k for (k of util.compileMacro(value).seen)] - .every(k => allowed.has(k)); + return util.compileMacro(value) + .seen.difference(allowed) + .size == 0; } }); diff --git a/common/content/events.js b/common/content/events.js index 86391f4e..b4d94edb 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -306,9 +306,12 @@ var Events = Module("events", { * @param {string} filter A regular expression filter string. A null * filter selects all macros. */ - getMacros: function (filter) { + getMacros: function (filter = null) { let re = RegExp(filter || ""); - return ([k, m.text] for ([k, m] of editor.registers) if (re.test(k))); + + return Array.from(editor.registers, + ([key, macro]) => [key, macro.text]) + .filter(([key]) => re.test(key)); }, /** @@ -1026,7 +1029,7 @@ var Events = Module("events", { completion: function initCompletion() { completion.macro = function macro(context) { context.title = ["Macro", "Keys"]; - context.completions = [item for (item of events.getMacros())]; + context.completions = Array.from(events.getMacros()); }; }, mappings: function initMappings() { diff --git a/common/content/hints.js b/common/content/hints.js index 5a7f71a8..d2307657 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -1090,8 +1090,8 @@ var Hints = Module("hints", { autocomplete: false, completer: function (context) { context.compare = () => 0; - context.completions = [[k, v.prompt] - for ([k, v] of iter(hints.modes))]; + context.completions = Object.entries(hints.modes) + .map(([key, mode]) => [key, mode.prompt]); }, onCancel: mappings.bound.popCommand, onSubmit: function (arg) { @@ -1234,16 +1234,16 @@ var Hints = Module("hints", { }), indexOf: function indexOf(dest, src) { let table = this.translitTable; - var end = dest.length - src.length; + let end = dest.length - src.length; if (src.length == 0) return 0; outer: - for (var i = 0; i <= end; i++) { - var j = i; - for (var k = 0; k < src.length;) { - var s = dest[j++]; + for (let i = 0; i <= end; i++) { + let j = i; + for (let k = 0; k < src.length;) { + let s = dest[j++]; s = table[s] || s; - for (var l = 0; l < s.length; l++, k++) { + for (let l = 0; l < s.length; l++, k++) { if (s[l] != src[k]) continue outer; if (k == src.length - 1) diff --git a/common/content/history.js b/common/content/history.js index 39259ad3..d4ecc4d8 100644 --- a/common/content/history.js +++ b/common/content/history.js @@ -350,11 +350,20 @@ var History = Module("history", { }; // FIXME: Schema-specific - context.generate = () => [ - Array.slice(row.rev_host).reverse().join("").slice(1) - for (row of iter(services.history.DBConnection - .createStatement("SELECT DISTINCT rev_host FROM moz_places WHERE rev_host IS NOT NULL;"))) - ].slice(2); + context.generate = () => { + // FIXME: Synchronous. + let statement = services.history.DBConnection + .createStatement(`SELECT DISTINCT rev_host FROM moz_places + WHERE rev_host IS NOT NULL;`); + + let result = Array.from(iter(statement), + ({ rev_host }) => Array.from(rev_host) + .reverse().join("") + .slice(1)); + + statement.finalize(); + return result.slice(2); // Why slice 2?; + }; }; completion.history = function _history(context, maxItems, sort) { diff --git a/common/content/mappings.js b/common/content/mappings.js index 95c4428a..00bb4a77 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -746,12 +746,15 @@ var Mappings = Module("mappings", { return null; } function uniqueModes(modes) { - let chars = [k for ([k, v] of iter(modules.modes.modeChars)) - if (v.every(mode => modes.indexOf(mode) >= 0))]; + let chars = ( + Object.entries(modules.modes.modeChars) + .filter(([char, modes_]) => modes_.every(m => modes.includes(m))) + .map(([char]) => char)); - return Ary.uniq(modes.filter(m => chars.indexOf(m.char) < 0) - .map(m => m.name.toLowerCase()) - .concat(chars)); + let names = modes.filter(m => !chars.includes(m.char)) + .map(m => m.name.toLowerCase()); + + return [...new RealSet([...chars, ...names])]; } commands.add(["feedkeys", "fk"], @@ -773,7 +776,8 @@ var Mappings = Module("mappings", { for (let mode of modes.mainModes) if (mode.char && !commands.get(mode.char + "map", true)) addMapCommands(mode.char, - [m.mask for (m of modes.mainModes) if (m.char == mode.char)], + modes.mainModes.filter(m => m.char == mode.char) + .map(m => m.mask), mode.displayName); let args = { @@ -841,9 +845,11 @@ var Mappings = Module("mappings", { let prefix = /^[bCmn]$/.test(mode.char) ? "" : mode.char + "_"; let haveTag = k => hasOwnProp(help.tags, k); - return ({ helpTag: prefix + map.name, __proto__: map } - for (map of self.iterate(args, true)) - if (map.hive === mappings.builtin || haveTag(prefix + map.name))); + return Array.from(self.iterate(args, true)) + .filter(map => (map.hive === mappings.builtin || + haveTag(prefix + map.name))) + .map(map => ({ helpTag: prefix + map.name, + __proto__: map })); }, description: "List all " + mode.displayName + " mode mappings along with their short descriptions", index: mode.char + "-map", @@ -870,8 +876,8 @@ var Mappings = Module("mappings", { [ null, function (context, obj, args) { - return [[m.names, m.description] - for (m of this.iterate(args[0]))]; + return Array.from(this.iterate(args[0]), + map => [map.names, map.description]); } ]); }, diff --git a/common/content/marks.js b/common/content/marks.js index 27737209..0479e60e 100644 --- a/common/content/marks.js +++ b/common/content/marks.js @@ -274,13 +274,14 @@ var Marks = Module("marks", { template.tabular( ["Mark", "HPos", "VPos", "File"], ["", "text-align: right", "text-align: right", "color: green"], - ([name, - mark.offset ? Math.round(mark.offset.x) - : Math.round(mark.position.x * 100) + "%", - mark.offset ? Math.round(mark.offset.y) - : Math.round(mark.position.y * 100) + "%", - mark.location] - for ([name, mark] of marks)))); + Array.from(marks, ([name, mark]) => [ + name, + mark.offset ? Math.round(mark.offset.x) + : Math.round(mark.position.x * 100) + "%", + mark.offset ? Math.round(mark.offset.y) + : Math.round(mark.position.y * 100) + "%", + mark.location, + ]))); }, _onPageLoad: function _onPageLoad(event) { @@ -399,9 +400,10 @@ var Marks = Module("marks", { return !host || util.isDomainURL(url, host); } function match(marks) { - return (k - for ([k, v] of iter(marks)) - if (timespan.contains(v.timestamp) && matchhost(v.location))); + return Array.from(marks) + .filter(([name, mark]) => (timespan.contains(marktimestamp) && + matchhost(marklocation))) + .map(([name]) => name); } for (let [url, local] of marks._localMarks) diff --git a/common/content/modes.js b/common/content/modes.js index c3cf2d34..7acc1bef 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -209,9 +209,9 @@ var Modes = Module("modes", { get all() { return this._modes.slice(); }, get mainModes() { - return (mode - for ([k, mode] of iter(modes._modeMap)) - if (!mode.extended && mode.name == k)); + return Object.entries(modes._modeMap) + .filter(([name, mode]) => !mode.extended && mode.name == name) + .map(([name, mode]) => mode); }, get mainMode() { return this._modeMap[this._main]; }, @@ -595,9 +595,9 @@ var Modes = Module("modes", { for (let base of mode.bases) tree[base.name][mode.name] = tree[mode.name]; - let roots = iter([m.name, tree[m.name]] - for (m of list) - if (!m.bases.length)).toObject(); + let roots = Ary.toObject( + list.filter(mode => !mode.bases.length) + .map(mode => [mode.name, tree[mode.name]])); function rec(obj) { let res = ["ul", { "dactyl:highlight": "Dense" }]; diff --git a/common/content/quickmarks.js b/common/content/quickmarks.js index b81b3936..e027948f 100644 --- a/common/content/quickmarks.js +++ b/common/content/quickmarks.js @@ -100,7 +100,8 @@ var QuickMarks = Module("quickmarks", { * @param {string} filter The list of quickmarks to display, e.g. "a-c i O-X". */ list: function list(filter) { - let marks = [k for ([k, v] of this._qmarks)]; + let marks = Array.from(this._qmarks, ([k]) => k); + let lowercaseMarks = marks.filter(bind("test", /[a-z]/)).sort(); let uppercaseMarks = marks.filter(bind("test", /[A-Z]/)).sort(); let numberMarks = marks.filter(bind("test", /[0-9]/)).sort(); @@ -115,8 +116,10 @@ var QuickMarks = Module("quickmarks", { dactyl.assert(marks.length >= 0, _("quickmark.noMatching", JSON.stringify(filter))); } - commandline.commandOutput(template.tabular(["QuickMark", "URL"], [], - ([mark, quickmarks._qmarks.get(mark)] for (mark of marks)))); + commandline.commandOutput(template.tabular( + ["QuickMark", "URL"], [], + Array.from(marks, + mark => [mark, quickmarks._qmarks.get(mark)]))); } }, { }, { diff --git a/common/content/tabs.js b/common/content/tabs.js index 256e13ec..0f705e8d 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -862,7 +862,8 @@ var Tabs = Module("tabs", { let arg = args[0]; if (tabs.indexFromSpec(arg) == -1) { - let list = [tab for (tab of tabs.match(args[0], args.count, true))]; + let list = Array.from(tabs.match(args[0], args.count, true)); + dactyl.assert(list.length, _("error.invalidArgument", arg)); dactyl.assert(list.length == 1, _("buffer.multipleMatching", arg)); arg = list[0]; @@ -1296,7 +1297,11 @@ var Tabs = Module("tabs", { ]; options.add(["activate", "act"], "Define when newly created tabs are automatically activated", - "stringlist", [g[0] for (g of activateGroups.slice(1)) if (!g[2] || !prefs.get("browser.tabs." + g[2]))].join(","), + "stringlist", activateGroups.slice(1) + .filter(g => (!g[2] || + !prefs.get("browser.tabs." + g[2]))) + .map(g => g[0]) + .join(","), { values: activateGroups, has: Option.has.toggleAll, |