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