From d6543c6510ea1d808a4038b5ff486b5ca5ff4dbf Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 4 Mar 2015 17:27:32 -0800 Subject: [PATCH] Rename 'array' class 'Ary'. --- common/content/abbreviations.js | 6 +- common/content/autocommands.js | 2 +- common/content/bookmarks.js | 12 ++-- common/content/browser.js | 6 +- common/content/commandline.js | 4 +- common/content/dactyl.js | 12 ++-- common/content/events.js | 4 +- common/content/hints.js | 4 +- common/content/history.js | 4 +- common/content/key-processors.js | 2 +- common/content/mappings.js | 40 ++++++++------ common/content/marks.js | 4 +- common/content/modes.js | 12 ++-- common/content/mow.js | 2 +- common/modules/addons.jsm | 8 +-- common/modules/base.jsm | 95 +++++++++++++++++++------------- common/modules/bookmarkcache.jsm | 6 +- common/modules/buffer.jsm | 10 ++-- common/modules/commands.jsm | 18 +++--- common/modules/completion.jsm | 6 +- common/modules/config.jsm | 10 ++-- common/modules/contexts.jsm | 2 +- common/modules/dom.jsm | 38 +++++++------ common/modules/finder.jsm | 8 +-- common/modules/help.jsm | 8 +-- common/modules/highlight.jsm | 18 +++--- common/modules/io.jsm | 16 +++--- common/modules/javascript.jsm | 4 +- common/modules/main.jsm | 2 +- common/modules/messages.jsm | 50 ++++++++--------- common/modules/options.jsm | 10 ++-- common/modules/overlay.jsm | 4 +- common/modules/storage.jsm | 18 ------ common/modules/styles.jsm | 12 ++-- common/modules/template.jsm | 2 +- common/modules/util.jsm | 12 ++-- 36 files changed, 239 insertions(+), 232 deletions(-) diff --git a/common/content/abbreviations.js b/common/content/abbreviations.js index a3e351e8..f5b918b8 100644 --- a/common/content/abbreviations.js +++ b/common/content/abbreviations.js @@ -56,7 +56,7 @@ var Abbreviation = Class("Abbreviation", { * @param {[Mode]} modes The modes to test. * @returns {boolean} The result of the comparison. */ - modesEqual: function (modes) array.equals(this.modes, modes), + modesEqual: function (modes) Ary.equals(this.modes, modes), /** * Returns true if this abbreviation is defined for *mode*. @@ -91,7 +91,7 @@ var Abbreviation = Class("Abbreviation", { get modeChar() Abbreviation.modeChar(this.modes) }, { modeChar: function (_modes) { - let result = array.uniq(_modes.map(m => m.char)).join(""); + let result = Ary.uniq(_modes.map(m => m.char)).join(""); if (result == "ci") result = "!"; return result; @@ -352,7 +352,7 @@ var Abbreviations = Module("abbreviations", { description: "Expand this abbreviation by evaluating its right-hand-side as JavaScript" } ], - serialize: function () array(abbreviations.userHives) + serialize: function () Ary(abbreviations.userHives) .filter(h => h.persist) .map(hive => [ { diff --git a/common/content/autocommands.js b/common/content/autocommands.js index 9f2ba39f..7ddd373a 100644 --- a/common/content/autocommands.js +++ b/common/content/autocommands.js @@ -23,7 +23,7 @@ var AutoCmdHive = Class("AutoCmdHive", Contexts.Hive, { this._store = []; }, - "@@iterator": function () array.iterValues(this._store), + "@@iterator": function () this._store[Symbol.iterator](), /** * Adds a new autocommand. *cmd* will be executed when one of the specified diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index fbbe3172..598a89d2 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -437,9 +437,9 @@ var Bookmarks = Module("bookmarks", { names: ["-tags", "-T"], description: "A comma-separated list of tags", completer: function tags(context, args) { - context.generate = function () array(b.tags - for (b in bookmarkcache) - if (b.tags)) + context.generate = function () Ary(b.tags + for (b in bookmarkcache) + if (b.tags)) .flatten().uniq().array; context.keys = { text: util.identity, description: util.identity }; }, @@ -593,7 +593,7 @@ var Bookmarks = Module("bookmarks", { bang: true, completer: function completer(context, args) completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] }), - domains: function (args) array.compact(args.map(util.getHost)), + domains: function (args) Ary.compact(args.map(util.getHost)), literal: 0, options: [tags, title, keyword], privateData: true @@ -758,8 +758,8 @@ var Bookmarks = Module("bookmarks", { ctxt.cache.request = bookmarks.getSuggestions(name, ctxt.filter); ctxt.cache.request.then(function (compl) { ctxt.incomplete = false; - ctxt.completions = array.uniq(ctxt.completions.filter(c => ~compl.indexOf(c)) - .concat(compl), true); + ctxt.completions = Ary.uniq(ctxt.completions.filter(c => ~compl.indexOf(c)) + .concat(compl), true); }).catch(function (e) { ctxt.incomplete = false; ctxt.completions = []; diff --git a/common/content/browser.js b/common/content/browser.js index 4641d61d..fe0f8980 100644 --- a/common/content/browser.js +++ b/common/content/browser.js @@ -211,8 +211,8 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), function (args) { dactyl.open(args[0] || "about:blank"); }, { completer: function (context) completion.url(context), - domains: function (args) array.compact(dactyl.parseURLs(args[0] || "") - .map(url => util.getHost(url))), + domains: function (args) Ary.compact(dactyl.parseURLs(args[0] || "") + .map(url => util.getHost(url))), literal: 0, privateData: true }); @@ -229,7 +229,7 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { argCount: "0" }); }, mappings: function initMappings(dactyl, modules, window) { - let openModes = array.toObject([ + let openModes = Ary.toObject([ [dactyl.CURRENT_TAB, ""], [dactyl.NEW_TAB, "tab"], [dactyl.NEW_BACKGROUND_TAB, "background tab"], diff --git a/common/content/commandline.js b/common/content/commandline.js index 1104a5db..1666ba7c 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -1219,8 +1219,8 @@ var CommandLine = Module("commandline", { get selected() this.itemList.selected, set selected(tuple) { - if (!array.equals(tuple || [], - this.itemList.selected || [])) + if (!Ary.equals(tuple || [], + this.itemList.selected || [])) this.itemList.select(tuple); if (!tuple) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 73fdf55a..53e03869 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -235,7 +235,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { let name = commands.add(params.name, params.description, function (args) { - let results = array(params.iterate(args)) + let results = Ary(params.iterate(args)) .sort((a, b) => String.localeCompare(a.name, b.name)); let filters = args.map(arg => { @@ -256,8 +256,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { context.keys.description = function () seen[this.text] + /*L*/" matching items"; context.ignoreCase = true; let seen = {}; - context.completions = array(keys(item).join(" ").toLowerCase().split(/[()\s]+/) - for (item of params.iterate(args))) + context.completions = Ary(keys(item).join(" ").toLowerCase().split(/[()\s]+/) + for (item of params.iterate(args))) .flatten() .map(function (k) { seen[k] = (seen[k] || 0) + 1; @@ -269,7 +269,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { if (params.index) this.indices[params.index] = function* () { - let results = array((params.iterateIndex || params.iterate).call(params, commands.get(name).newArgs())) + let results = Ary((params.iterateIndex || params.iterate).call(params, commands.get(name).newArgs())) .array.sort((a, b) => String.localeCompare(a.name, b.name)); for (let obj of values(results)) { @@ -1403,8 +1403,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { "rb" + [k for ([k, v] of iter(groups[1].opts)) if (!Dactyl.toolbarHidden(document.getElementById(v[1][0])))].join(""), - values: array(groups).map(g => [[k, v[0]] for ([k, v] of iter(g.opts))]) - .flatten(), + values: Ary(groups).map(g => [[k, v[0]] for ([k, v] of iter(g.opts))]) + .flatten(), setter: function (value) { for (let group of values(groups)) diff --git a/common/content/events.js b/common/content/events.js index 6d8c3733..ea6453c5 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -24,7 +24,7 @@ var EventHive = Class("EventHive", Contexts.Hive, { _events: function _events(event, callback) { if (!isObject(event)) - var [self, events] = [null, array.toObject([[event, callback]])]; + var [self, events] = [null, Ary.toObject([[event, callback]])]; else [self, events] = [event, event[callback || "events"]]; @@ -1148,7 +1148,7 @@ var Events = Module("events", { "sitemap", "", { flush: function flush() { memoize(this, "filters", function () this.value.filter(function (f) f(buffer.documentURI))); - memoize(this, "pass", function () new RealSet(array.flatten(this.filters.map(function (f) f.keys)))); + memoize(this, "pass", function () new RealSet(Ary.flatten(this.filters.map(function (f) f.keys)))); memoize(this, "commandHive", function hive() Hive(this.filters, "command")); memoize(this, "inputHive", function hive() Hive(this.filters, "input")); }, diff --git a/common/content/hints.js b/common/content/hints.js index 781f06e5..c3a9e3d4 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -286,7 +286,7 @@ var HintSession = Class("HintSession", CommandMode, { memoize(doc, "dactylLabels", () => iter([l.getAttribute("for"), l] - for (l of array.iterValues(doc.querySelectorAll("label[for]")))) + for (l of doc.querySelectorAll("label[for]"))) .toObject()); let [offsetX, offsetY] = this.getContainerOffsets(doc); @@ -1362,7 +1362,7 @@ var Hints = Module("hints", { }, validator: function (value) { let values = DOM.Event.parse(value).map(DOM.Event.bound.stringify); - return Option.validIf(array.uniq(values).length === values.length && values.length > 1, + return Option.validIf(Ary.uniq(values).length === values.length && values.length > 1, _("option.hintkeys.duplicate")); } }); diff --git a/common/content/history.js b/common/content/history.js index 875a487c..6542358c 100644 --- a/common/content/history.js +++ b/common/content/history.js @@ -65,7 +65,7 @@ var History = Module("history", { let obj = []; obj.__defineGetter__("index", () => sh.index); obj.__defineSetter__("index", function (val) { webNav.gotoIndex(val); }); - obj[Symbol.iterator] = function () array.iterItems(this); + obj[Symbol.iterator] = function () this.entries(); for (let item of iter(sh.SHistoryEnumerator, Ci.nsISHEntry)) obj.push(update(Object.create(item), { @@ -276,7 +276,7 @@ var History = Module("history", { description: "The sort order of the results", completer: function (context, args) { context.compare = CompletionContext.Sort.unsorted; - return array.flatten([ + return Ary.flatten([ "annotation", "date", "date added", diff --git a/common/content/key-processors.js b/common/content/key-processors.js index dfe60035..152450ce 100644 --- a/common/content/key-processors.js +++ b/common/content/key-processors.js @@ -17,7 +17,7 @@ var ProcessorStack = Class("ProcessorStack", { events.dbg("STACK " + mode); let main = { __proto__: mode.main, params: mode.params }; - this.modes = array([mode.params.keyModes, main, mode.main.allBases.slice(1)]).flatten().compact(); + this.modes = Ary([mode.params.keyModes, main, mode.main.allBases.slice(1)]).flatten().compact(); if (builtin) hives = hives.filter(h => h.name === "builtin"); diff --git a/common/content/mappings.js b/common/content/mappings.js index 67221f32..b4929b5e 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -1,6 +1,6 @@ // Copyright (c) 2006-2008 by Martin Stubenschrott // Copyright (c) 2007-2011 by Doug Kearns -// Copyright (c) 2008-2014 Kris Maglione +// Copyright (c) 2008-2015 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. @@ -107,7 +107,7 @@ var Map = Class("Map", { */ hasName: function (name) this.keys.indexOf(name) >= 0, - get keys() array.flatten(this.names.map(mappings.bound.expand)), + get keys() Ary.flatten(this.names.map(mappings.bound.expand)), /** * Execute the action for this mapping. @@ -284,7 +284,7 @@ var MapHive = Class("MapHive", Contexts.Hive, { return self; }, - "@@iterator": function () array.iterValues(this), + "@@iterator": function () Ary.iterValues(this), get candidates() this.states.candidates, get mappings() this.states.mappings, @@ -367,12 +367,16 @@ var Mappings = Module("mappings", { expand: function expand(keys) { if (!/<\*-/.test(keys)) var res = keys; - else - res = util.debrace(DOM.Event.iterKeys(keys).map(function (key) { + else { + let globbed = DOM.Event.iterKeys(keys) + .map(key => { if (/^<\*-/.test(key)) return ["<", this.prefixes, key.slice(3)]; return key; - }, this).flatten().array).map(k => DOM.Event.canonicalKeys(k)); + }).flatten().array; + + res = util.debrace(globbed).map(k => DOM.Event.canonicalKeys(k)); + } if (keys != arguments[0]) return [arguments[0]].concat(keys); @@ -382,7 +386,7 @@ var Mappings = Module("mappings", { iterate: function* (mode) { let seen = new RealSet; for (let hive of this.hives.iterValues()) - for (let map of array(hive.getStack(mode)).iterValues()) + for (let map of Ary.iterValues(hive.getStack(mode))) if (!seen.add(map.name)) yield map; }, @@ -521,7 +525,7 @@ var Mappings = Module("mappings", { commands: function initCommands(dactyl, modules, window) { function addMapCommands(ch, mapmodes, modeDescription) { function map(args, noremap) { - let mapmodes = array.uniq(args["-modes"].map(findMode)); + let mapmodes = Ary.uniq(args["-modes"].map(findMode)); let hives = args.explicitOpts["-group"] ? [args["-group"]] : null; if (!args.length) { @@ -561,7 +565,7 @@ var Mappings = Module("mappings", { const opts = { identifier: "map", completer: function (context, args) { - let mapmodes = array.uniq(args["-modes"].map(findMode)); + let mapmodes = Ary.uniq(args["-modes"].map(findMode)); if (args.length == 1) return completion.userMapping(context, mapmodes, args["-group"]); if (args.length == 2) { @@ -618,7 +622,7 @@ var Mappings = Module("mappings", { ], serialize: function () { return this.name != "map" ? [] : - array(mappings.userHives) + Ary(mappings.userHives) .filter(h => h.persist) .map(hive => [ { @@ -643,7 +647,7 @@ var Mappings = Module("mappings", { function* userMappings(hive) { let seen = new RealSet; for (let stack of values(hive.stacks)) - for (let map of array.iterValues(stack)) + for (let map of Ary.iterValues(stack)) if (!seen.add(map.id)) yield map; } @@ -666,7 +670,7 @@ var Mappings = Module("mappings", { util.assert(args.bang ^ !!args[0], _("error.argumentOrBang")); - let mapmodes = array.uniq(args["-modes"].map(findMode)); + let mapmodes = Ary.uniq(args["-modes"].map(findMode)); let found = 0; for (let mode of values(mapmodes)) @@ -701,7 +705,7 @@ var Mappings = Module("mappings", { names: ["-mode", "-m"], type: CommandOption.STRING, validator: function (value) Array.concat(value).every(findMode), - completer: function () [[array.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.description] + completer: function () [[Ary.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.description] for (mode of values(modes.all)) if (!mode.hidden)] }; @@ -718,9 +722,9 @@ var Mappings = Module("mappings", { let chars = [k for ([k, v] of iter(modules.modes.modeChars)) if (v.every(mode => modes.indexOf(mode) >= 0))]; - return array.uniq(modes.filter(m => chars.indexOf(m.char) < 0) - .map(m => m.name.toLowerCase()) - .concat(chars)); + return Ary.uniq(modes.filter(m => chars.indexOf(m.char) < 0) + .map(m => m.name.toLowerCase()) + .concat(chars)); } commands.add(["feedkeys", "fk"], @@ -756,7 +760,7 @@ var Mappings = Module("mappings", { // Bloody hell. --Kris for (let [i, mode] of iter(modes)) for (let hive of mappings.hives.iterValues()) - for (let map of array.iterValues(hive.getStack(mode))) + for (let map of Ary.iterValues(hive.getStack(mode))) for (let name of values(map.names)) if (!seen.add(name)) yield { @@ -779,7 +783,7 @@ var Mappings = Module("mappings", { template.linkifyHelp(map.description + (map.rhs ? ": " + map.rhs : "")) ], help: function (map) { - let char = array.compact(map.modes.map(m => m.char))[0]; + let char = Ary.compact(map.modes.map(m => m.char))[0]; return char === "n" ? map.name : char ? char + "_" + map.name : ""; }, headings: ["Command", "Mode", "Group", "Description"] diff --git a/common/content/marks.js b/common/content/marks.js index 9afd717a..8012d8df 100644 --- a/common/content/marks.js +++ b/common/content/marks.js @@ -198,12 +198,12 @@ var Marks = Module("marks", { this._pendingJumps.push(mark); let sh = tab.linkedBrowser.sessionHistory; - let items = array(util.range(0, sh.count)); + let items = Ary(util.range(0, sh.count)); let a = items.slice(0, sh.index).reverse(); let b = items.slice(sh.index); a.length = b.length = Math.max(a.length, b.length); - items = array(a).zip(b).flatten().compact(); + items = Ary(a).zip(b).flatten().compact(); for (let i of items.iterValues()) { let entry = sh.getEntryAtIndex(i, false); diff --git a/common/content/modes.js b/common/content/modes.js index 177a08bd..58df5290 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -194,7 +194,7 @@ var Modes = Module("modes", { NONE: 0, - "@@iterator": function __iterator__() array.iterValues(this.all), + "@@iterator": function __iterator__() Ary.iterValues(this.all), get all() this._modes.slice(), @@ -238,7 +238,7 @@ var Modes = Module("modes", { dumpStack: function dumpStack() { util.dump("Mode stack:"); - for (let [i, mode] of array.iterItems(this._modeStack)) + for (let [i, mode] of Ary.iterItems(this._modeStack)) util.dump(" " + i + ": " + mode); }, @@ -285,7 +285,7 @@ var Modes = Module("modes", { save: function save(id, obj, prop, test) { if (!(id in this.boundProperties)) - for (let elem of array.iterValues(this._modeStack)) + for (let elem of Ary.iterValues(this._modeStack)) elem.saved[id] = { obj: obj, prop: prop, value: obj[prop], test: test }; this.boundProperties[id] = { obj: util.weakReference(obj), prop: prop, test: test }; }, @@ -447,7 +447,7 @@ var Modes = Module("modes", { let seen = new RealSet, res = [], queue = [this].concat(this.bases); - for (let mode of array.iterValues(queue)) + for (let mode of queue) if (!seen.add(mode)) { res.push(mode); apply(queue, "push", mode.bases); @@ -633,8 +633,8 @@ var Modes = Module("modes", { validator: function validator(vals) vals.map(v => v.replace(/^!/, "")) .every(k => hasOwnProperty(this.values, k)), - get values() array.toObject([[m.name.toLowerCase(), m.description] - for (m of values(modes._modes)) if (!m.hidden)]) + get values() Ary.toObject([[m.name.toLowerCase(), m.description] + for (m of values(modes._modes)) if (!m.hidden)]) }; options.add(["passunknown", "pu"], diff --git a/common/content/mow.js b/common/content/mow.js index df47087d..0f8e2b70 100644 --- a/common/content/mow.js +++ b/common/content/mow.js @@ -201,7 +201,7 @@ var MOW = Module("mow", { selection: !window.document.commandDispatcher.focusedWindow.getSelection().isCollapsed }; - for (let node of array.iterValues(menu.children)) { + for (let node of menu.children) { let group = node.getAttributeNS(NS, "group"); node.hidden = group && !group.split(/\s+/).every(g => enabled[g]); } diff --git a/common/modules/addons.jsm b/common/modules/addons.jsm index 023b502d..149382ee 100644 --- a/common/modules/addons.jsm +++ b/common/modules/addons.jsm @@ -346,8 +346,8 @@ var AddonList = Class("AddonList", { var Addons = Module("addons", { errors: Class.Memoize(() => - array(["ERROR_NETWORK_FAILURE", "ERROR_INCORRECT_HASH", - "ERROR_CORRUPT_FILE", "ERROR_FILE_ACCESS"]) + Ary(["ERROR_NETWORK_FAILURE", "ERROR_INCORRECT_HASH", + "ERROR_CORRUPT_FILE", "ERROR_FILE_ACCESS"]) .map(e => [AddonManager[e], _("AddonManager." + e)]) .toObject()) }, { @@ -466,8 +466,8 @@ var Addons = Module("addons", { context.incomplete = true; AddonManager.getAllAddons(function (addons) { context.incomplete = false; - update(array.uniq(base.concat(addons.map(a => a.type)), - true)); + update(Ary.uniq(base.concat(addons.map(a => a.type)), + true)); }); } }; diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 6f710bc4..e08588a9 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -176,6 +176,7 @@ function require_(obj, name, from, targetName) { defineModule("base", { // sed -n 's/^(const|var|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt exports: [ + "Ary", "Cc", "Ci", "Class", @@ -269,7 +270,7 @@ function literal(comment) { function apply(obj, meth, args) { // The function's own apply method breaks in strange ways // when using CPOWs. - return Function.prototype.apply.call(obj[meth], obj, args); + return Function.apply.call(obj[meth], obj, args); } /** @@ -320,7 +321,8 @@ function* properties(obj, prototypes) { } return false; }; - return array.uniq([k for (k in obj)].concat( + + return Ary.uniq([k for (k in obj)].concat( Object.getOwnPropertyNames( XPCNativeWrapper.unwrap(obj)) .filter(filter))); @@ -880,7 +882,7 @@ function Class(...args) { Class.extend(Constructor, superclass, args[0]); memoize(Constructor, "bound", Class.makeClosure); - if (Iter && array) // Hack. :/ + if (Iter && Ary) // Hack. :/ Object.defineProperty(Constructor, "closure", deprecated("bound", { get: function closure() this.bound })); update(Constructor, args[1]); @@ -987,7 +989,10 @@ Class.Memoize = function Memoize(getter, wait) return Class.replaceProperty(obj, key, getter.call(this, key)); } catch (e) { - util.reportError(e); + if (loaded.util) + util.reportError(e); + else + defineModule.dump(" " + (e.filename || e.fileName) + ":" + e.lineNumber + ": " + e + "\n" + (e.stack || Error().stack) + "\n"); } }; @@ -1343,7 +1348,7 @@ function Struct(...args) { const Struct = Class(className || "Struct", StructBase, { length: args.length, - members: array.toObject(args.map((v, k) => [v, k])) + members: Ary(args).map((v, k) => [v, k]).toObject(), }); args.forEach(function (name, i) { Struct.prototype.__defineGetter__(name, function () this[i]); @@ -1539,12 +1544,12 @@ function iter(obj, iface) { else if (Symbol.iterator in obj) res = obj[Symbol.iterator](); else if (isinstance(obj, [Ci.nsIDOMHTMLCollection, Ci.nsIDOMNodeList])) - res = array.iterItems(obj); + res = Ary.iterItems(obj); else if (ctypes && ctypes.CData && obj instanceof ctypes.CData) { while (obj.constructor instanceof ctypes.PointerType) obj = obj.contents; if (obj.constructor instanceof ctypes.ArrayType) - res = array.iterItems(obj); + res = Ary.iterItems(obj); else if (obj.constructor instanceof ctypes.StructType) res = (function* () { for (let prop of values(obj.constructor.fields)) { @@ -1591,9 +1596,9 @@ function iter(obj, iface) { return Iter(res); } update(iter, { - toArray: function toArray(iter) array(iter).array, + toArray: function toArray(iter) Ary(iter).array, - // See array.prototype for API docs. + // See Ary.prototype for API docs. toObject: function toObject(iter) { let obj = {}; for (let [k, v] of iter) @@ -1688,8 +1693,7 @@ update(iter, { return undefined; }, - sort: function sort(iter, fn, self) - array(this.toArray(iter).sort(fn, self)), + sort: function sort(iter, fn, self) Ary(iter).sort(fn, self), uniq: function* uniq(iter) { let seen = new RealSet; @@ -1749,8 +1753,9 @@ function arrayWrap(fn) { function wrapper() { let res = fn.apply(this, arguments); if (isArray(res)) - return array(res); - if (isinstance(res, ["Iterator", "Generator"])) + return Ary(res); + + if (isObject(res) && Symbol.iterator in res) return iter(res); return res; } @@ -1761,32 +1766,30 @@ function arrayWrap(fn) { /** * Array utility methods. */ -var array = Class("array", Array, { +var Ary = Class("Ary", Array, { init: function (ary) { - if (Symbol.iterator in ary) + if (Symbol.iterator in ary && !isArray(ary)) ary = [k for (k of ary)]; - else if (isinstance(ary, ["Iterator", "Generator"]) || Symbol.iterator in ary) - ary = [k for (k of ary)]; - else if (ary.length) - ary = Array.slice(ary); let self = this; return new Proxy(ary, { get: function array_get(target, prop) { - if (prop in array && callable(array[prop])) - return arrayWrap(array[prop].bind(array, target)); - if (prop == "array") return target; - let p = target[prop]; - if (!/^\d+$/.test(prop) && - prop != "toString" && - prop != "toSource" && - callable(p)) - return arrayWrap(p); + if (prop in Ary && callable(Ary[prop])) + return arrayWrap(Ary[prop].bind(Ary, target)); - return p; + let p = target[prop]; + + if (typeof prop == "symbol" || + /^\d+$/.test(prop) || + prop == "toString" || + prop == "toSource" || + !callable(p)) + return p; + + return arrayWrap(p); } }); } @@ -1922,20 +1925,27 @@ let iterProto = Iter.prototype; Object.keys(iter).forEach(function (k) { iterProto[k] = function (...args) { let res = apply(iter, k, [this].concat(args)); - if (isinstance(res, ["Iterator", "Generator"])) - return Iter(res); + + if (k == "toArray") + return res; + + if (isObject(res) && Symbol.iterator in res) + return Iter(res[Symbol.iterator]()); + return res; }; }); -Object.keys(array).forEach(function (k) { +Object.keys(Ary).forEach(function (k) { if (!(k in iterProto)) iterProto[k] = function (...args) { - let res = apply(array, k, [this.toArray()].concat(args)); - if (isinstance(res, ["Iterator", "Generator"])) - return Iter(res); + let res = apply(Ary, k, [this.toArray()].concat(args)); + if (isArray(res)) - return array(res); + return Ary(res); + + if (isObject(res) && Symbol.iterator in res) + return Iter(res[Symbol.iterator]()); return res; }; }); @@ -1943,10 +1953,12 @@ Object.keys(array).forEach(function (k) { Object.getOwnPropertyNames(Array.prototype).forEach(function (k) { if (!(k in iterProto) && callable(Array.prototype[k])) iterProto[k] = function () { - let ary = iter(this).toArray(); + let ary = this.toArray(); let res = apply(ary, k, arguments); + if (isArray(res)) - return array(res); + return Ary(res); + return res; }; }); @@ -1954,6 +1966,13 @@ Object.getOwnPropertyNames(Array.prototype).forEach(function (k) { Object.defineProperty(Class.prototype, "closure", deprecated("bound", { get: function closure() this.bound })); +if (false) + var array = Class("array", Ary, { + init: deprecated("Ary", function init() { init.superapply(arguments) }) + }); +else + array = Ary; + endModule(); // catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);} diff --git a/common/modules/bookmarkcache.jsm b/common/modules/bookmarkcache.jsm index b5f6613c..e11e82b4 100644 --- a/common/modules/bookmarkcache.jsm +++ b/common/modules/bookmarkcache.jsm @@ -87,9 +87,9 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), { bookmarks: Class.Memoize(function () this.load()), - keywords: Class.Memoize(function () array.toObject([[b.keyword, b] - for (b of this) - if (b.keyword)])), + keywords: Class.Memoize(function () Ary.toObject([[b.keyword, b] + for (b of this) + if (b.keyword)])), rootFolders: ["toolbarFolder", "bookmarksMenuFolder", "unfiledBookmarksFolder"] .map(s => services.bookmarks[s]), diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index a587cbed..1daa6dd2 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -61,7 +61,7 @@ var Buffer = Module("Buffer", { * buffer. Only returns style sheets for the 'screen' media type. */ get alternateStyleSheets() { - let stylesheets = array.flatten( + let stylesheets = Ary.flatten( this.allFrames().map(w => Array.slice(w.document.styleSheets))); return stylesheets.filter( @@ -985,7 +985,7 @@ var Buffer = Module("Buffer", { if (win.scrollMaxX > 0 || win.scrollMaxY > 0) return win; - for (let frame of array.iterValues(win.frames)) + for (let frame of Ary.iterValues(win.frames)) if (frame.scrollMaxX > 0 || frame.scrollMaxY > 0) return frame; @@ -2304,8 +2304,8 @@ var Buffer = Module("Buffer", { let frames = buffer.allFrames(null, true); - let elements = array.flatten(frames.map(win => [m for (m of DOM.XPath(xpath, win.document))])) - .filter(function (elem) { + let elements = Ary.flatten(frames.map(win => [m for (m of DOM.XPath(xpath, win.document))])) + .filter(function (elem) { if (isinstance(elem, [Ci.nsIDOMHTMLFrameElement, Ci.nsIDOMHTMLIFrameElement])) return Editor.getEditor(elem.contentWindow); @@ -2767,7 +2767,7 @@ Buffer.addPageInfoSection("s", "Security", function* (verbose) { return; // For now // Modified from Firefox - function location(data) array.compact([ + function location(data) Ary.compact([ data.city, data.state, data.country ]).join(", "); diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 449bd5b3..cd0cb650 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -220,7 +220,7 @@ var Command = Class("Command", { parsedSpecs: Class.Memoize(function () Command.parseSpecs(this.specs)), /** @property {[string]} All of this command's short names, e.g., "com" */ - shortNames: Class.Memoize(function () array.compact(this.parsedSpecs.map(n => n[1]))), + shortNames: Class.Memoize(function () Ary.compact(this.parsedSpecs.map(n => n[1]))), /** * @property {[string]} All of this command's long names, e.g., "command" @@ -231,7 +231,7 @@ var Command = Class("Command", { name: Class.Memoize(function () this.longNames[0]), /** @property {[string]} All of this command's long and short names. */ - names: Class.Memoize(function () this.names = array.flatten(this.parsedSpecs)), + names: Class.Memoize(function () this.names = Ary.flatten(this.parsedSpecs)), /** @property {string} This command's description, as shown in :listcommands */ description: Messages.Localized(""), @@ -307,7 +307,7 @@ var Command = Class("Command", { }, this)), _options: [], - optionMap: Class.Memoize(function () array(this.options) + optionMap: Class.Memoize(function () Ary(this.options) .map(opt => opt.names.map(name => [name, opt])) .flatten().toObject()), @@ -455,7 +455,7 @@ var Ex = Module("Ex", { Class.replaceProperty(res, opt.names[0], val); res.explicitOpts[opt.names[0]] = val; } - for (let [i, val] of array.iterItems(args)) + for (let [i, val] of Ary.iterItems(args)) res[i] = String(val); return res; }, @@ -535,7 +535,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, { if (this.cached) this.modules.initDependencies("commands"); this.cached = false; - return array.iterValues(this._list.sort((a, b) => a.name > b.name)); + return Ary.iterValues(this._list.sort((a, b) => a.name > b.name)); }, /** @property {string} The last executed Ex command line. */ @@ -565,7 +565,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, { extra.hive = this; extra.parsedSpecs = Command.parseSpecs(specs); - let names = array.flatten(extra.parsedSpecs); + let names = Ary.flatten(extra.parsedSpecs); let name = names[0]; if (this.name != "builtin") { @@ -855,8 +855,8 @@ var Commands = Module("commands", { let defaults = {}; if (args.ignoreDefaults) - defaults = array(this.options).map(opt => [opt.names[0], opt.default]) - .toObject(); + defaults = Ary(this.options).map(opt => [opt.names[0], opt.default]) + .toObject(); for (let [opt, val] of iter(args.options || {})) { if (val === undefined) @@ -1675,7 +1675,7 @@ var Commands = Module("commands", { ], literal: 1, - serialize: function () array(commands.userHives) + serialize: function () Ary(commands.userHives) .filter(h => h.persist) .map(hive => [ { diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index ea5b8287..f0fbbbec 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -237,7 +237,7 @@ var CompletionContext = Class("CompletionContext", { try { let allItems = this.contextList.map(function m(context) context.hasItems && context.items.length); - if (this.cache.allItems && array.equals(this.cache.allItems, allItems)) + if (this.cache.allItems && Ary.equals(this.cache.allItems, allItems)) return this.cache.allItemsResult; this.cache.allItems = allItems; @@ -250,7 +250,7 @@ var CompletionContext = Class("CompletionContext", { get longestSubstring() self.longestAllSubstring, - get items() array.flatten(self.activeContexts.map(function m(context) { + get items() Ary.flatten(self.activeContexts.map(function m(context) { let prefix = self.value.substring(minStart, context.offset); return context.items.map(function m(item) ({ @@ -285,7 +285,7 @@ var CompletionContext = Class("CompletionContext", { lists.pop()); if (!substrings) // FIXME: How is this undefined? return []; - return array.uniq(Array.slice(substrings)); + return Ary.uniq(Array.slice(substrings)); }, // Temporary get longestAllSubstring() { diff --git a/common/modules/config.jsm b/common/modules/config.jsm index 6d2b9bd7..3745c26a 100644 --- a/common/modules/config.jsm +++ b/common/modules/config.jsm @@ -227,15 +227,15 @@ var ConfigBase = Class("ConfigBase", { .toArray(); } else { - res = array(f.leafName - // Fails on FF3: for (f of util.getFile(uri).iterDirectory()) - for (f of util.getFile(uri).readDirectory()) - if (f.isDirectory())).array; + res = Ary(f.leafName + // Fails on FF3: for (f of util.getFile(uri).iterDirectory()) + for (f of util.getFile(uri).readDirectory()) + if (f.isDirectory())).array; } let exists = function exists(pkg) services["resource:"].hasSubstitution("dactyl-locale-" + pkg); - return array.uniq([this.appLocale, this.appLocale.replace(/-.*/, "")] + return Ary.uniq([this.appLocale, this.appLocale.replace(/-.*/, "")] .filter(exists) .concat(res)); }), diff --git a/common/modules/contexts.jsm b/common/modules/contexts.jsm index 2b19d6af..7e1f76e9 100644 --- a/common/modules/contexts.jsm +++ b/common/modules/contexts.jsm @@ -182,7 +182,7 @@ var Contexts = Module("contexts", { return { enumerable: true, - get: () => array(contexts.groups[this.name]) + get: () => Ary(contexts.groups[this.name]) }; this.Hive = constructor; diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index d0c0e1c0..58e638f2 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -99,8 +99,8 @@ var DOM = Class("DOM", { get document() this._document || this[0] && (this[0].ownerDocument || this[0].document || this[0]), set document(val) this._document = val, - attrHooks: array.toObject([ - ["", { + attrHooks: { + "": { href: { get: elem => elem.href || elem.getAttribute("href") }, src: { get: elem => elem.src || elem.getAttribute("src") }, checked: { get: elem => elem.hasAttribute("checked") ? elem.getAttribute("checked") == "true" : elem.checked, @@ -109,8 +109,8 @@ var DOM = Class("DOM", { disabled: BooleanAttribute("disabled"), hidden: BooleanAttribute("hidden"), readonly: BooleanAttribute("readonly") - }] - ]), + } + }, matcher: function matcher(sel) elem => (elem.mozMatchesSelector && elem.mozMatchesSelector(sel)), @@ -309,7 +309,7 @@ var DOM = Class("DOM", { }, set list(val) { - let str = array.uniq(val).join(" ").trim(); + let str = Ary.uniq(val).join(" ").trim(); self.attrNS(NS, "highlight", str || null); }, @@ -457,7 +457,9 @@ var DOM = Class("DOM", { try { var res = node.ownerDocument.defaultView.getComputedStyle(node, null); } - catch (e) {} + catch (e) { + util.reportError(e); + } if (res == null) { util.dumpStack(_("error.nullComputedStyle", node)); @@ -615,7 +617,7 @@ var DOM = Class("DOM", { else { let tag = "<" + [namespaced(elem)].concat( [namespaced(a) + '="' + String.replace(a.value, /["<]/, DOM.escapeHTML) + '"' - for ([i, a] of array.iterItems(elem.attributes))]).join(" "); + for (a of elem.attributes)]).join(" "); res.push(tag + (!hasChildren ? "/>" : ">...")); } @@ -634,7 +636,7 @@ var DOM = Class("DOM", { attrNS: function attrNS(ns, key, val) { if (val !== undefined) - key = array.toObject([[key, val]]); + key = Ary.toObject([[key, val]]); let hooks = this.attrHooks[ns] || {}; @@ -667,7 +669,7 @@ var DOM = Class("DOM", { css: update(function css(key, val) { if (val !== undefined) - key = array.toObject([[key, val]]); + key = Ary.toObject([[key, val]]); if (isObject(key)) return this.each(function (elem) { @@ -830,7 +832,7 @@ var DOM = Class("DOM", { if (isObject(event)) capture = listener; else - event = array.toObject([[event, listener]]); + event = Ary.toObject([[event, listener]]); for (let [evt, callback] of iter(event)) event[evt] = util.wrapCallback(callback, true); @@ -844,7 +846,7 @@ var DOM = Class("DOM", { if (isObject(event)) capture = listener; else - event = array.toObject([[event, listener]]); + event = Ary.toObject([[event, listener]]); return this.each(function (elem) { for (let [k, v] of iter(event)) @@ -855,7 +857,7 @@ var DOM = Class("DOM", { if (isObject(event)) capture = listener; else - event = array.toObject([[event, listener]]); + event = Ary.toObject([[event, listener]]); for (let pair of iter(event)) { let [evt, callback] = pair; @@ -1146,7 +1148,7 @@ var DOM = Class("DOM", { */ parse: function parse(input, unknownOk=true) { if (isArray(input)) - return array.flatten(input.map(k => this.parse(k, unknownOk))); + return Ary.flatten(input.map(k => this.parse(k, unknownOk))); let out = []; for (let match of util.regexp.iterate(/<.*?>?>|[^<]|<(?!.*>)/g, input)) { @@ -1871,11 +1873,11 @@ var DOM = Class("DOM", { * @returns {string} */ makeXPath: function makeXPath(nodes) { - return array(nodes).map(util.debrace).flatten() - .map(node => /^[a-z]+:/.test(node) ? node - : [node, "xhtml:" + node]) - .flatten() - .map(node => "//" + node).join(" | "); + return Ary(nodes).map(util.debrace).flatten() + .map(node => /^[a-z]+:/.test(node) ? node + : [node, "xhtml:" + node]) + .flatten() + .map(node => "//" + node).join(" | "); }, namespaces: { diff --git a/common/modules/finder.jsm b/common/modules/finder.jsm index 4a63ada2..b97e525c 100644 --- a/common/modules/finder.jsm +++ b/common/modules/finder.jsm @@ -522,7 +522,7 @@ var RangeFind = Class("RangeFind", { this.regexp = false; if (regexp) { let re = RegExp(word, "gm" + this.flags); - for (this.range of array.iterValues(this.ranges)) { + for (this.range of this.ranges) { for (let match of util.regexp.iterate(re, DOM.stringify(this.range.range, true))) { let lastRange = this.lastRange; if (res = this.find(null, this.reverse, true)) @@ -575,7 +575,7 @@ var RangeFind = Class("RangeFind", { let pageStart = RangeFind.endpoint(pageRange, true); let pageEnd = RangeFind.endpoint(pageRange, false); - for (let frame of array.iterValues(win.frames)) { + for (let frame of Ary.iterValues(win.frames)) { let range = doc.createRange(); if (DOM(frame.frameElement).style.visibility == "visible") { range.selectNode(frame.frameElement); @@ -706,11 +706,11 @@ var RangeFind = Class("RangeFind", { set stale(val) this._stale = val, addListeners: function addListeners() { - for (let range of array.iterValues(this.ranges)) + for (let range of this.ranges) range.window.addEventListener("unload", this.bound.onUnload, true); }, purgeListeners: function purgeListeners() { - for (let range of array.iterValues(this.ranges)) + for (let range of this.ranges) try { range.window.removeEventListener("unload", this.bound.onUnload, true); } diff --git a/common/modules/help.jsm b/common/modules/help.jsm index 35bab00a..ccca2694 100644 --- a/common/modules/help.jsm +++ b/common/modules/help.jsm @@ -31,7 +31,7 @@ var HelpBuilder = Class("HelpBuilder", { [f.value for (f of DOM.XPath("//dactyl:include/@href", doc))]); // Scrape the tags from the rest of the help files. - array.flatten(files).forEach(function (file) { + Ary.flatten(files).forEach(function (file) { this.tags[file + ".xml"] = file; this.findHelpFile(file).forEach(function (doc) { this.addTags(file, doc); @@ -128,7 +128,7 @@ var Help = Module("Help", { let betas = util.regexp(/\[((?:b|rc)\d)\]/, "gx"); - let beta = array(betas.iterate(NEWS)) + let beta = Ary(betas.iterate(NEWS)) .map(m => m[1]).uniq().slice(-1)[0]; function rec(text, level, li) { @@ -151,7 +151,7 @@ var Help = Module("Help", { else if (match.par) { let [, par, tags] = /([^]*?)\s*((?:\[[^\]]+\])*)\n*$/.exec(match.par); let t = tags; - tags = array(betas.iterate(tags)).map(m => m[1]); + tags = Ary(betas.iterate(tags)).map(m => m[1]); let group = !tags.length ? "" : !tags.some(t => t == beta) ? "HelpNewsOld" : "HelpNewsNew"; @@ -317,7 +317,7 @@ var Help = Module("Help", { data.push(" xmlns=" + JSON.stringify(XHTML), " xmlns:dactyl=" + JSON.stringify(NS)); - for (let { name, value } of array.iterValues(node.attributes)) { + for (let { name, value } of node.attributes) { if (name == "dactyl:highlight") { styles.add(value); name = "class"; diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index 022034e1..c6f6064c 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -65,7 +65,7 @@ Highlight.defaultValue("value", function () this.defaultValue); update(Highlight.prototype, { get base() this.baseClass != this.class && highlight.highlight[this.baseClass] || null, - get bases() array.compact(this.extends.map(name => highlight.get(name))), + get bases() Ary.compact(this.extends.map(name => highlight.get(name))), get inheritedCSS() { if (this.gettingCSS) @@ -178,7 +178,7 @@ var Highlights = Module("Highlight", { } highlight.set("value", newStyle || ""); - highlight.extends = array.uniq(bases, true); + highlight.extends = Ary.uniq(bases, true); if (force) highlight.style.enabled = true; this.highlight[highlight.class] = highlight; @@ -432,13 +432,13 @@ var Highlights = Module("Highlight", { context.keys = { text: f => f.leafName.replace(extRe, ""), description: ".parent.path" }; context.completions = - array.flatten( - io.getRuntimeDirectories("colors").map( - dir => dir.readDirectory() - .filter(file => extRe.test(file.leafName)))) - .concat([ - { leafName: "default", parent: { path: /*L*/"Revert to builtin colorscheme" } } - ]); + Ary.flatten( + io.getRuntimeDirectories("colors").map( + dir => dir.readDirectory() + .filter(file => extRe.test(file.leafName)))) + .concat([ + { leafName: "default", parent: { path: /*L*/"Revert to builtin colorscheme" } } + ]); }; diff --git a/common/modules/io.jsm b/common/modules/io.jsm index aa957e2b..cbff066b 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -552,8 +552,8 @@ var IO = Module("io", { } else { cmd.write("cd " + shellEscape(this.cwd.path) + "\n" + - ["exec", ">" + shellEscape(stdout.path), "2>&1", "<" + shellEscape(stdin.path), - shellEscape(shell.path), shcf, shellEscape(command)].join(" ")); + ["exec", ">" + shellEscape(stdout.path), "2>&1", "<" + shellEscape(stdin.path), + shellEscape(shell.path), shcf, shellEscape(command)].join(" ")); res = this.run("/bin/sh", ["-e", cmd.path], callback ? async : true); } @@ -573,7 +573,7 @@ var IO = Module("io", { * otherwise, the return value of *func*. */ withTempFiles: function withTempFiles(func, self, checked, ext, label) { - let args = array(util.range(0, func.length)) + let args = Ary(util.range(0, func.length)) .map(bind("createTempFile", this, ext, label)).array; try { if (!args.every(util.identity)) @@ -665,7 +665,7 @@ var IO = Module("io", { for (cmd of commands.iterator()) if (cmd.serialize)]; - lines = array.flatten(lines); + lines = Ary.flatten(lines); lines.unshift('"' + config.version + "\n"); lines.push("\n\" vim: set ft=" + config.name + ":"); @@ -857,11 +857,11 @@ unlet s:cpo_save autocommands: wrap("syn keyword " + config.name + "AutoEvent ", keys(config.autocommands)), commands: wrap("syn keyword " + config.name + "Command ", - array(c.specs for (c of commands.iterator())).flatten()), + Ary(c.specs for (c of commands.iterator())).flatten()), options: wrap("syn keyword " + config.name + "Option ", - array(o.names for (o of options) if (o.type != "boolean")).flatten()), + Ary(o.names for (o of options) if (o.type != "boolean")).flatten()), toggleoptions: wrap("let s:toggleOptions = [", - array(o.realNames for (o of options) if (o.type == "boolean")) + Ary(o.realNames for (o of options) if (o.type == "boolean")) .flatten().map(String.quote), ", ") + "]" }; //}}} @@ -1063,7 +1063,7 @@ unlet s:cpo_save if (file.isFile() && file.isExecutable())]); } - return array.flatten(commands); + return Ary.flatten(commands); }; }; diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index 5bed78e7..e565c010 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -106,7 +106,7 @@ var JavaScript = Module("javascript", { let completions = [k for (k of this.iter(obj, toplevel))]; if (obj === this.modules) // Hack. - completions = array.uniq(completions.concat([k for (k of this.iter(this.modules.jsmodules, toplevel))])); + completions = Ary.uniq(completions.concat([k for (k of this.iter(this.modules.jsmodules, toplevel))])); return completions; }, @@ -623,7 +623,7 @@ var JavaScript = Module("javascript", { * enumerable by any standard method. */ globalNames: Class.Memoize(function () { - return array.uniq([ + return Ary.uniq([ "Array", "ArrayBuffer", "AttributeName", "Audio", "Boolean", "Components", "CSSFontFaceStyleDecl", "CSSGroupRuleRuleList", "CSSNameSpaceRule", "CSSRGBColor", "CSSRect", "ComputedCSSStyleDeclaration", "Date", "Error", diff --git a/common/modules/main.jsm b/common/modules/main.jsm index 9af7db74..f876e725 100644 --- a/common/modules/main.jsm +++ b/common/modules/main.jsm @@ -168,7 +168,7 @@ var Modules = function Modules(window) { newContext: newContext, - get ownPropertyValues() array.compact( + get ownPropertyValues() Ary.compact( Object.getOwnPropertyNames(this) .map(name => Object.getOwnPropertyDescriptor(this, name).value)), diff --git a/common/modules/messages.jsm b/common/modules/messages.jsm index 1cbf3be3..5d033578 100644 --- a/common/modules/messages.jsm +++ b/common/modules/messages.jsm @@ -39,21 +39,21 @@ var Messages = Module("messages", { }, bundles: Class.Memoize(function () - array.uniq([JSMLoader.getTarget("dactyl://locale/" + this.name + ".properties"), - JSMLoader.getTarget("dactyl://locale-local/" + this.name + ".properties"), - "resource://dactyl-locale/en-US/" + this.name + ".properties", - "resource://dactyl-locale-local/en-US/" + this.name + ".properties"], - true) - .map(services.stringBundle.createBundle) - .filter(function (bundle) { - try { - bundle.getSimpleEnumeration(); - return true; - } - catch (e) { - return false; - } - })), + Ary.uniq([JSMLoader.getTarget("dactyl://locale/" + this.name + ".properties"), + JSMLoader.getTarget("dactyl://locale-local/" + this.name + ".properties"), + "resource://dactyl-locale/en-US/" + this.name + ".properties", + "resource://dactyl-locale-local/en-US/" + this.name + ".properties"], + true) + .map(services.stringBundle.createBundle) + .filter(function (bundle) { + try { + bundle.getSimpleEnumeration(); + return true; + } + catch (e) { + return false; + } + })), iterate: function* () { let seen = new RealSet; @@ -113,7 +113,7 @@ var Messages = Module("messages", { yield key(prop) + " = " + obj[prop]; if (iter_.values) { - let iter_ = isArray(obj.values) ? array.iterValues(obj.values) + let iter_ = isArray(obj.values) ? obj.values : iter(obj.values); for (let [k, v] of iter_) @@ -130,15 +130,15 @@ var Messages = Module("messages", { }()).toArray(); file.write( - array(commands.allHives.map(h => properties("command", h))) - .concat(modes.all.map(m => - properties("map", values(mappings.builtin.getStack(m) - .filter(map => map.modes[0] == m))))) - .concat(properties("mode", values(modes.all.filter(m => !m.hidden)))) - .concat(properties("option", options)) - .concat(properties("hintmode", values(hints.modes), "prompt")) - .concat(properties("pageinfo", values(Buffer.pageInfo), "title")) - .concat(properties("sanitizeitem", values(sanitizer.itemMap))) + Ary(commands.allHives.map(h => properties("command", h))) + .concat(modes.all.map(m => + properties("map", values(mappings.builtin.getStack(m) + .filter(map => map.modes[0] == m))))) + .concat(properties("mode", values(modes.all.filter(m => !m.hidden)))) + .concat(properties("option", options)) + .concat(properties("hintmode", values(hints.modes), "prompt")) + .concat(properties("pageinfo", values(Buffer.pageInfo), "title")) + .concat(properties("sanitizeitem", values(sanitizer.itemMap))) .flatten().uniq().join("\n")); } }, { diff --git a/common/modules/options.jsm b/common/modules/options.jsm index a6b6d9dd..904787c0 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -500,7 +500,7 @@ var Option = Class("Option", { }, domains: { - sitelist: function (vals) array.compact(vals.map(site => util.getHost(site.filter))), + sitelist: function (vals) Ary.compact(vals.map(site => util.getHost(site.filter))), get sitemap() this.sitelist }, @@ -543,7 +543,7 @@ var Option = Class("Option", { return value.map(Option.parseSite, this); }, - stringmap: function stringmap(value) array.toObject( + stringmap: function stringmap(value) Ary.toObject( Option.splitList(value, true).map(function (v) { let [count, key, quote] = Commands.parseArg(v, /:/); return [key, Option.dequote(v.substr(count + 1))]; @@ -555,7 +555,7 @@ var Option = Class("Option", { list: function list(value, parse) { let prev = null; - return array.compact(Option.splitList(value, true) + return Ary.compact(Option.splitList(value, true) .map(function (v) { let [count, filter, quote] = Commands.parseArg(v, /:/, true); @@ -810,7 +810,7 @@ var Option = Class("Option", { update(BooleanOption.prototype, { names: Class.Memoize(function () - array.flatten([[name, "no" + name] for (name of values(this.realNames))])) + Ary.flatten([[name, "no" + name] for (name of values(this.realNames))])) }); var OptionHive = Class("OptionHive", Contexts.Hive, { @@ -1415,7 +1415,7 @@ var Options = Module("options", { update({ bang: true, completer: setCompleter, - domains: function domains(args) array.flatten(args.map(function (spec) { + domains: function domains(args) Ary.flatten(args.map(function (spec) { try { let opt = modules.options.parseOpt(spec); if (opt.option && opt.option.domains) diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm index c71d2a22..cb054ced 100644 --- a/common/modules/overlay.jsm +++ b/common/modules/overlay.jsm @@ -71,7 +71,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen let listeners = this.getData(doc, "listeners"); if (!isObject(event)) - var [self, events] = [null, array.toObject([[event, callback]])]; + var [self, events] = [null, Ary.toObject([[event, callback]])]; else [self, events] = [event, event[callback || "events"]]; @@ -309,7 +309,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen if (!(node instanceof Ci.nsIDOMDocumentFragment)) savedElems.push(node); else - for (let n of array.iterValues(node.childNodes)) + for (let n of node.childNodes) savedElems.push(n); fn(elem, node); diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index e4244005..19ef0b54 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -871,24 +871,6 @@ var AsyncFile = Class("AsyncFile", File, { yield OS.File.makeDir(path, options); }), - /** - * Iterates over the objects in this directory. - */ - iterDirectory: function* iterDirectory() { - if (!this.exists()) - throw Error(_("io.noSuchFile")); - if (!this.isDirectory()) - throw Error(_("io.eNotDir")); - for (let file of iter(this.directoryEntries)) - yield File(file); - }, - - /** - * Returns an iterator for all lines in a file. - */ - get lines() File.readLines(services.FileInStream(this.file, -1, 0, 0), - this.charset), - _setEncoding: function _setEncoding(options) { if (this.encoding != null && !("encoding" in options)) options = update({}, options, diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 79dc354e..e04cf945 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -119,9 +119,9 @@ var Hive = Class("Hive", { "@@iterator": function () iter(this.sheets), - get sites() array(this.sheets).map(s => s.sites) - .flatten() - .uniq().array, + get sites() Ary(this.sheets).map(s => s.sites) + .flatten() + .uniq().array, /** * Add a new style sheet. @@ -411,7 +411,7 @@ var Styles = Module("Styles", { context.keys.text = util.identity; context.keys.description = function (site) this.sheets.length + /*L*/" sheet" + (this.sheets.length == 1 ? "" : "s") + ": " + - array.compact(this.sheets.map(s => s.name)).join(", "); + Ary.compact(this.sheets.map(s => s.name)).join(", "); context.keys.sheets = site => group.sheets.filter(s => s.sites.indexOf(site) >= 0); context.keys.active = site => uris.some(Styles.matchFilter(site)); @@ -596,7 +596,7 @@ var Styles = Module("Styles", { if (args["-append"]) { let sheet = args["-group"].get(args["-name"]); if (sheet) { - filter = array(sheet.sites).concat(filter).uniq().join(","); + filter = Ary(sheet.sites).concat(filter).uniq().join(","); css = sheet.css + " " + css; } } @@ -633,7 +633,7 @@ var Styles = Module("Styles", { { names: ["-nopersist", "-N"], description: "Do not save this style to an auto-generated RC file" } ], serialize: function () - array(styles.hives) + Ary(styles.hives) .filter(hive => hive.persist) .map(hive => hive.sheets.filter(style => style.persist) diff --git a/common/modules/template.jsm b/common/modules/template.jsm index b6666bb9..fa33ddc9 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -154,7 +154,7 @@ var Template = Module("Template", { map: function map(iter_, func, sep, interruptable) { if (typeof iter_.length == "number") // FIXME: Kludge? - iter_ = array.iterValues(iter_); + iter_ = Ary.iterValues(iter_); let res = []; let n = 0; diff --git a/common/modules/util.jsm b/common/modules/util.jsm index d83ccc8e..1fd69c10 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -65,7 +65,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), Magic: Magic, init: function init() { - this.Array = array; + this.Array = Ary; this.addObserver(this); this.windows = []; @@ -301,7 +301,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), : "", { test: function test(obj) obj[char] != null })); - for (let elem of array.iterValues(stack)) + for (let elem of stack) elem.seen[char] = true; } } @@ -420,7 +420,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), })); } - for (let elem of array.iterValues(stack)) + for (let elem of stack) elem.seen.add(name); } } @@ -508,7 +508,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), let rec = function rec(acc) { if (acc.length == patterns.length) - res.push(array(substrings).zip(acc).flatten().join("")); + res.push(Ary(substrings).zip(acc).flatten().join("")); else for (let pattern of patterns[acc.length]) rec(acc.concat(pattern)); @@ -1400,7 +1400,7 @@ 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 () [k + "\n" + v for ([k, v] of array.iterValues(this))].join("\n\n"); + this.errors.toString = function () [k + "\n" + v for ([k, v] of this)].join("\n\n"); this.dump(String(error)); this.dump(obj); @@ -1755,7 +1755,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), } } }, { - Array: array + Array: Ary }); /**