js/src/jit-test/tests/basic/bug972961.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 // Bug 972961 - Test compiler with very long chains of property accesses
michael@0 2
michael@0 3 // Return true if we can compile a chain of n property accesses,
michael@0 4 // false if we cannot. Throw if compilation fails in an unexpected way.
michael@0 5 function test(n) {
michael@0 6 print("testing " + n);
michael@0 7 try {
michael@0 8 eval('if (false) {' + Array(n).join(("a.")) + 'a}');
michael@0 9 } catch (exc) {
michael@0 10 // Expected outcome if the expression is too deeply nested is an InternalError.
michael@0 11 if (!(exc instanceof InternalError))
michael@0 12 throw exc;
michael@0 13 print(exc.message);
michael@0 14 return false;
michael@0 15 }
michael@0 16 print("no exception");
michael@0 17 return true;
michael@0 18 }
michael@0 19
michael@0 20 // Find out how long a chain is enough to break the compiler.
michael@0 21 var n = 4, LIMIT = 0x000fffff;
michael@0 22 var lo = 1, hi = 1;
michael@0 23 while (n <= LIMIT && test(n)) {
michael@0 24 lo = n;
michael@0 25 n *= 4;
michael@0 26 }
michael@0 27
michael@0 28 // Using binary search, find a pass/fail boundary (in order to
michael@0 29 // test the edge case).
michael@0 30 if (n <= LIMIT) {
michael@0 31 hi = n;
michael@0 32 while (lo !== hi) {
michael@0 33 var mid = Math.floor((lo + hi) / 2);
michael@0 34 if (test(mid))
michael@0 35 lo = mid + 1;
michael@0 36 else
michael@0 37 hi = mid;
michael@0 38 }
michael@0 39 print((lo - 1) + " attributes should be enough for anyone");
michael@0 40 }

mercurial