Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / crypto / test / test-worker.js
blob47a365a66f69ee991c8ef3acf14c62a8378f3379
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* eslint-env worker */
7 // This file expects utils.js to be included in its scope
8 /* import-globals-from ./util.js */
9 importScripts("util.js");
10 importScripts("test-vectors.js");
12 var window = this;
14 function finish(result) {
15   postMessage(result);
18 function complete(test, valid) {
19   return function (x) {
20     if (valid) {
21       finish(valid(x));
22     } else {
23       finish(true);
24     }
25   };
28 function memcmp_complete(test, value) {
29   return function (x) {
30     finish(util.memcmp(x, value));
31   };
34 function error() {
35   return function (x) {
36     throw x;
37   };
40 onmessage = function (msg) {
41   // eslint-disable-next-line no-eval
42   var test = eval("(" + msg.data + ")");
44   try {
45     test.call({ complete: finish });
46   } catch (err) {
47     error(`Failed to run worker test: ${err}\n`);
48   }