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