test-worker.js (1003B)
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/. */ 4 5 /* eslint-env worker */ 6 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"); 11 12 var window = this; 13 14 function finish(result) { 15 postMessage(result); 16 } 17 18 function complete(test, valid) { 19 return function (x) { 20 if (valid) { 21 finish(valid(x)); 22 } else { 23 finish(true); 24 } 25 }; 26 } 27 28 function memcmp_complete(test, value) { 29 return function (x) { 30 finish(util.memcmp(x, value)); 31 }; 32 } 33 34 function error() { 35 return function (x) { 36 throw x; 37 }; 38 } 39 40 onmessage = function (msg) { 41 // eslint-disable-next-line no-eval 42 var test = eval("(" + msg.data + ")"); 43 44 try { 45 test.call({ complete: finish }); 46 } catch (err) { 47 error(`Failed to run worker test: ${err}\n`); 48 } 49 };