2 * A number of the tests in this file depend on the setting of
3 * HOTLOOP. Define some constants up front, so they're easy to grep
6 // The HOTLOOP constant we depend on; only readable from our stats
7 // object in debug builds.
8 const haveTracemonkey = !!(this.tracemonkey)
9 const HOTLOOP = haveTracemonkey ? tracemonkey.HOTLOOP : 2;
10 // The loop count at which we trace
11 const RECORDLOOP = HOTLOOP;
12 // The loop count at which we run the trace
13 const RUNLOOP = HOTLOOP + 1;
16 if ("arguments" in this && arguments.length > 0)
17 testName = arguments[0];
18 var fails = [], passes=[];
20 function jitstatHandler(f)
22 if (!haveTracemonkey) {
25 // XXXbz this is a nasty hack, but I can't figure out a way to
26 // just use jitstats.tbl here
30 f("sideExitIntoInterpreter");
31 f("typeMapMismatchAtEntry");
32 f("returnToDifferentLoopHeader");
34 f("globalShapeMismatchAtEntry");
37 f("unstableLoopVariable");
44 if (!testName || testName == f.name) {
45 // Collect our jit stats
46 var localJITstats = {};
47 jitstatHandler(function(prop, local, global) {
48 localJITstats[prop] = tracemonkey[prop];
50 check(f.name, f(), f.expected, localJITstats, f.jitstats);
54 function check(desc, actual, expected, oldJITstats, expectedJITstats)
56 if (expected == actual) {
58 jitstatHandler(function(prop) {
59 if (expectedJITstats && prop in expectedJITstats &&
60 expectedJITstats[prop] !=
61 tracemonkey[prop] - oldJITstats[prop]) {
67 return print(desc, ": passed");
71 var expectedStats = "";
72 if (expectedJITstats) {
73 jitstatHandler(function(prop) {
74 if (prop in expectedJITstats) {
78 prop + ": " + expectedJITstats[prop];
83 if (expectedJITstats) {
84 jitstatHandler(function(prop) {
85 if (prop in expectedJITstats) {
88 actualStats += prop + ": " + (tracemonkey[prop]-oldJITstats[prop]);
92 print(desc, ": FAILED: expected", typeof(expected), "(", expected, ")",
93 (expectedStats ? " [" + expectedStats + "] " : ""),
95 typeof(actual), "(", actual, ")",
96 (actualStats ? " [" + actualStats + "] " : ""));
99 function ifInsideLoop()
101 var cond = true, intCond = 5, count = 0;
102 for (var i = 0; i < 100; i++) {
110 ifInsideLoop.expected = 200;
113 function bitwiseAnd_inner(bitwiseAndValue) {
114 for (var i = 0; i < 60000; i++)
115 bitwiseAndValue = bitwiseAndValue & i;
116 return bitwiseAndValue;
118 function bitwiseAnd()
120 return bitwiseAnd_inner(12341234);
122 bitwiseAnd.expected = 0;
125 if (!testName || testName == "bitwiseGlobal") {
126 bitwiseAndValue = Math.pow(2,32);
127 for (var i = 0; i < 60000; i++)
128 bitwiseAndValue = bitwiseAndValue & i;
129 check("bitwiseGlobal", bitwiseAndValue, 0);
135 var i1 = 55, one = 1, zero = 0, undef;
136 var o1 = { }, o2 = { };
138 var hits = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
139 for (var i = 0; i < 5000; i++) {
140 if (i1 == 55) hits[0]++;
141 if (i1 != 56) hits[1]++;
142 if (i1 < 56) hits[2]++;
143 if (i1 > 50) hits[3]++;
144 if (i1 <= 60) hits[4]++;
145 if (i1 >= 30) hits[5]++;
146 if (i1 == 7) hits[6]++;
147 if (i1 != 55) hits[7]++;
148 if (i1 < 30) hits[8]++;
149 if (i1 > 90) hits[9]++;
150 if (i1 <= 40) hits[10]++;
151 if (i1 >= 70) hits[11]++;
152 if (o1 == o2) hits[12]++;
153 if (o2 != null) hits[13]++;
154 if (s < 10) hits[14]++;
155 if (true < zero) hits[15]++;
156 if (undef > one) hits[16]++;
157 if (undef < zero) hits[17]++;
159 return hits.toString();
161 equalInt.expected = "5000,5000,5000,5000,5000,5000,0,0,0,0,0,0,0,5000,5000,0,0,0";
167 a = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
168 a = a.concat(a, a, a);
170 for (var i = 0; i < l; i++) {
175 setelem.expected = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83";
178 function getelem_inner(a)
182 for (var i = 0; i < l; i++) {
189 return getelem_inner(a);
191 getelem.expected = 3486;
198 for (var i = 0; i < 100; i++)
206 if (!testName || testName == "globalGet") {
207 for (var i = 0; i < 500; i++)
208 globalInt = globalName + i;
209 check("globalGet", globalInt, globalName + 499);
212 if (!testName || testName == "globalSet") {
213 for (var i = 0; i < 500; i++)
215 check("globalSet", globalInt, 499);
221 for (var i = 0; i < 100; i++) {
222 accum += (i * 2) - 1;
226 arith.expected = 9800;
229 function lsh_inner(n)
232 for (var i = 0; i < 35; i++)
238 return [lsh_inner(15),lsh_inner(55),lsh_inner(1),lsh_inner(0)];
240 lsh.expected = "32768,8388608,2,1";
243 function rsh_inner(n)
246 for (var i = 0; i < 35; i++)
252 return [rsh_inner(8),rsh_inner(5),rsh_inner(35),rsh_inner(-1)];
254 rsh.expected = "1114369,8914952,35659808,0";
257 function ursh_inner(n)
260 for (var i = 0; i < 35; i++)
265 return [ursh_inner(8),ursh_inner(33),ursh_inner(0),ursh_inner(1)];
267 ursh.expected = "16777215,2147483620,4294967241,2147483620";
270 function doMath_inner(cos)
274 for (var i = 0; i < 200; i++)
275 s = -Math.pow(sin(i) + cos(i * 0.75), 4);
279 return doMath_inner(Math.cos);
281 doMath.expected = -0.5405549555611059;
284 function fannkuch() {
285 var count = Array(8);
289 // write-out the first 30 permutations
291 while (r != 1) { count[r - 1] = r; r--; }
293 count[r] = count[r] - 1;
294 if (count[r] > 0) break;
300 fannkuch.expected = 41;
306 for (var i = 0; i < 20; i++)
310 xprop.expected = 140;
314 function getprop_inner(o2)
319 for (var i = 0; i < 20; i++) {
321 x += o.a + o2.a + this.a + t.a;
326 return getprop_inner({a:9});
328 getprop.expected = 360;
333 var mods = [-1,-1,-1,-1];
334 var a = 9.5, b = -5, c = 42, d = (1/0);
335 for (var i = 0; i < 20; i++) {
342 return mods.toString();
344 mod.expected = "4.5,0,42,4,NaN";
355 var q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0;
364 for (var i = 0; i < 100; ++i) {
371 var ret = [q1, q2, q3, q4, q5];
374 call.expected = "100,100,100,100,100";
380 var obj2 = { b:-1, a:-1 };
381 for (var i = 0; i < 20; i++) {
384 return [obj.a, obj2.a, obj2.b].toString();
386 setprop.expected = "19,-1,19";
391 for (var i = 0; i < 100; i++) {
399 testif.expected = "0";
403 function testincops(n) {
404 var i = 0, o = {p:0}, a = [0];
407 for (i = 0; i < n; i++);
409 for (i = 0; i < n; ++i);
412 for (o.p = 0; o.p < n; o.p++) globalinc++;
413 while (o.p-- > 0) --globalinc;
414 for (o.p = 0; o.p < n; ++o.p) ++globalinc;
415 while (--o.p >= 0) globalinc--;
418 for (a[i] = 0; a[i] < n; a[i]++);
420 for (a[i] = 0; a[i] < n; ++a[i]);
423 return [++o.p, ++a[i], globalinc].toString();
425 testincops.expected = "0,0,0";
429 var i = 0, o = [0,0,0];
430 for (i = 0; i < 100; ++i) {
431 if ((i & 1) == 0) o[0]++;
432 else if ((i & 2) == 0) o[1]++;
437 trees.expected = "50,25,25";
440 function unboxint() {
443 for (var i = 0; i < 100; ++i)
447 unboxint.expected = "8";
453 var s = "abcdefghij", s2 = "a";
455 var c = 0, d = 0, e = 0, g = 0;
456 for (var i = 0; i < 10; i++) {
457 a[i] = (s.substring(i, i+1) + s[i] + String.fromCharCode(s2.charCodeAt(0) + i)).concat(i) + i;
463 g++; // f already used
468 return a.toString() + b + c + d + e + g;
470 strings.expected = "aaa00,bbb11,ccc22,ddd33,eee44,fff55,ggg66,hhh77,iii88,jjj991019100";
473 function dependentStrings()
476 var t = "abcdefghijklmnopqrst";
477 for (var i = 0; i < 10; i++) {
478 var s = t.substring(2*i, 2*i + 2);
483 dependentStrings.expected = "ab2cd2ef2gh2ij2kl2mn2op2qr2st2";
484 test(dependentStrings);
486 function stringConvert()
489 var s1 = "F", s2 = "1.3", s3 = "5";
490 for (var i = 0; i < 10; i++) {
503 stringConvert.expected = "1,8.7,75,37,1.360,,,5";
506 function orTestHelper(a, b, n)
509 for (var i = 0; i < n; i++) {
516 var orNaNTest1, orNaNTest2;
518 orNaNTest1 = new Function("return orTestHelper(NaN, NaN, 10);");
519 orNaNTest1.name = 'orNaNTest1';
520 orNaNTest1.expected = '0';
521 orNaNTest2 = new Function("return orTestHelper(NaN, 1, 10);");
522 orNaNTest2.name = 'orNaNTest2';
523 orNaNTest2.expected = '45';
527 function andTestHelper(a, b, n)
530 for (var i = 0; i < n; i++) {
537 if (!testName || testName == "truthies") {
539 var opsies = ["||", "&&"];
540 var falsies = [null, undefined, false, NaN, 0, ""];
541 var truthies = [{}, true, 1, 42, 1/0, -1/0, "blah"];
542 var boolies = [falsies, truthies];
544 // The for each here should abort tracing, so that this test framework
545 // relies only on the interpreter while the orTestHelper and andTestHelper
546 // functions get trace-JITed.
547 for each (var op in opsies) {
548 for (var i in boolies) {
549 for (var j in boolies[i]) {
550 var x = uneval(boolies[i][j]);
551 for (var k in boolies) {
552 for (var l in boolies[k]) {
553 var y = uneval(boolies[k][l]);
554 var prefix = (op == "||") ? "or" : "and";
555 var f = new Function("return " + prefix + "TestHelper(" + x + "," + y + ",10)");
556 f.name = prefix + "Test(" + x + "," + y + ")";
557 f.expected = eval(x + op + y) ? 45 : 0;
567 function nonEmptyStack1Helper(o, farble) {
575 function nonEmptyStack1() {
576 return nonEmptyStack1Helper({a:1,b:2,c:3,d:4,e:5,f:6,g:7,h:8}, "hi");
579 nonEmptyStack1.expected = "abcdefgh";
580 test(nonEmptyStack1);
582 function nonEmptyStack2()
585 for (var c in {a:1, b:2, c:3}) {
586 for (var i = 0; i < 10; i++)
591 nonEmptyStack2.expected = "135";
592 test(nonEmptyStack2);
594 function arityMismatchMissingArg(arg)
596 for (var a = 0, i = 1; i < 10000; i *= 2) {
601 arityMismatchMissingArg.expected = 16383;
602 test(arityMismatchMissingArg);
604 function arityMismatchExtraArg()
606 return arityMismatchMissingArg(1, 2);
608 arityMismatchExtraArg.expected = 16383;
609 test(arityMismatchExtraArg);
611 function MyConstructor(i)
615 MyConstructor.prototype.toString = function() {return this.i + ""};
620 for (var i = 0; i < 10; i++)
621 a[i] = new MyConstructor(i);
624 newTest.expected = "0123456789";
627 // The following functions use a delay line of length 2 to change the value
628 // of the callee without exiting the traced loop. This is obviously tuned to
629 // match the current HOTLOOP setting of 2.
630 function shapelessArgCalleeLoop(f, g, h, a)
632 for (var i = 0; i < 10; i++) {
639 function shapelessVarCalleeLoop(f0, g, h, a)
642 for (var i = 0; i < 10; i++) {
649 function shapelessLetCalleeLoop(f0, g, h, a)
651 for (var i = 0; i < 10; i++) {
659 function shapelessUnknownCalleeLoop(n, f, g, h, a)
661 for (var i = 0; i < 10; i++) {
668 function shapelessCalleeTest()
672 var helper = function (i, a) a[i] = i;
673 shapelessArgCalleeLoop(helper, helper, function (i, a) a[i] = -i, a);
675 helper = function (i, a) a[10 + i] = i;
676 shapelessVarCalleeLoop(helper, helper, function (i, a) a[10 + i] = -i, a);
678 helper = function (i, a) a[20 + i] = i;
679 shapelessLetCalleeLoop(helper, helper, function (i, a) a[20 + i] = -i, a);
681 helper = function (i, a) a[30 + i] = i;
682 shapelessUnknownCalleeLoop(null, helper, helper, function (i, a) a[30 + i] = -i, a);
686 shapelessUnknownCalleeLoop(null, helper, helper, helper, a);
688 if (e + "" != "TypeError: f is not a function")
689 print("shapelessUnknownCalleeLoop: unexpected exception " + e);
693 shapelessCalleeTest.expected = "01-2-3-4-5-6-7-8-901-2-3-4-5-6-7-8-9012345678901-2-3-4-5-6-7-8-9";
694 test(shapelessCalleeTest);
696 function typeofTest()
698 var values = ["hi", "hi", "hi", null, 5, 5.1, true, undefined, /foo/, typeofTest, [], {}], types = [];
699 for (var i = 0; i < values.length; i++)
700 types[i] = typeof values[i];
701 return types.toString();
703 typeofTest.expected = "string,string,string,object,number,number,boolean,undefined,object,function,object,object";
710 for (var i = 0; i < 8; i++)
711 a[i] = [String.fromCharCode(97 + i)];
712 for (i = 0; i < 8; i++) {
713 for (var j = 0; j < 8; j++)
716 for (i = 0; i < 8; i++)
720 joinTest.expected = "a,0,1,2,3,4,5,6,7b,0,1,2,3,4,5,6,7c,0,1,2,3,4,5,6,7d,0,1,2,3,4,5,6,7e,0,1,2,3,4,5,6,7f,0,1,2,3,4,5,6,7g,0,1,2,3,4,5,6,7h,0,1,2,3,4,5,6,7";
725 return (x == undefined) ? 1 : 0;
727 function missingArgTest() {
729 for (var i = 0; i < 10; i++) {
734 missingArgTest.expected = "1"
735 test(missingArgTest);
739 stringify: function stringify(value, whitelist) {
740 switch (typeof(value)) {
742 return value.constructor.name;
748 function missingArgTest2() {
752 ['{"foo":"bar"}', {"foo":"bar"}],
756 for (var i=0; i < testPairs.length; i++) {
757 var s = JSON.stringify(testPairs[i][1])
762 missingArgTest2.expected = "Object,Array,Object";
763 test(missingArgTest2);
765 function deepForInLoop() {
766 // NB: the number of props set in C is arefully tuned to match HOTLOOP = 2.
767 function C(){this.p = 1, this.q = 2}
768 C.prototype = {p:1, q:2, r:3, s:4, t:5};
776 deepForInLoop.expected = "pqrst";
779 function nestedExit(x) {
781 for (var i = 0; i < 10; ++i)
785 function nestedExitLoop() {
786 for (var j = 0; j < 10; ++j)
790 nestedExitLoop.expected = "ok";
791 test(nestedExitLoop);
793 function bitsinbyte(b) {
801 function TimeFunc(func) {
803 for(var y=0; y<256; y++) func(y);
805 function nestedExit2() {
806 TimeFunc(bitsinbyte);
809 nestedExit2.expected = "ok";
812 function parsingNumbers() {
816 var s2z = "123.456zzz";
821 var r1, r1z, r2, r2z;
823 for (var i = 0; i < 10; i++) {
827 r2z = parseFloat(s2z);
830 if (r1 == e1 && r1z == e1 && r2 == e2 && r2z == e2)
834 parsingNumbers.expected = "ok";
835 test(parsingNumbers);
837 function matchInLoop() {
839 for (var i = 0; i < 10; i++) {
840 var result = k.match(/hi/) != null;
844 matchInLoop.expected = true;
853 for (var i = 0; i < 100; ++i)
857 deep2.expected = "ok";
860 var merge_type_maps_x = 0, merge_type_maps_y = 0;
861 function merge_type_maps() {
862 for (merge_type_maps_x = 0; merge_type_maps_x < 50; ++merge_type_maps_x)
863 if ((merge_type_maps_x & 1) == 1)
865 return [merge_type_maps_x,merge_type_maps_y].join(",");
867 merge_type_maps.expected = "50,25";
868 test(merge_type_maps)
870 function inner_double_outer_int() {
872 for (var m = 0; m < 20; ++m)
873 for (var n = 0; n < 100; n += i)
879 inner_double_outer_int.expected = "100";
880 test(inner_double_outer_int);
882 function newArrayTest()
885 for (var i = 0; i < 10; i++)
887 return a.map(function(x) x.length).toString();
889 newArrayTest.expected="0,0,0,0,0,0,0,0,0,0";
892 function stringSplitTest()
896 for (var i = 0; i < 10; ++i)
900 stringSplitTest.expected="a,b";
901 test(stringSplitTest);
903 function stringSplitIntoArrayTest()
907 for (var i = 0; i < 10; ++i)
911 stringSplitIntoArrayTest.expected="a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b";
912 test(stringSplitIntoArrayTest);
914 function forVarInWith() {
915 function foo() ({notk:42});
916 function bar() ({p:1, q:2, r:3, s:4, t:5});
925 forVarInWith.expected = "pqrst";
928 function inObjectTest() {
929 var o = {p: 1, q: 2, r: 3, s: 4, t: 5};
940 inObjectTest.expected = 5;
943 function inArrayTest() {
944 var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
945 for (var i = 0; i < a.length; i++) {
951 inArrayTest.expected = 10;
954 function innerLoopIntOuterDouble() {
955 var n = 10000, i=0, j=0, count=0, limit=0;
956 for (i = 1; i <= n; ++i) {
958 for (j = 0; j < limit; ++j) {
964 innerLoopIntOuterDouble.expected="50005000";
965 test(innerLoopIntOuterDouble);
967 function outerline(){
971 for (i = 3; i<= 100000; i+=2)
972 for (j = 3; j < 1000; j+=2)
977 outerline.expected="ok";
980 function addAccumulations(f) {
986 function loopingAccumulator() {
989 for (var i = 0; i < 10; ++i) {
996 function testLoopingAccumulator() {
997 var x = addAccumulations(loopingAccumulator);
1000 testLoopingAccumulator.expected = 20;
1001 test(testLoopingAccumulator);
1003 function testBranchingLoop() {
1005 for (var i=0; i < 100; ++i) {
1013 testBranchingLoop.expected = 110;
1014 test(testBranchingLoop);
1016 function testBranchingUnstableLoop() {
1018 for (var i=0; i < 100; ++i) {
1026 testBranchingUnstableLoop.expected = 110.1;
1027 test(testBranchingUnstableLoop);
1029 function testBranchingUnstableLoopCounter() {
1031 for (var i=0; i < 100; ++i) {
1039 testBranchingUnstableLoopCounter.expected = 99;
1040 test(testBranchingUnstableLoopCounter);
1043 function testBranchingUnstableObject() {
1046 for (var i=0; i < 100; ++i) {
1055 testBranchingUnstableObject.expected = 100;
1056 test(testBranchingUnstableObject);
1058 function testArrayDensityChange() {
1061 for (var i=0; i < 100; ++i) {
1064 for (var i=0; i < x.length; ++i) {
1070 count += x[i].length;
1074 testArrayDensityChange.expected = 404;
1075 test(testArrayDensityChange);
1077 function testDoubleToStr() {
1080 for (var i = 0; i < 200; i++) {
1081 x += parseFloat(y.toString());
1085 testDoubleToStr.expected = 5.5*200;
1086 test(testDoubleToStr);
1088 function testDecayingInnerLoop() {
1090 for (i = 0; i < 5000; ++i) {
1091 for (j = 0; j < k; ++j);
1096 testDecayingInnerLoop.expected = 5000;
1097 test(testDecayingInnerLoop);
1099 function testContinue() {
1102 for (i = 0; i < 20; ++i) {
1109 testContinue.expected = 19;
1112 function testContinueWithLabel() {
1127 testContinueWithLabel.expected = 20;
1128 test(testContinueWithLabel);
1130 function testDivision() {
1139 testDivision.expected = 1;
1142 function testDivisionFloat() {
1151 testDivisionFloat.expected = true;
1152 test(testDivisionFloat);
1154 function testToUpperToLower() {
1155 var s = "Hello", s1, s2;
1156 for (i = 0; i < 100; ++i) {
1157 s1 = s.toLowerCase();
1158 s2 = s.toUpperCase();
1162 testToUpperToLower.expected = "helloHELLO";
1163 test(testToUpperToLower);
1165 function testReplace2() {
1166 var s = "H e l l o", s1;
1167 for (i = 0; i < 100; ++i) {
1168 s1 = s.replace(" ", "");
1172 testReplace2.expected = "He l l o";
1175 function testBitwise() {
1179 for (var i = 0; i < 50; i++) {
1186 testBitwise.expected = -1298;
1189 function testSwitch() {
1192 for (var i = 0; i < 100; ++i) {
1213 testSwitch.expected = 226;
1216 function testSwitchString() {
1219 for (var i = 0; i < 100; ++i) {
1243 testSwitchString.expected = 200;
1244 test(testSwitchString);
1246 function testNegZero1Helper(z) {
1247 for (let j = 0; j < 5; ++j) { z = -z; }
1248 return Math.atan2(0, -0) == Math.atan2(0, z);
1251 var testNegZero1 = function() { return testNegZero1Helper(0); }
1252 testNegZero1.expected = true;
1253 testNegZero1.name = 'testNegZero1';
1254 testNegZero1Helper(1);
1257 // No test case, just make sure this doesn't assert.
1258 function testNegZero2() {
1260 for (let j = 0; j < 5; ++j) { ({p: (-z)}); }
1264 function testConstSwitch() {
1266 for (var j=0;j<5;++j) { switch(1.1) { case NaN: case 2: } x = 2; }
1269 testConstSwitch.expected = 2;
1270 test(testConstSwitch);
1272 function testConstSwitch2() {
1274 for (var j = 0; j < 4; ++j) { switch(0/0) { } }
1277 testConstSwitch2.expected = "ok";
1278 test(testConstSwitch2);
1280 function testConstIf() {
1282 for (var j=0;j<5;++j) { if (1.1 || 5) { } x = 2;}
1285 testConstIf.expected = 2;
1288 function testTypeofHole() {
1289 var a = new Array(6);
1291 for (var i = 0; i < 6; ++i)
1295 testTypeofHole.expected = "undefined,undefined,undefined,undefined,undefined,number"
1296 test(testTypeofHole);
1298 function testNativeLog() {
1299 var a = new Array(5);
1300 for (var i = 0; i < 5; i++) {
1301 a[i] = Math.log(Math.pow(Math.E, 10));
1305 testNativeLog.expected = "10,10,10,10,10";
1306 test(testNativeLog);
1308 function test_JSOP_ARGSUB() {
1309 function f0() { return arguments[0]; }
1310 function f1() { return arguments[1]; }
1311 function f2() { return arguments[2]; }
1312 function f3() { return arguments[3]; }
1313 function f4() { return arguments[4]; }
1314 function f5() { return arguments[5]; }
1315 function f6() { return arguments[6]; }
1316 function f7() { return arguments[7]; }
1317 function f8() { return arguments[8]; }
1318 function f9() { return arguments[9]; }
1320 for (var i = 0; i < 10; i++) {
1323 a[2] = f2('a','b','c');
1324 a[3] = f3('a','b','c','d');
1325 a[4] = f4('a','b','c','d','e');
1326 a[5] = f5('a','b','c','d','e','f');
1327 a[6] = f6('a','b','c','d','e','f','g');
1328 a[7] = f7('a','b','c','d','e','f','g','h');
1329 a[8] = f8('a','b','c','d','e','f','g','h','i');
1330 a[9] = f9('a','b','c','d','e','f','g','h','i','j');
1334 test_JSOP_ARGSUB.expected = "abcdefghij";
1335 test(test_JSOP_ARGSUB);
1337 function test_JSOP_ARGCNT() {
1338 function f0() { return arguments.length; }
1339 function f1() { return arguments.length; }
1340 function f2() { return arguments.length; }
1341 function f3() { return arguments.length; }
1342 function f4() { return arguments.length; }
1343 function f5() { return arguments.length; }
1344 function f6() { return arguments.length; }
1345 function f7() { return arguments.length; }
1346 function f8() { return arguments.length; }
1347 function f9() { return arguments.length; }
1349 for (var i = 0; i < 10; i++) {
1352 a[2] = f2('a','b','c');
1353 a[3] = f3('a','b','c','d');
1354 a[4] = f4('a','b','c','d','e');
1355 a[5] = f5('a','b','c','d','e','f');
1356 a[6] = f6('a','b','c','d','e','f','g');
1357 a[7] = f7('a','b','c','d','e','f','g','h');
1358 a[8] = f8('a','b','c','d','e','f','g','h','i');
1359 a[9] = f9('a','b','c','d','e','f','g','h','i','j');
1363 test_JSOP_ARGCNT.expected = "1,2,3,4,5,6,7,8,9,10";
1364 test(test_JSOP_ARGCNT);
1366 function testNativeMax() {
1368 for (var i = 0; i < 5; ++i) {
1374 for (var i = 0; i < 5; ++i) {
1379 for (var i = 0; i < 5; ++i) {
1380 k = Math.max(0, -0);
1382 out.push((1 / k) < 0);
1383 return out.join(",");
1385 testNativeMax.expected = "NaN,4,false";
1386 test(testNativeMax);
1388 function testFloatArrayIndex() {
1390 for (var i = 0; i < 10; ++i) {
1394 return a[3] + "," + a[3.5];
1396 testFloatArrayIndex.expected = "5,7";
1397 test(testFloatArrayIndex);
1399 function testStrict() {
1401 for (var i = 0; i < 10; ++i) {
1404 a[2] = (n === null);
1409 testStrict.expected = "true,false,false,false";
1412 function testSetPropNeitherMissNorHit() {
1413 for (var j = 0; j < 5; ++j) { if (({}).__proto__ = 1) { } }
1416 testSetPropNeitherMissNorHit.expected = "ok";
1417 test(testSetPropNeitherMissNorHit);
1419 function testPrimitiveConstructorPrototype() {
1420 var f = function(){};
1421 f.prototype = false;
1422 for (let j=0;j<5;++j) { new f; }
1425 testPrimitiveConstructorPrototype.expected = "ok";
1426 test(testPrimitiveConstructorPrototype);
1428 function testSideExitInConstructor() {
1430 FCKConfig.CoreStyles =
1448 Styles : { 'background-color' : '' }
1452 var FCKStyle = function(A) {
1457 for (var s in FCKConfig.CoreStyles) {
1458 var x = new FCKStyle(FCKConfig.CoreStyles[s]);
1459 if (!x) pass = false;
1463 testSideExitInConstructor.expected = true;
1464 test(testSideExitInConstructor);
1466 function testNot() {
1467 var a = new Object(), b = null, c = "foo", d = "", e = 5, f = 0, g = 5.5, h = -0, i = true, j = false, k = undefined;
1469 for (var i = 0; i < 10; ++i) {
1470 r = [!a, !b, !c, !d, !e, !f, !g, !h, !i, !j, !k];
1474 testNot.expected = "false,true,false,true,false,true,false,true,false,true,true";
1477 function doTestDifferingArgc(a, b)
1480 for (var i = 0; i < 10; i++)
1486 function testDifferingArgc()
1489 x += doTestDifferingArgc(1, 2);
1490 x += doTestDifferingArgc(1);
1491 x += doTestDifferingArgc(1, 2, 3);
1494 testDifferingArgc.expected = 45*3;
1495 test(testDifferingArgc);
1497 function doTestMoreArgcThanNargs()
1500 for (var i = 0; i < 10; i++)
1502 x = x + arguments[3];
1506 function testMoreArgcThanNargs()
1508 return doTestMoreArgcThanNargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
1510 testMoreArgcThanNargs.expected = 4*10;
1511 test(testMoreArgcThanNargs);
1513 // Test stack reconstruction after a nested exit
1514 function testNestedExitStackInner(j, counter) {
1517 for (var i = 1; i <= RUNLOOP; i++) {
1520 // Make sure that once everything has been traced we suddenly switch to
1521 // a different control flow the first time we run the outermost tree,
1522 // triggering a side exit.
1532 function testNestedExitStackOuter() {
1534 for (var j = 1; j <= RUNLOOP; ++j) {
1535 for (var k = 1; k <= RUNLOOP; ++k) {
1536 counter = testNestedExitStackInner(j, counter);
1541 testNestedExitStackOuter.expected = 81;
1542 testNestedExitStackOuter.jitstats = {
1547 test(testNestedExitStackOuter);
1549 function testHOTLOOPSize() {
1552 testHOTLOOPSize.expected = true;
1553 test(testHOTLOOPSize);
1555 function testGlobalProtoAccess() {
1558 this.__proto__.a = 3; for (var j = 0; j < 4; ++j) { [a]; }
1559 testGlobalProtoAccess.expected = "ok";
1560 test(testGlobalProtoAccess);
1562 function testMatchStringObject() {
1563 var a = new String("foo");
1565 for (i = 0; i < 300; i++) {
1570 testMatchStringObject.expected = null;
1571 test(testMatchStringObject);
1573 function innerSwitch(k)
1586 function testInnerSwitchBreak()
1588 var r = new Array(5);
1589 for (var i = 0; i < 5; i++)
1591 r[i] = innerSwitch(0);
1596 testInnerSwitchBreak.expected = "1,1,1,1,1";
1597 test(testInnerSwitchBreak);
1599 function testArrayNaNIndex()
1601 for (var j = 0; j < 4; ++j) { [this[NaN]]; }
1602 for (var j = 0; j < 5; ++j) { if([1][-0]) { } }
1605 testArrayNaNIndex.expected = "ok";
1606 test(testArrayNaNIndex);
1608 function innerTestInnerMissingArgs(a,b,c,d)
1614 function doTestInnerMissingArgs(k)
1616 for (i = 0; i < 10; i++) {
1617 innerTestInnerMissingArgs(k);
1620 function testInnerMissingArgs()
1622 doTestInnerMissingArgs(1);
1623 doTestInnerMissingArgs(0);
1626 testInnerMissingArgs.expected = 1; //Expected: that we don't crash.
1627 test(testInnerMissingArgs);
1629 /* Keep these at the end so that we can see the summary after the trace-debug spew. */
1630 print("\npassed:", passes.length && passes.join(","));
1631 print("\nFAILED:", fails.length && fails.join(","));