tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

head.js (1278B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 /* eslint-env worker */
      7 
      8 const Cr = {
      9  NS_ERROR_NOT_IMPLEMENTED: 2147500033,
     10 };
     11 
     12 function add_task(func) {
     13  if (!add_task.tasks) {
     14    add_task.tasks = [];
     15    add_task.index = 0;
     16  }
     17 
     18  add_task.tasks.push(func);
     19 }
     20 
     21 addEventListener("message", async function onMessage(event) {
     22  function info(message) {
     23    postMessage({ op: "info", message });
     24  }
     25 
     26  function executeSoon(callback) {
     27    const channel = new MessageChannel();
     28    channel.port1.postMessage("");
     29    channel.port2.onmessage = function () {
     30      callback();
     31    };
     32  }
     33 
     34  function runNextTest() {
     35    if (add_task.index < add_task.tasks.length) {
     36      const task = add_task.tasks[add_task.index++];
     37      info("add_task | Entering test " + task.name);
     38      task()
     39        .then(function () {
     40          executeSoon(runNextTest);
     41          info("add_task | Leaving test " + task.name);
     42        })
     43        .catch(function (ex) {
     44          postMessage({ op: "failure", message: "" + ex });
     45        });
     46    } else {
     47      postMessage({ op: "finish" });
     48    }
     49  }
     50 
     51  removeEventListener("message", onMessage);
     52 
     53  const data = event.data;
     54  importScripts(...data);
     55 
     56  executeSoon(runNextTest);
     57 });