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