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: Created Jan. 13, 2017, 12:11 p.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
« chrome/ext/common.js ('K') | « lib/url.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/utils.js
diff --git a/lib/utils.js b/lib/utils.js
index e965cad717e4cb7f2c19a8181a4edbebf322f14c..88f86921214dc3c6108d9d4869a0c8fa3a970b96 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -15,19 +15,16 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-var Utils = exports.Utils = {
+let Utils = exports.Utils = {
systemPrincipal: null,
- getString: function(id)
- {
- return ext.i18n.getMessage("global_" + id);
- },
- runAsync: function(callback)
+ getString: id => 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 +38,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;
- },
+ // We cannot calculate MD5 checksums yet :-(
+ generateChecksum: lines => null,
checkLocalePrefixMatch: function(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 +94,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: () =>
{
}
};
« chrome/ext/common.js ('K') | « lib/url.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld