diff options
Diffstat (limited to 'services/sync/modules')
28 files changed, 155 insertions, 130 deletions
diff --git a/services/sync/modules/addonsreconciler.js b/services/sync/modules/addonsreconciler.js index 2e838e885..96752a511 100644 --- a/services/sync/modules/addonsreconciler.js +++ b/services/sync/modules/addonsreconciler.js @@ -17,7 +17,7 @@ "use strict"; -const Cu = Components.utils; +var Cu = Components.utils; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-sync/util.js"); @@ -218,11 +218,12 @@ AddonsReconciler.prototype = { } this._addons = json.addons; - for each (let record in this._addons) { + for (let id in this._addons) { + let record = this._addons[id]; record.modified = new Date(record.modified); } - for each (let [time, change, id] in json.changes) { + for (let [time, change, id] of json.changes) { this._changes.push([new Date(time), change, id]); } @@ -246,9 +247,9 @@ AddonsReconciler.prototype = { let file = path || DEFAULT_STATE_FILE; let state = {version: 1, addons: {}, changes: []}; - for (let [id, record] in Iterator(this._addons)) { + for (let [id, record] of Object.entries(this._addons)) { state.addons[id] = {}; - for (let [k, v] in Iterator(record)) { + for (let [k, v] of Object.entries(record)) { if (k == "modified") { state.addons[id][k] = v.getTime(); } @@ -258,7 +259,7 @@ AddonsReconciler.prototype = { } } - for each (let [time, change, id] in this._changes) { + for (let [time, change, id] of this._changes) { state.changes.push([time.getTime(), change, id]); } @@ -350,14 +351,14 @@ AddonsReconciler.prototype = { AddonManager.getAllAddons(function (addons) { let ids = {}; - for each (let addon in addons) { + for (let addon of addons) { ids[addon.id] = true; this.rectifyStateFromAddon(addon); } // Look for locally-defined add-ons that no longer exist and update their // record. - for (let [id, addon] in Iterator(this._addons)) { + for (let [id, addon] of Object.entries(this._addons)) { if (id in ids) { continue; } @@ -373,7 +374,7 @@ AddonsReconciler.prototype = { } let installFound = false; - for each (let install in installs) { + for (let install of installs) { if (install.addon && install.addon.id == id && install.state == AddonManager.STATE_INSTALLED) { @@ -416,7 +417,7 @@ AddonsReconciler.prototype = { * Addon instance being updated. */ rectifyStateFromAddon: function rectifyStateFromAddon(addon) { - this._log.debug("Rectifying state for addon: " + addon.id); + this._log.debug(`Rectifying state for addon ${addon.name} (version=${addon.version}, id=${addon.id})`); this._ensureStateLoaded(); let id = addon.id; @@ -483,7 +484,7 @@ AddonsReconciler.prototype = { this._log.info("Change recorded for " + state.id); this._changes.push([date, change, state.id]); - for each (let listener in this._listeners) { + for (let listener of this._listeners) { try { listener.changeListener.call(listener, date, change, state); } catch (ex) { @@ -554,7 +555,8 @@ AddonsReconciler.prototype = { * @return Object on success on null on failure. */ getAddonStateFromSyncGUID: function getAddonStateFromSyncGUID(guid) { - for each (let addon in this.addons) { + for (let id in this.addons) { + let addon = this.addons[id]; if (addon.guid == guid) { return addon; } diff --git a/services/sync/modules/addonutils.js b/services/sync/modules/addonutils.js index 54b441b9e..11b6b0397 100644 --- a/services/sync/modules/addonutils.js +++ b/services/sync/modules/addonutils.js @@ -6,7 +6,7 @@ this.EXPORTED_SYMBOLS = ["AddonUtils"]; -const {interfaces: Ci, utils: Cu} = Components; +var {interfaces: Ci, utils: Cu} = Components; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Log.jsm"); @@ -248,7 +248,7 @@ AddonUtilsInternal.prototype = { } let ids = []; - for each (let addon in installs) { + for (let addon of installs) { ids.push(addon.id); } @@ -298,7 +298,7 @@ AddonUtilsInternal.prototype = { // server-side metrics aren't skewed (bug 708134). The server should // ideally send proper URLs, but this solution was deemed too // complicated at the time the functionality was implemented. - for each (let addon in addons) { + for (let addon of addons) { // sourceURI presence isn't enforced by AddonRepository. So, we skip // add-ons without a sourceURI. if (!addon.sourceURI) { @@ -342,9 +342,9 @@ AddonUtilsInternal.prototype = { // Start all the installs asynchronously. They will report back to us // as they finish, eventually triggering the global callback. - for each (let addon in toInstall) { + for (let addon of toInstall) { let options = {}; - for each (let install in installs) { + for (let install of installs) { if (install.id == addon.id) { options = install; break; @@ -365,7 +365,7 @@ AddonUtilsInternal.prototype = { /** * Update the user disabled flag for an add-on. * - * The supplied callback will ba called when the operation is + * The supplied callback will be called when the operation is * complete. If the new flag matches the existing or if the add-on * isn't currently active, the function will fire the callback * immediately. Else, the callback is invoked when the AddonManager diff --git a/services/sync/modules/browserid_identity.js b/services/sync/modules/browserid_identity.js index bc8ea6b30..9709b9196 100644 --- a/services/sync/modules/browserid_identity.js +++ b/services/sync/modules/browserid_identity.js @@ -6,7 +6,7 @@ this.EXPORTED_SYMBOLS = ["BrowserIDManager"]; -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-common/async.js"); @@ -39,7 +39,7 @@ XPCOMUtils.defineLazyGetter(this, 'log', function() { }); // FxAccountsCommon.js doesn't use a "namespace", so create one here. -let fxAccountsCommon = {}; +var fxAccountsCommon = {}; Cu.import("resource://gre/modules/FxAccountsCommon.js", fxAccountsCommon); const OBSERVER_TOPICS = [ @@ -144,7 +144,7 @@ this.BrowserIDManager.prototype = { // re-entering of credentials by the user is necessary we don't take any // further action - an observer will fire when the user does that. if (Weave.Status.login == LOGIN_FAILED_LOGIN_REJECTED) { - return Promise.reject(); + return Promise.reject(new Error("User needs to re-authenticate")); } // So - we've a previous auth problem and aren't currently attempting to diff --git a/services/sync/modules/engines.js b/services/sync/modules/engines.js index eabddae2b..35e8d6954 100644 --- a/services/sync/modules/engines.js +++ b/services/sync/modules/engines.js @@ -10,7 +10,7 @@ this.EXPORTED_SYMBOLS = [ "Store" ]; -const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components; +var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components; Cu.import("resource://services-common/async.js"); Cu.import("resource://gre/modules/Log.jsm"); @@ -104,7 +104,7 @@ Tracker.prototype = { Utils.jsonLoad("changes/" + this.file, this, function(json) { if (json && (typeof(json) == "object")) { this.changedIDs = json; - } else { + } else if (json !== null) { this._log.warn("Changed IDs file " + this.file + " contains non-object value."); json = null; } @@ -135,7 +135,7 @@ Tracker.prototype = { return false; } - if (this.ignoreAll || (id in this._ignored)) { + if (this.ignoreAll || this._ignored.includes(id)) { return false; } @@ -159,8 +159,9 @@ Tracker.prototype = { this._log.warn("Attempted to remove undefined ID to tracker"); return false; } - if (this.ignoreAll || (id in this._ignored)) + if (this.ignoreAll || this._ignored.includes(id)) { return false; + } if (this.changedIDs[id] != null) { this._log.trace("Removing changed ID " + id); delete this.changedIDs[id]; @@ -299,7 +300,7 @@ Store.prototype = { */ applyIncomingBatch: function (records) { let failed = []; - for each (let record in records) { + for (let record of records) { try { this.applyIncoming(record); } catch (ex if (ex.code == Engine.prototype.eEngineAbortApplyIncoming)) { @@ -483,7 +484,11 @@ EngineManager.prototype = { }, getAll: function () { - return [engine for ([name, engine] in Iterator(this._engines))]; + let engines = []; + for (let [, engine] of Object.entries(this._engines)) { + engines.push(engine); + } + return engines; }, /** @@ -496,7 +501,7 @@ EngineManager.prototype = { }, get enabledEngineNames() { - return [e.name for each (e in this.getEnabled())]; + return this.getEnabled().map(e => e.name); }, persistDeclined: function () { @@ -1245,7 +1250,7 @@ SyncEngine.prototype = { // because some state may change during the course of this function and we // need to operate on the original values. let existsLocally = this._store.itemExists(item.id); - let locallyModified = item.id in this._modified; + let locallyModified = this._modified.has(item.id); // TODO Handle clock drift better. Tracked in bug 721181. let remoteAge = AsyncResource.serverTime - item.modified; @@ -1444,14 +1449,14 @@ SyncEngine.prototype = { + failed_ids.join(", ")); // Clear successfully uploaded objects. - for each (let id in resp.obj.success) { + for (let id of resp.obj.success) { delete this._modified[id]; } up.clearRecords(); }); - for each (let id in modifiedIDs) { + for (let id of modifiedIDs) { try { let out = this._createRecord(id); if (this._log.level <= Log.Level.Trace) @@ -1489,7 +1494,7 @@ SyncEngine.prototype = { coll.delete(); }); - for (let [key, val] in Iterator(this._delete)) { + for (let [key, val] of Object.entries(this._delete)) { // Remove the key for future uses delete this._delete[key]; diff --git a/services/sync/modules/engines/addons.js b/services/sync/modules/engines/addons.js index ab3131c30..3081e3e87 100644 --- a/services/sync/modules/engines/addons.js +++ b/services/sync/modules/engines/addons.js @@ -33,7 +33,7 @@ */ "use strict"; -const {classes: Cc, interfaces: Ci, utils: Cu} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu} = Components; Cu.import("resource://services-sync/addonutils.js"); Cu.import("resource://services-sync/addonsreconciler.js"); @@ -150,7 +150,7 @@ AddonsEngine.prototype = { */ getChangedIDs: function getChangedIDs() { let changes = {}; - for (let [id, modified] in Iterator(this._tracker.changedIDs)) { + for (let [id, modified] of Object.entries(this._tracker.changedIDs)) { changes[id] = modified; } @@ -160,7 +160,7 @@ AddonsEngine.prototype = { // we assume this function is only called from within a sync. let reconcilerChanges = this._reconciler.getChangesSinceDate(lastSyncDate); let addons = this._reconciler.addons; - for each (let change in reconcilerChanges) { + for (let change of reconcilerChanges) { let changeTime = change[0]; let id = change[2]; @@ -291,7 +291,7 @@ AddonsStore.prototype = { id: record.addonID, syncGUID: record.id, enabled: record.enabled, - requireSecureURI: !Svc.Prefs.get("addons.ignoreRepositoryChecking", false), + requireSecureURI: this._extensionsPrefs.get("install.requireSecureOrigin", true), }], cb); // This will throw if there was an error. This will get caught by the sync @@ -299,7 +299,7 @@ AddonsStore.prototype = { let results = cb.wait(); let addon; - for each (let a in results.addons) { + for (let a of results.addons) { if (a.id == record.addonID) { addon = a; break; @@ -443,7 +443,8 @@ AddonsStore.prototype = { let ids = {}; let addons = this.reconciler.addons; - for each (let addon in addons) { + for (let id in addons) { + let addon = addons[id]; if (this.isAddonSyncable(addon)) { ids[addon.guid] = true; } diff --git a/services/sync/modules/engines/bookmarks.js b/services/sync/modules/engines/bookmarks.js index 1936afc3f..42d91f57e 100644 --- a/services/sync/modules/engines/bookmarks.js +++ b/services/sync/modules/engines/bookmarks.js @@ -6,9 +6,9 @@ this.EXPORTED_SYMBOLS = ['BookmarksEngine', "PlacesItem", "Bookmark", "BookmarkFolder", "BookmarkQuery", "Livemark", "BookmarkSeparator"]; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; Cu.import("resource://gre/modules/PlacesUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); diff --git a/services/sync/modules/engines/clients.js b/services/sync/modules/engines/clients.js index f423242c9..6c8e37a7b 100644 --- a/services/sync/modules/engines/clients.js +++ b/services/sync/modules/engines/clients.js @@ -7,7 +7,7 @@ this.EXPORTED_SYMBOLS = [ "ClientsRec" ]; -const {classes: Cc, interfaces: Ci, utils: Cu} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu} = Components; Cu.import("resource://services-common/stringbundle.js"); Cu.import("resource://services-sync/constants.js"); @@ -66,10 +66,13 @@ ClientEngine.prototype = { numClients: 1, }; - for each (let {name, type} in this._store._remoteClients) { - stats.hasMobile = stats.hasMobile || type == "mobile"; - stats.names.push(name); - stats.numClients++; + for (let id in this._store._remoteClients) { + let {name, type, stale} = this._store._remoteClients[id]; + if (!stale) { + stats.hasMobile = stats.hasMobile || type == DEVICE_TYPE_MOBILE; + stats.names.push(name); + stats.numClients++; + } } return stats; @@ -85,7 +88,11 @@ ClientEngine.prototype = { counts.set(this.localType, 1); - for each (let record in this._store._remoteClients) { + for (let id in this._store._remoteClients) { + let record = this._store._remoteClients[id]; + if (record.stale) { + continue; // pretend "stale" records don't exist. + } let type = record.type; if (!counts.has(type)) { counts.set(type, 0); diff --git a/services/sync/modules/engines/forms.js b/services/sync/modules/engines/forms.js index d26d57176..26b289119 100644 --- a/services/sync/modules/engines/forms.js +++ b/services/sync/modules/engines/forms.js @@ -4,9 +4,9 @@ this.EXPORTED_SYMBOLS = ['FormEngine', 'FormRec']; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://services-sync/engines.js"); @@ -30,7 +30,7 @@ FormRec.prototype = { Utils.deferGetSet(FormRec, "cleartext", ["name", "value"]); -let FormWrapper = { +var FormWrapper = { _log: Log.repository.getLogger("Sync.Engine.Forms"), _getEntryCols: ["fieldname", "value"], diff --git a/services/sync/modules/engines/history.js b/services/sync/modules/engines/history.js index 99ecb4506..7c8aabf83 100644 --- a/services/sync/modules/engines/history.js +++ b/services/sync/modules/engines/history.js @@ -4,10 +4,10 @@ this.EXPORTED_SYMBOLS = ['HistoryEngine', 'HistoryRec']; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; -const Cr = Components.results; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; const HISTORY_TTL = 5184000; // 60 days @@ -51,7 +51,8 @@ function HistoryStore(name, engine) { // Explicitly nullify our references to our cached services so we don't leak Svc.Obs.add("places-shutdown", function() { - for each ([query, stmt] in Iterator(this._stmts)) { + for (let query in this._stmts) { + let stmt = this._stmts; stmt.finalize(); } this._stmts = {}; diff --git a/services/sync/modules/engines/passwords.js b/services/sync/modules/engines/passwords.js index 994b59767..2837b6a10 100644 --- a/services/sync/modules/engines/passwords.js +++ b/services/sync/modules/engines/passwords.js @@ -4,7 +4,7 @@ this.EXPORTED_SYMBOLS = ['PasswordEngine', 'LoginRec']; -const {classes: Cc, interfaces: Ci, utils: Cu} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu} = Components; Cu.import("resource://services-sync/record.js"); Cu.import("resource://services-sync/constants.js"); @@ -83,7 +83,7 @@ PasswordEngine.prototype = { this._store._sleep(0); // Yield back to main thread after synchronous operation. // Look for existing logins that match the hostname, but ignore the password. - for each (let local in logins) { + for (let local of logins) { if (login.matches(local, true) && local instanceof Ci.nsILoginMetaInfo) { return local.guid; } diff --git a/services/sync/modules/engines/prefs.js b/services/sync/modules/engines/prefs.js index 82091d5b4..792e0c66a 100644 --- a/services/sync/modules/engines/prefs.js +++ b/services/sync/modules/engines/prefs.js @@ -4,9 +4,9 @@ this.EXPORTED_SYMBOLS = ['PrefsEngine', 'PrefRec']; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; const SYNC_PREFS_PREFIX = "services.sync.prefs.sync."; diff --git a/services/sync/modules/engines/tabs.js b/services/sync/modules/engines/tabs.js index 1fce737d2..167faf625 100644 --- a/services/sync/modules/engines/tabs.js +++ b/services/sync/modules/engines/tabs.js @@ -4,7 +4,7 @@ this.EXPORTED_SYMBOLS = ["TabEngine", "TabSetRecord"]; -const {classes: Cc, interfaces: Ci, utils: Cu} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu} = Components; const TABS_TTL = 604800; // 7 days. const TAB_ENTRIES_LIMIT = 25; // How many URLs to include in tab history. @@ -302,7 +302,7 @@ TabTracker.prototype = { _registerListenersForWindow: function (window) { this._log.trace("Registering tab listeners in window"); - for each (let topic in this._topics) { + for (let topic of this._topics) { window.addEventListener(topic, this.onTab, false); } window.addEventListener("unload", this._unregisterListeners, false); @@ -315,7 +315,7 @@ TabTracker.prototype = { _unregisterListenersForWindow: function (window) { this._log.trace("Removing tab listeners in window"); window.removeEventListener("unload", this._unregisterListeners, false); - for each (let topic in this._topics) { + for (let topic of this._topics) { window.removeEventListener(topic, this.onTab, false); } }, diff --git a/services/sync/modules/identity.js b/services/sync/modules/identity.js index 2bee13b5b..cd28f5efe 100644 --- a/services/sync/modules/identity.js +++ b/services/sync/modules/identity.js @@ -6,7 +6,7 @@ this.EXPORTED_SYMBOLS = ["IdentityManager"]; -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Promise.jsm"); @@ -206,7 +206,7 @@ IdentityManager.prototype = { return null; } - for each (let login in this._getLogins(PWDMGR_PASSWORD_REALM)) { + for (let login of this._getLogins(PWDMGR_PASSWORD_REALM)) { if (login.username.toLowerCase() == username) { // It should already be UTF-8 encoded, but we don't take any chances. this._basicPassword = Utils.encodeUTF8(login.password); @@ -260,7 +260,7 @@ IdentityManager.prototype = { return null; } - for each (let login in this._getLogins(PWDMGR_PASSPHRASE_REALM)) { + for (let login of this._getLogins(PWDMGR_PASSPHRASE_REALM)) { if (login.username.toLowerCase() == username) { this._syncKey = login.password; } @@ -411,7 +411,7 @@ IdentityManager.prototype = { this._setLogin(PWDMGR_PASSWORD_REALM, this.username, this._basicPassword); } else { - for each (let login in this._getLogins(PWDMGR_PASSWORD_REALM)) { + for (let login of this._getLogins(PWDMGR_PASSWORD_REALM)) { Services.logins.removeLogin(login); } } @@ -423,7 +423,7 @@ IdentityManager.prototype = { if (this._syncKey) { this._setLogin(PWDMGR_PASSPHRASE_REALM, this.username, this._syncKey); } else { - for each (let login in this._getLogins(PWDMGR_PASSPHRASE_REALM)) { + for (let login of this._getLogins(PWDMGR_PASSPHRASE_REALM)) { Services.logins.removeLogin(login); } } @@ -477,7 +477,7 @@ IdentityManager.prototype = { */ _setLogin: function _setLogin(realm, username, password) { let exists = false; - for each (let login in this._getLogins(realm)) { + for (let login of this._getLogins(realm)) { if (login.username == username && login.password == password) { exists = true; } else { @@ -513,7 +513,7 @@ IdentityManager.prototype = { deleteSyncCredentials: function deleteSyncCredentials() { for (let host of this._getSyncCredentialsHosts()) { let logins = Services.logins.findLogins({}, host, "", ""); - for each (let login in logins) { + for (let login of logins) { Services.logins.removeLogin(login); } } diff --git a/services/sync/modules/jpakeclient.js b/services/sync/modules/jpakeclient.js index 10f405371..625dc91b6 100644 --- a/services/sync/modules/jpakeclient.js +++ b/services/sync/modules/jpakeclient.js @@ -4,7 +4,7 @@ this.EXPORTED_SYMBOLS = ["JPAKEClient", "SendCredentialsController"]; -const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components; +var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-common/rest.js"); @@ -281,8 +281,7 @@ JPAKEClient.prototype = { let rng = Cc["@mozilla.org/security/random-generator;1"] .createInstance(Ci.nsIRandomGenerator); let bytes = rng.generateRandomBytes(JPAKE_LENGTH_CLIENTID / 2); - this._clientID = [("0" + byte.toString(16)).slice(-2) - for each (byte in bytes)].join(""); + this._clientID = bytes.map(byte => ("0" + byte.toString(16)).slice(-2)).join(""); }, _createSecret: function _createSecret() { @@ -291,8 +290,7 @@ JPAKEClient.prototype = { let rng = Cc["@mozilla.org/security/random-generator;1"] .createInstance(Ci.nsIRandomGenerator); let bytes = rng.generateRandomBytes(JPAKE_LENGTH_SECRET); - return [key[Math.floor(byte * key.length / 256)] - for each (byte in bytes)].join(""); + return bytes.map(byte => key[Math.floor(byte * key.length / 256)]).join(""); }, _newRequest: function _newRequest(uri) { diff --git a/services/sync/modules/keys.js b/services/sync/modules/keys.js index bf909bdc2..b93de7f31 100644 --- a/services/sync/modules/keys.js +++ b/services/sync/modules/keys.js @@ -9,7 +9,7 @@ this.EXPORTED_SYMBOLS = [ "SyncKeyBundle" ]; -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; Cu.import("resource://services-sync/constants.js"); Cu.import("resource://gre/modules/Log.jsm"); diff --git a/services/sync/modules/main.js b/services/sync/modules/main.js index 488a2594b..e8e705e72 100644 --- a/services/sync/modules/main.js +++ b/services/sync/modules/main.js @@ -6,7 +6,7 @@ this.EXPORTED_SYMBOLS = ['Weave']; this.Weave = {}; Components.utils.import("resource://services-sync/constants.js", Weave); -let lazies = { +var lazies = { "jpakeclient.js": ["JPAKEClient", "SendCredentialsController"], "notifications.js": ["Notifications", "Notification", "NotificationButton"], "service.js": ["Service"], @@ -15,12 +15,14 @@ let lazies = { }; function lazyImport(module, dest, props) { - function getter(prop) function() { - let ns = {}; - Components.utils.import(module, ns); - delete dest[prop]; - return dest[prop] = ns[prop]; - }; + function getter(prop) { + return function() { + let ns = {}; + Components.utils.import(module, ns); + delete dest[prop]; + return dest[prop] = ns[prop]; + }; + } props.forEach(function (prop) { dest.__defineGetter__(prop, getter(prop)); }); } diff --git a/services/sync/modules/notifications.js b/services/sync/modules/notifications.js index 1ee24f2cd..72187a4ce 100644 --- a/services/sync/modules/notifications.js +++ b/services/sync/modules/notifications.js @@ -4,10 +4,10 @@ this.EXPORTED_SYMBOLS = ["Notifications", "Notification", "NotificationButton"]; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const Cu = Components.utils; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cr = Components.results; +var Cu = Components.utils; Cu.import("resource://services-common/observers.js"); Cu.import("resource://gre/modules/Log.jsm"); diff --git a/services/sync/modules/policies.js b/services/sync/modules/policies.js index d799cb235..38f118d3f 100644 --- a/services/sync/modules/policies.js +++ b/services/sync/modules/policies.js @@ -7,7 +7,7 @@ this.EXPORTED_SYMBOLS = [ "SyncScheduler", ]; -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-sync/constants.js"); diff --git a/services/sync/modules/record.js b/services/sync/modules/record.js index 04ccd2dd2..e609ad1bc 100644 --- a/services/sync/modules/record.js +++ b/services/sync/modules/record.js @@ -10,10 +10,10 @@ this.EXPORTED_SYMBOLS = [ "Collection", ]; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const Cu = Components.utils; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cr = Components.results; +var Cu = Components.utils; const CRYPTO_COLLECTION = "crypto"; const KEYS_WBO = "keys"; @@ -85,7 +85,7 @@ WBORecord.prototype = { toJSON: function toJSON() { // Copy fields from data to be stringified, making sure payload is a string let obj = {}; - for (let [key, val] in Iterator(this.data)) + for (let [key, val] of Object.entries(this.data)) obj[key] = key == "payload" ? JSON.stringify(val) : val; if (this.ttl) obj.ttl = this.ttl; @@ -309,7 +309,7 @@ CollectionKeyManager.prototype = { // Return a sorted, unique array. changed.sort(); let last; - changed = [x for each (x in changed) if ((x != last) && (last = x))]; + changed = changed.filter(x => (x != last) && (last = x)); return {same: changed.length == 0, changed: changed}; }, diff --git a/services/sync/modules/resource.js b/services/sync/modules/resource.js index 1c2a67b90..b31d129a5 100644 --- a/services/sync/modules/resource.js +++ b/services/sync/modules/resource.js @@ -7,10 +7,10 @@ this.EXPORTED_SYMBOLS = [ "Resource" ]; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const Cu = Components.utils; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cr = Components.results; +var Cu = Components.utils; Cu.import("resource://gre/modules/Preferences.jsm"); Cu.import("resource://services-common/async.js"); @@ -174,7 +174,7 @@ AsyncResource.prototype = { if (this.authenticator) { let result = this.authenticator(this, method); if (result && result.headers) { - for (let [k, v] in Iterator(result.headers)) { + for (let [k, v] of Object.entries(result.headers)) { headers[k.toLowerCase()] = v; } } @@ -182,7 +182,7 @@ AsyncResource.prototype = { this._log.debug("No authenticator found."); } - for (let [key, value] in Iterator(headers)) { + for (let [key, value] of Object.entries(headers)) { if (key == 'authorization') this._log.trace("HTTP Header " + key + ": ***** (suppressed)"); else diff --git a/services/sync/modules/rest.js b/services/sync/modules/rest.js index 34382eed5..106ece222 100644 --- a/services/sync/modules/rest.js +++ b/services/sync/modules/rest.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; +var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-common/rest.js"); diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index 637760b8f..f3837a949 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -4,10 +4,10 @@ this.EXPORTED_SYMBOLS = ["Service"]; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const Cu = Components.utils; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cr = Components.results; +var Cu = Components.utils; // How long before refreshing the cluster const CLUSTER_BACKOFF = 5 * 60 * 1000; // 5 minutes @@ -432,7 +432,7 @@ Sync11Service.prototype = { // Map each old pref to the current pref branch let oldPref = new Preferences(oldPrefBranch); - for each (let pref in oldPrefNames) + for (let pref of oldPrefNames) Svc.Prefs.set(pref, oldPref.get(pref)); // Remove all the old prefs and remember that we've migrated @@ -890,7 +890,7 @@ Sync11Service.prototype = { // Deletion doesn't make sense if we aren't set up yet! if (this.clusterURL != "") { // Clear client-specific data from the server, including disabled engines. - for each (let engine in [this.clientsEngine].concat(this.engineManager.getAll())) { + for (let engine of [this.clientsEngine].concat(this.engineManager.getAll())) { try { engine.removeClientData(); } catch(ex) { @@ -1497,7 +1497,7 @@ Sync11Service.prototype = { // Wipe everything we know about except meta because we just uploaded it let engines = [this.clientsEngine].concat(this.engineManager.getAll()); - let collections = [engine.name for each (engine in engines)]; + let collections = engines.map(engine => engine.name); // TODO: there's a bug here. We should be calling resetClient, no? // Generate, upload, and download new keys. Do this last so we don't wipe @@ -1657,7 +1657,7 @@ Sync11Service.prototype = { } // Have each engine drop any temporary meta data - for each (let engine in engines) { + for (let engine of engines) { engine.resetClient(); } })(); diff --git a/services/sync/modules/stages/cluster.js b/services/sync/modules/stages/cluster.js index dd358bf98..41afe61d8 100644 --- a/services/sync/modules/stages/cluster.js +++ b/services/sync/modules/stages/cluster.js @@ -4,7 +4,7 @@ this.EXPORTED_SYMBOLS = ["ClusterManager"]; -const {utils: Cu} = Components; +var {utils: Cu} = Components; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-sync/constants.js"); diff --git a/services/sync/modules/stages/declined.js b/services/sync/modules/stages/declined.js index b0877e929..ff8a14181 100644 --- a/services/sync/modules/stages/declined.js +++ b/services/sync/modules/stages/declined.js @@ -11,7 +11,7 @@ this.EXPORTED_SYMBOLS = ["DeclinedEngines"]; -const {utils: Cu} = Components; +var {utils: Cu} = Components; Cu.import("resource://services-sync/constants.js"); Cu.import("resource://gre/modules/Log.jsm"); @@ -29,8 +29,8 @@ this.DeclinedEngines = function (service) { } this.DeclinedEngines.prototype = { updateDeclined: function (meta, engineManager=this.service.engineManager) { - let enabled = new Set([e.name for each (e in engineManager.getEnabled())]); - let known = new Set([e.name for each (e in engineManager.getAll())]); + let enabled = new Set(engineManager.getEnabled().map(e => e.name)); + let known = new Set(engineManager.getAll().map(e => e.name)); let remoteDeclined = new Set(meta.payload.declined || []); let localDeclined = new Set(engineManager.getDeclined()); diff --git a/services/sync/modules/stages/enginesync.js b/services/sync/modules/stages/enginesync.js index ed91adddb..ce7fce94d 100644 --- a/services/sync/modules/stages/enginesync.js +++ b/services/sync/modules/stages/enginesync.js @@ -8,7 +8,7 @@ this.EXPORTED_SYMBOLS = ["EngineSynchronizer"]; -const {utils: Cu} = Components; +var {utils: Cu} = Components; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-sync/constants.js"); @@ -224,8 +224,15 @@ EngineSynchronizer.prototype = { // If we're the only client, and no engines are marked as enabled, // thumb our noses at the server data: it can't be right. // Belt-and-suspenders approach to Bug 615926. - if ((numClients <= 1) && - ([e for (e in meta.payload.engines) if (e != "clients")].length == 0)) { + let hasEnabledEngines = false; + for (let e in meta.payload.engines) { + if (e != "clients") { + hasEnabledEngines = true; + break; + } + } + + if ((numClients <= 1) && !hasEnabledEngines) { this._log.info("One client and no enabled engines: not touching local engine status."); return; } @@ -289,7 +296,7 @@ EngineSynchronizer.prototype = { } // Any remaining engines were either enabled locally or disabled remotely. - for each (let engineName in enabled) { + for (let engineName of enabled) { let engine = engineManager.get(engineName); if (Svc.Prefs.get("engineStatusChanged." + engine.prefName, false)) { this._log.trace("The " + engineName + " engine was enabled locally."); diff --git a/services/sync/modules/status.js b/services/sync/modules/status.js index 19dff9712..4b26f62bd 100644 --- a/services/sync/modules/status.js +++ b/services/sync/modules/status.js @@ -4,10 +4,10 @@ this.EXPORTED_SYMBOLS = ["Status"]; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const Cu = Components.utils; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cr = Components.results; +var Cu = Components.utils; Cu.import("resource://services-sync/constants.js"); Cu.import("resource://gre/modules/Log.jsm"); diff --git a/services/sync/modules/userapi.js b/services/sync/modules/userapi.js index ec77d63e2..e906440bd 100644 --- a/services/sync/modules/userapi.js +++ b/services/sync/modules/userapi.js @@ -8,7 +8,7 @@ this.EXPORTED_SYMBOLS = [ "UserAPI10Client", ]; -const {utils: Cu} = Components; +var {utils: Cu} = Components; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-common/rest.js"); diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index 67cc3f063..b063a29ac 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -4,7 +4,7 @@ this.EXPORTED_SYMBOLS = ["XPCOMUtils", "Services", "Utils", "Async", "Svc", "Str"]; -const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components; +var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components; Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-common/observers.js"); @@ -338,12 +338,14 @@ this.Utils = { try { json = yield CommonUtils.readJSON(path); - } catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) { - // Ignore non-existent files. } catch (e) { - if (that._log) { - that._log.debug("Failed to load json: " + - CommonUtils.exceptionStr(e)); + if (e instanceof OS.File.Error && e.becauseNoSuchFile) { + // Ignore non-existent files, but explicitly return null. + json = null; + } else { + if (that._log) { + that._log.debug("Failed to load json", e); + } } } @@ -690,7 +692,7 @@ Svc.Prefs = new Preferences(PREFS_BRANCH); Svc.DefaultPrefs = new Preferences({branch: PREFS_BRANCH, defaultBranch: true}); Svc.Obs = Observers; -let _sessionCID = Services.appinfo.ID == SEAMONKEY_ID ? +var _sessionCID = Services.appinfo.ID == SEAMONKEY_ID ? "@mozilla.org/suite/sessionstore;1" : "@mozilla.org/browser/sessionstore;1"; |