From 17b11996aebb9b2792cfb3869382ac98a6c20a56 Mon Sep 17 00:00:00 2001 From: Georg Fritzsche Date: Thu, 17 Apr 2014 15:47:37 +0200 Subject: [PATCH] Bug 989137 - Part 18: Fix experiments uninit behavior. r=bsmedberg --- browser/experiments/Experiments.jsm | 16 ++++++++++++++-- .../test/browser/browser_experiments.js | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/browser/experiments/Experiments.jsm b/browser/experiments/Experiments.jsm index 25118681ce0..a7dc7825472 100644 --- a/browser/experiments/Experiments.jsm +++ b/browser/experiments/Experiments.jsm @@ -327,6 +327,14 @@ Experiments.Policy.prototype = { }, }; +function AlreadyShutdownError(message="already shut down") { + this.name = "AlreadyShutdownError"; + this.message = message; +} + +AlreadyShutdownError.prototype = new Error(); +AlreadyShutdownError.prototype.constructor = AlreadyShutdownError; + /** * Manages the experiments and provides an interface to control them. */ @@ -434,7 +442,11 @@ Experiments.Experiments.prototype = { this._shutdown = true; if (this._mainTask) { - yield this._mainTask; + try { + yield this._mainTask; + } catch (e if e instanceof AlreadyShutdownError) { + // We error out of tasks after shutdown via that exception. + } } this._log.info("Completed uninitialization."); @@ -457,7 +469,7 @@ Experiments.Experiments.prototype = { */ _checkForShutdown: function() { if (this._shutdown) { - throw Error("uninit() already called"); + throw new AlreadyShutdownError("uninit() already called"); } }, diff --git a/toolkit/mozapps/extensions/test/browser/browser_experiments.js b/toolkit/mozapps/extensions/test/browser/browser_experiments.js index d592a3f2b05..cbb072372ff 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_experiments.js +++ b/toolkit/mozapps/extensions/test/browser/browser_experiments.js @@ -39,6 +39,7 @@ add_task(function* initializeState() { // this test running. We have to initialize the instance first, then // uninitialize it to prevent this. gExperiments = tmp.Experiments.instance(); + yield gExperiments._mainTask; yield gExperiments.uninit(); } });