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 else
cb(ret); cb(ret);
} }
callback.wait = function() Async.waitForSyncCallback(cb); callback.wait = () => Async.waitForSyncCallback(cb);
return callback; return callback;
}, },

View File

@@ -120,9 +120,11 @@ this.HawkClient.prototype = {
errorString: error.toString(), errorString: error.toString(),
message: restResponse.statusText, message: restResponse.statusText,
code: restResponse.status, 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"]; let retryAfter = restResponse.headers && restResponse.headers["retry-after"];
retryAfter = retryAfter ? parseInt(retryAfter) : retryAfter; retryAfter = retryAfter ? parseInt(retryAfter) : retryAfter;
if (retryAfter) { if (retryAfter) {

View File

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

View File

@@ -64,7 +64,9 @@ function do_check_throws_message(aFunc, aResult) {
* @usage _("Hello World") -> prints "Hello World" * @usage _("Hello World") -> prints "Hello World"
* @usage _(1, 2, 3) -> prints "1 2 3" * @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) { function httpd_setup (handlers, port=-1) {
let server = new HttpServer(); let server = new HttpServer();

View File

@@ -70,4 +70,6 @@ addResourceAlias();
* @usage _("Hello World") -> prints "Hello World" * @usage _("Hello World") -> prints "Hello World"
* @usage _(1, 2, 3) -> prints "1 2 3" * @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. // 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); yield fxa.setSignedInUser(creds);
// This should have stored stuff in the .json, and the login manager stuff // 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); yield CommonUtils.writeJSON(toWrite, path);
// pretend the MP is locked. // 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 // now load it - it should *not* migrate, but should only give the JSON-safe
// data back. // data back.
@@ -186,7 +186,7 @@ add_task(function test_migrationMPLocked() {
Assert.deepEqual(data, toWrite); Assert.deepEqual(data, toWrite);
// Now "unlock" and re-ask for the signedInUser - it should migrate. // 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(); data = yield fxa.getSignedInUser();
// this time we should have got all the data, not just the JSON-safe fields. // this time we should have got all the data, not just the JSON-safe fields.
Assert.strictEqual(data.kA, creds.kA); 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 // tell the storage that the MP is locked - this will prevent logout from
// being able to clear the data. // being able to clear the data.
fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", function() false); fxa.internal.signedInUserStorage.__defineGetter__("_isLoggedIn", () => false);
// now set the second credentials. // now set the second credentials.
yield fxa.setSignedInUser(creds2); yield fxa.setSignedInUser(creds2);

View File

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

View File

@@ -185,12 +185,24 @@ let kSpecialIds = {
return null; return null;
}, },
get menu() PlacesUtils.bookmarksMenuFolderId, get menu() {
get places() PlacesUtils.placesRootId, return PlacesUtils.bookmarksMenuFolderId;
get tags() PlacesUtils.tagsFolderId, },
get toolbar() PlacesUtils.toolbarFolderId, get places() {
get unfiled() PlacesUtils.unfiledBookmarksFolderId, return PlacesUtils.placesRootId;
get mobile() this.findMobileRoot(true), },
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) { this.BookmarksEngine = function BookmarksEngine(service) {
@@ -1271,7 +1283,7 @@ BookmarksStore.prototype = {
} }
// Filter out any null/undefined/empty tags. // 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. // Temporarily tag a dummy URI to preserve tag ids when untagging.
let dummyURI = Utils.makeURI("about:weave#BStore_tagURI"); let dummyURI = Utils.makeURI("about:weave#BStore_tagURI");
@@ -1445,9 +1457,9 @@ BookmarksTracker.prototype = {
}, },
_ensureMobileQuery: function _ensureMobileQuery() { _ensureMobileQuery: function _ensureMobileQuery() {
let find = function (val) let find = val =>
PlacesUtils.annotations.getItemsWithAnnotation(ORGANIZERQUERY_ANNO, {}).filter( 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 // 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 // Treat reset the same as wiping for locally cached clients
_resetClient: function _resetClient() this._wipeClient(), _resetClient() {
this._wipeClient();
},
_wipeClient: function _wipeClient() { _wipeClient: function _wipeClient() {
SyncEngine.prototype._resetClient.call(this); SyncEngine.prototype._resetClient.call(this);
@@ -268,7 +270,7 @@ ClientEngine.prototype = {
this.clearCommands(); this.clearCommands();
// Process each command in order. // 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 + ")"); this._log.debug("Processing command: " + command + "(" + args + ")");
let engines = [args[0]]; let engines = [args[0]];
@@ -400,7 +402,9 @@ function ClientStore(name, engine) {
ClientStore.prototype = { ClientStore.prototype = {
__proto__: Store.prototype, __proto__: Store.prototype,
create: function create(record) this.update(record), create(record) {
this.update(record)
},
update: function update(record) { update: function update(record) {
// Only grab commands from the server; local name/type always wins // Only grab commands from the server; local name/type always wins
@@ -436,7 +440,9 @@ ClientStore.prototype = {
return record; return record;
}, },
itemExists: function itemExists(id) id in this.getAllIDs(), itemExists(id) {
return id in this.getAllIDs();
},
getAllIDs: function getAllIDs() { getAllIDs: function getAllIDs() {
let ids = {}; let ids = {};

View File

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

View File

@@ -21,7 +21,7 @@ function lazyImport(module, dest, props) {
delete dest[prop]; delete dest[prop];
return dest[prop] = ns[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) { for (let mod in lazies) {

View File

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

View File

@@ -183,7 +183,7 @@ this.Utils = {
*/ */
deferGetSet: function Utils_deferGetSet(obj, defer, prop) { deferGetSet: function Utils_deferGetSet(obj, defer, prop) {
if (Array.isArray(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; let prot = obj.prototype;
@@ -204,7 +204,7 @@ this.Utils = {
lazyStrings: function Weave_lazyStrings(name) { lazyStrings: function Weave_lazyStrings(name) {
let bundle = "chrome://weave/locale/services/" + name + ".properties"; let bundle = "chrome://weave/locale/services/" + name + ".properties";
return function() new StringBundle(bundle); return () => new StringBundle(bundle);
}, },
deepEquals: function eq(a, b) { deepEquals: function eq(a, b) {
@@ -507,7 +507,7 @@ this.Utils = {
arraySub: function arraySub(minuend, subtrahend) { arraySub: function arraySub(minuend, subtrahend) {
if (!minuend.length || !subtrahend.length) if (!minuend.length || !subtrahend.length)
return minuend; 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"); let engine = engineManager.get("catapult");
engine.enabled = true; engine.enabled = true;
engine.exception = {status: 400, engine.exception = {status: 400,
toString: function() "14"}; toString() {
return "14";
}};
try { try {
do_check_eq(Status.sync, SYNC_SUCCEEDED); do_check_eq(Status.sync, SYNC_SUCCEEDED);

View File

@@ -159,7 +159,7 @@ add_test(function test_login_on_sync() {
// Stub mpLocked. // Stub mpLocked.
let mpLockedF = Utils.mpLocked; let mpLockedF = Utils.mpLocked;
let mpLocked = true; let mpLocked = true;
Utils.mpLocked = function() mpLocked; Utils.mpLocked = () => mpLocked;
// Stub scheduleNextSync. This gets called within checkSyncStatus if we're // Stub scheduleNextSync. This gets called within checkSyncStatus if we're
// ready to sync, so use it as an indicator. // 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. // Pretend user did not unlock master password.
let origLocked = Utils.mpLocked; let origLocked = Utils.mpLocked;
Utils.mpLocked = function() true; Utils.mpLocked = () => true;
let origGetter = Service.identity.__lookupGetter__("syncKey"); let origGetter = Service.identity.__lookupGetter__("syncKey");
let origSetter = Service.identity.__lookupSetter__("syncKey"); let origSetter = Service.identity.__lookupSetter__("syncKey");

View File

@@ -7,7 +7,7 @@ function run_test() {
const key = "abcdefghijkmnpqrstuvwxyz23456789"; const key = "abcdefghijkmnpqrstuvwxyz23456789";
_("Passphrase only contains [" + key + "]."); _("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."); _("Hyphenated passphrase has 5 hyphens.");
let hyphenated = Utils.hyphenatePassphrase(pp); let hyphenated = Utils.hyphenatePassphrase(pp);

View File

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