tor-browser

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

importForeignScripts_worker.js (1189B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 var target = self;
      7 var response;
      8 
      9 function runTests() {
     10  response = "good";
     11  try {
     12    importScripts("http://example.org/tests/dom/workers/test/foreign.js");
     13  } catch (e) {
     14    dump("Got error " + e + " when calling importScripts");
     15  }
     16  if (response === "good") {
     17    try {
     18      importScripts("redirect_to_foreign.sjs");
     19    } catch (e) {
     20      dump("Got error " + e + " when calling importScripts");
     21    }
     22  }
     23  target.postMessage(response);
     24 
     25  // Now, test a nested worker.
     26  if (location.search !== "?nested") {
     27    var worker = new Worker("importForeignScripts_worker.js?nested");
     28 
     29    worker.onmessage = function (e) {
     30      target.postMessage(e.data);
     31      target.postMessage("finish");
     32    };
     33 
     34    worker.onerror = function () {
     35      target.postMessage("nested worker error");
     36    };
     37 
     38    worker.postMessage("start");
     39  }
     40 }
     41 
     42 onmessage = function (e) {
     43  if (e.data === "start") {
     44    runTests();
     45  }
     46 };
     47 
     48 onconnect = function (e) {
     49  target = e.ports[0];
     50  e.ports[0].onmessage = function (msg) {
     51    if (msg.data === "start") {
     52      runTests();
     53    }
     54  };
     55 };