diff --git a/common/content/abbreviations.js b/common/content/abbreviations.js index 4822e97a..e353a719 100644 --- a/common/content/abbreviations.js +++ b/common/content/abbreviations.js @@ -105,7 +105,7 @@ var AbbrevHive = Class("AbbrevHive", Contexts.Hive, { }, /** @property {boolean} True if there are no abbreviations. */ - get empty() { return !values(this._store).find(util.identity); }, + get empty() { return !values(this._store).find(identity); }, /** * Adds a new abbreviation. @@ -251,7 +251,7 @@ var Abbreviations = Module("abbreviations", { let match = this._match.exec(text); if (match) return this.hives.map(h => h.get(mode, match[2] || match[4] || match[6])) - .find(util.identity); + .find(identity); return null; }, diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index aa14e32f..efb292ec 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -438,7 +438,7 @@ var Bookmarks = Module("bookmarks", { for (b of bookmarkcache) if (b.tags)) .flatten().uniq().array; - context.keys = { text: util.identity, description: util.identity }; + context.keys = { text: identity, description: identity }; }, type: CommandOption.LIST }; @@ -705,7 +705,7 @@ var Bookmarks = Module("bookmarks", { } catch (e) {} return null; - }).filter(util.identity); + }).filter(identity); }; }); }; @@ -742,7 +742,7 @@ var Bookmarks = Module("bookmarks", { let ctxt = context.fork(name, 0); ctxt.title = [/*L*/desc + " Suggestions"]; - ctxt.keys = { text: util.identity, description: function () "" }; + ctxt.keys = { text: identity, description: function () "" }; ctxt.compare = CompletionContext.Sort.unsorted; ctxt.filterFunc = null; diff --git a/common/content/commandline.js b/common/content/commandline.js index 28ee5561..55717f26 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -166,7 +166,7 @@ var CommandWidgets = Class("CommandWidgets", { this.elements[obj.name] = obj; function get(prefix, map, id) { - return (obj.getElement || util.identity)(map[id] || document.getElementById(prefix + id)); + return (obj.getElement || identity)(map[id] || document.getElementById(prefix + id)); } this.active.__defineGetter__(obj.name, () => this.activeGroup[obj.name][obj.name]); @@ -200,7 +200,7 @@ var CommandWidgets = Class("CommandWidgets", { else { highlight.highlightNode(elem, (val[0] != null ? val[0] : obj.defaultGroup) - .split(/\s/).filter(util.identity) + .split(/\s/).filter(identity) .map(g => g + " " + nodeSet.group + g) .join(" ")); elem.value = val[1]; diff --git a/common/content/dactyl.js b/common/content/dactyl.js index e1bc814f..f7e430d6 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -256,7 +256,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { { argCount: "*", completer: function (context, args) { - context.keys.text = util.identity; + context.keys.text = identity; context.keys.description = function () { return seen[this.text] + /*L*/" matching items"; }; @@ -662,7 +662,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { */ generateHelp: function generateHelp(obj, extraHelp, str, specOnly) { let link, tag, spec; - link = tag = spec = util.identity; + link = tag = spec = identity; let args = null; if (obj instanceof Command) { @@ -1286,7 +1286,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { template.map(iter(dactyl.indices), ([name, iter]) => ["dl", { insertafter: name + "-index" }, - template.map(iter(), util.identity)], + template.map(iter(), identity)], "\n\n")]); }, true); diff --git a/common/content/editor.js b/common/content/editor.js index 252abb93..8ff52b17 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -777,7 +777,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { completion: function initCompletion() { completion.register = function complete_register(context) { context = context.fork("registers"); - context.keys = { text: util.identity, description: editor.bound.getRegister }; + context.keys = { text: identity, description: editor.bound.getRegister }; context.match = function (r) { return !this.filter || this.filter.contains(r); @@ -1413,7 +1413,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { let res = {}; services.spell.getDictionaryList(res, {}); context.completions = res.value; - context.keys = { text: util.identity, description: util.identity }; + context.keys = { text: identity, description: identity }; } }); }, diff --git a/common/content/history.js b/common/content/history.js index fe410d73..c3cdfdf5 100644 --- a/common/content/history.js +++ b/common/content/history.js @@ -331,7 +331,7 @@ var History = Module("history", { completion.domain = context => { context.anchored = false; context.compare = (a, b) => String.localeCompare(a.key, b.key); - context.keys = { text: util.identity, description: util.identity, + context.keys = { text: identity, description: identity, key: function (host) host.split(".").reverse().join(".") }; // FIXME: Schema-specific diff --git a/common/content/mappings.js b/common/content/mappings.js index 20f49f3d..873cd3e9 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -196,7 +196,7 @@ var MapHive = Class("MapHive", Contexts.Hive, { */ add: function (modes, keys, description, action, extra={}) { modes = Array.concat(modes); - if (!modes.every(util.identity)) + if (!modes.every(identity)) throw TypeError(/*L*/"Invalid modes: " + modes); let map = Map(modes, keys, description, action, extra); diff --git a/common/content/marks.js b/common/content/marks.js index 326153f4..ba461638 100644 --- a/common/content/marks.js +++ b/common/content/marks.js @@ -301,14 +301,14 @@ var Marks = Module("marks", { "(" + Math.round(mark.offset.x * 100), Math.round(mark.offset.y * 100) + ")", (tab && "tab: " + tabs.index(tab)) - ].filter(util.identity).join(", "); + ].filter(identity).join(", "); if (mark.position) return [name, mark.location, "(" + Math.round(mark.position.x * 100) + "%", Math.round(mark.position.y * 100) + "%)", (tab && "tab: " + tabs.index(tab)) - ].filter(util.identity).join(", "); + ].filter(identity).join(", "); }, isLocalMark: bind("test", /^[a-z`']$/), diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 7b5acf50..34754a96 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -201,6 +201,7 @@ defineModule("base", { "deprecated", "endModule", "hasOwnProperty", + "identity", "isArray", "isGenerator", "isObject", @@ -724,6 +725,14 @@ function call(fn, self, ...args) { return fn; } +/** + * Returns *val*. + * + * @param {*} val + * @returns {*} + */ +function identity(val) { return val; } + /** * Memoizes an object property value. * @@ -1632,7 +1641,7 @@ update(iter, { compact: function compact(iter) (item for (item of iter) if (item != null)), every: function every(iter, pred, self) { - pred = pred || util.identity; + pred = pred || identity; for (let elem of iter) if (!pred.call(self, elem)) return false; @@ -1640,7 +1649,7 @@ update(iter, { }, some: function every(iter, pred, self) { - pred = pred || util.identity; + pred = pred || identity; for (let elem of iter) if (pred.call(self, elem)) return true; diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index 17bbb8a4..42a404fd 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -2552,7 +2552,7 @@ var Buffer = Module("Buffer", { res = iter.find(filter.matcher(doc), elem => ((elem.nodeValue || elem.textContent).trim() == line && DOM(elem).display != "none")) - || iter.nth(filter.matcher(doc), util.identity, line - 1); + || iter.nth(filter.matcher(doc), identity, line - 1); if (res) break; } diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index a6945f31..ead17c3a 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -917,7 +917,7 @@ var Commands = Module("commands", { * @returns {Command} */ get: function get(name, full) iter(this.hives).map(([i, hive]) => hive.get(name, full)) - .find(util.identity), + .find(identity), /** * Returns true if a command invocation contains a URL referring to the @@ -1569,7 +1569,7 @@ var Commands = Module("commands", { let quote = RegExp.$2; context.quote = null; context.offset -= idx; - context.filter = str.substr(0, idx) + (quote ? Option.quote : util.identity)(context.filter); + context.filter = str.substr(0, idx) + (quote ? Option.quote : identity)(context.filter); context.fork("ex", 0, completion, "ex"); }; diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 722c4168..d05314ec 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -366,7 +366,7 @@ var CompletionContext = Class("CompletionContext", { get createRow() { return this._createRow || template.completionRow; }, // XXX set createRow(createRow) { return this._createRow = createRow; }, - get filterFunc() { return this._filterFunc || util.identity; }, + get filterFunc() { return this._filterFunc || identity; }, set filterFunc(val) { this._filterFunc = val; }, get filter() { @@ -595,7 +595,7 @@ var CompletionContext = Class("CompletionContext", { if (this._substrings) return this._substrings; - let fixCase = this.ignoreCase ? String.toLowerCase : util.identity; + let fixCase = this.ignoreCase ? String.toLowerCase : identity; let text = fixCase(items[0].text); let filter = fixCase(this.filter); @@ -1035,7 +1035,7 @@ var Completion = Module("completion", { if (/^jar:[^!]*$/.test(context.filter)) { context.advance(4); - context.quote = context.quote || ["", util.identity, ""]; + context.quote = context.quote || ["", identity, ""]; let quote = context.quote[1]; context.quote[1] = function quote_1(str) { return quote(str.replace(/!/g, escape)); @@ -1185,7 +1185,7 @@ var Completion = Module("completion", { }); }); - let re = RegExp(tokens.filter(util.identity).map(util.regexp.escape).join("|"), "g"); + let re = RegExp(tokens.filter(identity).map(util.regexp.escape).join("|"), "g"); function highlight(item, text, i) { return process[i].call(this, item, template.highlightRegexp(text, re)); } diff --git a/common/modules/contexts.jsm b/common/modules/contexts.jsm index 52aaec7f..0ba5c875 100644 --- a/common/modules/contexts.jsm +++ b/common/modules/contexts.jsm @@ -528,7 +528,7 @@ var Contexts = Module("contexts", { }); } - let process = util.identity; + let process = identity; if (callable(params)) var makeParams = function makeParams(self, args) { @@ -663,7 +663,7 @@ var Contexts = Module("contexts", { if (!group.builtin && args.has("-args")) { group.argsExtra = contexts.bindMacro({ literalArg: "return " + args["-args"] }, - "-javascript", util.identity); + "-javascript", identity); group.args = args["-args"]; } diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index e11f1143..dbb5636f 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -659,7 +659,7 @@ var DOM = Class("DOM", { res.push({}.toString.call(elem)); } }, this); - res = template.map(res, util.identity, ","); + res = template.map(res, identity, ","); return color ? res : res.join(""); }, diff --git a/common/modules/downloads.jsm b/common/modules/downloads.jsm index 5bb4cbe4..cf91c287 100644 --- a/common/modules/downloads.jsm +++ b/common/modules/downloads.jsm @@ -165,7 +165,7 @@ var Download = Class("Download", { let val = this._compare[order.substr(1)](this, other); return (order[0] == "-") ? -val : val; - }, this).find(util.identity) || 0, + }, this).find(identity) || 0, timeRemaining: Infinity, diff --git a/common/modules/io.jsm b/common/modules/io.jsm index aecd6ab5..a93477fa 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -584,7 +584,7 @@ var IO = Module("io", { let args = Ary(util.range(0, func.length)) .map(bind("createTempFile", this, ext, label)).array; try { - if (!args.every(util.identity)) + if (!args.every(identity)) return false; var res = func.apply(self || this, args); } @@ -979,7 +979,7 @@ unlet s:cpo_save completion.charset = context => { context.anchored = false; context.keys = { - text: util.identity, + text: identity, description: charset => io.charsetTitle(charset) }; context.completions = io.charsets; @@ -1163,7 +1163,7 @@ unlet s:cpo_save }); options.add(["cdpath", "cd"], "List of directories searched when executing :cd", - "stringlist", ["."].concat(services.environment.get("CDPATH").split(/[:;]/).filter(util.identity)).join(","), + "stringlist", ["."].concat(services.environment.get("CDPATH").split(/[:;]/).filter(identity)).join(","), { get files() { return this.value.map(path => File(path, modules.io.cwd)) diff --git a/common/modules/options.jsm b/common/modules/options.jsm index 9117412b..4122f0bc 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -1322,7 +1322,7 @@ var Options = Module("options", { [option.stringValue, _("option.currentValue")], [option.stringDefaultValue, _("option.defaultValue")] ].filter(f => f[0] !== ""); - context.quote = ["", util.identity, ""]; + context.quote = ["", identity, ""]; }); } diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index 3d48b06a..f6f496f1 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -620,7 +620,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef context.title = ["Domain"]; context.anchored = false; context.compare = modules.CompletionContext.Sort.unsorted; - context.keys = { text: util.identity, description: util.identity }; + context.keys = { text: identity, description: identity }; context.completions = res; }; }, diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 80693a94..eaf69f14 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -156,7 +156,7 @@ var Hive = Class("Hive", { sheet.sites = filter; } else { - sheet = Sheet(name, styles._id++, filter.filter(util.identity), String(css), this, agent); + sheet = Sheet(name, styles._id++, filter.filter(identity), String(css), this, agent); this.sheets.push(sheet); } @@ -414,7 +414,7 @@ var Styles = Module("Styles", { context.generate = () => values(group.sites); - context.keys.text = util.identity; + context.keys.text = identity; context.keys.description = function (site) { return this.sheets.length + /*L*/" sheet" + (this.sheets.length == 1 ? "" : "s") + ": " + diff --git a/common/modules/util.jsm b/common/modules/util.jsm index b0502e15..d60a6fa4 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -98,6 +98,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), haveGecko: deprecated("config.haveGecko", { get: function haveGecko() config.bound.haveGecko }), OS: deprecated("config.OS", { get: function OS() config.OS }), + identity: deprecated("identity", { get: function identity() global.identity }), + dactyl: update(function dactyl(obj) { if (obj) var global = Class.objectGlobal(obj); @@ -346,7 +348,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), return this[this.length - 1]; }); - let unknown = util.identity; + let unknown = identity; if (!keepUnknown) unknown = () => ""; @@ -395,7 +397,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), let [, flags, name] = /^((?:[a-z]-)*)(.*)/.exec(macro); flags = new RealSet(flags); - let quote = util.identity; + let quote = identity; if (flags.has("q")) quote = function quote(obj) { return typeof obj === "number" ? obj : JSON.stringify(obj); @@ -851,14 +853,6 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), }); }, - /** - * The identity function. - * - * @param {Object} k - * @returns {Object} - */ - identity: function identity(k) k, - /** * Returns the intersection of two rectangles. *