Bug 1133284 - Remove nonstandard expression closures from services/sync. r=rnewman

This commit is contained in:
Chris Peterson
2015-01-24 23:50:01 -08:00
parent 39b28f63a4
commit 2a89a44168
19 changed files with 98 additions and 51 deletions

View File

@@ -142,7 +142,7 @@ this.Async = {
else
cb(ret);
}
callback.wait = function() Async.waitForSyncCallback(cb);
callback.wait = () => Async.waitForSyncCallback(cb);
return callback;
},

View File

@@ -120,9 +120,11 @@ this.HawkClient.prototype = {
errorString: error.toString(),
message: restResponse.statusText,
code: restResponse.status,
errno: restResponse.status
errno: restResponse.status,
toString() {
return this.code + ": " + this.message;
},
};
errorObj.toString = function() this.code + ": " + this.message;
let retryAfter = restResponse.headers && restResponse.headers["retry-after"];
retryAfter = retryAfter ? parseInt(retryAfter) : retryAfter;
if (retryAfter) {

View File

@@ -60,7 +60,7 @@ StringBundle.prototype = {
let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService).
createBundle(this.url, this._appLocale);
this.__defineGetter__("_stringBundle", function() stringBundle);
this.__defineGetter__("_stringBundle", () => stringBundle);
return this._stringBundle;
},

View File

@@ -64,7 +64,9 @@ function do_check_throws_message(aFunc, aResult) {
* @usage _("Hello World") -> prints "Hello World"
* @usage _(1, 2, 3) -> prints "1 2 3"
*/
let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));
let _ = function(some, debug, text, to) {
print(Array.slice(arguments).join(" "));
};
function httpd_setup (handlers, port=-1) {
let server = new HttpServer();

View File

@@ -70,4 +70,6 @@ addResourceAlias();
* @usage _("Hello World") -> prints "Hello World"
* @usage _(1, 2, 3) -> prints "1 2 3"
*/
let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));
let _ = function(some, debug, text, to) {
print(Array.slice(arguments).join(" "));
};

View File

@@ -84,7 +84,7 @@ add_task(function test_MPLocked() {
};
// tell the storage that the MP is locked.
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", function() false);
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", () => false);
yield fxa.setSignedInUser(creds);
// This should have stored stuff in the .json, and the login manager stuff
@@ -173,7 +173,7 @@ add_task(function test_migrationMPLocked() {
yield CommonUtils.writeJSON(toWrite, path);
// pretend the MP is locked.
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", function() false);
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", () => false);
// now load it - it should *not* migrate, but should only give the JSON-safe
// data back.
@@ -186,7 +186,7 @@ add_task(function test_migrationMPLocked() {
Assert.deepEqual(data, toWrite);
// Now "unlock" and re-ask for the signedInUser - it should migrate.
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", function() true);
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", () => true);
data = yield fxa.getSignedInUser();
// this time we should have got all the data, not just the JSON-safe fields.
Assert.strictEqual(data.kA, creds.kA);
@@ -240,7 +240,7 @@ add_task(function test_consistentWithMPEdgeCases() {
// tell the storage that the MP is locked - this will prevent logout from
// being able to clear the data.
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", function() false);
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", () => false);
// now set the second credentials.
yield fxa.setSignedInUser(creds2);

View File

@@ -628,7 +628,10 @@ Engine.prototype = {
// Signal to the engine that processing further records is pointless.
eEngineAbortApplyIncoming: "error.engine.abort.applyincoming",
get prefName() this.name,
get prefName() {
return this.name;
},
get enabled() {
return Svc.Prefs.get("engine." + this.prefName, false);
},
@@ -637,17 +640,19 @@ Engine.prototype = {
Svc.Prefs.set("engine." + this.prefName, !!val);
},
get score() this._tracker.score,
get score() {
return this._tracker.score;
},
get _store() {
let store = new this._storeObj(this.Name, this);
this.__defineGetter__("_store", function() store);
this.__defineGetter__("_store", () => store);
return store;
},
get _tracker() {
let tracker = new this._trackerObj(this.Name, this);
this.__defineGetter__("_tracker", function() tracker);
this.__defineGetter__("_tracker", () => tracker);
return tracker;
},
@@ -730,13 +735,21 @@ SyncEngine.prototype = {
// How many records to process in a single batch.
applyIncomingBatchSize: DEFAULT_STORE_BATCH_SIZE,
get storageURL() this.service.storageURL,
get storageURL() {
return this.service.storageURL;
},
get engineURL() this.storageURL + this.name,
get engineURL() {
return this.storageURL + this.name;
},
get cryptoKeysURL() this.storageURL + "crypto/keys",
get cryptoKeysURL() {
return this.storageURL + "crypto/keys";
},
get metaURL() this.storageURL + "meta/global",
get metaURL() {
return this.storageURL + "meta/global";
},
get syncID() {
// Generate a random syncID if we don't have one
@@ -766,7 +779,9 @@ SyncEngine.prototype = {
this.lastSyncLocal = 0;
},
get toFetch() this._toFetch,
get toFetch() {
return this._toFetch;
},
set toFetch(val) {
let cb = (error) => this._log.error(Utils.exceptionStr(error));
// Coerce the array to a string for more efficient comparison.
@@ -789,7 +804,9 @@ SyncEngine.prototype = {
});
},
get previousFailed() this._previousFailed,
get previousFailed() {
return this._previousFailed;
},
set previousFailed(val) {
let cb = (error) => this._log.error(Utils.exceptionStr(error));
// Coerce the array to a string for more efficient comparison.

View File

@@ -185,12 +185,24 @@ let kSpecialIds = {
return null;
},
get menu() PlacesUtils.bookmarksMenuFolderId,
get places() PlacesUtils.placesRootId,
get tags() PlacesUtils.tagsFolderId,
get toolbar() PlacesUtils.toolbarFolderId,
get unfiled() PlacesUtils.unfiledBookmarksFolderId,
get mobile() this.findMobileRoot(true),
get menu() {
return PlacesUtils.bookmarksMenuFolderId;
},
get places() {
return PlacesUtils.placesRootId;
},
get tags() {
return PlacesUtils.tagsFolderId;
},
get toolbar() {
return PlacesUtils.toolbarFolderId;
},
get unfiled() {
return PlacesUtils.unfiledBookmarksFolderId;
},
get mobile() {
return this.findMobileRoot(true);
},
};
this.BookmarksEngine = function BookmarksEngine(service) {
@@ -1271,7 +1283,7 @@ BookmarksStore.prototype = {
}
// Filter out any null/undefined/empty tags.
tags = tags.filter(function(t) t);
tags = tags.filter(t => t);
// Temporarily tag a dummy URI to preserve tag ids when untagging.
let dummyURI = Utils.makeURI("about:weave#BStore_tagURI");
@@ -1445,9 +1457,9 @@ BookmarksTracker.prototype = {
},
_ensureMobileQuery: function _ensureMobileQuery() {
let find = function (val)
let find = val =>
PlacesUtils.annotations.getItemsWithAnnotation(ORGANIZERQUERY_ANNO, {}).filter(
function (id) PlacesUtils.annotations.getItemAnnotation(id, ORGANIZERQUERY_ANNO) == val
id => PlacesUtils.annotations.getItemAnnotation(id, ORGANIZERQUERY_ANNO) == val
);
// Don't continue if the Library isn't ready

View File

@@ -164,7 +164,9 @@ ClientEngine.prototype = {
},
// Treat reset the same as wiping for locally cached clients
_resetClient: function _resetClient() this._wipeClient(),
_resetClient() {
this._wipeClient();
},
_wipeClient: function _wipeClient() {
SyncEngine.prototype._resetClient.call(this);
@@ -268,7 +270,7 @@ ClientEngine.prototype = {
this.clearCommands();
// Process each command in order.
for each ({command: command, args: args} in commands) {
for each (let {command, args} in commands) {
this._log.debug("Processing command: " + command + "(" + args + ")");
let engines = [args[0]];
@@ -400,7 +402,9 @@ function ClientStore(name, engine) {
ClientStore.prototype = {
__proto__: Store.prototype,
create: function create(record) this.update(record),
create(record) {
this.update(record)
},
update: function update(record) {
// Only grab commands from the server; local name/type always wins
@@ -436,7 +440,9 @@ ClientStore.prototype = {
return record;
},
itemExists: function itemExists(id) id in this.getAllIDs(),
itemExists(id) {
return id in this.getAllIDs();
},
getAllIDs: function getAllIDs() {
let ids = {};

View File

@@ -99,6 +99,10 @@ PasswordStore.prototype = {
__proto__: Store.prototype,
_nsLoginInfoFromRecord: function (record) {
function nullUndefined(x) {
return (x == undefined) ? null : x;
}
if (record.formSubmitURL && record.httpRealm) {
this._log.warn("Record " + record.id + " has both formSubmitURL and httpRealm. Skipping.");
return null;
@@ -107,7 +111,6 @@ PasswordStore.prototype = {
// Passing in "undefined" results in an empty string, which later
// counts as a value. Explicitly `|| null` these fields according to JS
// truthiness. Records with empty strings or null will be unmolested.
function nullUndefined(x) (x == undefined) ? null : x;
let info = new this._nsLoginInfo(record.hostname,
nullUndefined(record.formSubmitURL),
nullUndefined(record.httpRealm),

View File

@@ -21,7 +21,7 @@ function lazyImport(module, dest, props) {
delete dest[prop];
return dest[prop] = ns[prop];
};
props.forEach(function(prop) dest.__defineGetter__(prop, getter(prop)));
props.forEach(function (prop) { dest.__defineGetter__(prop, getter(prop)); });
}
for (let mod in lazies) {

View File

@@ -15,9 +15,9 @@ Cu.import("resource://services-sync/util.js");
this.Notifications = {
// Match the referenced values in toolkit/content/widgets/notification.xml.
get PRIORITY_INFO() 1, // PRIORITY_INFO_LOW
get PRIORITY_WARNING() 4, // PRIORITY_WARNING_LOW
get PRIORITY_ERROR() 7, // PRIORITY_CRITICAL_LOW
get PRIORITY_INFO() { return 1; }, // PRIORITY_INFO_LOW
get PRIORITY_WARNING() { return 4; }, // PRIORITY_WARNING_LOW
get PRIORITY_ERROR() { return 7; }, // PRIORITY_CRITICAL_LOW
// FIXME: instead of making this public, dress the Notifications object
// to behave like an iterator (using generators?) and have callers access
@@ -68,8 +68,8 @@ this.Notifications = {
* Title of notifications to remove; falsy value means remove all
*/
removeAll: function Notifications_removeAll(title) {
this.notifications.filter(function(old) old.title == title || !title).
forEach(function(old) this.remove(old), this);
this.notifications.filter(old => (old.title == title || !title)).
forEach(old => { this.remove(old); }, this);
},
// replaces all existing notifications with the same title as the new one

View File

@@ -1589,7 +1589,9 @@ Sync11Service.prototype = {
// Only wipe the engines provided.
if (engines) {
engines.forEach(function(e) this.clientsEngine.sendCommand("wipeEngine", [e]), this);
engines.forEach(function(e) {
this.clientsEngine.sendCommand("wipeEngine", [e]);
}, this);
}
// Tell the remote machines to wipe themselves.
else {

View File

@@ -183,7 +183,7 @@ this.Utils = {
*/
deferGetSet: function Utils_deferGetSet(obj, defer, prop) {
if (Array.isArray(prop))
return prop.map(function(prop) Utils.deferGetSet(obj, defer, prop));
return prop.map(prop => Utils.deferGetSet(obj, defer, prop));
let prot = obj.prototype;
@@ -204,7 +204,7 @@ this.Utils = {
lazyStrings: function Weave_lazyStrings(name) {
let bundle = "chrome://weave/locale/services/" + name + ".properties";
return function() new StringBundle(bundle);
return () => new StringBundle(bundle);
},
deepEquals: function eq(a, b) {
@@ -507,7 +507,7 @@ this.Utils = {
arraySub: function arraySub(minuend, subtrahend) {
if (!minuend.length || !subtrahend.length)
return minuend;
return minuend.filter(function(i) subtrahend.indexOf(i) == -1);
return minuend.filter(i => subtrahend.indexOf(i) == -1);
},
/**

View File

@@ -146,7 +146,9 @@ add_identity_test(this, function test_overQuota() {
let engine = engineManager.get("catapult");
engine.enabled = true;
engine.exception = {status: 400,
toString: function() "14"};
toString() {
return "14";
}};
try {
do_check_eq(Status.sync, SYNC_SUCCEEDED);

View File

@@ -159,7 +159,7 @@ add_test(function test_login_on_sync() {
// Stub mpLocked.
let mpLockedF = Utils.mpLocked;
let mpLocked = true;
Utils.mpLocked = function() mpLocked;
Utils.mpLocked = () => mpLocked;
// Stub scheduleNextSync. This gets called within checkSyncStatus if we're
// ready to sync, so use it as an indicator.

View File

@@ -510,7 +510,7 @@ add_task(function test_autoconnect_mp_locked() {
// Pretend user did not unlock master password.
let origLocked = Utils.mpLocked;
Utils.mpLocked = function() true;
Utils.mpLocked = () => true;
let origGetter = Service.identity.__lookupGetter__("syncKey");
let origSetter = Service.identity.__lookupSetter__("syncKey");

View File

@@ -7,7 +7,7 @@ function run_test() {
const key = "abcdefghijkmnpqrstuvwxyz23456789";
_("Passphrase only contains [" + key + "].");
do_check_true(pp.split('').every(function(chr) key.indexOf(chr) != -1));
do_check_true(pp.split('').every(chr => key.indexOf(chr) != -1));
_("Hyphenated passphrase has 5 hyphens.");
let hyphenated = Utils.hyphenatePassphrase(pp);

View File

@@ -72,7 +72,7 @@ var HistoryEntry = {
"FROM moz_places " +
"WHERE url = :url) " +
"ORDER BY date DESC LIMIT 10");
this.__defineGetter__("_visitStm", function() stm);
this.__defineGetter__("_visitStm", () => stm);
return stm;
},
@@ -198,4 +198,3 @@ var HistoryEntry = {
}
},
};