Bug 1010289 - Experiments.jsm should now handle its errors. r=bsmedberg

This commit is contained in:
David Rajchenbach-Teller 2014-05-15 03:12:00 +02:00
Родитель 6442f87e4c
Коммит fdb3455861
2 изменённых файлов: 22 добавлений и 18 удалений

Просмотреть файл

@ -336,11 +336,14 @@ Experiments.Policy.prototype = {
};
function AlreadyShutdownError(message="already shut down") {
Error.call(this, message);
let error = new Error();
this.name = "AlreadyShutdownError";
this.message = message;
this.stack = error.stack;
}
AlreadyShutdownError.prototype = new Error();
AlreadyShutdownError.prototype = Object.create(Error.prototype);
AlreadyShutdownError.prototype.constructor = AlreadyShutdownError;
/**
@ -403,22 +406,19 @@ Experiments.Experiments.prototype = {
this._registerWithAddonManager();
let deferred = Promise.defer();
this._loadTask = this._loadFromCache();
this._loadTask.then(
return this._loadTask.then(
() => {
this._log.trace("_loadTask finished ok");
this._loadTask = null;
this._run().then(deferred.resolve, deferred.reject);
return this._run();
},
(e) => {
this._log.error("_loadFromCache caught error: " + e);
deferred.reject(e);
throw e;
}
);
return deferred.promise;
},
/**
@ -666,18 +666,22 @@ Experiments.Experiments.prototype = {
this._log.trace("_run");
this._checkForShutdown();
if (!this._mainTask) {
this._mainTask = Task.spawn(this._main.bind(this));
this._mainTask.then(
() => {
this._log.trace("_main finished, scheduling next run");
this._mainTask = null;
this._scheduleNextRun();
},
(e) => {
this._mainTask = Task.spawn(function*() {
try {
yield this._main();
} catch (e) {
this._log.error("_main caught error: " + e);
return;
} finally {
this._mainTask = null;
}
);
this._log.trace("_main finished, scheduling next run");
try {
yield this._scheduleNextRun();
} catch (ex if ex instanceof AlreadyShutdownError) {
// We error out of tasks after shutdown via that exception.
}
}.bind(this));
}
return this._mainTask;
},

Просмотреть файл

@ -1564,7 +1564,7 @@ add_task(function* test_foreignUninstallAndRestart() {
Assert.ok(!experimentList[0].active, "Experiment 1 should not be active anymore.");
// Fake restart behaviour.
experiments.uninit();
yield experiments.uninit();
restartManager();
experiments = new Experiments.Experiments(gPolicy);
yield experiments.updateManifest();