From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../tests/xpcshell/data/chrome.manifest | 1 + .../promiseworker/tests/xpcshell/data/worker.js | 40 ++++++++++++++++++++++ .../promiseworker/tests/xpcshell/data/worker.mjs | 36 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 toolkit/components/promiseworker/tests/xpcshell/data/chrome.manifest create mode 100644 toolkit/components/promiseworker/tests/xpcshell/data/worker.js create mode 100644 toolkit/components/promiseworker/tests/xpcshell/data/worker.mjs (limited to 'toolkit/components/promiseworker/tests/xpcshell/data') diff --git a/toolkit/components/promiseworker/tests/xpcshell/data/chrome.manifest b/toolkit/components/promiseworker/tests/xpcshell/data/chrome.manifest new file mode 100644 index 0000000000..9e5dd29b22 --- /dev/null +++ b/toolkit/components/promiseworker/tests/xpcshell/data/chrome.manifest @@ -0,0 +1 @@ +content promiseworker ./ diff --git a/toolkit/components/promiseworker/tests/xpcshell/data/worker.js b/toolkit/components/promiseworker/tests/xpcshell/data/worker.js new file mode 100644 index 0000000000..30087bdc4a --- /dev/null +++ b/toolkit/components/promiseworker/tests/xpcshell/data/worker.js @@ -0,0 +1,40 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* eslint-env worker */ + +"use strict"; + +// Trivial worker definition + +/* import-globals-from /toolkit/components/workerloader/require.js */ +importScripts("resource://gre/modules/workers/require.js"); +var PromiseWorker = require("resource://gre/modules/workers/PromiseWorker.js"); + +var worker = new PromiseWorker.AbstractWorker(); +worker.dispatch = function (method, args = []) { + return Agent[method](...args); +}; +worker.postMessage = function (...args) { + self.postMessage(...args); +}; +worker.close = function () { + self.close(); +}; +worker.log = function (...args) { + dump("Worker: " + args.join(" ") + "\n"); +}; +self.addEventListener("message", msg => worker.handleMessage(msg)); +self.addEventListener("unhandledrejection", function (error) { + throw error.reason; +}); + +var Agent = { + bounce(...args) { + return args; + }, + + throwError(msg, ...args) { + throw new Error(msg); + }, +}; diff --git a/toolkit/components/promiseworker/tests/xpcshell/data/worker.mjs b/toolkit/components/promiseworker/tests/xpcshell/data/worker.mjs new file mode 100644 index 0000000000..98a4b0ee5b --- /dev/null +++ b/toolkit/components/promiseworker/tests/xpcshell/data/worker.mjs @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* eslint-env mozilla/worker */ + +// Trivial worker definition + +import { PromiseWorker } from "resource://gre/modules/workers/PromiseWorker.mjs"; + +var worker = new PromiseWorker.AbstractWorker(); +worker.dispatch = function (method, args = []) { + return Agent[method](...args); +}; +worker.postMessage = function (...args) { + self.postMessage(...args); +}; +worker.close = function () { + self.close(); +}; +worker.log = function (...args) { + dump("Worker: " + args.join(" ") + "\n"); +}; +self.addEventListener("message", msg => worker.handleMessage(msg)); +self.addEventListener("unhandledrejection", function (error) { + throw error.reason; +}); + +var Agent = { + bounce(...args) { + return args; + }, + + throwError(msg, ...args) { + throw new Error(msg); + }, +}; -- cgit v1.2.3