tor-browser

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

importScripts_worker.js (1558B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 // Try no args. This shouldn't do anything.
      6 importScripts();
      7 
      8 // This caused security exceptions in the past, make sure it doesn't!
      9 var constructor = {}.constructor;
     10 
     11 importScripts("importScripts_worker_imported1.js");
     12 
     13 // Try to call a function defined in the imported script.
     14 importedScriptFunction();
     15 
     16 function tryBadScripts() {
     17  var badScripts = [
     18    // Has a syntax error
     19    "importScripts_worker_imported3.js",
     20    // Throws an exception
     21    "importScripts_worker_imported4.js",
     22    // Shouldn't exist!
     23    "http://example.com/non-existing/importScripts_worker_foo.js",
     24    // Not a valid url
     25    "http://notadomain::notafile aword",
     26  ];
     27 
     28  for (var i = 0; i < badScripts.length; i++) {
     29    var caughtException = false;
     30    var url = badScripts[i];
     31    try {
     32      importScripts(url);
     33    } catch (e) {
     34      caughtException = true;
     35    }
     36    if (!caughtException) {
     37      throw "Bad script didn't throw exception: " + url;
     38    }
     39  }
     40 }
     41 
     42 const url = "data:text/javascript,const startResponse = 'started';";
     43 importScripts(url);
     44 
     45 onmessage = function (event) {
     46  switch (event.data) {
     47    case "start":
     48      importScripts("importScripts_worker_imported2.js");
     49      importedScriptFunction2();
     50      tryBadScripts();
     51      postMessage(startResponse);
     52      break;
     53    case "stop":
     54      tryBadScripts();
     55      postMessage("stopped");
     56      break;
     57    default:
     58      throw new Error("Bad message: " + event.data);
     59  }
     60 };
     61 
     62 tryBadScripts();