script_bug602838.sjs (986B)
1 function setOurState(data) { 2 x = { 3 data, 4 QueryInterface(iid) { 5 return this; 6 }, 7 }; 8 x.wrappedJSObject = x; 9 setObjectState("bug602838", x); 10 } 11 12 function getOurState() { 13 var data; 14 getObjectState("bug602838", function (x) { 15 // x can be null if no one has set any state yet 16 if (x) { 17 data = x.wrappedJSObject.data; 18 } 19 }); 20 return data; 21 } 22 23 function handleRequest(request, response) { 24 if (request.queryString) { 25 let blockedResponse = getOurState(); 26 if (typeof blockedResponse == "object") { 27 blockedResponse.finish(); 28 setOurState(null); 29 } else { 30 setOurState("unblocked"); 31 } 32 return; 33 } 34 response.setHeader("Cache-Control", "no-cache", false); 35 response.setHeader("Content-Type", "text/javascript", false); 36 response.write( 37 "ok(asyncRan, 'Async script should have run first.'); firstRan = true;" 38 ); 39 if (getOurState() != "unblocked") { 40 response.processAsync(); 41 setOurState(response); 42 } 43 }