2014-08-01 05:54:44 +04:00
|
|
|
// Any copyright is dedicated to the Public Domain.
|
|
|
|
// http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
//
|
|
|
|
// Worker-side wrapper script for the worker_driver.js helper code. See
|
|
|
|
// the comments at the top of worker_driver.js for more information.
|
|
|
|
|
|
|
|
function ok(a, msg) {
|
|
|
|
dump("OK: " + !!a + " => " + a + ": " + msg + "\n");
|
|
|
|
postMessage({ type: "status", status: !!a, msg: a + ": " + msg });
|
|
|
|
}
|
|
|
|
|
|
|
|
function is(a, b, msg) {
|
|
|
|
dump("IS: " + (a === b) + " => " + a + " | " + b + ": " + msg + "\n");
|
|
|
|
postMessage({
|
|
|
|
type: "status",
|
|
|
|
status: a === b,
|
|
|
|
msg: a + " === " + b + ": " + msg,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function workerTestArrayEquals(a, b) {
|
|
|
|
if (!Array.isArray(a) || !Array.isArray(b) || a.length != b.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (var i = 0, n = a.length; i < n; ++i) {
|
|
|
|
if (a[i] !== b[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function workerTestDone() {
|
|
|
|
postMessage({ type: "finish" });
|
|
|
|
}
|
|
|
|
|
|
|
|
function workerTestGetPermissions(permissions, cb) {
|
|
|
|
addEventListener("message", function workerTestGetPermissionsCB(e) {
|
|
|
|
if (
|
|
|
|
e.data.type != "returnPermissions" ||
|
|
|
|
!workerTestArrayEquals(permissions, e.data.permissions)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
removeEventListener("message", workerTestGetPermissionsCB);
|
|
|
|
cb(e.data.result);
|
|
|
|
});
|
|
|
|
postMessage({
|
|
|
|
type: "getPermissions",
|
2019-09-02 14:22:27 +03:00
|
|
|
permissions,
|
2014-08-01 05:54:44 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-11 01:19:26 +03:00
|
|
|
function workerTestGetHelperData(cb) {
|
|
|
|
addEventListener("message", function workerTestGetHelperDataCB(e) {
|
|
|
|
if (e.data.type !== "returnHelperData") {
|
2014-08-01 05:54:44 +04:00
|
|
|
return;
|
|
|
|
}
|
2018-12-11 01:19:26 +03:00
|
|
|
removeEventListener("message", workerTestGetHelperDataCB);
|
2014-08-01 05:54:44 +04:00
|
|
|
cb(e.data.result);
|
|
|
|
});
|
|
|
|
postMessage({
|
2018-12-11 01:19:26 +03:00
|
|
|
type: "getHelperData",
|
2014-08-30 03:50:06 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-01 05:54:44 +04:00
|
|
|
addEventListener("message", function workerWrapperOnMessage(e) {
|
|
|
|
removeEventListener("message", workerWrapperOnMessage);
|
|
|
|
var data = e.data;
|
|
|
|
try {
|
|
|
|
importScripts(data.script);
|
2019-06-14 21:04:01 +03:00
|
|
|
} catch (ex) {
|
2014-08-01 05:54:44 +04:00
|
|
|
postMessage({
|
|
|
|
type: "status",
|
|
|
|
status: false,
|
2019-06-14 21:04:01 +03:00
|
|
|
msg: "worker failed to import " + data.script + "; error: " + ex.message,
|
2014-08-01 05:54:44 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|