diff --git a/common/content/abbreviations.js b/common/content/abbreviations.js index 1c81b1d5..4338da88 100644 --- a/common/content/abbreviations.js +++ b/common/content/abbreviations.js @@ -267,7 +267,7 @@ var Abbreviations = Module("abbreviations", { let hives = (hives || this.userHives).filter(h => !h.empty); function abbrevs(hive) - hive.merged.filter(ab => (ab.inModes(modes) && ab.lhs.indexOf(lhs) == 0)); + hive.merged.filter(ab => (ab.inModes(modes) && ab.lhs.startsWith(lhs))); let list = ["table", {}, ["tr", { highlight: "Title" }, diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 842fc894..3e3c254e 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -656,7 +656,7 @@ var Bookmarks = Module("bookmarks", { keyword, true); let item = keywords[keyword]; - if (item && item.url.indexOf("%s") > -1) + if (item && item.url.contains("%s")) context.fork("keyword/" + keyword, keyword.length + space.length, null, function (context) { context.format = history.format; context.title = [/*L*/keyword + " Quick Search"]; @@ -669,7 +669,7 @@ var Bookmarks = Module("bookmarks", { return history.get({ uri: util.newURI(begin), uriIsPrefix: true }).map(function (item) { let rest = item.url.length - end.length; let query = item.url.substring(begin.length, rest); - if (item.url.substr(rest) == end && query.indexOf("&") == -1) + if (item.url.substr(rest) == end && query.contains("&")) try { item.url = decodeURIComponent(query.replace(/#.*/, "").replace(/\+/g, " ")); return item; @@ -718,14 +718,14 @@ var Bookmarks = Module("bookmarks", { return; let words = ctxt.filter.toLowerCase().split(/\s+/g); - ctxt.completions = ctxt.completions.filter(i => words.every(w => i.toLowerCase().indexOf(w) >= 0)); + ctxt.completions = ctxt.completions.filter(i => words.every(w => i.toLowerCase().contains(w))); ctxt.hasItems = ctxt.completions.length; ctxt.incomplete = true; 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) >= 0) + ctxt.completions = array.uniq(ctxt.completions.filter(c => compl.contains(c)) .concat(compl), true); }, Cu.reportError); }); diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 080d9495..e4c48d04 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -136,14 +136,14 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { && !item.hidden && !/rdf:http:/.test(item.getAttribute("label"))) { // FIXME item.dactylPath = parent + item.getAttribute("label"); - if (!targetPath || targetPath.indexOf(item.dactylPath) == 0) + if (!targetPath || targetPath.startsWith(item.dactylPath)) items.push(item); } else { let path = parent; if (item.localName == "menu") path += item.getAttribute("label") + "."; - if (!targetPath || targetPath.indexOf(path) == 0) + if (!targetPath || targetPath.startsWith(path)) addChildren(item, path); } } @@ -459,7 +459,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { */ loadScript: function loadScript(uri, context) { let prefix = "literal:" + uri + ":"; - cache.flush(s => s.indexOf(prefix) == 0); + cache.flush(s => s.startsWith(prefix)); delete literal.files[uri]; JSMLoader.loadSubScript(uri, context, File.defaultEncoding); }, @@ -1147,7 +1147,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { if (error instanceof FailedAssertion && error.noTrace || error.message === "Interrupted") { let context = contexts.context; let prefix = context ? context.file + ":" + context.line + ": " : ""; - if (error.message && error.message.indexOf(prefix) !== 0 && + if (error.message && !error.message.startsWith(prefix) && prefix != "[Command Line]:1: ") error.message = prefix + error.message; diff --git a/common/content/editor.js b/common/content/editor.js index c7f5d59a..942623b7 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -764,7 +764,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { context = context.fork("registers"); context.keys = { text: util.identity, description: editor.closure.getRegister }; - context.match = function (r) !this.filter || ~this.filter.indexOf(r); + context.match = function (r) !this.filter || this.filter.contains(r); context.fork("clipboard", 0, this, function (ctxt) { ctxt.match = context.match; diff --git a/common/content/hints.js b/common/content/hints.js index 30d72724..d22bfcff 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -695,7 +695,7 @@ var HintSession = Class("HintSession", CommandMode, { updateValidNumbers: function updateValidNumbers(always) { let string = this.getHintString(this.hintNumber); for (let hint in values(this.validHints)) - hint.valid = always || hint.span.getAttribute("number").indexOf(string) == 0; + hint.valid = always || hint.span.getAttribute("number").startsWith(string); }, tab: function tab(previous) { @@ -1071,7 +1071,7 @@ var Hints = Module("hints", { mappings.popCommand(); }, onChange: function (arg) { - if (Object.keys(hints.modes).some(m => m != arg && m.indexOf(arg) == 0)) + if (Object.keys(hints.modes).some(m => m != arg && m.startsWith(arg))) return; this.accepted = true; diff --git a/common/content/mappings.js b/common/content/mappings.js index ca18742e..2ba1c7c5 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -714,6 +714,7 @@ var Mappings = Module("mappings", { function uniqueModes(modes) { let chars = [k for ([k, v] in Iterator(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)); diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index d8f0490a..7a9247a9 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -1152,7 +1152,7 @@ var Buffer = Module("Buffer", { else { let url = loc || doc.location.href; const PREFIX = "view-source:"; - if (url.indexOf(PREFIX) == 0) + if (url.startsWith(PREFIX)) url = url.substr(PREFIX.length); else url = PREFIX + url; diff --git a/common/modules/cache.jsm b/common/modules/cache.jsm index e334b613..cbf2a3f6 100644 --- a/common/modules/cache.jsm +++ b/common/modules/cache.jsm @@ -62,7 +62,7 @@ var Cache = Module("Cache", XPCOM(Ci.nsIRequestObserver), { }), parse: function parse(str) { - if (~'{['.indexOf(str[0])) + if ('{['.contains(str[0])) return JSON.parse(str); return str; }, diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 46a93d6d..ca03051c 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -764,7 +764,7 @@ var Commands = Module("commands", { return ""; } // TODO: allow matching of aliases? - function cmds(hive) hive._list.filter(cmd => cmd.name.indexOf(filter || "") == 0) + function cmds(hive) hive._list.filter(cmd => cmd.name.startsWith(filter || "")) let hives = (hives || this.userHives).map(h => [h, cmds(h)]) .filter(([h, c]) => c.length); @@ -1067,7 +1067,7 @@ var Commands = Module("commands", { if (!onlyArgumentsRemaining) { for (let [, opt] in Iterator(options)) { for (let [, optname] in Iterator(opt.names)) { - if (sub.indexOf(optname) == 0) { + if (sub.startsWith(optname)) { let count = 0; let invalid = false; let arg, quote, quoted; diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 3cfddce4..b1aa205e 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -512,7 +512,7 @@ var CompletionContext = Class("CompletionContext", { filtered.sort(this.compare); if (!this.anchored) { let filter = this.filter; - filtered.sort(function s(a, b) (b.text.indexOf(filter) == 0) - (a.text.indexOf(filter) == 0)); + filtered.sort(function s(a, b) b.text.startsWith(filter) - a.text.startsWith(filter)); } } @@ -549,7 +549,7 @@ var CompletionContext = Class("CompletionContext", { var substrings = [text]; } else { - var compare = function compare(text, s) text.indexOf(s) >= 0; + var compare = function compare(text, s) text.contains(s); var substrings = []; let start = 0; let idx; @@ -970,7 +970,7 @@ var Completion = Module("completion", { context.generate = function generate_() { return [[k.substr(services.ABOUT.length), ""] for (k in Cc) - if (k.indexOf(services.ABOUT) == 0)]; + if (k.startsWith(services.ABOUT))]; }; }); @@ -1056,7 +1056,7 @@ var Completion = Module("completion", { let contains = String.indexOf; if (context.ignoreCase) { compare = util.compareIgnoreCase; - contains = function contains_(a, b) a && a.toLowerCase().indexOf(b.toLowerCase()) > -1; + contains = function contains_(a, b) a && a.toLowerCase().contains(b.toLowerCase()); } if (tags) @@ -1180,7 +1180,7 @@ var Completion = Module("completion", { .concat([let (name = k.substr(services.AUTOCOMPLETE.length)) ["native:" + name, _("autocomplete.description", name)] for (k in Cc) - if (k.indexOf(services.AUTOCOMPLETE) == 0)]), + if (k.startsWith(services.AUTOCOMPLETE))]), setter: function setter(values) { if (values.length == 1 && !hasOwnProperty(values[0], this.values) diff --git a/common/modules/downloads.jsm b/common/modules/downloads.jsm index 9341e5b1..6e1c6286 100644 --- a/common/modules/downloads.jsm +++ b/common/modules/downloads.jsm @@ -20,7 +20,7 @@ var MAX_LOAD_TIME = 10 * 1000; let prefix = "DOWNLOAD_"; var states = iter([v, k.slice(prefix.length).toLowerCase()] for ([k, v] in Iterator(Ci.nsIDownloadManager)) - if (k.indexOf(prefix) == 0)) + if (k.startsWith(prefix))) .toObject(); var Download = Class("Download", { @@ -288,7 +288,7 @@ var DownloadList = Class("DownloadList", addDownload: function addDownload(download) { if (!this.downloads.has(download)) { download = Download(download, this); - if (this.filter && download.displayName.indexOf(this.filter) === -1) + if (this.filter && !download.displayName.contains(this.filter)) return; this.downloads.set(download.download, download); diff --git a/common/modules/finder.jsm b/common/modules/finder.jsm index 738b1777..2aa1f40d 100644 --- a/common/modules/finder.jsm +++ b/common/modules/finder.jsm @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2013 Kris Maglione +// Copyright (c) 2008-2014 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. @@ -626,7 +626,7 @@ var RangeFind = Class("RangeFind", { if (!this.matchCase) pattern = pattern.toLowerCase(); - if (!again && (pattern === "" || pattern.indexOf(this.lastString) !== 0 || this.backward)) { + if (!again && (pattern === "" || !pattern.startsWith(this.lastString) || this.backward)) { if (!private_) this.range.deselect(); if (pattern === "") diff --git a/common/modules/help.jsm b/common/modules/help.jsm index eca255ba..cc66a595 100644 --- a/common/modules/help.jsm +++ b/common/modules/help.jsm @@ -325,7 +325,7 @@ var Help = Module("Help", { } if (name == "href") { value = node.href || value; - if (value.indexOf("dactyl://help-tag/") == 0) { + if (value.startsWith("dactyl://help-tag/")) { try { let uri = services.io.newChannel(value, null, null).originalURI; value = uri.spec == value ? "javascript:;" : uri.path.substr(1); diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index 58b24017..a5a3f64b 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -348,7 +348,7 @@ var JavaScript = Module("javascript", { else { base.quote = [last, text => util.escapeString(text, ""), last]; if (prefix) - base.filters.push(item => item.item.indexOf(prefix) === 0); + base.filters.push(item => item.item.startsWith(prefix)); } if (!compl) { diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm index 4a2470bc..b1f1cab7 100644 --- a/common/modules/overlay.jsm +++ b/common/modules/overlay.jsm @@ -358,7 +358,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen delete desc.writable; desc.get = function get() value; desc.set = function set(val) { - if (!callable(val) || Function.prototype.toString(val).indexOf(sentinel) < 0) + if (!callable(val) || !Function.prototype.toString(val).contains(sentinel)) Class.replaceProperty(this, k, val); else { let package_ = util.newURI(Components.stack.caller.filename).host; diff --git a/common/modules/prefs.jsm b/common/modules/prefs.jsm index 47fec508..c3b53daa 100644 --- a/common/modules/prefs.jsm +++ b/common/modules/prefs.jsm @@ -1,6 +1,6 @@ // Copyright (c) 2006-2008 by Martin Stubenschrott // Copyright (c) 2007-2011 by Doug Kearns -// Copyright (c) 2008-2013 Kris Maglione +// Copyright (c) 2008-2014 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. @@ -398,7 +398,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) function prefs() { for (let [, pref] in Iterator(prefArray)) { let userValue = services.pref.prefHasUserValue(pref); - if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1) + if (onlyNonDefault && !userValue || !pref.contains(filter)) continue; let value = this.get(pref); diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index dbb27894..1c59c4b6 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -399,7 +399,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef for (let c in iter(services.cookies, Ci.nsICookie2)) if (!host || util.isSubdomain(c.rawHost, host) || c.host[0] == "." && c.host.length < host.length - && host.indexOf(c.host) == host.length - c.host.length) + && host.endsWith(c.host)) yield c; }, @@ -597,7 +597,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef completion: function initCompletion(dactyl, modules, window) { modules.completion.visibleHosts = function completeHosts(context) { let res = util.visibleHosts(window.content); - if (context.filter && !res.some(host => host.indexOf(context.filter) >= 0)) + if (context.filter && !res.some(host => host.contains(context.filter))) res.push(context.filter); context.title = ["Domain"]; diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 29801088..41a67a3b 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -212,7 +212,7 @@ var Hive = Class("Hive", { name = null; } - if (filter && filter.indexOf(",") > -1) + if (filter && filter.contains(",")) return filter.split(",").reduce( (n, f) => n + this.removeSheet(name, f, index), 0); diff --git a/common/modules/util.jsm b/common/modules/util.jsm index f7f41529..ca69b092 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -482,7 +482,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), return obj.res; } - if (pattern.indexOf("{") == -1) + if (!pattern.contains("{")) return [pattern]; let res = []; @@ -516,7 +516,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), rec([]); return res; } - catch (e if e.message && ~e.message.indexOf("res is undefined")) { + catch (e if e.message && e.message.contains("res is undefined")) { // prefs.safeSet() would be reset on :rehash prefs.set("javascript.options.methodjit.chrome", false); util.dactyl.warn(_(UTF8("error.damnYouJägermonkey"))); @@ -544,7 +544,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @returns {string} */ dequote: function dequote(pattern, chars) - pattern.replace(/\\(.)/, (m0, m1) => chars.indexOf(m1) >= 0 ? m1 : m0), + pattern.replace(/\\(.)/, (m0, m1) => chars.contains(m1) ? m1 : m0), /** * Returns the nsIDocShell for the given window. @@ -1110,9 +1110,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), function rec(data, level, seen) { if (isObject(data)) { - if (~seen.indexOf(data)) + seen = RealSet(seen); + if (seen.add(data)) throw Error("Recursive object passed"); - seen = seen.concat([data]); } let prefix = level + INDENT; @@ -1160,7 +1160,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), } let res = []; - rec(data, "", []); + rec(data, "", RealSet()); return res.join(""); },