js/src/jit-test/tests/gc/bug-886630.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial