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 | |
michael@0 | 2 | // Test various code paths associated with fused getprop/poly inlining. |
michael@0 | 3 | |
michael@0 | 4 | function A(a) { this.a = a; } |
michael@0 | 5 | A.prototype.foo = function (x) { return (x % 3) + this.a; }; |
michael@0 | 6 | |
michael@0 | 7 | function B(b) { this.b = b; } |
michael@0 | 8 | B.prototype.foo = function (x) { return (x % 3) + this.b + 1; }; |
michael@0 | 9 | |
michael@0 | 10 | // c.foo() for some (c instanceof C) should always hit the fallback |
michael@0 | 11 | // path of any fused poly inline cache created for it. |
michael@0 | 12 | function C(c) { this.c = c; } |
michael@0 | 13 | var GLOBX = {'x': function (x) { |
michael@0 | 14 | if (x > 29500) |
michael@0 | 15 | throw new Error("ERROR"); |
michael@0 | 16 | return 2; |
michael@0 | 17 | }}; |
michael@0 | 18 | function C_foo1(x) { |
michael@0 | 19 | return (x % 3) + this.c + GLOBX.x(x) + 1; |
michael@0 | 20 | } |
michael@0 | 21 | function C_foo2(x) { |
michael@0 | 22 | return (x % 3) + this.c + GLOBX.x(x) + 2; |
michael@0 | 23 | } |
michael@0 | 24 | C.prototype.foo = C_foo1; |
michael@0 | 25 | |
michael@0 | 26 | // Create an array of As, Bs, and Cs. |
michael@0 | 27 | function makeArray(n) { |
michael@0 | 28 | var classes = [A, B, C]; |
michael@0 | 29 | var arr = []; |
michael@0 | 30 | for (var i = 0; i < n; i++) { |
michael@0 | 31 | arr.push(new classes[i % 3](i % 3)); |
michael@0 | 32 | } |
michael@0 | 33 | return arr; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | // Call foo on them, sum up results into first elem of resultArray |
michael@0 | 37 | function runner(arr, resultArray, len) { |
michael@0 | 38 | for (var i = 0; i < len; i++) { |
michael@0 | 39 | // This changes the type of returned value from C.foo(), leading to |
michael@0 | 40 | // a bailout fater the call obj.foo() below. |
michael@0 | 41 | var obj = arr[i]; |
michael@0 | 42 | resultArray[0] += obj.foo(i); |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | // Make an array of instance. |
michael@0 | 47 | var resultArray = [0]; |
michael@0 | 48 | var arr = makeArray(30000); |
michael@0 | 49 | |
michael@0 | 50 | // Run runner for a bit with C.prototype.foo being C_foo1 |
michael@0 | 51 | runner(arr, resultArray, 100); |
michael@0 | 52 | |
michael@0 | 53 | // Run runner for a bit with C.prototype.foo being C_foo2 |
michael@0 | 54 | C.prototype.foo = C_foo2; |
michael@0 | 55 | runner(arr, resultArray, 100); |
michael@0 | 56 | |
michael@0 | 57 | // Run runner for a bit longer to force GLOBX.x to raise |
michael@0 | 58 | // an error inside a call to C.prototype.foo within runner. |
michael@0 | 59 | var gotError = false; |
michael@0 | 60 | try { |
michael@0 | 61 | runner(arr, resultArray, 30000); |
michael@0 | 62 | } catch(err) { |
michael@0 | 63 | gotError = true; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | // Check results. |
michael@0 | 67 | assertEq(gotError, true); |
michael@0 | 68 | assertEq(resultArray[0], 108859); |