tor-browser

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

bug-886630.js (3808B)


      1 function errorToString(e) {
      2    try {} catch (e2) {}
      3 }
      4 Object.getOwnPropertyNames(this);
      5 if (false) {
      6    for (let x of constructors)
      7    print(x);
      8 }
      9 var tryRunning = tryRunningDirectly;
     10 function unlikelyToHang(code) {
     11    var codeL = code.replace(/\s/g, " ");
     12    return true && code.indexOf("infloop") == -1 && !(codeL.match(/const.*for/)) // can be an infinite loop: function() { const x = 1; for(x in ({a1:1})) dumpln(3); }
     13    && !(codeL.match(/for.*const/)) // can be an infinite loop: for (x in ...); const x;
     14    && !(codeL.match(/for.*in.*uneval/)) // can be slow to loop through the huge string uneval(this), for example
     15    && !(codeL.match(/for.*for.*for/)) // nested for loops (including for..in, etc) can take a while
     16    && !(codeL.match(/for.*for.*gc/))
     17 }
     18 function whatToTestSpidermonkeyTrunk(code) {
     19    var codeL = code.replace(/\s/g, " ");
     20    return {
     21        allowParse: true,
     22        allowExec: unlikelyToHang(code),
     23        allowIter: true,
     24        expectConsistentOutput: true && code.indexOf("Date") == -1 // time marches on
     25        && code.indexOf("random") == -1 && code.indexOf("dumpObject") == -1 // shows heap addresses
     26        && code.indexOf("oomAfterAllocations") == -1 && code.indexOf("ParallelArray") == -1,
     27        expectConsistentOutputAcrossIter: true && code.indexOf("options") == -1 // options() is per-cx, and the js shell doesn't create a new cx for each sandbox/compartment
     28        ,
     29        expectConsistentOutputAcrossJITs: true && code.indexOf("'strict") == -1 // bug 743425
     30        && code.indexOf("preventExtensions") == -1 // bug 887521
     31        && !(codeL.match(/\/.*[\u0000\u0080-\uffff]/)) // doesn't stay valid utf-8 after going through python (?)
     32    };
     33 }
     34 function tryRunningDirectly(f, code, wtt) {
     35    try {
     36        eval(code);
     37    } catch (e) {}
     38    try {
     39        var rv = f();
     40        tryIteration(rv);
     41    } catch (runError) {
     42        var err = errorToString(runError);
     43    }
     44    tryEnsureSanity();
     45 }
     46 var realEval = eval;
     47 var realMath = Math;
     48 var realFunction = Function;
     49 var realGC = gc;
     50 function tryEnsureSanity() {
     51    try {
     52        delete this.Math;
     53        delete this.Function;
     54        delete this.gc;
     55        this.Math = realMath;
     56        this.eval = realEval;
     57        this.Function = realFunction;
     58        this.gc = realGC;
     59    } catch (e) {}
     60 }
     61 function tryIteration(rv) {
     62    try {
     63        var iterCount = 0;
     64        for /* each */
     65        ( /* let */ iterValue in rv)
     66        print("Iterating succeeded, iterCount == " + iterCount);
     67    } catch (iterError) {}
     68 }
     69 function failsToCompileInTry(code) {
     70    try {
     71        new Function(" try { " + code + " } catch(e) { }");
     72    } catch (e) {}
     73 }
     74 function tryItOut(code) {
     75    if (count % 1000 == 0) {
     76        gc();
     77    }
     78    var wtt = whatToTestSpidermonkeyTrunk(code);
     79    code = code.replace(/\/\*DUPTRY\d+\*\//, function(k) {
     80        var n = parseInt(k.substr(8), 10);
     81        print(n);
     82        return strTimes("try{}catch(e){}", n);
     83    })
     84    try {
     85        f = new Function(code);
     86    } catch (compileError) {}
     87    if (code.indexOf("\n") == -1 && code.indexOf("\r") == -1 && code.indexOf("\f") == -1 && code.indexOf("\0") == -1 && code.indexOf("\u2028") == -1 && code.indexOf("\u2029") == -1 && code.indexOf("<--") == -1 && code.indexOf("-->") == -1 && code.indexOf("//") == -1) {
     88        var nCode = code;
     89        if (nCode.indexOf("return") != -1 || nCode.indexOf("yield") != -1 || nCode.indexOf("const") != -1 || failsToCompileInTry(nCode)) nCode = "(function(){" + nCode + "})()"
     90    }
     91    tryRunning(f, code, false);
     92 }
     93 var count = 0;
     94 tryItOut("");
     95 count = 2
     96 tryItOut("");
     97 tryItOut("");
     98 tryItOut("o")
     99 tryItOut("")
    100 tryItOut("")
    101 tryItOut("\
    102         with((/ /-7))\
    103         {\
    104         for(let mjcpxc=0;mjcpxc<9;++mjcpxc)\
    105         {\
    106         e=mjcpxc;\
    107         yield/x/\
    108         }}")