Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Bug 972961 - Test compiler with very long chains of property accesses
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 }
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 }
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 }