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 | // Call a function with no arguments. |
michael@0 | 2 | function a_g() { |
michael@0 | 3 | return 5; |
michael@0 | 4 | } |
michael@0 | 5 | |
michael@0 | 6 | function a_f(g) { |
michael@0 | 7 | return g(); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | a_g(); |
michael@0 | 11 | assertEq(a_f(a_g), 5); |
michael@0 | 12 | |
michael@0 | 13 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 14 | // Call a function with one argument. |
michael@0 | 15 | function b_g(a) { |
michael@0 | 16 | return a; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function b_f(h,b) { |
michael@0 | 20 | return h(5); |
michael@0 | 21 | } |
michael@0 | 22 | b_g(5); |
michael@0 | 23 | assertEq(b_f(b_g,4), 5); |
michael@0 | 24 | |
michael@0 | 25 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 26 | // Try to confuse the register allocator. |
michael@0 | 27 | function c_g(a) { |
michael@0 | 28 | return a; |
michael@0 | 29 | } |
michael@0 | 30 | function c_f(h,b) { |
michael@0 | 31 | var x = h(5); |
michael@0 | 32 | var y = x + 1; |
michael@0 | 33 | var z = h(h(y + x + 2)); |
michael@0 | 34 | var k = 2 + z + 3; |
michael@0 | 35 | return h(h(h(k))); |
michael@0 | 36 | } |
michael@0 | 37 | c_g(2); // prime g(). |
michael@0 | 38 | assertEq(c_f(c_g,7), 18) |
michael@0 | 39 | |
michael@0 | 40 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 41 | // Fail during unboxing, get kicked to interpreter. |
michael@0 | 42 | // Interpreter throws an exception; handle it. |
michael@0 | 43 | |
michael@0 | 44 | function d_f(a) { |
michael@0 | 45 | return a(); // Call a known non-object. This fails in unboxing. |
michael@0 | 46 | } |
michael@0 | 47 | var d_x = 0; |
michael@0 | 48 | try { |
michael@0 | 49 | d_f(1); // Don't assert. |
michael@0 | 50 | } catch(e) { |
michael@0 | 51 | d_x = 1; |
michael@0 | 52 | } |
michael@0 | 53 | assertEq(d_x, 1); |
michael@0 | 54 | |
michael@0 | 55 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 56 | // Try passing an uncompiled function. |
michael@0 | 57 | |
michael@0 | 58 | function e_uncompiled(a,b,c) { |
michael@0 | 59 | return eval("b"); |
michael@0 | 60 | } |
michael@0 | 61 | function e_f(h) { |
michael@0 | 62 | return h(0,h(2,4,6),1); |
michael@0 | 63 | } |
michael@0 | 64 | assertEq(e_f(e_uncompiled),4); |
michael@0 | 65 | |
michael@0 | 66 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 67 | // Try passing a native function. |
michael@0 | 68 | |
michael@0 | 69 | function f_app(f,n) { |
michael@0 | 70 | return f(n); |
michael@0 | 71 | } |
michael@0 | 72 | assertEq(f_app(Math.sqrt, 16), 4); |
michael@0 | 73 | |
michael@0 | 74 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 75 | // Handle the case where too few arguments are passed. |
michael@0 | 76 | function g_g(a,b,c,d,e) { |
michael@0 | 77 | return e; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | function g_f(g) { |
michael@0 | 81 | return g(2); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | g_g(); |
michael@0 | 85 | assertEq(g_f(g_g), undefined); |
michael@0 | 86 | |
michael@0 | 87 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 88 | // Don't assert when given a non-function object. |
michael@0 | 89 | function h_f(a) { |
michael@0 | 90 | return a(); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | var x = new Object(); |
michael@0 | 94 | var h_ret = 0; |
michael@0 | 95 | try { |
michael@0 | 96 | h_f(x); // don't assert. |
michael@0 | 97 | } catch (e) { |
michael@0 | 98 | h_ret = 1; |
michael@0 | 99 | } |
michael@0 | 100 | assertEq(h_ret, 1); |
michael@0 | 101 |