1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/gc/bug-886630.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +function errorToString(e) { 1.5 + try {} catch (e2) {} 1.6 +} 1.7 +Object.getOwnPropertyNames(this); 1.8 +if (false) { 1.9 + for (let x of constructors) 1.10 + print(x); 1.11 +} 1.12 +var tryRunning = tryRunningDirectly; 1.13 +function unlikelyToHang(code) { 1.14 + var codeL = code.replace(/\s/g, " "); 1.15 + 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); } 1.16 + && !(codeL.match(/for.*const/)) // can be an infinite loop: for each(x in ...); const x; 1.17 + && !(codeL.match(/for.*in.*uneval/)) // can be slow to loop through the huge string uneval(this), for example 1.18 + && !(codeL.match(/for.*for.*for/)) // nested for loops (including for..in, array comprehensions, etc) can take a while 1.19 + && !(codeL.match(/for.*for.*gc/)) 1.20 +} 1.21 +function whatToTestSpidermonkeyTrunk(code) { 1.22 + var codeL = code.replace(/\s/g, " "); 1.23 + return { 1.24 + allowParse: true, 1.25 + allowExec: unlikelyToHang(code), 1.26 + allowIter: true, 1.27 + expectConsistentOutput: true && code.indexOf("Date") == -1 // time marches on 1.28 + && code.indexOf("random") == -1 && code.indexOf("dumpObject") == -1 // shows heap addresses 1.29 + && code.indexOf("oomAfterAllocations") == -1 && code.indexOf("ParallelArray") == -1, 1.30 + expectConsistentOutputAcrossIter: true && code.indexOf("options") == -1 // options() is per-cx, and the js shell doesn't create a new cx for each sandbox/compartment 1.31 + , 1.32 + expectConsistentOutputAcrossJITs: true && code.indexOf("'strict") == -1 // bug 743425 1.33 + && code.indexOf("preventExtensions") == -1 // bug 887521 1.34 + && !(codeL.match(/\/.*[\u0000\u0080-\uffff]/)) // doesn't stay valid utf-8 after going through python (?) 1.35 + }; 1.36 +} 1.37 +function tryRunningDirectly(f, code, wtt) { 1.38 + try { 1.39 + eval(code); 1.40 + } catch (e) {} 1.41 + try { 1.42 + var rv = f(); 1.43 + tryIteration(rv); 1.44 + } catch (runError) { 1.45 + var err = errorToString(runError); 1.46 + } 1.47 + tryEnsureSanity(); 1.48 +} 1.49 +var realEval = eval; 1.50 +var realMath = Math; 1.51 +var realFunction = Function; 1.52 +var realGC = gc; 1.53 +var realUneval = uneval; 1.54 +function tryEnsureSanity() { 1.55 + try { 1.56 + delete this.Math; 1.57 + delete this.Function; 1.58 + delete this.gc; 1.59 + delete this.uneval; 1.60 + this.Math = realMath; 1.61 + this.eval = realEval; 1.62 + this.Function = realFunction; 1.63 + this.gc = realGC; 1.64 + this.uneval = realUneval; 1.65 + } catch (e) {} 1.66 +} 1.67 +function tryIteration(rv) { 1.68 + try { 1.69 + var iterCount = 0; 1.70 + for /* each */ 1.71 + ( /* let */ iterValue in rv) 1.72 + print("Iterating succeeded, iterCount == " + iterCount); 1.73 + } catch (iterError) {} 1.74 +} 1.75 +function failsToCompileInTry(code) { 1.76 + try { 1.77 + new Function(" try { " + code + " } catch(e) { }"); 1.78 + } catch (e) {} 1.79 +} 1.80 +function tryItOut(code) { 1.81 + if (count % 1000 == 0) { 1.82 + gc(); 1.83 + } 1.84 + var wtt = whatToTestSpidermonkeyTrunk(code); 1.85 + code = code.replace(/\/\*DUPTRY\d+\*\//, function(k) { 1.86 + var n = parseInt(k.substr(8), 10); 1.87 + print(n); 1.88 + return strTimes("try{}catch(e){}", n); 1.89 + }) 1.90 + try { 1.91 + f = new Function(code); 1.92 + } catch (compileError) {} 1.93 + 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) { 1.94 + var nCode = code; 1.95 + if (nCode.indexOf("return") != -1 || nCode.indexOf("yield") != -1 || nCode.indexOf("const") != -1 || failsToCompileInTry(nCode)) nCode = "(function(){" + nCode + "})()" 1.96 + } 1.97 + tryRunning(f, code, false); 1.98 +} 1.99 +var count = 0; 1.100 +tryItOut(""); 1.101 +count = 2 1.102 +tryItOut(""); 1.103 +tryItOut(""); 1.104 +tryItOut("o") 1.105 +tryItOut("") 1.106 +tryItOut("") 1.107 +tryItOut("\ 1.108 + with((/ /-7))\ 1.109 + {\ 1.110 + for(let mjcpxc=0;mjcpxc<9;++mjcpxc)\ 1.111 + {\ 1.112 + e=mjcpxc;\ 1.113 + yield/x/\ 1.114 + }}") 1.115 +