summaryrefslogtreecommitdiffstats
path: root/toolkit/components/telemetry/tests/unit/file_UninstallPing.worker.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/telemetry/tests/unit/file_UninstallPing.worker.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/telemetry/tests/unit/file_UninstallPing.worker.js')
-rw-r--r--toolkit/components/telemetry/tests/unit/file_UninstallPing.worker.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/toolkit/components/telemetry/tests/unit/file_UninstallPing.worker.js b/toolkit/components/telemetry/tests/unit/file_UninstallPing.worker.js
new file mode 100644
index 0000000000..fcc8007a2f
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/file_UninstallPing.worker.js
@@ -0,0 +1,37 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/. */
+
+/* eslint-env mozilla/chrome-worker */
+
+/* import-globals-from /toolkit/components/workerloader/require.js */
+importScripts("resource://gre/modules/workers/require.js");
+
+const PromiseWorker = require("resource://gre/modules/workers/PromiseWorker.js");
+
+const Agent = {
+ _file: null,
+ open(path) {
+ this._file = IOUtils.openFileForSyncReading(path);
+ },
+ close() {
+ this._file.close();
+ },
+};
+
+// This boilerplate connects the PromiseWorker to the Agent so
+// that messages from the main thread map to methods on the
+// Agent.
+const worker = new PromiseWorker.AbstractWorker();
+worker.dispatch = function (method, args = []) {
+ return Agent[method](...args);
+};
+worker.postMessage = function (result, ...transfers) {
+ self.postMessage(result, ...transfers);
+};
+worker.close = function () {
+ self.close();
+};
+self.addEventListener("message", msg => worker.handleMessage(msg));
+self.addEventListener("unhandledrejection", function (error) {
+ throw error.reason;
+});