michael@0: // Bug 972961 - Test compiler with very long chains of property accesses michael@0: michael@0: // Return true if we can compile a chain of n property accesses, michael@0: // false if we cannot. Throw if compilation fails in an unexpected way. michael@0: function test(n) { michael@0: print("testing " + n); michael@0: try { michael@0: eval('if (false) {' + Array(n).join(("a.")) + 'a}'); michael@0: } catch (exc) { michael@0: // Expected outcome if the expression is too deeply nested is an InternalError. michael@0: if (!(exc instanceof InternalError)) michael@0: throw exc; michael@0: print(exc.message); michael@0: return false; michael@0: } michael@0: print("no exception"); michael@0: return true; michael@0: } michael@0: michael@0: // Find out how long a chain is enough to break the compiler. michael@0: var n = 4, LIMIT = 0x000fffff; michael@0: var lo = 1, hi = 1; michael@0: while (n <= LIMIT && test(n)) { michael@0: lo = n; michael@0: n *= 4; michael@0: } michael@0: michael@0: // Using binary search, find a pass/fail boundary (in order to michael@0: // test the edge case). michael@0: if (n <= LIMIT) { michael@0: hi = n; michael@0: while (lo !== hi) { michael@0: var mid = Math.floor((lo + hi) / 2); michael@0: if (test(mid)) michael@0: lo = mid + 1; michael@0: else michael@0: hi = mid; michael@0: } michael@0: print((lo - 1) + " attributes should be enough for anyone"); michael@0: }