Bug 1215965 - Remove use of non-standard features from toolkit/components/social/SocialService.jsm. r=mixedpuppy
authorTooru Fujisawa <arai_a@mac.com>
Mon, 19 Oct 2015 05:07:55 +0900
changeset 269711 c41fe3decc83c6c02aff6ed4e0a502e142c31fed
parent 269710 98c007c604157648f091c4ce8ac63b4c8a8ca3f5
child 269712 ac6b14d2736a14c9ce3c2571d39623dd9aed4307
push id29588
push userkwierso@gmail.com
push dateTue, 27 Oct 2015 19:18:01 +0000
treeherdermozilla-central@5430b2dba98b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1215965
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1215965 - Remove use of non-standard features from toolkit/components/social/SocialService.jsm. r=mixedpuppy
toolkit/components/social/SocialService.jsm
--- a/toolkit/components/social/SocialService.jsm
+++ b/toolkit/components/social/SocialService.jsm
@@ -34,19 +34,19 @@ XPCOMUtils.defineLazyServiceGetter(this,
 
 // Internal helper methods and state
 var SocialServiceInternal = {
   get enabled() {
     return this.providerArray.length > 0;
   },
 
   get providerArray() {
-    return [p for ([, p] of Iterator(this.providers))];
+    return Object.keys(this.providers).map(origin => this.providers[origin]);
   },
-  get manifests() {
+  *manifestsGenerator() {
     // Retrieve the manifests of installed providers from prefs
     let MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
     let prefs = MANIFEST_PREFS.getChildList("", []);
     for (let pref of prefs) {
       // we only consider manifests in user level prefs to be *installed*
       if (!MANIFEST_PREFS.prefHasUserValue(pref))
         continue;
       try {
@@ -54,16 +54,19 @@ var SocialServiceInternal = {
         if (manifest && typeof(manifest) == "object" && manifest.origin)
           yield manifest;
       } catch (err) {
         Cu.reportError("SocialService: failed to load manifest: " + pref +
                        ", exception: " + err);
       }
     }
   },
+  get manifests() {
+    return this.manifestsGenerator();
+  },
   getManifestPrefname: function(origin) {
     // Retrieve the prefname for a given origin/manifest.
     // If no existing pref, return a generated prefname.
     let MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
     let prefs = MANIFEST_PREFS.getChildList("", []);
     for (let pref of prefs) {
       try {
         var manifest = JSON.parse(MANIFEST_PREFS.getComplexValue(pref, Ci.nsISupportsString).data);
@@ -91,23 +94,23 @@ var SocialServiceInternal = {
     // object from the query results.
     let hosts = [];
     let providers = {};
 
     for (let p of SocialServiceInternal.providerArray) {
       p.frecency = 0;
       providers[p.domain] = p;
       hosts.push(p.domain);
-    };
+    }
 
     // cannot bind an array to stmt.params so we have to build the string
     let stmt = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
                                  .DBConnection.createAsyncStatement(
       "SELECT host, frecency FROM moz_hosts WHERE host IN (" +
-      [ '"' + host + '"' for each (host in hosts) ].join(",") + ") "
+      hosts.map(host => '"' + host + '"').join(",") + ") "
     );
 
     try {
       stmt.executeAsync({
         handleResult: function(aResultSet) {
           let row;
           while ((row = aResultSet.getNextRow())) {
             let rh = row.getResultByName("host");
@@ -356,17 +359,17 @@ function schedule(callback) {
 this.SocialService = {
   get hasEnabledProviders() {
     // used as an optimization during startup, can be used to check if further
     // initialization should be done (e.g. creating the instances of
     // SocialProvider and turning on UI). ActiveProviders may have changed and
     // not yet flushed so we check the active providers array
     for (let p in ActiveProviders._providers) {
       return true;
-    };
+    }
     return false;
   },
   get enabled() {
     return SocialServiceInternal.enabled;
   },
   set enabled(val) {
     throw new Error("not allowed to set SocialService.enabled");
   },
@@ -514,17 +517,17 @@ this.SocialService = {
       installOrigin = data.origin;
     }
     // force/fixup origin
     let URI = Services.io.newURI(installOrigin, null, null);
     principal = Services.scriptSecurityManager.createCodebasePrincipal(URI, {});
     data.origin = principal.origin;
 
     // iconURL and name are required
-    let providerHasFeatures = [url for (url of featureURLs) if (data[url])].length > 0;
+    let providerHasFeatures = featureURLs.some(url => data[url]);
     if (!providerHasFeatures) {
       Cu.reportError("SocialService.manifestFromData manifest missing required urls.");
       return null;
     }
     if (!data['name'] || !data['iconURL']) {
       Cu.reportError("SocialService.manifestFromData manifest missing name or iconURL.");
       return null;
     }
@@ -943,17 +946,17 @@ SocialProvider.prototype = {
     try {
       let fullURL = this.principal.URI.resolve(url);
       return Services.io.newURI(fullURL, null, null);
     } catch (ex) {
       Cu.reportError("mozSocial: failed to resolve window URL: " + url + "; " + ex);
       return null;
     }
   }
-}
+};
 
 function getAddonIDFromOrigin(origin) {
   let originUri = Services.io.newURI(origin, null, null);
   return originUri.host + ID_SUFFIX;
 }
 
 function getPrefnameFromOrigin(origin) {
   return "social.manifest." + SocialServiceInternal.getManifestPrefname(origin);
@@ -983,20 +986,20 @@ function AddonInstaller(sourceURI, aMani
     Services.prefs.setComplexValue(getPrefnameFromOrigin(aManifest.origin), Ci.nsISupportsString, string);
 
     if (isNewInstall) {
       AddonManagerPrivate.callAddonListeners("onInstalled", addon);
     }
     installCallback(aManifest);
   };
   this.cancel = function() {
-    Services.prefs.clearUserPref(getPrefnameFromOrigin(aManifest.origin))
-  },
+    Services.prefs.clearUserPref(getPrefnameFromOrigin(aManifest.origin));
+  };
   this.addon = new AddonWrapper(aManifest);
-};
+}
 
 var SocialAddonProvider = {
   startup: function() {},
 
   shutdown: function() {},
 
   updateAddonAppDisabledStates: function() {
     // we wont bother with "enabling" services that are released from blocklist
@@ -1024,30 +1027,30 @@ var SocialAddonProvider = {
     aCallback(null);
   },
 
   getAddonsByTypes: function(aTypes, aCallback) {
     if (aTypes && aTypes.indexOf(ADDON_TYPE_SERVICE) == -1) {
       aCallback([]);
       return;
     }
-    aCallback([new AddonWrapper(a) for each (a in SocialServiceInternal.manifests)]);
+    aCallback([...SocialServiceInternal.manifests].map(a => new AddonWrapper(a)));
   },
 
   removeAddon: function(aAddon, aCallback) {
     AddonManagerPrivate.callAddonListeners("onUninstalling", aAddon, false);
     aAddon.pendingOperations |= AddonManager.PENDING_UNINSTALL;
     Services.prefs.clearUserPref(getPrefnameFromOrigin(aAddon.manifest.origin));
     aAddon.pendingOperations -= AddonManager.PENDING_UNINSTALL;
     AddonManagerPrivate.callAddonListeners("onUninstalled", aAddon);
     SocialService._notifyProviderListeners("provider-uninstalled", aAddon.manifest.origin);
     if (aCallback)
       schedule(aCallback);
   }
-}
+};
 
 
 function AddonWrapper(aManifest) {
   this.manifest = aManifest;
   this.id = getAddonIDFromOrigin(this.manifest.origin);
   this._pending = AddonManager.PENDING_NONE;
 }
 AddonWrapper.prototype = {