Bug 508128. Fix do_timeout to hold references to pending timers so that they don't get GCed and automatically cancelled. r=jwalden

This commit is contained in:
Robert O'Callahan 2009-11-04 07:39:40 +13:00
Родитель a03c404963
Коммит 61e419b364
2 изменённых файлов: 8 добавлений и 2 удалений

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

@ -49,6 +49,7 @@ var _passed = true;
var _tests_pending = 0;
var _passedChecks = 0, _falsePassedChecks = 0;
var _cleanupFunctions = [];
var _pendingCallbacks = [];
// Disable automatic network detection, so tests work correctly when
// not connected to a network.
@ -73,8 +74,10 @@ if ("@mozilla.org/toolkit/crash-reporter;1" in Components.classes) {
}
function _TimerCallback(expr) {
function _TimerCallback(expr, timer) {
this._expr = expr;
// Keep timer alive until it fires
_pendingCallbacks.push(timer);
}
_TimerCallback.prototype = {
_expr: "",
@ -88,6 +91,7 @@ _TimerCallback.prototype = {
},
notify: function(timer) {
_pendingCallbacks.splice(_pendingCallbacks.indexOf(timer), 1);
eval(this._expr);
}
};
@ -173,7 +177,7 @@ function _load_files(aFiles) {
function do_timeout(delay, expr) {
var timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
timer.initWithCallback(new _TimerCallback(expr), delay, timer.TYPE_ONE_SHOT);
timer.initWithCallback(new _TimerCallback(expr, timer), delay, timer.TYPE_ONE_SHOT);
}
function do_execute_soon(callback) {

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

@ -357,6 +357,8 @@ function run_test() {
gEM.installItemFromFile(do_get_addon(ADDONS[i].addon),
NS_INSTALL_LOCATION_APPPROFILE);
}
dump("\n\n*** DONE INSTALLING NEW ITEMS\n\n");
do_test_pending();
// Give time for phone home to complete.