1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/file_bug503481.sjs Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,43 @@ 1.4 +// 'timer' is global to avoid getting GCed which would cancel the timer 1.5 +var timer; 1.6 +const nsITimer = Components.interfaces.nsITimer; 1.7 + 1.8 +function attemptUnblock(s) { 1.9 + try { 1.10 + let blockedResponse = null; 1.11 + getObjectState("bug503481_" + s, function(x) {blockedResponse = x.wrappedJSObject.r}); 1.12 + blockedResponse.finish(); 1.13 + setObjectState("bug503481_" + s, null); 1.14 + } catch(e) { 1.15 + dump("unable to unblock " + s + "retrying in half a second\n"); 1.16 + timer = Components.classes["@mozilla.org/timer;1"] 1.17 + .createInstance(nsITimer); 1.18 + timer.initWithCallback(function () { attemptUnblock(s) }, 500, nsITimer.TYPE_ONE_SHOT); 1.19 + } 1.20 +} 1.21 + 1.22 +function handleRequest(request, response) 1.23 +{ 1.24 + var query = {}; 1.25 + request.queryString.split('&').forEach(function (val) { 1.26 + var [name, value] = val.split('='); 1.27 + query[name] = unescape(value); 1.28 + }); 1.29 + 1.30 + dump("processing:" + request.queryString + "\n"); 1.31 + 1.32 + if (query.unblock) { 1.33 + attemptUnblock(query.unblock); 1.34 + } 1.35 + 1.36 + if (query.blockOn) { 1.37 + response.processAsync(); 1.38 + x = { r: response, QueryInterface: function(iid) { return this } }; 1.39 + x.wrappedJSObject = x; 1.40 + setObjectState("bug503481_" + query.blockOn, x); 1.41 + } 1.42 + 1.43 + response.setHeader("Cache-Control", "no-cache", false); 1.44 + response.setHeader("Content-Type", "text/plain", false); 1.45 + response.write(query.body); 1.46 +}