js/src/jit-test/tests/basic/bug972961.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/bug972961.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,40 @@
     1.4 +// Bug 972961 - Test compiler with very long chains of property accesses
     1.5 +
     1.6 +// Return true if we can compile a chain of n property accesses,
     1.7 +// false if we cannot. Throw if compilation fails in an unexpected way.
     1.8 +function test(n) {
     1.9 +    print("testing " + n);
    1.10 +    try {
    1.11 +        eval('if (false) {' + Array(n).join(("a.")) + 'a}');
    1.12 +    } catch (exc) {
    1.13 +        // Expected outcome if the expression is too deeply nested is an InternalError.
    1.14 +        if (!(exc instanceof InternalError))
    1.15 +            throw exc;
    1.16 +        print(exc.message);
    1.17 +        return false;
    1.18 +    }
    1.19 +    print("no exception");
    1.20 +    return true;
    1.21 +}
    1.22 +
    1.23 +// Find out how long a chain is enough to break the compiler.
    1.24 +var n = 4, LIMIT = 0x000fffff;
    1.25 +var lo = 1, hi = 1;
    1.26 +while (n <= LIMIT && test(n)) {
    1.27 +    lo = n;
    1.28 +    n *= 4;
    1.29 +}
    1.30 +
    1.31 +// Using binary search, find a pass/fail boundary (in order to
    1.32 +// test the edge case).
    1.33 +if (n <= LIMIT) {
    1.34 +    hi = n;
    1.35 +    while (lo !== hi) {
    1.36 +        var mid = Math.floor((lo + hi) / 2);
    1.37 +        if (test(mid))
    1.38 +            lo = mid + 1;
    1.39 +        else
    1.40 +            hi = mid;
    1.41 +    }
    1.42 +    print((lo - 1) + " attributes should be enough for anyone");
    1.43 +}

mercurial