Files
palemoon27/toolkit/devtools/shared/tests/browser/browser_devtools-worker-03.js
T
roytam1 7529dc68e8 import changes from `dev' branch of rmottola/Arctic-Fox:
- import VMX Blur from TenFourFox and adapt moz.build with HAVE_ALTIVEC (f23006226)
- Bug 1176083. Remove the now-dead code for the XPCOM version of setTimeout/setInterval. r=smaug (af84a61a6)
- Bug 1148593 - Pass JSContext to CallbackObject constructor. r=bz (548cda0cc)
- Bug 1164564 - Clean up the worker loader;r=jlong (c22a9241c)
- Bug 1164564 - Refactor Promise-backend.js so it can be required as a CommonJS module;r=jlong (6ced4a7f2)
- Bug 1084525 - Part 4: Add listPromises method to PromisesActor r=fitzgen (132c6b062)
- Bug 1084525 - Part 5: Add onNewPromise event handler to PromisesActor r=fitzgen (07098d58c)
- Bug 1084525 - Part 6: Add onPromiseSettled event handler to PromisesActor r=fitzgen (11d0c7430)
- Bug 1164483 - move worker helpers from frontend of devtools to backend r=jsantell (d5a0d16af)
- Bug 1164632 - use new worker helpers in debugger for pretty-printing r=jsantell (de356582a)
- do not run a test program to see if -maltivec is supported, since GCC always accepts it, even if an incompatible processor is selected. Offer explicit enable-altivec option and also set CXXFLAGS (c78bc8e43)
- extend removing of optimizations to all newer GCC versions, since it is a code issue, not compiler one (29639f4d5)
2021-04-19 11:02:56 +08:00

53 lines
1.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that the devtools/shared/worker can handle:
// returned primitives (or promise or Error)
//
// And tests `workerify` by doing so.
const { DevToolsWorker, workerify } = devtools.require("devtools/shared/worker");
function square (x) {
return x * x;
}
function squarePromise (x) {
return new Promise((resolve) => resolve(x*x));
}
function squareError (x) {
return new Error("Nope");
}
function squarePromiseReject (x) {
return new Promise((_, reject) => reject("Nope"));
}
add_task(function*() {
let fn = workerify(square);
is((yield fn(5)), 25, "return primitives successful");
fn.destroy();
fn = workerify(squarePromise);
is((yield fn(5)), 25, "promise primitives successful");
fn.destroy();
fn = workerify(squareError);
try {
yield fn(5);
ok(false, "return error should reject");
} catch (e) {
ok(true, "return error should reject");
}
fn.destroy();
fn = workerify(squarePromiseReject);
try {
yield fn(5);
ok(false, "returned rejected promise rejects");
} catch (e) {
ok(true, "returned rejected promise rejects");
}
fn.destroy();
});