Bug 995027 - MockProvider._delayCallback can lose or mis-call callbacks in several ways. r=irving

--HG--
extra : rebase_source : 14eb97a913c0888dd5f803bf64062910f17bca11
This commit is contained in:
Benjamin Smedberg 2014-05-06 14:50:11 -04:00
Родитель b5e445e96d
Коммит ff8222fa7a
1 изменённых файлов: 14 добавлений и 6 удалений

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

@ -783,8 +783,13 @@ MockProvider.prototype = {
* Called when the provider should shutdown.
*/
shutdown: function MP_shutdown() {
for (let timer of this.callbackTimers)
if (this.callbackTimers.length) {
info("MockProvider: pending callbacks at shutdown(): calling immediately");
}
for (let timer of this.callbackTimers) {
timer.callback();
timer.cancel();
}
this.callbackTimers = [];
this.started = false;
@ -968,17 +973,20 @@ MockProvider.prototype = {
*/
_delayCallback: function MP_delayCallback(aCallback, ...aArgs) {
if (!this.useAsyncCallbacks) {
aCallback.apply(null, params);
aCallback.apply(null, aArgs);
return;
}
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
// Need to keep a reference to the timer, so it doesn't get GC'ed
var pos = this.callbackTimers.length;
this.callbackTimers.push(timer);
var self = this;
timer.initWithCallback(function() {
self.callbackTimers.splice(pos, 1);
timer.initWithCallback(() => {
let idx = this.callbackTimers.indexOf(timer);
if (idx == -1) {
info("MockProvider._delayCallback lost track of a timer.");
} else {
this.callbackTimers.splice(idx, 1);
}
aCallback.apply(null, aArgs);
}, this.apiDelay, timer.TYPE_ONE_SHOT);
}