tor-browser

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

head.js (1306B)


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