Backed out changeset f594e6f00208 (bug 1940883) for causing crashes in bug 1941164.
[gecko.git] / toolkit / components / promiseworker / tests / xpcshell / data / worker.mjs
blob91b27ac8f16bcf66c2075cfb6de9d3f670d141da
1 /* Any copyright is dedicated to the Public Domain.
2  * http://creativecommons.org/publicdomain/zero/1.0/ */
4 /* eslint-env mozilla/worker */
6 // Trivial worker definition
8 import { PromiseWorker } from "resource://gre/modules/workers/PromiseWorker.mjs";
10 var worker = new PromiseWorker.AbstractWorker();
11 worker.dispatch = function (method, args = []) {
12   return Agent[method](...args);
14 worker.postMessage = function (...args) {
15   self.postMessage(...args);
17 worker.close = function () {
18   self.close();
20 worker.log = function (...args) {
21   dump("Worker: " + args.join(" ") + "\n");
23 self.addEventListener("message", msg => worker.handleMessage(msg));
24 self.addEventListener("unhandledrejection", function (error) {
25   throw error.reason;
26 });
28 var Agent = {
29   bounce(...args) {
30     return args;
31   },
33   throwError(msg) {
34     throw new Error(msg);
35   },