content/base/test/file_bug503481.sjs

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // 'timer' is global to avoid getting GCed which would cancel the timer
michael@0 2 var timer;
michael@0 3 const nsITimer = Components.interfaces.nsITimer;
michael@0 4
michael@0 5 function attemptUnblock(s) {
michael@0 6 try {
michael@0 7 let blockedResponse = null;
michael@0 8 getObjectState("bug503481_" + s, function(x) {blockedResponse = x.wrappedJSObject.r});
michael@0 9 blockedResponse.finish();
michael@0 10 setObjectState("bug503481_" + s, null);
michael@0 11 } catch(e) {
michael@0 12 dump("unable to unblock " + s + "retrying in half a second\n");
michael@0 13 timer = Components.classes["@mozilla.org/timer;1"]
michael@0 14 .createInstance(nsITimer);
michael@0 15 timer.initWithCallback(function () { attemptUnblock(s) }, 500, nsITimer.TYPE_ONE_SHOT);
michael@0 16 }
michael@0 17 }
michael@0 18
michael@0 19 function handleRequest(request, response)
michael@0 20 {
michael@0 21 var query = {};
michael@0 22 request.queryString.split('&').forEach(function (val) {
michael@0 23 var [name, value] = val.split('=');
michael@0 24 query[name] = unescape(value);
michael@0 25 });
michael@0 26
michael@0 27 dump("processing:" + request.queryString + "\n");
michael@0 28
michael@0 29 if (query.unblock) {
michael@0 30 attemptUnblock(query.unblock);
michael@0 31 }
michael@0 32
michael@0 33 if (query.blockOn) {
michael@0 34 response.processAsync();
michael@0 35 x = { r: response, QueryInterface: function(iid) { return this } };
michael@0 36 x.wrappedJSObject = x;
michael@0 37 setObjectState("bug503481_" + query.blockOn, x);
michael@0 38 }
michael@0 39
michael@0 40 response.setHeader("Cache-Control", "no-cache", false);
michael@0 41 response.setHeader("Content-Type", "text/plain", false);
michael@0 42 response.write(query.body);
michael@0 43 }

mercurial