test_bug1752863_worker.js (1053B)
1 var xhr; 2 var myself; 3 4 async function handleLoadstart() { 5 try { 6 xhr.open("POST", "FOOBAR", false); 7 // This will potentially queue another "loadstart" event 8 // before we can catch (err). But the order should be 9 // guaranteed, that is the first postMessage arriving at 10 // our parent is from the first catch (err). 11 xhr.send(); 12 myself.postMessage("MissingError"); 13 } catch (err) { 14 if (err instanceof DOMException) { 15 // This is what we expect to happen on the first error 16 // and the parent will check for this to arrive. 17 myself.postMessage("DOMException"); 18 } else { 19 myself.postMessage("OtherError"); 20 } 21 // Let's ensure we still bail out from the processing. 22 xhr.removeEventListener("loadstart", handleLoadstart, true); 23 throw err; 24 } 25 } 26 27 self.onmessage = async function () { 28 xhr = new XMLHttpRequest({ mozAnon: false }); 29 myself = self; 30 xhr.addEventListener("loadstart", handleLoadstart, true); 31 xhr.open("POST", "FOOBAR", false); 32 xhr.send(); 33 postMessage("TERMINATE"); 34 };