blob: 58d4591e47111b6eda6a960de0bbbea69c9c53b6 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const Cr = {
NS_ERROR_NOT_IMPLEMENTED: 2147500033,
};
function add_task(func) {
if (!add_task.tasks) {
add_task.tasks = [];
add_task.index = 0;
}
add_task.tasks.push(func);
}
addEventListener("message", async function onMessage(event) {
function info(message) {
postMessage({ op: "info", message });
}
function executeSoon(callback) {
const channel = new MessageChannel();
channel.port1.postMessage("");
channel.port2.onmessage = function() {
callback();
};
}
function runNextTest() {
if (add_task.index < add_task.tasks.length) {
const task = add_task.tasks[add_task.index++];
info("add_task | Entering test " + task.name);
task()
.then(function() {
executeSoon(runNextTest);
info("add_task | Leaving test " + task.name);
})
.catch(function(ex) {
postMessage({ op: "failure", message: "" + ex });
});
} else {
postMessage({ op: "finish" });
}
}
removeEventListener("message", onMessage);
const data = event.data;
importScripts(...data);
executeSoon(runNextTest);
});
|