js/src/jit-test/tests/baseline/funcall-array.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
michael@0 2 var emptyArray = [];
michael@0 3 var denseArray = [1, 2, 3, 4];
michael@0 4 var sparseArray = [1,,2,,3,,4];
michael@0 5 var bigArray = new Array();
michael@0 6 for (var i = 0; i < 128; i++) {
michael@0 7 bigArray.push(i);
michael@0 8 }
michael@0 9 var nonArray = {0:1, 1:2, 2:3, 3:4, length:2};
michael@0 10 var indexedGetterArray = new Array();
michael@0 11 Object.defineProperty(indexedGetterArray, '2', {get:function () { return 51; }});
michael@0 12
michael@0 13 var ARRAYS = [emptyArray, denseArray, sparseArray, bigArray, nonArray, indexedGetterArray];
michael@0 14
michael@0 15 var targetFun = function (a, b, c, d) {
michael@0 16 if (a === undefined)
michael@0 17 a = 0;
michael@0 18 if (b === undefined)
michael@0 19 b = 0;
michael@0 20 if (c === undefined)
michael@0 21 c = 0;
michael@0 22 if (d === undefined)
michael@0 23 d = 0;
michael@0 24 this.count += arguments.length + a + b + c + d;
michael@0 25 }
michael@0 26
michael@0 27 var PERMUTATIONS = ARRAYS.length * ARRAYS.length;
michael@0 28 function arrayPermutation(num) {
michael@0 29 var idx1 = num % ARRAYS.length;
michael@0 30 var idx2 = ((num / ARRAYS.length)|0) % ARRAYS.length;
michael@0 31 var resultArray = [];
michael@0 32 resultArray.push(ARRAYS[idx1]);
michael@0 33 resultArray.push(ARRAYS[idx2]);
michael@0 34 return resultArray;
michael@0 35 }
michael@0 36 var EXPECTED_RESULTS = {
michael@0 37 0:0, 1:280, 2:200, 3:2680, 4:100, 5:1080, 6:280, 7:560, 8:480, 9:2960,
michael@0 38 10:380, 11:1360, 12:200, 13:480, 14:400, 15:2880, 16:300, 17:1280, 18:2680,
michael@0 39 19:2960, 20:2880, 21:5360, 22:2780, 23:3760, 24:100, 25:380, 26:300, 27:2780,
michael@0 40 28:200, 29:1180, 30:1080, 31:1360, 32:1280, 33:3760, 34:1180, 35:2160
michael@0 41 };
michael@0 42
michael@0 43 var callerNo = 0;
michael@0 44 function generateCaller() {
michael@0 45 var fn;
michael@0 46
michael@0 47 // Salt eval-string with callerNo to make sure eval caching doesn't take effect.
michael@0 48 var s = "function caller" + callerNo + "(fn, thisObj, arrays) {" +
michael@0 49 " for (var i = 0; i < arrays.length; i++) {" +
michael@0 50 " fn.apply(thisObj, arrays[i]);" +
michael@0 51 " }" +
michael@0 52 "}" +
michael@0 53 "fn = caller" + callerNo + ";";
michael@0 54 eval(s);
michael@0 55 return fn;
michael@0 56 };
michael@0 57
michael@0 58 function main() {
michael@0 59 for (var i = 0; i < PERMUTATIONS; i++) {
michael@0 60 var obj = {count:0};
michael@0 61 var arrs = arrayPermutation(i);
michael@0 62 var fn = generateCaller(arrs.length);
michael@0 63 // Loop 20 times so baseline compiler has chance to kick in and compile the scripts.
michael@0 64 for (var j = 0; j < 20; j++)
michael@0 65 fn(targetFun, obj, arrs);
michael@0 66 assertEq(obj.count, EXPECTED_RESULTS[i]);
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 main();

mercurial