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.
michael@0 | 1 | String.prototype.repeat = function(num) { |
michael@0 | 2 | return new Array(num + 1).join(this); |
michael@0 | 3 | } |
michael@0 | 4 | |
michael@0 | 5 | function set_to_length(length, frag_size) |
michael@0 | 6 | { |
michael@0 | 7 | var fragment = "'" + "x".repeat(frag_size) + "' + "; |
michael@0 | 8 | var frags = Math.floor((length - 1)/frag_size); |
michael@0 | 9 | var code = "var x = " + fragment.repeat(frags) + "'" + |
michael@0 | 10 | "x".repeat(length - frags * frag_size) + "';"; |
michael@0 | 11 | |
michael@0 | 12 | try { |
michael@0 | 13 | eval(code); |
michael@0 | 14 | } |
michael@0 | 15 | catch(err) { |
michael@0 | 16 | if (err.message && err.message == "Out of memory") |
michael@0 | 17 | return -1; |
michael@0 | 18 | if (err == "out of memory") |
michael@0 | 19 | return -1; |
michael@0 | 20 | throw(err); /* Oops, broke something. */ |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | return code.length; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | var first_fail; |
michael@0 | 27 | var first_pass; |
michael@0 | 28 | var frag_size; |
michael@0 | 29 | var pass_code_length; |
michael@0 | 30 | |
michael@0 | 31 | function search_up() |
michael@0 | 32 | { |
michael@0 | 33 | if (set_to_length(first_fail, frag_size) < 0) { |
michael@0 | 34 | setTimeout(binary_search, 0); |
michael@0 | 35 | return; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | first_fail *= 2; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function binary_search() |
michael@0 | 42 | { |
michael@0 | 43 | if (first_fail - first_pass > 1) { |
michael@0 | 44 | var length = (first_pass + first_fail) / 2; |
michael@0 | 45 | var code_len = set_to_length(length, frag_size); |
michael@0 | 46 | if (code_len > 0) { |
michael@0 | 47 | first_pass = length; |
michael@0 | 48 | pass_code_length = code_len; |
michael@0 | 49 | } else |
michael@0 | 50 | first_fail = length; |
michael@0 | 51 | setTimeout(binary_search, 0); |
michael@0 | 52 | return; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function run_find_limit() |
michael@0 | 57 | { |
michael@0 | 58 | frag_size = 64; |
michael@0 | 59 | first_fail = 65536; /* A guess */ |
michael@0 | 60 | first_pass = 0; |
michael@0 | 61 | pass_code_length = 0; |
michael@0 | 62 | |
michael@0 | 63 | for (var i=0; i<5; i++) |
michael@0 | 64 | search_up(0); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | run_find_limit(); |