mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
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:
parent
a03c404963
commit
61e419b364
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user