mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 633566 - Prevent the timer to be eaten alive by the GC. r=bz a=tests
This commit is contained in:
parent
73dcf9ff90
commit
a69b1f71d9
@ -25,6 +25,12 @@ const IMAGE_DATA =
|
||||
0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82,
|
||||
];
|
||||
|
||||
/**
|
||||
* The timer is needed when a delay is set. We need it to be out of the method
|
||||
* so it is not eaten alive by the GC.
|
||||
*/
|
||||
var timer;
|
||||
|
||||
function handleRequest(request, response) {
|
||||
var query = {};
|
||||
request.queryString.split('&').forEach(function (val) {
|
||||
@ -40,16 +46,20 @@ function handleRequest(request, response) {
|
||||
stream.writeByteArray(IMAGE_DATA, IMAGE_DATA.length);
|
||||
}
|
||||
|
||||
if ("delay" in query) {
|
||||
response.processAsync();
|
||||
const nsITimer = Components.interfaces.nsITimer;
|
||||
|
||||
var timer = Components.classes["@mozilla.org/timer;1"].createInstance(nsITimer);
|
||||
timer.initWithCallback(function() {
|
||||
imageWrite();
|
||||
response.finish();
|
||||
}, query["delay"], nsITimer.TYPE_ONE_SHOT);
|
||||
} else {
|
||||
// If there is no delay, we write the image and leave.
|
||||
if (!("delay" in query)) {
|
||||
imageWrite();
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is a delay, we create a timer which, when it fires, will write
|
||||
// image and leave.
|
||||
response.processAsync();
|
||||
const nsITimer = Components.interfaces.nsITimer;
|
||||
|
||||
timer = Components.classes["@mozilla.org/timer;1"].createInstance(nsITimer);
|
||||
timer.initWithCallback(function() {
|
||||
imageWrite();
|
||||
response.finish();
|
||||
}, query["delay"], nsITimer.TYPE_ONE_SHOT);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user