js/src/jit-test/tests/basic/doMath.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 function map_test(t, cases)
michael@0 2 {
michael@0 3 for (var i = 0; i < cases.length; i++) {
michael@0 4 function c() { return t(cases[i].input); }
michael@0 5 var expected = cases[i].expected;
michael@0 6 assertEq(c(), expected);
michael@0 7 }
michael@0 8 }
michael@0 9
michael@0 10 function lsh_inner(n)
michael@0 11 {
michael@0 12 var r;
michael@0 13 for (var i = 0; i < 35; i++)
michael@0 14 r = 0x1 << n;
michael@0 15 return r;
michael@0 16 }
michael@0 17 map_test (lsh_inner,
michael@0 18 [{input: 15, expected: 32768},
michael@0 19 {input: 55, expected: 8388608},
michael@0 20 {input: 1, expected: 2},
michael@0 21 {input: 0, expected: 1}]);
michael@0 22
michael@0 23 function rsh_inner(n)
michael@0 24 {
michael@0 25 var r;
michael@0 26 for (var i = 0; i < 35; i++)
michael@0 27 r = 0x11010101 >> n;
michael@0 28 return r;
michael@0 29 }
michael@0 30 map_test (rsh_inner,
michael@0 31 [{input: 8, expected: 1114369},
michael@0 32 {input: 5, expected: 8914952},
michael@0 33 {input: 35, expected: 35659808},
michael@0 34 {input: -1, expected: 0}]);
michael@0 35
michael@0 36 function ursh_inner(n)
michael@0 37 {
michael@0 38 var r;
michael@0 39 for (var i = 0; i < 35; i++)
michael@0 40 r = -55 >>> n;
michael@0 41 return r;
michael@0 42 }
michael@0 43 map_test (ursh_inner,
michael@0 44 [{input: 8, expected: 16777215},
michael@0 45 {input: 33, expected: 2147483620},
michael@0 46 {input: 0, expected: 4294967241},
michael@0 47 {input: 1, expected: 2147483620}]);
michael@0 48
michael@0 49 function doMath_inner(cos)
michael@0 50 {
michael@0 51 var s = 0;
michael@0 52 var sin = Math.sin;
michael@0 53 for (var i = 0; i < 200; i++)
michael@0 54 s = -Math.pow(sin(i) + cos(i * 0.75), 4);
michael@0 55 return s;
michael@0 56 }
michael@0 57 function doMath() {
michael@0 58 return doMath_inner(Math.cos);
michael@0 59 }
michael@0 60 assertEq(doMath(), -0.5405549555611059);

mercurial