Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/utils.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Workaround limiation with iterating element collections in older versions of Chrome Created Jan. 16, 2017, 8:46 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/utils.js
diff --git a/lib/utils.js b/lib/utils.js
index e965cad717e4cb7f2c19a8181a4edbebf322f14c..142ca9f81f68442d2d3c558b116c7ff52258b304 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -15,19 +15,18 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-var Utils = exports.Utils = {
+"use strict";
+
+let Utils = exports.Utils = {
systemPrincipal: null,
- getString: function(id)
- {
- return ext.i18n.getMessage("global_" + id);
- },
- runAsync: function(callback)
+ getString(id) { return ext.i18n.getMessage("global_" + id); },
+ runAsync(callback)
{
if (document.readyState == "loading")
{
// Make sure to not run asynchronous actions before all
// scripts loaded. This caused issues on Opera in the past.
- let onDOMContentLoaded = function()
+ let onDOMContentLoaded = () =>
{
document.removeEventListener("DOMContentLoaded", onDOMContentLoaded);
callback();
@@ -41,40 +40,35 @@ var Utils = exports.Utils = {
},
get appLocale()
{
- var locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
+ let locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
Object.defineProperty(this, "appLocale", {value: locale, enumerable: true});
return this.appLocale;
},
- generateChecksum: function(lines)
- {
- // We cannot calculate MD5 checksums yet :-(
- return null;
- },
- checkLocalePrefixMatch: function(prefixes)
+ // We cannot calculate MD5 checksums yet :-(
+ generateChecksum(lines) { return null; },
+ checkLocalePrefixMatch(prefixes)
{
if (!prefixes)
return null;
- var list = prefixes.split(",");
- for (var i = 0; i < list.length; i++)
- if (new RegExp("^" + list[i] + "\\b").test(this.appLocale))
- return list[i];
+ for (let prefix of prefixes.split(","))
+ if (new RegExp("^" + prefix + "\\b").test(this.appLocale))
+ return prefix;
return null;
},
- chooseFilterSubscription: function(subscriptions)
+ chooseFilterSubscription(subscriptions)
{
- var selectedItem = null;
- var selectedPrefix = null;
- var matchCount = 0;
- for (var i = 0; i < subscriptions.length; i++)
+ let selectedItem = null;
+ let selectedPrefix = null;
+ let matchCount = 0;
+ for (let subscription of subscriptions)
{
- var subscription = subscriptions[i];
if (!selectedItem)
selectedItem = subscription;
- var prefix = require("utils").Utils.checkLocalePrefixMatch(subscription.getAttribute("prefixes"));
+ let prefix = require("utils").Utils.checkLocalePrefixMatch(subscription.getAttribute("prefixes"));
if (prefix)
{
if (!selectedPrefix || selectedPrefix.length < prefix.length)
@@ -102,14 +96,14 @@ var Utils = exports.Utils = {
return selectedItem;
},
- getDocLink: function(linkID)
+ getDocLink(linkID)
{
- var Prefs = require("prefs").Prefs;
- var docLink = Prefs.documentation_link;
+ let Prefs = require("prefs").Prefs;
+ let docLink = Prefs.documentation_link;
return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale);
},
- yield: function()
+ yield()
{
}
};
« lib/notificationHelper.js ('K') | « lib/url.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld