From bf73483d4296adcaf20c88f36bf682be6e26f2a2 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 7 Dec 2010 01:13:22 -0500 Subject: [PATCH] Settle stupid naming dispute. --- common/content/bookmarks.js | 2 +- common/content/commands.js | 10 ++++------ common/content/tabs.js | 2 +- common/modules/base.jsm | 22 +++++++++++----------- common/modules/sanitizer.jsm | 3 +-- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 1446812b..f7b9941a 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -188,7 +188,7 @@ const Bookmarks = Module("bookmarks", { * @returns {nsISearchEngine} The search engine. */ getSearchEngine: function getSearchEngine(alias) - this.searchEngines.filter(function (e) e.keyword === alias)[0], + array.nth(this.searchEngines, function (e) e.keyword === alias, 0), getSearchEngines: deprecated("Please use bookmarks.searchEngines instead", function getSearchEngines() this.searchEngines), /** diff --git a/common/content/commands.js b/common/content/commands.js index 4b6eb6ea..9aef751e 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -614,9 +614,8 @@ const Commands = Module("commands", { * any of the command's names. * @returns {Command} */ - get: function (name, full) { - return this._exMap[name] || !full && this._exCommands.filter(function (cmd) cmd.hasName(name))[0] || null; - }, + get: function (name, full) + this._exMap[name] || !full && array.nth(this._exCommands, function (cmd) cmd.hasName(name), 0) || null, /** * Returns the user-defined command with matching *name*. @@ -625,9 +624,8 @@ const Commands = Module("commands", { * any of the command's names. * @returns {Command} */ - getUserCommand: function (name) { - return this._exCommands.filter(function (cmd) cmd.user && cmd.hasName(name))[0] || null; - }, + getUserCommand: function (name) + array.nth(this._exCommands, function (cmd) cmd.user && cmd.hasName(name), 0) || null, /** * Returns all user-defined commands. diff --git a/common/content/tabs.js b/common/content/tabs.js index 39a61a74..44fc6287 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -432,7 +432,7 @@ const Tabs = Module("tabs", { if (matches) return tabs.select(this.allTabs[parseInt(matches[1], 10) - 1], false); - matches = array.first(tabs.allTabs, function (t) t.linkedBrowser.lastURI.spec === buffer); + matches = array.nth(tabs.allTabs, function (t) t.linkedBrowser.lastURI.spec === buffer, 0); if (matches) return tabs.select(matches, false); diff --git a/common/modules/base.jsm b/common/modules/base.jsm index bda7f1fe..0e33af38 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -1071,17 +1071,6 @@ const array = Class("array", Array, { equals: function (ary1, ary2) ary1.length === ary2.length && Array.every(ary1, function (e, i) e === ary2[i]), - /** - * Returns the first member of the given array that matches the - * given predicate. - */ - first: function first(ary, pred, self) { - for (let elem in values(ary)) - if (pred.call(self, elem)) - return elem; - return undefined; - }, - /** * Flattens an array, such that all elements of the array are * joined into a single array: @@ -1116,6 +1105,17 @@ const array = Class("array", Array, { yield [i, ary[i]]; }, + /** + * Returns the nth member of the given array that matches the + * given predicate. + */ + nth: function first(ary, pred, n, self) { + for (let elem in values(ary)) + if (pred.call(self, elem) && n-- === 0) + return elem; + return undefined; + }, + /** * Filters out all duplicates from an array. If *unsorted* is false, the * array is sorted before duplicates are removed. diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index fed55177..cb3226f6 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -624,8 +624,7 @@ const Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakR ["prompt", "Always prompt for a lifetime"], ["session", "The current session"] ], - getter: function () (this.completer()[prefs.get(this.PREF)] - || [prefs.get(this.PREF_DAYS)])[0], + getter: function () (this.completer()[prefs.get(this.PREF)] || [prefs.get(this.PREF_DAYS)])[0], setter: function (value) { let val = this.completer().map(function (i) i[0]).indexOf(value); if (val > -1)