Debian Codegraph @

rhino/testsrc/tests/js1_8_1/trace/trace-test.js

raw symbols SCIP
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 var gTestfile = 'trace-test.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 'none';
9 var summary = 'trace-capability mini-testsuite';
10
11 printBugNumber(BUGNUMBER);
12 printStatus (summary);
13
14 jit(true);
15
16 /**
17 * A number of the tests in this file depend on the setting of
18 * HOTLOOP. Define some constants up front, so they're easy to grep
19 * for.
20 */
21 // The HOTLOOP constant we depend on; only readable from our stats
22 // object in debug builds.
23 const haveTracemonkey = !!(this.tracemonkey)
24 const HOTLOOP = haveTracemonkey ? tracemonkey.HOTLOOP : 2;
25 // The loop count at which we trace
26 const RECORDLOOP = HOTLOOP;
27 // The loop count at which we run the trace
28 const RUNLOOP = HOTLOOP + 1;
29
30 var gDoMandelbrotTest = true;
31 if ("gSkipSlowTests" in this && gSkipSlowTests) {
32 print("** Skipping slow tests");
33 gDoMandelbrotTest = false;
34 }
35
36 if (!('gSrcdir' in this))
37 gSrcdir = '.';
38
39 if (!('gReportSummary' in this))
40 gReportSummary = true;
41
42 var testName = null;
43 if ("arguments" in this && arguments.length > 0)
44 testName = arguments[0];
45 var fails = [], passes=[];
46
47 function jitstatHandler(f)
48 {
49 if (!haveTracemonkey)
50 return;
51
52 // XXXbz this is a nasty hack, but I can't figure out a way to
53 // just use jitstats.tbl here
54 f("recorderStarted");
55 f("recorderAborted");
56 f("traceCompleted");
57 f("sideExitIntoInterpreter");
58 f("timeoutIntoInterpreter");
59 f("typeMapMismatchAtEntry");
60 f("returnToDifferentLoopHeader");
61 f("traceTriggered");
62 f("globalShapeMismatchAtEntry");
63 f("treesTrashed");
64 f("slotPromoted");
65 f("unstableLoopVariable");
66 f("breakLoopExits");
67 f("returnLoopExits");
68 f("mergedLoopExits");
69 f("noCompatInnerTrees");
70 }
71
72 var jitProps = {};
73 jitstatHandler(function(prop) {
74 jitProps[prop] = true;
75 });
76 var hadJITstats = false;
77 for (var p in jitProps)
78 hadJITstats = true;
79
80 function test(f)
81 {
82 // Clear out any accumulated confounding state in the oracle / JIT cache.
83 gc();
84
85 if (!testName || testName == f.name) {
86 var expectedJITstats = f.jitstats;
87 if (hadJITstats && expectedJITstats)
88 {
89 var expectedProps = {};
90 jitstatHandler(function(prop) {
91 if (prop in expectedJITstats)
92 expectedProps[prop] = true;
93 });
94 for (var p in expectedJITstats)
95 {
96 if (!(p in expectedProps))
97 throw "Bad property in " + f.name + ".jitstats: " + p;
98 }
99 }
100
101 // Collect our jit stats
102 var localJITstats = {};
103 jitstatHandler(function(prop) {
104 localJITstats[prop] = tracemonkey[prop];
105 });
106 check(f.name, f(), f.expected, localJITstats, expectedJITstats);
107 }
108 }
109
110 function map_test(t, cases)
111 {
112 for (var i = 0; i < cases.length; i++) {
113 function c() { return t(cases[i].input); }
114 c.expected = cases[i].expected;
115 c.name = t.name + "(" + uneval(cases[i].input) + ")";
116 test(c);
117 }
118 }
119
120 // Use this function to compare expected and actual test results.
121 // Types must match.
122 // For numbers, treat NaN as matching NaN, distinguish 0 and -0, and
123 // tolerate a certain degree of error for other values.
124 //
125 // These are the same criteria used by the tests in js/tests, except that
126 // we distinguish 0 and -0.
127 function close_enough(expected, actual)
128 {
129 if (typeof expected != typeof actual)
130 return false;
131 if (typeof expected != 'number')
132 return actual == expected;
133
134 // Distinguish NaN from other values. Using x != x comparisons here
135 // works even if tests redefine isNaN.
136 if (actual != actual)
137 return expected != expected
138 if (expected != expected)
139 return false;
140
141 // Tolerate a certain degree of error.
142 if (actual != expected)
143 return Math.abs(actual - expected) <= 1E-10;
144
145 // Distinguish 0 and -0.
146 if (actual == 0)
147 return (1 / actual > 0) == (1 / expected > 0);
148
149 return true;
150 }
151
152 function check(desc, actual, expected, oldJITstats, expectedJITstats)
153 {
154 var pass = false;
155 if (close_enough(expected, actual)) {
156 pass = true;
157 jitstatHandler(function(prop) {
158 if (expectedJITstats && prop in expectedJITstats &&
159 expectedJITstats[prop] !=
160 tracemonkey[prop] - oldJITstats[prop]) {
161 pass = false;
162 }
163 });
164 if (pass) {
165 reportCompare(expected, actual, desc);
166 passes.push(desc);
167 return print("TEST-PASS | trace-test.js |", desc);
168 }
169 }
170
171 if (expected instanceof RegExp) {
172 pass = reportMatch(expected, actual + '', desc);
173 if (pass) {
174 jitstatHandler(function(prop) {
175 if (expectedJITstats && prop in expectedJITstats &&
176 expectedJITstats[prop] !=
177 tracemonkey[prop] - oldJITstats[prop]) {
178 pass = false;
179 }
180 });
181 }
182 if (pass) {
183 passes.push(desc);
184 return print(desc, ": passed");
185 }
186 }
187
188 reportCompare(expected, actual, desc);
189
190 fails.push(desc);
191 var expectedStats = "";
192 if (expectedJITstats) {
193 jitstatHandler(function(prop) {
194 if (prop in expectedJITstats) {
195 if (expectedStats)
196 expectedStats += " ";
197 expectedStats +=
198 prop + ": " + expectedJITstats[prop];
199 }
200 });
201 }
202 var actualStats = "";
203 if (expectedJITstats) {
204 jitstatHandler(function(prop) {
205 if (prop in expectedJITstats) {
206 if (actualStats)
207 actualStats += " ";
208 actualStats += prop + ": " + (tracemonkey[prop]-oldJITstats[prop]);
209 }
210 });
211 }
212 print("TEST-UNEXPECTED-FAIL | trace-test.js |", desc, ": expected", typeof(expected),
213 "(", uneval(expected), ")",
214 (expectedStats ? " [" + expectedStats + "] " : ""),
215 "!= actual",
216 typeof(actual), "(", uneval(actual), ")",
217 (actualStats ? " [" + actualStats + "] " : ""));
218 }
219
220 function ifInsideLoop()
221 {
222 var cond = true, intCond = 5, count = 0;
223 for (var i = 0; i < 100; i++) {
224 if (cond)
225 count++;
226 if (intCond)
227 count++;
228 }
229 return count;
230 }
231 ifInsideLoop.expected = 200;
232 test(ifInsideLoop);
233
234 function bitwiseAnd_inner(bitwiseAndValue) {
235 for (var i = 0; i < 60000; i++)
236 bitwiseAndValue = bitwiseAndValue & i;
237 return bitwiseAndValue;
238 }
239 function bitwiseAnd()
240 {
241 return bitwiseAnd_inner(12341234);
242 }
243 bitwiseAnd.expected = 0;
244 test(bitwiseAnd);
245
246 if (!testName || testName == "bitwiseGlobal") {
247 bitwiseAndValue = Math.pow(2,32);
248 for (var i = 0; i < 60000; i++)
249 bitwiseAndValue = bitwiseAndValue & i;
250 check("bitwiseGlobal", bitwiseAndValue, 0);
251 }
252
253
254 function equalInt()
255 {
256 var i1 = 55, one = 1, zero = 0, undef;
257 var o1 = { }, o2 = { };
258 var s = "5";
259 var hits = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
260 for (var i = 0; i < 5000; i++) {
261 if (i1 == 55) hits[0]++;
262 if (i1 != 56) hits[1]++;
263 if (i1 < 56) hits[2]++;
264 if (i1 > 50) hits[3]++;
265 if (i1 <= 60) hits[4]++;
266 if (i1 >= 30) hits[5]++;
267 if (i1 == 7) hits[6]++;
268 if (i1 != 55) hits[7]++;
269 if (i1 < 30) hits[8]++;
270 if (i1 > 90) hits[9]++;
271 if (i1 <= 40) hits[10]++;
272 if (i1 >= 70) hits[11]++;
273 if (o1 == o2) hits[12]++;
274 if (o2 != null) hits[13]++;
275 if (s < 10) hits[14]++;
276 if (true < zero) hits[15]++;
277 if (undef > one) hits[16]++;
278 if (undef < zero) hits[17]++;
279 }
280 return hits.toString();
281 }
282 equalInt.expected = "5000,5000,5000,5000,5000,5000,0,0,0,0,0,0,0,5000,5000,0,0,0";
283 test(equalInt);
284
285 var a;
286 function setelem()
287 {
288 a = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
289 a = a.concat(a, a, a);
290 var l = a.length;
291 for (var i = 0; i < l; i++) {
292 a[i] = i;
293 }
294 return a.toString();
295 }
296 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";
297 test(setelem);
298
299 function getelem_inner(a)
300 {
301 var accum = 0;
302 var l = a.length;
303 for (var i = 0; i < l; i++) {
304 accum += a[i];
305 }
306 return accum;
307 }
308 function getelem()
309 {
310 return getelem_inner(a);
311 }
312 getelem.expected = 3486;
313 test(getelem);
314
315 globalName = 907;
316 function name()
317 {
318 var a = 0;
319 for (var i = 0; i < 100; i++)
320 a = globalName;
321 return a;
322 }
323 name.expected = 907;
324 test(name);
325
326 var globalInt = 0;
327 if (!testName || testName == "globalGet") {
328 for (var i = 0; i < 500; i++)
329 globalInt = globalName + i;
330 check("globalGet", globalInt, globalName + 499);
331 }
332
333 if (!testName || testName == "globalSet") {
334 for (var i = 0; i < 500; i++)
335 globalInt = i;
336 check("globalSet", globalInt, 499);
337 }
338
339 function arith()
340 {
341 var accum = 0;
342 for (var i = 0; i < 100; i++) {
343 accum += (i * 2) - 1;
344 }
345 return accum;
346 }
347 arith.expected = 9800;
348 test(arith);
349
350 function lsh_inner(n)
351 {
352 var r;
353 for (var i = 0; i < 35; i++)
354 r = 0x1 << n;
355 return r;
356 }
357
358 map_test (lsh_inner,
359 [{input: 15, expected: 32768},
360 {input: 55, expected: 8388608},
361 {input: 1, expected: 2},
362 {input: 0, expected: 1}]);
363
364 function rsh_inner(n)
365 {
366 var r;
367 for (var i = 0; i < 35; i++)
368 r = 0x11010101 >> n;
369 return r;
370 }
371 map_test (rsh_inner,
372 [{input: 8, expected: 1114369},
373 {input: 5, expected: 8914952},
374 {input: 35, expected: 35659808},
375 {input: -1, expected: 0}]);
376
377 function ursh_inner(n)
378 {
379 var r;
380 for (var i = 0; i < 35; i++)
381 r = -55 >>> n;
382 return r;
383 }
384 map_test (ursh_inner,
385 [{input: 8, expected: 16777215},
386 {input: 33, expected: 2147483620},
387 {input: 0, expected: 4294967241},
388 {input: 1, expected: 2147483620}]);
389
390 function doMath_inner(cos)
391 {
392 var s = 0;
393 var sin = Math.sin;
394 for (var i = 0; i < 200; i++)
395 s = -Math.pow(sin(i) + cos(i * 0.75), 4);
396 return s;
397 }
398 function doMath() {
399 return doMath_inner(Math.cos);
400 }
401 doMath.expected = -0.5405549555611059;
402 test(doMath);
403
404 function fannkuch() {
405 var count = Array(8);
406 var r = 8;
407 var done = 0;
408 while (done < 40) {
409 // write-out the first 30 permutations
410 done += r;
411 while (r != 1) { count[r - 1] = r; r--; }
412 while (true) {
413 count[r] = count[r] - 1;
414 if (count[r] > 0) break;
415 r++;
416 }
417 }
418 return done;
419 }
420 fannkuch.expected = 41;
421 test(fannkuch);
422
423 function xprop()
424 {
425 a = 0;
426 for (var i = 0; i < 20; i++)
427 a += 7;
428 return a;
429 }
430 xprop.expected = 140;
431 test(xprop);
432
433 var a = 2;
434 function getprop_inner(o2)
435 {
436 var o = {a:5};
437 var t = this;
438 var x = 0;
439 for (var i = 0; i < 20; i++) {
440 t = this;
441 x += o.a + o2.a + this.a + t.a;
442 }
443 return x;
444 }
445 function getprop() {
446 return getprop_inner({a:9});
447 }
448 getprop.expected = 360;
449 test(getprop);
450
451 function mod()
452 {
453 var mods = [-1,-1,-1,-1];
454 var a = 9.5, b = -5, c = 42, d = (1/0);
455 for (var i = 0; i < 20; i++) {
456 mods[0] = a % b;
457 mods[1] = b % 1;
458 mods[2] = c % d;
459 mods[3] = c % a;
460 mods[4] = b % 0;
461 }
462 return mods.toString();
463 }
464 mod.expected = "4.5,0,42,4,NaN";
465 test(mod);
466
467 function glob_f1() {
468 return 1;
469 }
470 function glob_f2() {
471 return glob_f1();
472 }
473 function call()
474 {
475 var q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0;
476 var o = {};
477 function f1() {
478 return 1;
479 }
480 function f2(f) {
481 return f();
482 }
483 o.f = f1;
484 for (var i = 0; i < 100; ++i) {
485 q1 += f1();
486 q2 += f2(f1);
487 q3 += glob_f1();
488 q4 += o.f();
489 q5 += glob_f2();
490 }
491 var ret = String([q1, q2, q3, q4, q5]);
492 return ret;
493 }
494 call.expected = "100,100,100,100,100";
495 test(call);
496
497 function setprop()
498 {
499 var obj = { a:-1 };
500 var obj2 = { b:-1, a:-1 };
501 for (var i = 0; i < 20; i++) {
502 obj2.b = obj.a = i;
503 }
504 return [obj.a, obj2.a, obj2.b].toString();
505 }
506 setprop.expected = "19,-1,19";
507 test(setprop);
508
509 function testif() {
510 var q = 0;
511 for (var i = 0; i < 100; i++) {
512 if ((i & 1) == 0)
513 q++;
514 else
515 q--;
516 }
517 return q;
518 }
519 testif.expected = 0;
520 test(testif);
521
522 var globalinc = 0;
523 function testincops(n) {
524 var i = 0, o = {p:0}, a = [0];
525 n = 100;
526
527 for (i = 0; i < n; i++);
528 while (i-- > 0);
529 for (i = 0; i < n; ++i);
530 while (--i >= 0);
531
532 for (o.p = 0; o.p < n; o.p++) globalinc++;
533 while (o.p-- > 0) --globalinc;
534 for (o.p = 0; o.p < n; ++o.p) ++globalinc;
535 while (--o.p >= 0) globalinc--;
536
537 ++i; // set to 0
538 for (a[i] = 0; a[i] < n; a[i]++);
539 while (a[i]-- > 0);
540 for (a[i] = 0; a[i] < n; ++a[i]);
541 while (--a[i] >= 0);
542
543 return [++o.p, ++a[i], globalinc].toString();
544 }
545 testincops.expected = "0,0,0";
546 test(testincops);
547
548 function trees() {
549 var i = 0, o = [0,0,0];
550 for (i = 0; i < 100; ++i) {
551 if ((i & 1) == 0) o[0]++;
552 else if ((i & 2) == 0) o[1]++;
553 else o[2]++;
554 }
555 return String(o);
556 }
557 trees.expected = "50,25,25";
558 test(trees);
559
560 function unboxint() {
561 var q = 0;
562 var o = [4];
563 for (var i = 0; i < 100; ++i)
564 q = o[0] << 1;
565 return q;
566 }
567 unboxint.expected = 8;
568 test(unboxint);
569
570 function strings()
571 {
572 var a = [], b = -1;
573 var s = "abcdefghij", s2 = "a";
574 var f = "f";
575 var c = 0, d = 0, e = 0, g = 0;
576 for (var i = 0; i < 10; i++) {
577 a[i] = (s.substring(i, i+1) + s[i] + String.fromCharCode(s2.charCodeAt(0) + i)).concat(i) + i;
578 if (s[i] == f)
579 c++;
580 if (s[i] != 'b')
581 d++;
582 if ("B" > s2)
583 g++; // f already used
584 if (s2 < "b")
585 e++;
586 b = s.length;
587 }
588 return a.toString() + b + c + d + e + g;
589 }
590 strings.expected = "aaa00,bbb11,ccc22,ddd33,eee44,fff55,ggg66,hhh77,iii88,jjj991019100";
591 test(strings);
592
593 function dependentStrings()
594 {
595 var a = [];
596 var t = "abcdefghijklmnopqrst";
597 for (var i = 0; i < 10; i++) {
598 var s = t.substring(2*i, 2*i + 2);
599 a[i] = s + s.length;
600 }
601 return a.join("");
602 }
603 dependentStrings.expected = "ab2cd2ef2gh2ij2kl2mn2op2qr2st2";
604 test(dependentStrings);
605
606 function stringConvert()
607 {
608 var a = [];
609 var s1 = "F", s2 = "1.3", s3 = "5";
610 for (var i = 0; i < 10; i++) {
611 a[0] = 1 >> s1;
612 a[1] = 10 - s2;
613 a[2] = 15 * s3;
614 a[3] = s3 | 32;
615 a[4] = s2 + 60;
616 // a[5] = 9 + s3;
617 // a[6] = -s3;
618 a[7] = s3 & "7";
619 // a[8] = ~s3;
620 }
621 return a.toString();
622 }
623 stringConvert.expected = "1,8.7,75,37,1.360,,,5";
624 test(stringConvert);
625
626 function orTestHelper(a, b, n)
627 {
628 var k = 0;
629 for (var i = 0; i < n; i++) {
630 if (a || b)
631 k += i;
632 }
633 return k;
634 }
635
636 var orNaNTest1, orNaNTest2;
637
638 orNaNTest1 = new Function("return orTestHelper(NaN, NaN, 10);");
639 orNaNTest1.name = 'orNaNTest1';
640 orNaNTest1.expected = 0;
641 orNaNTest2 = new Function("return orTestHelper(NaN, 1, 10);");
642 orNaNTest2.name = 'orNaNTest2';
643 orNaNTest2.expected = 45;
644 test(orNaNTest1);
645 test(orNaNTest2);
646
647 function andTestHelper(a, b, n)
648 {
649 var k = 0;
650 for (var i = 0; i < n; i++) {
651 if (a && b)
652 k += i;
653 }
654 return k;
655 }
656
657 if (!testName || testName == "truthies") {
658 (function () {
659 var opsies = ["||", "&&"];
660 var falsies = [null, undefined, false, NaN, 0, ""];
661 var truthies = [{}, true, 1, 42, 1/0, -1/0, "blah"];
662 var boolies = [falsies, truthies];
663
664 // The for each here should abort tracing, so that this test framework
665 // relies only on the interpreter while the orTestHelper and andTestHelper
666 // functions get trace-JITed.
667 for each (var op in opsies) {
668 for (var i in boolies) {
669 for (var j in boolies[i]) {
670 var x = uneval(boolies[i][j]);
671 for (var k in boolies) {
672 for (var l in boolies[k]) {
673 var y = uneval(boolies[k][l]);
674 var prefix = (op == "||") ? "or" : "and";
675 var f = new Function("return " + prefix + "TestHelper(" + x + "," + y + ",10)");
676 f.name = prefix + "Test(" + x + "," + y + ")";
677 f.expected = eval(x + op + y) ? 45 : 0;
678 test(f);
679 }
680 }
681 }
682 }
683 }
684 })();
685 }
686
687 function nonEmptyStack1Helper(o, farble) {
688 var a = [];
689 var j = 0;
690 for (var i in o)
691 a[j++] = i;
692 return a.join("");
693 }
694
695 function nonEmptyStack1() {
696 return nonEmptyStack1Helper({a:1,b:2,c:3,d:4,e:5,f:6,g:7,h:8}, "hi");
697 }
698
699 nonEmptyStack1.expected = "abcdefgh";
700 test(nonEmptyStack1);
701
702 function nonEmptyStack2()
703 {
704 var a = 0;
705 for (var c in {a:1, b:2, c:3}) {
706 for (var i = 0; i < 10; i++)
707 a += i;
708 }
709 return String(a);
710 }
711 nonEmptyStack2.expected = "135";
712 test(nonEmptyStack2);
713
714 function arityMismatchMissingArg(arg)
715 {
716 for (var a = 0, i = 1; i < 10000; i *= 2) {
717 a += i;
718 }
719 return a;
720 }
721 arityMismatchMissingArg.expected = 16383;
722 test(arityMismatchMissingArg);
723
724 function arityMismatchExtraArg()
725 {
726 return arityMismatchMissingArg(1, 2);
727 }
728 arityMismatchExtraArg.expected = 16383;
729 test(arityMismatchExtraArg);
730
731 function MyConstructor(i)
732 {
733 this.i = i;
734 }
735 MyConstructor.prototype.toString = function() {return this.i + ""};
736
737 function newTest()
738 {
739 var a = [];
740 for (var i = 0; i < 10; i++)
741 a[i] = new MyConstructor(i);
742 return a.join("");
743 }
744 newTest.expected = "0123456789";
745 test(newTest);
746
747 // The following functions use a delay line of length 2 to change the value
748 // of the callee without exiting the traced loop. This is obviously tuned to
749 // match the current HOTLOOP setting of 2.
750 function shapelessArgCalleeLoop(f, g, h, a)
751 {
752 for (var i = 0; i < 10; i++) {
753 f(i, a);
754 f = g;
755 g = h;
756 }
757 }
758
759 function shapelessVarCalleeLoop(f0, g, h, a)
760 {
761 var f = f0;
762 for (var i = 0; i < 10; i++) {
763 f(i, a);
764 f = g;
765 g = h;
766 }
767 }
768
769 function shapelessLetCalleeLoop(f0, g, h, a)
770 {
771 for (var i = 0; i < 10; i++) {
772 let f = f0;
773 f(i, a);
774 f = g;
775 g = h;
776 }
777 }
778
779 function shapelessUnknownCalleeLoop(n, f, g, h, a)
780 {
781 for (var i = 0; i < 10; i++) {
782 (n || f)(i, a);
783 f = g;
784 g = h;
785 }
786 }
787
788 function shapelessCalleeTest()
789 {
790 var a = [];
791
792 var helper = function (i, a) a[i] = i;
793 shapelessArgCalleeLoop(helper, helper, function (i, a) a[i] = -i, a);
794
795 helper = function (i, a) a[10 + i] = i;
796 shapelessVarCalleeLoop(helper, helper, function (i, a) a[10 + i] = -i, a);
797
798 helper = function (i, a) a[20 + i] = i;
799 shapelessLetCalleeLoop(helper, helper, function (i, a) a[20 + i] = -i, a);
800
801 helper = function (i, a) a[30 + i] = i;
802 shapelessUnknownCalleeLoop(null, helper, helper, function (i, a) a[30 + i] = -i, a);
803
804 try {
805 helper = {hack: 42};
806 shapelessUnknownCalleeLoop(null, helper, helper, helper, a);
807 } catch (e) {
808 if (e + "" != "TypeError: f is not a function")
809 print("shapelessUnknownCalleeLoop: unexpected exception " + e);
810 }
811 return a.join("");
812 }
813 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";
814 test(shapelessCalleeTest);
815
816 function typeofTest()
817 {
818 var values = ["hi", "hi", "hi", null, 5, 5.1, true, undefined, /foo/, typeofTest, [], {}], types = [];
819 for (var i = 0; i < values.length; i++)
820 types[i] = typeof values[i];
821 return types.toString();
822 }
823 typeofTest.expected = "string,string,string,object,number,number,boolean,undefined,object,function,object,object";
824 test(typeofTest);
825
826 function joinTest()
827 {
828 var s = "";
829 var a = [];
830 for (var i = 0; i < 8; i++)
831 a[i] = [String.fromCharCode(97 + i)];
832 for (i = 0; i < 8; i++) {
833 for (var j = 0; j < 8; j++)
834 a[i][1 + j] = j;
835 }
836 for (i = 0; i < 8; i++)
837 s += a[i].join(",");
838 return s;
839 }
840 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";
841 test(joinTest);
842
843 function arity1(x)
844 {
845 return (x == undefined) ? 1 : 0;
846 }
847 function missingArgTest() {
848 var q;
849 for (var i = 0; i < 10; i++) {
850 q = arity1();
851 }
852 return q;
853 }
854 missingArgTest.expected = 1;
855 test(missingArgTest);
856
857 JSON = function () {
858 return {
859 stringify: function stringify(value, whitelist) {
860 switch (typeof(value)) {
861 case "object":
862 return value.constructor.name;
863 }
864 }
865 };
866 }();
867
868 function missingArgTest2() {
869 var testPairs = [
870 ["{}", {}],
871 ["[]", []],
872 ['{"foo":"bar"}', {"foo":"bar"}],
873 ]
874
875 var a = [];
876 for (var i=0; i < testPairs.length; i++) {
877 var s = JSON.stringify(testPairs[i][1])
878 a[i] = s;
879 }
880 return a.join(",");
881 }
882 missingArgTest2.expected = /(Object,Array,Object|{},\[\],{"foo":"bar"})/;
883 test(missingArgTest2);
884
885 function deepForInLoop() {
886 // NB: the number of props set in C is arefully tuned to match HOTLOOP = 2.
887 function C(){this.p = 1, this.q = 2}
888 C.prototype = {p:1, q:2, r:3, s:4, t:5};
889 var o = new C;
890 var j = 0;
891 var a = [];
892 for (var i in o)
893 a[j++] = i;
894 return a.join("");
895 }
896 deepForInLoop.expected = "pqrst";
897 test(deepForInLoop);
898
899 function nestedExit(x) {
900 var q = 0;
901 for (var i = 0; i < 10; ++i)
902 {
903 if (x)
904 ++q;
905 }
906 }
907 function nestedExitLoop() {
908 for (var j = 0; j < 10; ++j)
909 nestedExit(j < 7);
910 return "ok";
911 }
912 nestedExitLoop.expected = "ok";
913 test(nestedExitLoop);
914
915 function bitsinbyte(b) {
916 var m = 1, c = 0;
917 while(m<0x100) {
918 if(b & m) c++;
919 m <<= 1;
920 }
921 return 1;
922 }
923 function TimeFunc(func) {
924 var x,y;
925 for(var y=0; y<256; y++) func(y);
926 }
927 function nestedExit2() {
928 TimeFunc(bitsinbyte);
929 return "ok";
930 }
931 nestedExit2.expected = "ok";
932 test(nestedExit2);
933
934 function parsingNumbers() {
935 var s1 = "123";
936 var s1z = "123zzz";
937 var s2 = "123.456";
938 var s2z = "123.456zzz";
939
940 var e1 = 123;
941 var e2 = 123.456;
942
943 var r1, r1z, r2, r2z;
944
945 for (var i = 0; i < 10; i++) {
946 r1 = parseInt(s1);
947 r1z = parseInt(s1z);
948 r2 = parseFloat(s2);
949 r2z = parseFloat(s2z);
950 }
951
952 if (r1 == e1 && r1z == e1 && r2 == e2 && r2z == e2)
953 return "ok";
954 return "fail";
955 }
956 parsingNumbers.expected = "ok";
957 test(parsingNumbers);
958
959 function matchInLoop() {
960 var k = "hi";
961 for (var i = 0; i < 10; i++) {
962 var result = k.match(/hi/) != null;
963 }
964 return result;
965 }
966 matchInLoop.expected = true;
967 test(matchInLoop);
968
969 function testMatchAsCondition() {
970 var a = ['0', '0', '0', '0'];
971 var r = /0/;
972 "x".q;
973 for (var z = 0; z < 4; z++)
974 a[z].match(r) ? 1 : 2;
975 }
976 test(testMatchAsCondition);
977
978 function deep1(x) {
979 if (x > 90)
980 return 1;
981 return 2;
982 }
983 function deep2() {
984 for (var i = 0; i < 100; ++i)
985 deep1(i);
986 return "ok";
987 }
988 deep2.expected = "ok";
989 test(deep2);
990
991 function heavyFn1(i) {
992 if (i == 3) {
993 var x = 3;
994 return [0, i].map(function (i) i + x);
995 }
996 return [];
997 }
998 function testHeavy() {
999 for (var i = 0; i <= 3; i++)
1000 heavyFn1(i);
1001 }
1002 test(testHeavy);
1003
1004 function heavyFn2(i) {
1005 if (i < 1000)
1006 return heavyFn1(i);
1007 return function () i;
1008 }
1009 function testHeavy2() {
1010 for (var i = 0; i <= 3; i++)
1011 heavyFn2(i);
1012 }
1013 test(testHeavy2);
1014
1015 var merge_type_maps_x = 0, merge_type_maps_y = 0;
1016 function merge_type_maps() {
1017 for (merge_type_maps_x = 0; merge_type_maps_x < 50; ++merge_type_maps_x)
1018 if ((merge_type_maps_x & 1) == 1)
1019 ++merge_type_maps_y;
1020 return [merge_type_maps_x,merge_type_maps_y].join(",");
1021 }
1022 merge_type_maps.expected = "50,25";
1023 test(merge_type_maps)
1024
1025 function inner_double_outer_int() {
1026 function f(i) {
1027 for (var m = 0; m < 20; ++m)
1028 for (var n = 0; n < 100; n += i)
1029 ;
1030 return n;
1031 }
1032 return f(.5);
1033 }
1034 inner_double_outer_int.expected = 100;
1035 test(inner_double_outer_int);
1036
1037 function newArrayTest()
1038 {
1039 var a = [];
1040 for (var i = 0; i < 10; i++)
1041 a[i] = new Array();
1042 return a.map(function(x) x.length).toString();
1043 }
1044 newArrayTest.expected="0,0,0,0,0,0,0,0,0,0";
1045 test(newArrayTest);
1046
1047 function stringSplitTest()
1048 {
1049 var s = "a,b"
1050 var a = null;
1051 for (var i = 0; i < 10; ++i)
1052 a = s.split(",");
1053 return a.join();
1054 }
1055 stringSplitTest.expected="a,b";
1056 test(stringSplitTest);
1057
1058 function stringSplitIntoArrayTest()
1059 {
1060 var s = "a,b"
1061 var a = [];
1062 for (var i = 0; i < 10; ++i)
1063 a[i] = s.split(",");
1064 return a.join();
1065 }
1066 stringSplitIntoArrayTest.expected="a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b";
1067 test(stringSplitIntoArrayTest);
1068
1069 function forVarInWith() {
1070 function foo() ({notk:42});
1071 function bar() ({p:1, q:2, r:3, s:4, t:5});
1072 var o = foo();
1073 var a = [];
1074 with (o) {
1075 for (var k in bar())
1076 a[a.length] = k;
1077 }
1078 return a.join("");
1079 }
1080 forVarInWith.expected = "pqrst";
1081 test(forVarInWith);
1082
1083 function inObjectTest() {
1084 var o = {p: 1, q: 2, r: 3, s: 4, t: 5};
1085 var r = 0;
1086 for (var i in o) {
1087 if (!(i in o))
1088 break;
1089 if ((i + i) in o)
1090 break;
1091 ++r;
1092 }
1093 return r;
1094 }
1095 inObjectTest.expected = 5;
1096 test(inObjectTest);
1097
1098 function inArrayTest() {
1099 var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
1100 for (var i = 0; i < a.length; i++) {
1101 if (!(i in a))
1102 break;
1103 }
1104 return i;
1105 }
1106 inArrayTest.expected = 10;
1107 test(inArrayTest);
1108
1109 function innerLoopIntOuterDouble() {
1110 var n = 10000, i=0, j=0, count=0, limit=0;
1111 for (i = 1; i <= n; ++i) {
1112 limit = i * 1;
1113 for (j = 0; j < limit; ++j) {
1114 ++count;
1115 }
1116 }
1117 return "" + count;
1118 }
1119 innerLoopIntOuterDouble.expected="50005000";
1120 test(innerLoopIntOuterDouble);
1121
1122 function outerline(){
1123 var i=0;
1124 var j=0;
1125
1126 for (i = 3; i<= 100000; i+=2)
1127 {
1128 for (j = 3; j < 1000; j+=2)
1129 {
1130 if ((i & 1) == 1)
1131 break;
1132 }
1133 }
1134 return "ok";
1135 }
1136 outerline.expected="ok";
1137 test(outerline);
1138
1139 function addAccumulations(f) {
1140 var a = f();
1141 var b = f();
1142 return a() + b();
1143 }
1144
1145 function loopingAccumulator() {
1146 var x = 0;
1147 return function () {
1148 for (var i = 0; i < 10; ++i) {
1149 ++x;
1150 }
1151 return x;
1152 }
1153 }
1154
1155 function testLoopingAccumulator() {
1156 var x = addAccumulations(loopingAccumulator);
1157 return x;
1158 }
1159 testLoopingAccumulator.expected = 20;
1160 test(testLoopingAccumulator);
1161
1162 function testBranchingLoop() {
1163 var x = 0;
1164 for (var i=0; i < 100; ++i) {
1165 if (i == 51) {
1166 x += 10;
1167 }
1168 x++;
1169 }
1170 return x;
1171 }
1172 testBranchingLoop.expected = 110;
1173 test(testBranchingLoop);
1174
1175 function testBranchingUnstableLoop() {
1176 var x = 0;
1177 for (var i=0; i < 100; ++i) {
1178 if (i == 51) {
1179 x += 10.1;
1180 }
1181 x++;
1182 }
1183 return x;
1184 }
1185 testBranchingUnstableLoop.expected = 110.1;
1186 test(testBranchingUnstableLoop);
1187
1188 function testBranchingUnstableLoopCounter() {
1189 var x = 0;
1190 for (var i=0; i < 100; ++i) {
1191 if (i == 51) {
1192 i += 1.1;
1193 }
1194 x++;
1195 }
1196 return x;
1197 }
1198 testBranchingUnstableLoopCounter.expected = 99;
1199 test(testBranchingUnstableLoopCounter);
1200
1201
1202 function testBranchingUnstableObject() {
1203 var x = {s: "a"};
1204 var t = "";
1205 for (var i=0; i < 100; ++i) {
1206 if (i == 51)
1207 {
1208 x.s = 5;
1209 }
1210 t += x.s;
1211 }
1212 return t.length;
1213 }
1214 testBranchingUnstableObject.expected = 100;
1215 test(testBranchingUnstableObject);
1216
1217 function testArrayDensityChange() {
1218 var x = [];
1219 var count = 0;
1220 for (var i=0; i < 100; ++i) {
1221 x[i] = "asdf";
1222 }
1223 for (var i=0; i < x.length; ++i) {
1224 if (i == 51)
1225 {
1226 x[199] = "asdf";
1227 }
1228 if (x[i])
1229 count += x[i].length;
1230 }
1231 return count;
1232 }
1233 testArrayDensityChange.expected = 404;
1234 test(testArrayDensityChange);
1235
1236 function testDoubleToStr() {
1237 var x = 0.0;
1238 var y = 5.5;
1239 for (var i = 0; i < 200; i++) {
1240 x += parseFloat(y.toString());
1241 }
1242 return x;
1243 }
1244 testDoubleToStr.expected = 5.5*200;
1245 test(testDoubleToStr);
1246
1247 function testNumberToString() {
1248 var x = new Number(0);
1249 for (var i = 0; i < 4; i++)
1250 x.toString();
1251 }
1252 test(testNumberToString);
1253
1254 function testDecayingInnerLoop() {
1255 var i, j, k = 10;
1256 for (i = 0; i < 5000; ++i) {
1257 for (j = 0; j < k; ++j);
1258 --k;
1259 }
1260 return i;
1261 }
1262 testDecayingInnerLoop.expected = 5000;
1263 test(testDecayingInnerLoop);
1264
1265 function testContinue() {
1266 var i;
1267 var total = 0;
1268 for (i = 0; i < 20; ++i) {
1269 if (i == 11)
1270 continue;
1271 total++;
1272 }
1273 return total;
1274 }
1275 testContinue.expected = 19;
1276 test(testContinue);
1277
1278 function testContinueWithLabel() {
1279 var i = 0;
1280 var j = 20;
1281 checkiandj :
1282 while (i<10) {
1283 i+=1;
1284 checkj :
1285 while (j>10) {
1286 j-=1;
1287 if ((j%2)==0)
1288 continue checkj;
1289 }
1290 }
1291 return i + j;
1292 }
1293 testContinueWithLabel.expected = 20;
1294 test(testContinueWithLabel);
1295
1296 function testDivision() {
1297 var a = 32768;
1298 var b;
1299 while (b !== 1) {
1300 b = a / 2;
1301 a = b;
1302 }
1303 return a;
1304 }
1305 testDivision.expected = 1;
1306 test(testDivision);
1307
1308 function testDivisionFloat() {
1309 var a = 32768.0;
1310 var b;
1311 while (b !== 1) {
1312 b = a / 2.0;
1313 a = b;
1314 }
1315 return a === 1.0;
1316 }
1317 testDivisionFloat.expected = true;
1318 test(testDivisionFloat);
1319
1320 function testToUpperToLower() {
1321 var s = "Hello", s1, s2;
1322 for (i = 0; i < 100; ++i) {
1323 s1 = s.toLowerCase();
1324 s2 = s.toUpperCase();
1325 }
1326 return s1 + s2;
1327 }
1328 testToUpperToLower.expected = "helloHELLO";
1329 test(testToUpperToLower);
1330
1331 function testReplace2() {
1332 var s = "H e l l o", s1;
1333 for (i = 0; i < 100; ++i)
1334 s1 = s.replace(" ", "");
1335 return s1;
1336 }
1337 testReplace2.expected = "He l l o";
1338 test(testReplace2);
1339
1340 function testBitwise() {
1341 var x = 10000;
1342 var y = 123456;
1343 var z = 987234;
1344 for (var i = 0; i < 50; i++) {
1345 x = x ^ y;
1346 y = y | z;
1347 z = ~x;
1348 }
1349 return x + y + z;
1350 }
1351 testBitwise.expected = -1298;
1352 test(testBitwise);
1353
1354 function testSwitch() {
1355 var x = 0;
1356 var ret = 0;
1357 for (var i = 0; i < 100; ++i) {
1358 switch (x) {
1359 case 0:
1360 ret += 1;
1361 break;
1362 case 1:
1363 ret += 2;
1364 break;
1365 case 2:
1366 ret += 3;
1367 break;
1368 case 3:
1369 ret += 4;
1370 break;
1371 default:
1372 x = 0;
1373 }
1374 x++;
1375 }
1376 return ret;
1377 }
1378 testSwitch.expected = 226;
1379 test(testSwitch);
1380
1381 function testSwitchString() {
1382 var x = "asdf";
1383 var ret = 0;
1384 for (var i = 0; i < 100; ++i) {
1385 switch (x) {
1386 case "asdf":
1387 x = "asd";
1388 ret += 1;
1389 break;
1390 case "asd":
1391 x = "as";
1392 ret += 2;
1393 break;
1394 case "as":
1395 x = "a";
1396 ret += 3;
1397 break;
1398 case "a":
1399 x = "foo";
1400 ret += 4;
1401 break;
1402 default:
1403 x = "asdf";
1404 }
1405 }
1406 return ret;
1407 }
1408 testSwitchString.expected = 200;
1409 test(testSwitchString);
1410
1411 function testNegZero1Helper(z) {
1412 for (let j = 0; j < 5; ++j) { z = -z; }
1413 return Math.atan2(0, -0) == Math.atan2(0, z);
1414 }
1415
1416 var testNegZero1 = function() { return testNegZero1Helper(0); }
1417 testNegZero1.expected = true;
1418 testNegZero1.name = 'testNegZero1';
1419 testNegZero1Helper(1);
1420 test(testNegZero1);
1421
1422 // No test case, just make sure this doesn't assert.
1423 function testNegZero2() {
1424 var z = 0;
1425 for (let j = 0; j < 5; ++j) { ({p: (-z)}); }
1426 }
1427 testNegZero2();
1428
1429 function testConstSwitch() {
1430 var x;
1431 for (var j=0;j<5;++j) { switch(1.1) { case NaN: case 2: } x = 2; }
1432 return x;
1433 }
1434 testConstSwitch.expected = 2;
1435 test(testConstSwitch);
1436
1437 function testConstSwitch2() {
1438 var x;
1439 for (var j = 0; j < 4; ++j) { switch(0/0) { } }
1440 return "ok";
1441 }
1442 testConstSwitch2.expected = "ok";
1443 test(testConstSwitch2);
1444
1445 function testConstIf() {
1446 var x;
1447 for (var j=0;j<5;++j) { if (1.1 || 5) { } x = 2;}
1448 return x;
1449 }
1450 testConstIf.expected = 2;
1451 test(testConstIf);
1452
1453 function testTypeofHole() {
1454 var a = new Array(6);
1455 a[5] = 3;
1456 for (var i = 0; i < 6; ++i)
1457 a[i] = typeof a[i];
1458 return a.join(",");
1459 }
1460 testTypeofHole.expected = "undefined,undefined,undefined,undefined,undefined,number"
1461 test(testTypeofHole);
1462
1463 function testNativeLog() {
1464 var a = new Array(5);
1465 for (var i = 0; i < 5; i++) {
1466 a[i] = Math.log(Math.pow(Math.E, 10));
1467 }
1468 return a.join(",");
1469 }
1470 testNativeLog.expected = "10,10,10,10,10";
1471 test(testNativeLog);
1472
1473 function test_JSOP_ARGSUB() {
1474 function f0() { return arguments[0]; }
1475 function f1() { return arguments[1]; }
1476 function f2() { return arguments[2]; }
1477 function f3() { return arguments[3]; }
1478 function f4() { return arguments[4]; }
1479 function f5() { return arguments[5]; }
1480 function f6() { return arguments[6]; }
1481 function f7() { return arguments[7]; }
1482 function f8() { return arguments[8]; }
1483 function f9() { return arguments[9]; }
1484 var a = [];
1485 for (var i = 0; i < 10; i++) {
1486 a[0] = f0('a');
1487 a[1] = f1('a','b');
1488 a[2] = f2('a','b','c');
1489 a[3] = f3('a','b','c','d');
1490 a[4] = f4('a','b','c','d','e');
1491 a[5] = f5('a','b','c','d','e','f');
1492 a[6] = f6('a','b','c','d','e','f','g');
1493 a[7] = f7('a','b','c','d','e','f','g','h');
1494 a[8] = f8('a','b','c','d','e','f','g','h','i');
1495 a[9] = f9('a','b','c','d','e','f','g','h','i','j');
1496 }
1497 return a.join("");
1498 }
1499 test_JSOP_ARGSUB.expected = "abcdefghij";
1500 test(test_JSOP_ARGSUB);
1501
1502 function test_JSOP_ARGCNT() {
1503 function f0() { return arguments.length; }
1504 function f1() { return arguments.length; }
1505 function f2() { return arguments.length; }
1506 function f3() { return arguments.length; }
1507 function f4() { return arguments.length; }
1508 function f5() { return arguments.length; }
1509 function f6() { return arguments.length; }
1510 function f7() { return arguments.length; }
1511 function f8() { return arguments.length; }
1512 function f9() { return arguments.length; }
1513 var a = [];
1514 for (var i = 0; i < 10; i++) {
1515 a[0] = f0('a');
1516 a[1] = f1('a','b');
1517 a[2] = f2('a','b','c');
1518 a[3] = f3('a','b','c','d');
1519 a[4] = f4('a','b','c','d','e');
1520 a[5] = f5('a','b','c','d','e','f');
1521 a[6] = f6('a','b','c','d','e','f','g');
1522 a[7] = f7('a','b','c','d','e','f','g','h');
1523 a[8] = f8('a','b','c','d','e','f','g','h','i');
1524 a[9] = f9('a','b','c','d','e','f','g','h','i','j');
1525 }
1526 return a.join(",");
1527 }
1528 test_JSOP_ARGCNT.expected = "1,2,3,4,5,6,7,8,9,10";
1529 test(test_JSOP_ARGCNT);
1530
1531 function testNativeMax() {
1532 var out = [], k;
1533 for (var i = 0; i < 5; ++i) {
1534 k = Math.max(k, i);
1535 }
1536 out.push(k);
1537
1538 k = 0;
1539 for (var i = 0; i < 5; ++i) {
1540 k = Math.max(k, i);
1541 }
1542 out.push(k);
1543
1544 for (var i = 0; i < 5; ++i) {
1545 k = Math.max(0, -0);
1546 }
1547 out.push((1 / k) < 0);
1548 return out.join(",");
1549 }
1550 testNativeMax.expected = "NaN,4,false";
1551 test(testNativeMax);
1552
1553 function testFloatArrayIndex() {
1554 var a = [];
1555 for (var i = 0; i < 10; ++i) {
1556 a[3] = 5;
1557 a[3.5] = 7;
1558 }
1559 return a[3] + "," + a[3.5];
1560 }
1561 testFloatArrayIndex.expected = "5,7";
1562 test(testFloatArrayIndex);
1563
1564 function testStrict() {
1565 var n = 10, a = [];
1566 for (var i = 0; i < 10; ++i) {
1567 a[0] = (n === 10);
1568 a[1] = (n !== 10);
1569 a[2] = (n === null);
1570 a[3] = (n == null);
1571 }
1572 return a.join(",");
1573 }
1574 testStrict.expected = "true,false,false,false";
1575 test(testStrict);
1576
1577 function testSetPropNeitherMissNorHit() {
1578 for (var j = 0; j < 5; ++j) { if (({}).__proto__ = 1) { } }
1579 return "ok";
1580 }
1581 testSetPropNeitherMissNorHit.expected = "ok";
1582 test(testSetPropNeitherMissNorHit);
1583
1584 function testPrimitiveConstructorPrototype() {
1585 var f = function(){};
1586 f.prototype = false;
1587 for (let j=0;j<5;++j) { new f; }
1588 return "ok";
1589 }
1590 testPrimitiveConstructorPrototype.expected = "ok";
1591 test(testPrimitiveConstructorPrototype);
1592
1593 function testSideExitInConstructor() {
1594 var FCKConfig = {};
1595 FCKConfig.CoreStyles =
1596 {
1597 'Bold': { },
1598 'Italic': { },
1599 'FontFace': { },
1600 'Size' :
1601 {
1602 Overrides: [ ]
1603 },
1604
1605 'Color' :
1606 {
1607 Element: '',
1608 Styles: { },
1609 Overrides: [ ]
1610 },
1611 'BackColor': {
1612 Element : '',
1613 Styles : { 'background-color' : '' }
1614 },
1615
1616 };
1617 var FCKStyle = function(A) {
1618 A.Element;
1619 };
1620
1621 var pass = true;
1622 for (var s in FCKConfig.CoreStyles) {
1623 var x = new FCKStyle(FCKConfig.CoreStyles[s]);
1624 if (!x)
1625 pass = false;
1626 }
1627 return pass;
1628 }
1629 testSideExitInConstructor.expected = true;
1630 test(testSideExitInConstructor);
1631
1632 function testNot() {
1633 var a = new Object(), b = null, c = "foo", d = "", e = 5, f = 0, g = 5.5, h = -0, i = true, j = false, k = undefined;
1634 var r;
1635 for (var i = 0; i < 10; ++i)
1636 r = [!a, !b, !c, !d, !e, !f, !g, !h, !i, !j, !k];
1637 return r.join(",");
1638 }
1639 testNot.expected = "false,true,false,true,false,true,false,true,false,true,true";
1640 test(testNot);
1641
1642 function doTestDifferingArgc(a, b)
1643 {
1644 var k = 0;
1645 for (var i = 0; i < 10; i++)
1646 {
1647 k += i;
1648 }
1649 return k;
1650 }
1651 function testDifferingArgc()
1652 {
1653 var x = 0;
1654 x += doTestDifferingArgc(1, 2);
1655 x += doTestDifferingArgc(1);
1656 x += doTestDifferingArgc(1, 2, 3);
1657 return x;
1658 }
1659 testDifferingArgc.expected = 45*3;
1660 test(testDifferingArgc);
1661
1662 function doTestMoreArgcThanNargs()
1663 {
1664 var x = 0;
1665 for (var i = 0; i < 10; i++)
1666 {
1667 x = x + arguments[3];
1668 }
1669 return x;
1670 }
1671 function testMoreArgcThanNargs()
1672 {
1673 return doTestMoreArgcThanNargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
1674 }
1675 testMoreArgcThanNargs.expected = 4*10;
1676 test(testMoreArgcThanNargs);
1677
1678 // Test stack reconstruction after a nested exit
1679 function testNestedExitStackInner(j, counter) {
1680 ++counter;
1681 var b = 0;
1682 for (var i = 1; i <= RUNLOOP; i++) {
1683 ++b;
1684 var a;
1685 // Make sure that once everything has been traced we suddenly switch to
1686 // a different control flow the first time we run the outermost tree,
1687 // triggering a side exit.
1688 if (j < RUNLOOP)
1689 a = 1;
1690 else
1691 a = 0;
1692 ++b;
1693 b += a;
1694 }
1695 return counter + b;
1696 }
1697 function testNestedExitStackOuter() {
1698 var counter = 0;
1699 for (var j = 1; j <= RUNLOOP; ++j) {
1700 for (var k = 1; k <= RUNLOOP; ++k) {
1701 counter = testNestedExitStackInner(j, counter);
1702 }
1703 }
1704 return counter;
1705 }
1706 testNestedExitStackOuter.expected = 81;
1707 test(testNestedExitStackOuter);
1708
1709 function testHOTLOOPSize() {
1710 return HOTLOOP > 1;
1711 }
1712 testHOTLOOPSize.expected = true;
1713 test(testHOTLOOPSize);
1714
1715 function testMatchStringObject() {
1716 var a = new String("foo");
1717 var b;
1718 for (i = 0; i < 300; i++)
1719 b = a.match(/bar/);
1720 return b;
1721 }
1722 testMatchStringObject.expected = null;
1723 test(testMatchStringObject);
1724
1725 function innerSwitch(k)
1726 {
1727 var m = 0;
1728
1729 switch (k)
1730 {
1731 case 0:
1732 m = 1;
1733 break;
1734 }
1735
1736 return m;
1737 }
1738 function testInnerSwitchBreak()
1739 {
1740 var r = new Array(5);
1741 for (var i = 0; i < 5; i++)
1742 {
1743 r[i] = innerSwitch(0);
1744 }
1745
1746 return r.join(",");
1747 }
1748 testInnerSwitchBreak.expected = "1,1,1,1,1";
1749 test(testInnerSwitchBreak);
1750
1751 function testArrayNaNIndex()
1752 {
1753 for (var j = 0; j < 4; ++j) { [this[NaN]]; }
1754 for (var j = 0; j < 5; ++j) { if([1][-0]) { } }
1755 return "ok";
1756 }
1757 testArrayNaNIndex.expected = "ok";
1758 test(testArrayNaNIndex);
1759
1760 function innerTestInnerMissingArgs(a,b,c,d)
1761 {
1762 if (a) {
1763 } else {
1764 }
1765 }
1766 function doTestInnerMissingArgs(k)
1767 {
1768 for (i = 0; i < 10; i++) {
1769 innerTestInnerMissingArgs(k);
1770 }
1771 }
1772 function testInnerMissingArgs()
1773 {
1774 doTestInnerMissingArgs(1);
1775 doTestInnerMissingArgs(0);
1776 return 1;
1777 }
1778 testInnerMissingArgs.expected = 1; //Expected: that we don't crash.
1779 test(testInnerMissingArgs);
1780
1781 function regexpLastIndex()
1782 {
1783 var n = 0;
1784 var re = /hi/g;
1785 var ss = " hi hi hi hi hi hi hi hi hi hi";
1786 for (var i = 0; i < 10; i++) {
1787 // re.exec(ss);
1788 n += (re.lastIndex > 0) ? 3 : 0;
1789 re.lastIndex = 0;
1790 }
1791 return n;
1792 }
1793 regexpLastIndex.expected = 0; // 30;
1794 test(regexpLastIndex);
1795
1796 function testHOTLOOPCorrectness() {
1797 var b = 0;
1798 for (var i = 0; i < HOTLOOP; ++i)
1799 ++b;
1800 return b;
1801 }
1802 testHOTLOOPCorrectness.expected = HOTLOOP;
1803 testHOTLOOPCorrectness.jitstats = {
1804 recorderStarted: 1,
1805 recorderAborted: 0,
1806 traceTriggered: 0
1807 };
1808 // Change the global shape right before doing the test
1809 this.testHOTLOOPCorrectnessVar = 1;
1810 test(testHOTLOOPCorrectness);
1811
1812 function testRUNLOOPCorrectness() {
1813 var b = 0;
1814 for (var i = 0; i < RUNLOOP; ++i) {
1815 ++b;
1816 }
1817 return b;
1818 }
1819 testRUNLOOPCorrectness.expected = RUNLOOP;
1820 testRUNLOOPCorrectness.jitstats = {
1821 recorderStarted: 1,
1822 recorderAborted: 0,
1823 traceTriggered: 1
1824 };
1825 // Change the global shape right before doing the test
1826 this.testRUNLOOPCorrectnessVar = 1;
1827 test(testRUNLOOPCorrectness);
1828
1829 function testDateNow() {
1830 // Accessing global.Date for the first time will change the global shape,
1831 // so do it before the loop starts; otherwise we have to loop an extra time
1832 // to pick things up.
1833 var time = Date.now();
1834 for (var j = 0; j < RUNLOOP; ++j)
1835 time = Date.now();
1836 return "ok";
1837 }
1838 testDateNow.expected = "ok";
1839 testDateNow.jitstats = {
1840 recorderStarted: 1,
1841 recorderAborted: 0,
1842 traceTriggered: 1
1843 };
1844 test(testDateNow);
1845
1846 function testINITELEM()
1847 {
1848 var x;
1849 for (var i = 0; i < 10; ++i)
1850 x = { 0: 5, 1: 5 };
1851 return x[0] + x[1];
1852 }
1853 testINITELEM.expected = 10;
1854 test(testINITELEM);
1855
1856 function testUndefinedBooleanCmp()
1857 {
1858 var t = true, f = false, x = [];
1859 for (var i = 0; i < 10; ++i) {
1860 x[0] = t == undefined;
1861 x[1] = t != undefined;
1862 x[2] = t === undefined;
1863 x[3] = t !== undefined;
1864 x[4] = t < undefined;
1865 x[5] = t > undefined;
1866 x[6] = t <= undefined;
1867 x[7] = t >= undefined;
1868 x[8] = f == undefined;
1869 x[9] = f != undefined;
1870 x[10] = f === undefined;
1871 x[11] = f !== undefined;
1872 x[12] = f < undefined;
1873 x[13] = f > undefined;
1874 x[14] = f <= undefined;
1875 x[15] = f >= undefined;
1876 }
1877 return x.join(",");
1878 }
1879 testUndefinedBooleanCmp.expected = "false,true,false,true,false,false,false,false,false,true,false,true,false,false,false,false";
1880 test(testUndefinedBooleanCmp);
1881
1882 function testConstantBooleanExpr()
1883 {
1884 for (var j = 0; j < 3; ++j) { if(true <= true) { } }
1885 return "ok";
1886 }
1887 testConstantBooleanExpr.expected = "ok";
1888 test(testConstantBooleanExpr);
1889
1890 function testNegativeGETELEMIndex()
1891 {
1892 for (let i=0;i<3;++i) /x/[-4];
1893 return "ok";
1894 }
1895 testNegativeGETELEMIndex.expected = "ok";
1896 test(testNegativeGETELEMIndex);
1897
1898 function doTestInvalidCharCodeAt(input)
1899 {
1900 var q = "";
1901 for (var i = 0; i < 10; i++)
1902 q += input.charCodeAt(i);
1903 return q;
1904 }
1905 function testInvalidCharCodeAt()
1906 {
1907 return doTestInvalidCharCodeAt("");
1908 }
1909 testInvalidCharCodeAt.expected = "NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN";
1910 test(testInvalidCharCodeAt);
1911
1912 function FPQuadCmp()
1913 {
1914 for (let j = 0; j < 3; ++j) { true == 0; }
1915 return "ok";
1916 }
1917 FPQuadCmp.expected = "ok";
1918 test(FPQuadCmp);
1919
1920 function testDestructuring() {
1921 var t = 0;
1922 for (var i = 0; i < HOTLOOP + 1; ++i) {
1923 var [r, g, b] = [1, 1, 1];
1924 t += r + g + b;
1925 }
1926 return t
1927 }
1928 testDestructuring.expected = (HOTLOOP + 1) * 3;
1929 test(testDestructuring);
1930
1931 function loopWithUndefined1(t, val) {
1932 var a = new Array(6);
1933 for (var i = 0; i < 6; i++)
1934 a[i] = (t > val);
1935 return a;
1936 }
1937 loopWithUndefined1(5.0, 2); //compile version with val=int
1938
1939 function testLoopWithUndefined1() {
1940 return loopWithUndefined1(5.0).join(","); //val=undefined
1941 };
1942 testLoopWithUndefined1.expected = "false,false,false,false,false,false";
1943 test(testLoopWithUndefined1);
1944
1945 function loopWithUndefined2(t, dostuff, val) {
1946 var a = new Array(6);
1947 for (var i = 0; i < 6; i++) {
1948 if (dostuff) {
1949 val = 1;
1950 a[i] = (t > val);
1951 } else {
1952 a[i] = (val == undefined);
1953 }
1954 }
1955 return a;
1956 }
1957 function testLoopWithUndefined2() {
1958 var a = loopWithUndefined2(5.0, true, 2);
1959 var b = loopWithUndefined2(5.0, true);
1960 var c = loopWithUndefined2(5.0, false, 8);
1961 var d = loopWithUndefined2(5.0, false);
1962 return [a[0], b[0], c[0], d[0]].join(",");
1963 }
1964 testLoopWithUndefined2.expected = "true,true,false,true";
1965 test(testLoopWithUndefined2);
1966
1967 //test no multitrees assert
1968 function testBug462388() {
1969 var c = 0, v; for each (let x in ["",v,v,v]) { for (c=0;c<4;++c) { } }
1970 return true;
1971 }
1972 testBug462388.expected = true;
1973 test(testBug462388);
1974
1975 //test no multitrees assert
1976 function testBug462407() {
1977 for each (let i in [0, {}, 0, 1.5, {}, 0, 1.5, 0, 0]) { }
1978 return true;
1979 }
1980 testBug462407.expected = true;
1981 test(testBug462407);
1982
1983 //test no multitrees assert
1984 function testBug463490() {
1985 function f(a, b, d) {
1986 for (var i = 0; i < 10; i++) {
1987 if (d)
1988 b /= 2;
1989 }
1990 return a + b;
1991 }
1992 //integer stable loop
1993 f(2, 2, false);
1994 //double stable loop
1995 f(3, 4.5, false);
1996 //integer unstable branch
1997 f(2, 2, true);
1998 return true;
1999 };
2000 testBug463490.expected = true;
2001 test(testBug463490);
2002
2003 // Test no assert (bug 464089)
2004 function shortRecursiveLoop(b, c) {
2005 for (var i = 0; i < c; i++) {
2006 if (b)
2007 shortRecursiveLoop(c - 1);
2008 }
2009 }
2010 function testClosingRecursion() {
2011 shortRecursiveLoop(false, 1);
2012 shortRecursiveLoop(true, 3);
2013 return true;
2014 }
2015 testClosingRecursion.expected = true;
2016 test(testClosingRecursion);
2017
2018 // Test no assert or crash from outer recorders (bug 465145)
2019 function testBug465145() {
2020 this.__defineSetter__("x", function(){});
2021 this.watch("x", function(){});
2022 y = this;
2023 for (var z = 0; z < 2; ++z) { x = y };
2024 this.__defineSetter__("x", function(){});
2025 for (var z = 0; z < 2; ++z) { x = y };
2026 }
2027
2028 function testTrueShiftTrue() {
2029 var a = new Array(5);
2030 for (var i=0;i<5;++i) a[i] = "" + (true << true);
2031 return a.join(",");
2032 }
2033 testTrueShiftTrue.expected = "2,2,2,2,2";
2034 test(testTrueShiftTrue);
2035
2036 // Test no assert or crash
2037 function testBug465261() {
2038 for (let z = 0; z < 2; ++z) { for each (let x in [0, true, (void 0), 0, (void
2039 0)]) { if(x){} } };
2040 return true;
2041 }
2042 testBug465261.expected = true;
2043 test(testBug465261);
2044
2045 function testBug465272() {
2046 var a = new Array(5);
2047 for (j=0;j<5;++j) a[j] = "" + ((5) - 2);
2048 return a.join(",");
2049 }
2050 testBug465272.expected = "3,3,3,3,3"
2051 test(testBug465272);
2052
2053 function testBug465483() {
2054 var a = new Array(4);
2055 var c = 0;
2056 for each (i in [4, 'a', 'b', (void 0)]) a[c++] = '' + (i + i);
2057 return a.join(',');
2058 }
2059 testBug465483.expected = '8,aa,bb,NaN';
2060 test(testBug465483);
2061
2062 function testNullCallee() {
2063 try {
2064 function f() {
2065 var x = new Array(5);
2066 for (var i = 0; i < 5; i++)
2067 x[i] = a[i].toString();
2068 return x.join(',');
2069 }
2070 f([[1],[2],[3],[4],[5]]);
2071 f([null, null, null, null, null]);
2072 } catch (e) {
2073 return true;
2074 }
2075 return false;
2076 }
2077 testNullCallee.expected = true;
2078 test(testNullCallee);
2079
2080 //test no multitrees assert
2081 function testBug466128() {
2082 for (let a = 0; a < 3; ++a) {
2083 for each (let b in [1, 2, "three", 4, 5, 6, 7, 8]) {
2084 }
2085 }
2086 return true;
2087 }
2088 testBug466128.expected = true;
2089 test(testBug466128);
2090
2091 //test no assert
2092 function testBug465688() {
2093 for each (let d in [-0x80000000, -0x80000000]) - -d;
2094 return true;
2095 }
2096 testBug465688.expected = true;
2097 test(testBug465688);
2098
2099 //test no assert
2100 function testBug466262() {
2101 var e = 1;
2102 for (var d = 0; d < 3; ++d) {
2103 if (d == 2) {
2104 e = "";
2105 }
2106 }
2107 return true;
2108 }
2109 testBug466262.expected = true;
2110 test(testBug466262);
2111
2112 function testNewDate()
2113 {
2114 // Accessing global.Date for the first time will change the global shape,
2115 // so do it before the loop starts; otherwise we have to loop an extra time
2116 // to pick things up.
2117 var start = new Date();
2118 var time = new Date();
2119 for (var j = 0; j < RUNLOOP; ++j)
2120 time = new Date();
2121 return time > 0 && time >= start;
2122 }
2123 testNewDate.expected = true;
2124 testNewDate.jitstats = {
2125 recorderStarted: 1,
2126 recorderAborted: 0,
2127 traceTriggered: 1
2128 };
2129 test(testNewDate);
2130
2131 function testArrayPushPop() {
2132 var a = [], sum1 = 0, sum2 = 0;
2133 for (var i = 0; i < 10; ++i)
2134 sum1 += a.push(i);
2135 for (var i = 0; i < 10; ++i)
2136 sum2 += a.pop();
2137 a.push(sum1);
2138 a.push(sum2);
2139 return a.join(",");
2140 }
2141 testArrayPushPop.expected = "55,45";
2142 test(testArrayPushPop);
2143
2144 function testSlowArrayPop() {
2145 var a = [];
2146 for (var i = 0; i < RUNLOOP; i++)
2147 a[i] = [0];
2148 a[RUNLOOP-1].__defineGetter__("0", function () { return 'xyzzy'; });
2149
2150 var last;
2151 for (var i = 0; i < RUNLOOP; i++)
2152 last = a[i].pop(); // reenters interpreter in getter
2153 return last;
2154 }
2155 testSlowArrayPop.expected = 'xyzzy';
2156 test(testSlowArrayPop);
2157
2158 // Same thing but it needs to reconstruct multiple stack frames (so,
2159 // multiple functions called inside the loop)
2160 function testSlowArrayPopMultiFrame() {
2161 var a = [];
2162 for (var i = 0; i < RUNLOOP; i++)
2163 a[i] = [0];
2164 a[RUNLOOP-1].__defineGetter__("0", function () { return 23; });
2165
2166 function child(a, i) {
2167 return a[i].pop(); // reenters interpreter in getter
2168 }
2169 function parent(a, i) {
2170 return child(a, i);
2171 }
2172 function gramps(a, i) {
2173 return parent(a, i);
2174 }
2175
2176 var last;
2177 for (var i = 0; i < RUNLOOP; i++)
2178 last = gramps(a, i);
2179 return last;
2180 }
2181 testSlowArrayPopMultiFrame.expected = 23;
2182 test(testSlowArrayPopMultiFrame);
2183
2184 // Same thing but nested trees, each reconstructing one or more stack frames
2185 // (so, several functions with loops, such that the loops end up being
2186 // nested though they are not lexically nested)
2187
2188 function testSlowArrayPopNestedTrees() {
2189 var a = [];
2190 for (var i = 0; i < RUNLOOP; i++)
2191 a[i] = [0];
2192 a[RUNLOOP-1].__defineGetter__("0", function () { return 3.14159 });
2193
2194 function child(a, i, j, k) {
2195 var last = 2.71828;
2196 for (var l = 0; l < RUNLOOP; l++)
2197 if (i == RUNLOOP-1 && j == RUNLOOP-1 && k == RUNLOOP-1)
2198 last = a[l].pop(); // reenters interpreter in getter
2199 return last;
2200 }
2201 function parent(a, i, j) {
2202 var last;
2203 for (var k = 0; k < RUNLOOP; k++)
2204 last = child(a, i, j, k);
2205 return last;
2206 }
2207 function gramps(a, i) {
2208 var last;
2209 for (var j = 0; j < RUNLOOP; j++)
2210 last = parent(a, i, j);
2211 return last;
2212 }
2213
2214 var last;
2215 for (var i = 0; i < RUNLOOP; i++)
2216 last = gramps(a, i);
2217 return last;
2218 }
2219 testSlowArrayPopNestedTrees.expected = 3.14159;
2220 test(testSlowArrayPopNestedTrees);
2221
2222 function testResumeOp() {
2223 var a = [1,"2",3,"4",5,"6",7,"8",9,"10",11,"12",13,"14",15,"16"];
2224 var x = "";
2225 while (a.length > 0)
2226 x += a.pop();
2227 return x;
2228 }
2229 testResumeOp.expected = "16151413121110987654321";
2230 test(testResumeOp);
2231
2232 function testUndefinedCmp() {
2233 var a = false;
2234 for (var j = 0; j < 4; ++j) { if (undefined < false) { a = true; } }
2235 return a;
2236 }
2237 testUndefinedCmp.expected = false;
2238 test(testUndefinedCmp);
2239
2240 function reallyDeepNestedExit(schedule)
2241 {
2242 var c = 0, j = 0;
2243 for (var i = 0; i < 5; i++) {
2244 for (j = 0; j < 4; j++) {
2245 c += (schedule[i*4 + j] == 1) ? 1 : 2;
2246 }
2247 }
2248 return c;
2249 }
2250 function testReallyDeepNestedExit()
2251 {
2252 var c = 0;
2253 var schedule1 = new Array(5*4);
2254 var schedule2 = new Array(5*4);
2255 for (var i = 0; i < 5*4; i++) {
2256 schedule1[i] = 0;
2257 schedule2[i] = 0;
2258 }
2259 /**
2260 * First innermost compile: true branch runs through.
2261 * Second '': false branch compiles new loop edge.
2262 * First outer compile: expect true branch.
2263 * Second '': hit false branch.
2264 */
2265 schedule1[0*4 + 3] = 1;
2266 var schedules = [schedule1,
2267 schedule2,
2268 schedule1,
2269 schedule2,
2270 schedule2];
2271
2272 for (var i = 0; i < 5; i++) {
2273 c += reallyDeepNestedExit(schedules[i]);
2274 }
2275 return c;
2276 }
2277 testReallyDeepNestedExit.expected = 198;
2278 test(testReallyDeepNestedExit);
2279
2280 function testRegExpTest() {
2281 var r = /abc/;
2282 var flag = false;
2283 for (var i = 0; i < 10; ++i)
2284 flag = r.test("abc");
2285 return flag;
2286 }
2287 testRegExpTest.expected = true;
2288 test(testRegExpTest);
2289
2290 function testNumToString() {
2291 var r = [];
2292 var d = 123456789;
2293 for (var i = 0; i < 10; ++i) {
2294 r = [
2295 d.toString(),
2296 (-d).toString(),
2297 d.toString(10),
2298 (-d).toString(10),
2299 d.toString(16),
2300 (-d).toString(16),
2301 d.toString(36),
2302 (-d).toString(36)
2303 ];
2304 }
2305 return r.join(",");
2306 }
2307 testNumToString.expected = "123456789,-123456789,123456789,-123456789,75bcd15,-75bcd15,21i3v9,-21i3v9";
2308 test(testNumToString);
2309
2310 function testLongNumToString() {
2311 var s;
2312 for (var i = 0; i < 5; i++)
2313 s = (0x08000000).toString(2);
2314 return s;
2315 }
2316 testLongNumToString.expected = '1000000000000000000000000000';
2317 test(testLongNumToString);
2318
2319 function testSubstring() {
2320 for (var i = 0; i < 5; ++i) {
2321 actual = "".substring(5);
2322 }
2323 return actual;
2324 }
2325 testSubstring.expected = "";
2326 test(testSubstring);
2327
2328 function testForInLoopChangeIteratorType() {
2329 for(y in [0,1,2]) y = NaN;
2330 (function(){
2331 [].__proto__.u = void 0;
2332 for (let y in [5,6,7,8])
2333 y = NaN;
2334 delete [].__proto__.u;
2335 })()
2336 return "ok";
2337 }
2338 testForInLoopChangeIteratorType.expected = "ok";
2339 test(testForInLoopChangeIteratorType);
2340
2341 function testGrowDenseArray() {
2342 var a = new Array();
2343 for (var i = 0; i < 10; ++i)
2344 a[i] |= 5;
2345 return a.join(",");
2346 }
2347 testGrowDenseArray.expected = "5,5,5,5,5,5,5,5,5,5";
2348 test(testGrowDenseArray);
2349
2350 function testCallProtoMethod() {
2351 function X() { this.x = 1; }
2352 X.prototype.getName = function () { return "X"; }
2353
2354 function Y() { this.x = 2; }
2355 Y.prototype.getName = function() "Y";
2356
2357 var a = [new X, new X, new X, new X, new Y];
2358 var s = '';
2359 for (var i = 0; i < a.length; i++)
2360 s += a[i].getName();
2361 return s;
2362 }
2363 testCallProtoMethod.expected = 'XXXXY';
2364 test(testCallProtoMethod);
2365
2366 function testTypeUnstableForIn() {
2367 var a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
2368 var x = 0;
2369 for (var i in a) {
2370 i = parseInt(i);
2371 x++;
2372 }
2373 return x;
2374 }
2375 testTypeUnstableForIn.expected = 16;
2376 test(testTypeUnstableForIn);
2377
2378 function testAddUndefined() {
2379 for (var j = 0; j < 3; ++j)
2380 (0 + void 0) && 0;
2381 }
2382 test(testAddUndefined);
2383
2384 function testStringify() {
2385 var t = true, f = false, u = undefined, n = 5, d = 5.5, s = "x";
2386 var a = [];
2387 for (var i = 0; i < 10; ++i) {
2388 a[0] = "" + t;
2389 a[1] = t + "";
2390 a[2] = "" + f;
2391 a[3] = f + "";
2392 a[4] = "" + u;
2393 a[5] = u + "";
2394 a[6] = "" + n;
2395 a[7] = n + "";
2396 a[8] = "" + d;
2397 a[9] = d + "";
2398 a[10] = "" + s;
2399 a[11] = s + "";
2400 }
2401 return a.join(",");
2402 }
2403 testStringify.expected = "true,true,false,false,undefined,undefined,5,5,5.5,5.5,x,x";
2404 test(testStringify);
2405
2406 function testObjectToString() {
2407 var o = {toString: function()"foo"};
2408 var s = "";
2409 for (var i = 0; i < 10; i++)
2410 s += o;
2411 return s;
2412 }
2413 testObjectToString.expected = "foofoofoofoofoofoofoofoofoofoo";
2414 test(testObjectToString);
2415
2416 function testObjectToNumber() {
2417 var o = {valueOf: function()-3};
2418 var x = 0;
2419 for (var i = 0; i < 10; i++)
2420 x -= o;
2421 return x;
2422 }
2423 testObjectToNumber.expected = 30;
2424 test(testObjectToNumber);
2425
2426 function my_iterator_next() {
2427 if (this.i == 10) {
2428 this.i = 0;
2429 throw this.StopIteration;
2430 }
2431 return this.i++;
2432 }
2433 function testCustomIterator() {
2434 var o = {
2435 __iterator__: function () {
2436 return {
2437 i: 0,
2438 next: my_iterator_next,
2439 StopIteration: StopIteration
2440 };
2441 }
2442 };
2443 var a=[];
2444 for (var k = 0; k < 100; k += 10) {
2445 for(var j in o) {
2446 a[k + (j >> 0)] = j*k;
2447 }
2448 }
2449 return a.join();
2450 }
2451 testCustomIterator.expected = "0,0,0,0,0,0,0,0,0,0,0,10,20,30,40,50,60,70,80,90,0,20,40,60,80,100,120,140,160,180,0,30,60,90,120,150,180,210,240,270,0,40,80,120,160,200,240,280,320,360,0,50,100,150,200,250,300,350,400,450,0,60,120,180,240,300,360,420,480,540,0,70,140,210,280,350,420,490,560,630,0,80,160,240,320,400,480,560,640,720,0,90,180,270,360,450,540,630,720,810";
2452 test(testCustomIterator);
2453
2454 function bug464403() {
2455 print(8);
2456 var u = [print, print, function(){}]
2457 for each (x in u) for (u.e in [1,1,1,1]);
2458 return "ok";
2459 }
2460 bug464403.expected = "ok";
2461 test(bug464403);
2462
2463 function testBoxDoubleWithDoubleSizedInt()
2464 {
2465 var i = 0;
2466 var a = new Array(3);
2467
2468 while (i < a.length)
2469 a[i++] = 0x5a827999;
2470 return a.join(",");
2471 }
2472 testBoxDoubleWithDoubleSizedInt.expected = "1518500249,1518500249,1518500249";
2473 test(testBoxDoubleWithDoubleSizedInt);
2474
2475 function testObjectOrderedCmp()
2476 {
2477 var a = new Array(5);
2478 for(var i=0;i<5;++i) a[i] = ({} < {});
2479 return a.join(",");
2480 }
2481 testObjectOrderedCmp.expected = "false,false,false,false,false";
2482 test(testObjectOrderedCmp);
2483
2484 function testObjectOrderedCmp2()
2485 {
2486 var a = new Array(5);
2487 for(var i=0;i<5;++i) a[i] = ("" <= null);
2488 return a.join(",");
2489 }
2490 testObjectOrderedCmp2.expected = "true,true,true,true,true";
2491 test(testObjectOrderedCmp2);
2492
2493 function testLogicalNotNaN() {
2494 var i = 0;
2495 var a = new Array(5);
2496 while (i < a.length)
2497 a[i++] = !NaN;
2498 return a.join();
2499 }
2500 testLogicalNotNaN.expected = "true,true,true,true,true";
2501 test(testLogicalNotNaN);
2502
2503 function testStringToInt32() {
2504 var s = "";
2505 for (let j = 0; j < 5; ++j) s += ("1e+81" ^ 3);
2506 return s;
2507 }
2508 testStringToInt32.expected = "33333";
2509 test(testStringToInt32);
2510
2511 function testIn() {
2512 var array = [3];
2513 var obj = { "-1": 5, "1.7": 3, "foo": 5, "1": 7 };
2514 var a = [];
2515 for (let j = 0; j < 5; ++j) {
2516 a.push("0" in array);
2517 a.push(-1 in obj);
2518 a.push(1.7 in obj);
2519 a.push("foo" in obj);
2520 a.push(1 in obj);
2521 a.push("1" in array);
2522 a.push(-2 in obj);
2523 a.push(2.7 in obj);
2524 a.push("bar" in obj);
2525 a.push(2 in obj);
2526 }
2527 return a.join(",");
2528 }
2529 testIn.expected = "true,true,true,true,true,false,false,false,false,false,true,true,true,true,true,false,false,false,false,false,true,true,true,true,true,false,false,false,false,false,true,true,true,true,true,false,false,false,false,false,true,true,true,true,true,false,false,false,false,false";
2530 test(testIn);
2531
2532 function testBranchCse() {
2533 empty = [];
2534 out = [];
2535 for (var j=0;j<10;++j) { empty[42]; out.push((1 * (1)) | ""); }
2536 return out.join(",");
2537 }
2538 testBranchCse.expected = "1,1,1,1,1,1,1,1,1,1";
2539 test(testBranchCse);
2540
2541 function testMulOverflow() {
2542 var a = [];
2543 for (let j=0;j<5;++j) a.push(0 | ((0x60000009) * 0x60000009));
2544 return a.join(",");
2545 }
2546 testMulOverflow.expected = "-1073741824,-1073741824,-1073741824,-1073741824,-1073741824";
2547 test(testMulOverflow);
2548
2549 function testThinLoopDemote() {
2550 function f()
2551 {
2552 var k = 1;
2553 for (var n = 0; n < 4; n++) {
2554 k = (k * 10);
2555 }
2556 return k;
2557 }
2558 f();
2559 return f();
2560 }
2561 testThinLoopDemote.expected = 10000;
2562 testThinLoopDemote.jitstats = {
2563 recorderStarted: 2,
2564 recorderAborted: 0,
2565 traceCompleted: 2,
2566 traceTriggered: 2,
2567 unstableLoopVariable: 1
2568 };
2569 test(testThinLoopDemote);
2570
2571 var global = this;
2572 function testWeirdDateParseOuter()
2573 {
2574 var vDateParts = ["11", "17", "2008"];
2575 var out = [];
2576 for (var vI = 0; vI < vDateParts.length; vI++)
2577 out.push(testWeirdDateParseInner(vDateParts[vI]));
2578 /* Mutate the global shape so we fall off trace; this causes
2579 * additional oddity */
2580 global.x = Math.random();
2581 return out;
2582 }
2583 function testWeirdDateParseInner(pVal)
2584 {
2585 var vR = 0;
2586 for (var vI = 0; vI < pVal.length; vI++) {
2587 var vC = pVal.charAt(vI);
2588 if ((vC >= '0') && (vC <= '9'))
2589 vR = (vR * 10) + parseInt(vC);
2590 }
2591 return vR;
2592 }
2593 function testWeirdDateParse() {
2594 var result = [];
2595 result.push(testWeirdDateParseInner("11"));
2596 result.push(testWeirdDateParseInner("17"));
2597 result.push(testWeirdDateParseInner("2008"));
2598 result.push(testWeirdDateParseInner("11"));
2599 result.push(testWeirdDateParseInner("17"));
2600 result.push(testWeirdDateParseInner("2008"));
2601 result = result.concat(testWeirdDateParseOuter());
2602 result = result.concat(testWeirdDateParseOuter());
2603 result.push(testWeirdDateParseInner("11"));
2604 result.push(testWeirdDateParseInner("17"));
2605 result.push(testWeirdDateParseInner("2008"));
2606 return result.join(",");
2607 }
2608 testWeirdDateParse.expected = "11,17,2008,11,17,2008,11,17,2008,11,17,2008,11,17,2008";
2609 testWeirdDateParse.jitstats = {
2610 recorderStarted: 8,
2611 recorderAborted: 1,
2612 traceCompleted: 7,
2613 traceTriggered: 14,
2614 unstableLoopVariable: 3,
2615 noCompatInnerTrees: 1
2616 };
2617 test(testWeirdDateParse);
2618
2619 function testUndemotableBinaryOp() {
2620 var out = [];
2621 for (let j = 0; j < 5; ++j) { out.push(6 - ((void 0) ^ 0x80000005)); }
2622 return out.join(",");
2623 }
2624 testUndemotableBinaryOp.expected = "2147483649,2147483649,2147483649,2147483649,2147483649";
2625 test(testUndemotableBinaryOp);
2626
2627 function testNullRelCmp() {
2628 var out = [];
2629 for(j=0;j<3;++j) { out.push(3 > null); out.push(3 < null); out.push(0 == null); out.push(3 == null); }
2630 return out.join(",");
2631 }
2632 testNullRelCmp.expected = "true,false,false,false,true,false,false,false,true,false,false,false";
2633 test(testNullRelCmp);
2634
2635 function testEqFalseEmptyString() {
2636 var x = [];
2637 for (var i=0;i<5;++i) x.push(false == "");
2638 return x.join(",");
2639 }
2640 testEqFalseEmptyString.expected = "true,true,true,true,true";
2641 test(testEqFalseEmptyString);
2642
2643 function testIncDec2(ii) {
2644 var x = [];
2645 for (let j=0;j<5;++j) {
2646 ii=j;
2647 jj=j;
2648 var kk=j;
2649 x.push(ii--);
2650 x.push(jj--);
2651 x.push(kk--);
2652 x.push(++ii);
2653 x.push(++jj);
2654 x.push(++kk);
2655 }
2656 return x.join(",");
2657 }
2658 function testIncDec() {
2659 return testIncDec2(0);
2660 }
2661 testIncDec.expected = "0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4";
2662 test(testIncDec);
2663
2664 function testApply() {
2665 var q = [];
2666 for (var i = 0; i < 10; ++i)
2667 Array.prototype.push.apply(q, [5]);
2668 return q.join(",");
2669 }
2670 testApply.expected = "5,5,5,5,5,5,5,5,5,5";
2671 test(testApply);
2672
2673 function testNestedForIn() {
2674 var a = {x: 1, y: 2, z: 3};
2675 var s = '';
2676 for (var p1 in a)
2677 for (var p2 in a)
2678 s += p1 + p2 + ' ';
2679 return s;
2680 }
2681 testNestedForIn.expected = 'xx xy xz yx yy yz zx zy zz ';
2682 test(testNestedForIn);
2683
2684 function testForEach() {
2685 var r;
2686 var a = ["zero", "one", "two", "three"];
2687 for (var i = 0; i < RUNLOOP; i++) {
2688 r = "";
2689 for each (var s in a)
2690 r += s + " ";
2691 }
2692 return r;
2693 }
2694 testForEach.expected = "zero one two three ";
2695 test(testForEach);
2696
2697 function testThinForEach() {
2698 var a = ["red"];
2699 var n = 0;
2700 for (var i = 0; i < 10; i++)
2701 for each (var v in a)
2702 if (v)
2703 n++;
2704 return n;
2705 }
2706 testThinForEach.expected = 10;
2707 test(testThinForEach);
2708
2709 function testComparisons()
2710 {
2711 // All the special values from each of the types in
2712 // ECMA-262, 3rd ed. section 8
2713 var undefinedType, nullType, booleanType, stringType, numberType, objectType;
2714
2715 var types = [];
2716 types[undefinedType = 0] = "Undefined";
2717 types[nullType = 1] = "Null";
2718 types[booleanType = 2] = "Boolean";
2719 types[stringType = 3] = "String";
2720 types[numberType = 4] = "Number";
2721 types[objectType = 5] = "Object";
2722
2723 var JSVAL_INT_MIN = -Math.pow(2, 30);
2724 var JSVAL_INT_MAX = Math.pow(2, 30) - 1;
2725
2726 // Values from every ES3 type, hitting all the edge-case and special values
2727 // that can be dreamed up
2728 var values =
2729 {
2730 "undefined":
2731 {
2732 value: function() { return undefined; },
2733 type: undefinedType
2734 },
2735 "null":
2736 {
2737 value: function() { return null; },
2738 type: nullType
2739 },
2740 "true":
2741 {
2742 value: function() { return true; },
2743 type: booleanType
2744 },
2745 "false":
2746 {
2747 value: function() { return false; },
2748 type: booleanType
2749 },
2750 '""':
2751 {
2752 value: function() { return ""; },
2753 type: stringType
2754 },
2755 '"a"':
2756 {
2757 // a > [, for string-object comparisons
2758 value: function() { return "a"; },
2759 type: stringType
2760 },
2761 '"Z"':
2762 {
2763 // Z < [, for string-object comparisons
2764 value: function() { return "Z"; },
2765 type: stringType
2766 },
2767 "0":
2768 {
2769 value: function() { return 0; },
2770 type: numberType
2771 },
2772 "-0":
2773 {
2774 value: function() { return -0; },
2775 type: numberType
2776 },
2777 "1":
2778 {
2779 value: function() { return 1; },
2780 type: numberType
2781 },
2782 "Math.E":
2783 {
2784 value: function() { return Math.E; },
2785 type: numberType
2786 },
2787 "JSVAL_INT_MIN - 1":
2788 {
2789 value: function() { return JSVAL_INT_MIN - 1; },
2790 type: numberType
2791 },
2792 "JSVAL_INT_MIN":
2793 {
2794 value: function() { return JSVAL_INT_MIN; },
2795 type: numberType
2796 },
2797 "JSVAL_INT_MIN + 1":
2798 {
2799 value: function() { return JSVAL_INT_MIN + 1; },
2800 type: numberType
2801 },
2802 "JSVAL_INT_MAX - 1":
2803 {
2804 value: function() { return JSVAL_INT_MAX - 1; },
2805 type: numberType
2806 },
2807 "JSVAL_INT_MAX":
2808 {
2809 value: function() { return JSVAL_INT_MAX; },
2810 type: numberType
2811 },
2812 "JSVAL_INT_MAX + 1":
2813 {
2814 value: function() { return JSVAL_INT_MAX + 1; },
2815 type: numberType
2816 },
2817 "Infinity":
2818 {
2819 value: function() { return Infinity; },
2820 type: numberType
2821 },
2822 "-Infinity":
2823 {
2824 value: function() { return -Infinity; },
2825 type: numberType
2826 },
2827 "NaN":
2828 {
2829 value: function() { return NaN; },
2830 type: numberType
2831 },
2832 "{}":
2833 {
2834 value: function() { return {}; },
2835 type: objectType
2836 },
2837 "{ valueOf: undefined }":
2838 {
2839 value: function() { return { valueOf: undefined }; },
2840 type: objectType
2841 },
2842 "[]":
2843 {
2844 value: function() { return []; },
2845 type: objectType
2846 },
2847 '[""]':
2848 {
2849 value: function() { return [""]; },
2850 type: objectType
2851 },
2852 '["a"]':
2853 {
2854 value: function() { return ["a"]; },
2855 type: objectType
2856 },
2857 "[0]":
2858 {
2859 value: function() { return [0]; },
2860 type: objectType
2861 }
2862 };
2863
2864 var orderOps =
2865 {
2866 "<": function(a, b) { return a < b; },
2867 ">": function(a, b) { return a > b; },
2868 "<=": function(a, b) { return a <= b; },
2869 ">=": function(a, b) { return a >= b; }
2870 };
2871 var eqOps =
2872 {
2873 "==": function(a, b) { return a == b; },
2874 "!=": function(a, b) { return a != b; },
2875 "===": function(a, b) { return a === b; },
2876 "!==": function(a, b) { return a !== b; }
2877 };
2878
2879
2880 var notEqualIncomparable =
2881 {
2882 eq: { "==": false, "!=": true, "===": false, "!==": true },
2883 order: { "<": false, ">": false, "<=": false, ">=": false }
2884 };
2885 var notEqualLessThan =
2886 {
2887 eq: { "==": false, "!=": true, "===": false, "!==": true },
2888 order: { "<": true, ">": false, "<=": true, ">=": false }
2889 };
2890 var notEqualGreaterThan =
2891 {
2892 eq: { "==": false, "!=": true, "===": false, "!==": true },
2893 order: { "<": false, ">": true, "<=": false, ">=": true }
2894 };
2895 var notEqualNorDifferent =
2896 {
2897 eq: { "==": false, "!=": true, "===": false, "!==": true },
2898 order: { "<": false, ">": false, "<=": true, ">=": true }
2899 };
2900 var strictlyEqual =
2901 {
2902 eq: { "==": true, "!=": false, "===": true, "!==": false },
2903 order: { "<": false, ">": false, "<=": true, ">=": true }
2904 };
2905 var looselyEqual =
2906 {
2907 eq: { "==": true, "!=": false, "===": false, "!==": true },
2908 order: { "<": false, ">": false, "<=": true, ">=": true }
2909 };
2910 var looselyEqualNotDifferent =
2911 {
2912 eq: { "==": true, "!=": false, "===": false, "!==": true },
2913 order: { "<": false, ">": false, "<=": true, ">=": true }
2914 };
2915 var looselyEqualIncomparable =
2916 {
2917 eq: { "==": true, "!=": false, "===": false, "!==": true },
2918 order: { "<": false, ">": false, "<=": false, ">=": false }
2919 };
2920 var strictlyEqualNotDifferent =
2921 {
2922 eq: { "==": true, "!=": false, "===": true, "!==": false },
2923 order: { "<": false, ">": false, "<=": true, ">=": true }
2924 };
2925 var strictlyEqualIncomparable =
2926 {
2927 eq: { "==": true, "!=": false, "===": true, "!==": false },
2928 order: { "<": false, ">": false, "<=": false, ">=": false }
2929 };
2930
2931 var comparingZeroToSomething =
2932 {
2933 "undefined": notEqualIncomparable,
2934 "null": notEqualNorDifferent,
2935 "true": notEqualLessThan,
2936 "false": looselyEqual,
2937 '""': looselyEqualNotDifferent,
2938 '"a"': notEqualIncomparable,
2939 '"Z"': notEqualIncomparable,
2940 "0": strictlyEqual,
2941 "-0": strictlyEqual,
2942 "1": notEqualLessThan,
2943 "Math.E": notEqualLessThan,
2944 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
2945 "JSVAL_INT_MIN": notEqualGreaterThan,
2946 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
2947 "JSVAL_INT_MAX - 1": notEqualLessThan,
2948 "JSVAL_INT_MAX": notEqualLessThan,
2949 "JSVAL_INT_MAX + 1": notEqualLessThan,
2950 "Infinity": notEqualLessThan,
2951 "-Infinity": notEqualGreaterThan,
2952 "NaN": notEqualIncomparable,
2953 "{}": notEqualIncomparable,
2954 "{ valueOf: undefined }": notEqualIncomparable,
2955 "[]": looselyEqual,
2956 '[""]': looselyEqual,
2957 '["a"]': notEqualIncomparable,
2958 "[0]": looselyEqual
2959 };
2960
2961 var comparingObjectOrObjectWithValueUndefined =
2962 {
2963 "undefined": notEqualIncomparable,
2964 "null": notEqualIncomparable,
2965 "true": notEqualIncomparable,
2966 "false": notEqualIncomparable,
2967 '""': notEqualGreaterThan,
2968 '"a"': notEqualLessThan,
2969 '"Z"': notEqualGreaterThan,
2970 "0": notEqualIncomparable,
2971 "-0": notEqualIncomparable,
2972 "1": notEqualIncomparable,
2973 "Math.E": notEqualIncomparable,
2974 "JSVAL_INT_MIN - 1": notEqualIncomparable,
2975 "JSVAL_INT_MIN": notEqualIncomparable,
2976 "JSVAL_INT_MIN + 1": notEqualIncomparable,
2977 "JSVAL_INT_MAX - 1": notEqualIncomparable,
2978 "JSVAL_INT_MAX": notEqualIncomparable,
2979 "JSVAL_INT_MAX + 1": notEqualIncomparable,
2980 "Infinity": notEqualIncomparable,
2981 "-Infinity": notEqualIncomparable,
2982 "NaN": notEqualIncomparable,
2983 "{}": notEqualNorDifferent,
2984 "{ valueOf: undefined }": notEqualNorDifferent,
2985 "[]": notEqualGreaterThan,
2986 '[""]': notEqualGreaterThan,
2987 '["a"]': notEqualLessThan,
2988 "[0]": notEqualGreaterThan
2989 };
2990
2991 // Constructed expected-value matrix
2992 var expected =
2993 {
2994 "undefined":
2995 {
2996 "undefined": strictlyEqualIncomparable,
2997 "null": looselyEqualIncomparable,
2998 "true": notEqualIncomparable,
2999 "false": notEqualIncomparable,
3000 '""': notEqualIncomparable,
3001 '"a"': notEqualIncomparable,
3002 '"Z"': notEqualIncomparable,
3003 "0": notEqualIncomparable,
3004 "-0": notEqualIncomparable,
3005 "1": notEqualIncomparable,
3006 "Math.E": notEqualIncomparable,
3007 "JSVAL_INT_MIN - 1": notEqualIncomparable,
3008 "JSVAL_INT_MIN": notEqualIncomparable,
3009 "JSVAL_INT_MIN + 1": notEqualIncomparable,
3010 "JSVAL_INT_MAX - 1": notEqualIncomparable,
3011 "JSVAL_INT_MAX": notEqualIncomparable,
3012 "JSVAL_INT_MAX + 1": notEqualIncomparable,
3013 "Infinity": notEqualIncomparable,
3014 "-Infinity": notEqualIncomparable,
3015 "NaN": notEqualIncomparable,
3016 "{}": notEqualIncomparable,
3017 "{ valueOf: undefined }": notEqualIncomparable,
3018 "[]": notEqualIncomparable,
3019 '[""]': notEqualIncomparable,
3020 '["a"]': notEqualIncomparable,
3021 "[0]": notEqualIncomparable
3022 },
3023 "null":
3024 {
3025 "undefined": looselyEqualIncomparable,
3026 "null": strictlyEqualNotDifferent,
3027 "true": notEqualLessThan,
3028 "false": notEqualNorDifferent,
3029 '""': notEqualNorDifferent,
3030 '"a"': notEqualIncomparable,
3031 '"Z"': notEqualIncomparable,
3032 "0": notEqualNorDifferent,
3033 "-0": notEqualNorDifferent,
3034 "1": notEqualLessThan,
3035 "Math.E": notEqualLessThan,
3036 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3037 "JSVAL_INT_MIN": notEqualGreaterThan,
3038 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3039 "JSVAL_INT_MAX - 1": notEqualLessThan,
3040 "JSVAL_INT_MAX": notEqualLessThan,
3041 "JSVAL_INT_MAX + 1": notEqualLessThan,
3042 "Infinity": notEqualLessThan,
3043 "-Infinity": notEqualGreaterThan,
3044 "NaN": notEqualIncomparable,
3045 "{}": notEqualIncomparable,
3046 "{ valueOf: undefined }": notEqualIncomparable,
3047 "[]": notEqualNorDifferent,
3048 '[""]': notEqualNorDifferent,
3049 '["a"]': notEqualIncomparable,
3050 "[0]": notEqualNorDifferent
3051 },
3052 "true":
3053 {
3054 "undefined": notEqualIncomparable,
3055 "null": notEqualGreaterThan,
3056 "true": strictlyEqual,
3057 "false": notEqualGreaterThan,
3058 '""': notEqualGreaterThan,
3059 '"a"': notEqualIncomparable,
3060 '"Z"': notEqualIncomparable,
3061 "0": notEqualGreaterThan,
3062 "-0": notEqualGreaterThan,
3063 "1": looselyEqual,
3064 "Math.E": notEqualLessThan,
3065 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3066 "JSVAL_INT_MIN": notEqualGreaterThan,
3067 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3068 "JSVAL_INT_MAX - 1": notEqualLessThan,
3069 "JSVAL_INT_MAX": notEqualLessThan,
3070 "JSVAL_INT_MAX + 1": notEqualLessThan,
3071 "Infinity": notEqualLessThan,
3072 "-Infinity": notEqualGreaterThan,
3073 "NaN": notEqualIncomparable,
3074 "{}": notEqualIncomparable,
3075 "{ valueOf: undefined }": notEqualIncomparable,
3076 "[]": notEqualGreaterThan,
3077 '[""]': notEqualGreaterThan,
3078 '["a"]': notEqualIncomparable,
3079 "[0]": notEqualGreaterThan
3080 },
3081 "false":
3082 {
3083 "undefined": notEqualIncomparable,
3084 "null": notEqualNorDifferent,
3085 "true": notEqualLessThan,
3086 "false": strictlyEqual,
3087 '""': looselyEqualNotDifferent,
3088 '"a"': notEqualIncomparable,
3089 '"Z"': notEqualIncomparable,
3090 "0": looselyEqual,
3091 "-0": looselyEqual,
3092 "1": notEqualLessThan,
3093 "Math.E": notEqualLessThan,
3094 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3095 "JSVAL_INT_MIN": notEqualGreaterThan,
3096 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3097 "JSVAL_INT_MAX - 1": notEqualLessThan,
3098 "JSVAL_INT_MAX": notEqualLessThan,
3099 "JSVAL_INT_MAX + 1": notEqualLessThan,
3100 "Infinity": notEqualLessThan,
3101 "-Infinity": notEqualGreaterThan,
3102 "NaN": notEqualIncomparable,
3103 "{}": notEqualIncomparable,
3104 "{ valueOf: undefined }": notEqualIncomparable,
3105 "[]": looselyEqual,
3106 '[""]': looselyEqual,
3107 '["a"]': notEqualIncomparable,
3108 "[0]": looselyEqual
3109 },
3110 '""':
3111 {
3112 "undefined": notEqualIncomparable,
3113 "null": notEqualNorDifferent,
3114 "true": notEqualLessThan,
3115 "false": looselyEqual,
3116 '""': strictlyEqual,
3117 '"a"': notEqualLessThan,
3118 '"Z"': notEqualLessThan,
3119 "0": looselyEqual,
3120 "-0": looselyEqual,
3121 "1": notEqualLessThan,
3122 "Math.E": notEqualLessThan,
3123 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3124 "JSVAL_INT_MIN": notEqualGreaterThan,
3125 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3126 "JSVAL_INT_MAX - 1": notEqualLessThan,
3127 "JSVAL_INT_MAX": notEqualLessThan,
3128 "JSVAL_INT_MAX + 1": notEqualLessThan,
3129 "Infinity": notEqualLessThan,
3130 "-Infinity": notEqualGreaterThan,
3131 "NaN": notEqualIncomparable,
3132 "{}": notEqualLessThan,
3133 "{ valueOf: undefined }": notEqualLessThan,
3134 "[]": looselyEqual,
3135 '[""]': looselyEqual,
3136 '["a"]': notEqualLessThan,
3137 "[0]": notEqualLessThan
3138 },
3139 '"a"':
3140 {
3141 "undefined": notEqualIncomparable,
3142 "null": notEqualIncomparable,
3143 "true": notEqualIncomparable,
3144 "false": notEqualIncomparable,
3145 '""': notEqualGreaterThan,
3146 '"a"': strictlyEqual,
3147 '"Z"': notEqualGreaterThan,
3148 "0": notEqualIncomparable,
3149 "-0": notEqualIncomparable,
3150 "1": notEqualIncomparable,
3151 "Math.E": notEqualIncomparable,
3152 "JSVAL_INT_MIN - 1": notEqualIncomparable,
3153 "JSVAL_INT_MIN": notEqualIncomparable,
3154 "JSVAL_INT_MIN + 1": notEqualIncomparable,
3155 "JSVAL_INT_MAX - 1": notEqualIncomparable,
3156 "JSVAL_INT_MAX": notEqualIncomparable,
3157 "JSVAL_INT_MAX + 1": notEqualIncomparable,
3158 "Infinity": notEqualIncomparable,
3159 "-Infinity": notEqualIncomparable,
3160 "NaN": notEqualIncomparable,
3161 "{}": notEqualGreaterThan,
3162 "{ valueOf: undefined }": notEqualGreaterThan,
3163 "[]": notEqualGreaterThan,
3164 '[""]': notEqualGreaterThan,
3165 '["a"]': looselyEqualNotDifferent,
3166 "[0]": notEqualGreaterThan
3167 },
3168 '"Z"':
3169 {
3170 "undefined": notEqualIncomparable,
3171 "null": notEqualIncomparable,
3172 "true": notEqualIncomparable,
3173 "false": notEqualIncomparable,
3174 '""': notEqualGreaterThan,
3175 '"a"': notEqualLessThan,
3176 '"Z"': strictlyEqual,
3177 "0": notEqualIncomparable,
3178 "-0": notEqualIncomparable,
3179 "1": notEqualIncomparable,
3180 "Math.E": notEqualIncomparable,
3181 "JSVAL_INT_MIN - 1": notEqualIncomparable,
3182 "JSVAL_INT_MIN": notEqualIncomparable,
3183 "JSVAL_INT_MIN + 1": notEqualIncomparable,
3184 "JSVAL_INT_MAX - 1": notEqualIncomparable,
3185 "JSVAL_INT_MAX": notEqualIncomparable,
3186 "JSVAL_INT_MAX + 1": notEqualIncomparable,
3187 "Infinity": notEqualIncomparable,
3188 "-Infinity": notEqualIncomparable,
3189 "NaN": notEqualIncomparable,
3190 "{}": notEqualLessThan,
3191 "{ valueOf: undefined }": notEqualLessThan,
3192 "[]": notEqualGreaterThan,
3193 '[""]': notEqualGreaterThan,
3194 '["a"]': notEqualLessThan,
3195 "[0]": notEqualGreaterThan
3196 },
3197 "0": comparingZeroToSomething,
3198 "-0": comparingZeroToSomething,
3199 "1":
3200 {
3201 "undefined": notEqualIncomparable,
3202 "null": notEqualGreaterThan,
3203 "true": looselyEqual,
3204 "false": notEqualGreaterThan,
3205 '""': notEqualGreaterThan,
3206 '"a"': notEqualIncomparable,
3207 '"Z"': notEqualIncomparable,
3208 "0": notEqualGreaterThan,
3209 "-0": notEqualGreaterThan,
3210 "1": strictlyEqual,
3211 "Math.E": notEqualLessThan,
3212 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3213 "JSVAL_INT_MIN": notEqualGreaterThan,
3214 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3215 "JSVAL_INT_MAX - 1": notEqualLessThan,
3216 "JSVAL_INT_MAX": notEqualLessThan,
3217 "JSVAL_INT_MAX + 1": notEqualLessThan,
3218 "Infinity": notEqualLessThan,
3219 "-Infinity": notEqualGreaterThan,
3220 "NaN": notEqualIncomparable,
3221 "{}": notEqualIncomparable,
3222 "{ valueOf: undefined }": notEqualIncomparable,
3223 "[]": notEqualGreaterThan,
3224 '[""]': notEqualGreaterThan,
3225 '["a"]': notEqualIncomparable,
3226 "[0]": notEqualGreaterThan
3227 },
3228 "Math.E":
3229 {
3230 "undefined": notEqualIncomparable,
3231 "null": notEqualGreaterThan,
3232 "true": notEqualGreaterThan,
3233 "false": notEqualGreaterThan,
3234 '""': notEqualGreaterThan,
3235 '"a"': notEqualIncomparable,
3236 '"Z"': notEqualIncomparable,
3237 "0": notEqualGreaterThan,
3238 "-0": notEqualGreaterThan,
3239 "1": notEqualGreaterThan,
3240 "Math.E": strictlyEqual,
3241 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3242 "JSVAL_INT_MIN": notEqualGreaterThan,
3243 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3244 "JSVAL_INT_MAX - 1": notEqualLessThan,
3245 "JSVAL_INT_MAX": notEqualLessThan,
3246 "JSVAL_INT_MAX + 1": notEqualLessThan,
3247 "Infinity": notEqualLessThan,
3248 "-Infinity": notEqualGreaterThan,
3249 "NaN": notEqualIncomparable,
3250 "{}": notEqualIncomparable,
3251 "{ valueOf: undefined }": notEqualIncomparable,
3252 "[]": notEqualGreaterThan,
3253 '[""]': notEqualGreaterThan,
3254 '["a"]': notEqualIncomparable,
3255 "[0]": notEqualGreaterThan
3256 },
3257 "JSVAL_INT_MIN - 1":
3258 {
3259 "undefined": notEqualIncomparable,
3260 "null": notEqualLessThan,
3261 "true": notEqualLessThan,
3262 "false": notEqualLessThan,
3263 '""': notEqualLessThan,
3264 '"a"': notEqualIncomparable,
3265 '"Z"': notEqualIncomparable,
3266 "0": notEqualLessThan,
3267 "-0": notEqualLessThan,
3268 "1": notEqualLessThan,
3269 "Math.E": notEqualLessThan,
3270 "JSVAL_INT_MIN - 1": strictlyEqual,
3271 "JSVAL_INT_MIN": notEqualLessThan,
3272 "JSVAL_INT_MIN + 1": notEqualLessThan,
3273 "JSVAL_INT_MAX - 1": notEqualLessThan,
3274 "JSVAL_INT_MAX": notEqualLessThan,
3275 "JSVAL_INT_MAX + 1": notEqualLessThan,
3276 "Infinity": notEqualLessThan,
3277 "-Infinity": notEqualGreaterThan,
3278 "NaN": notEqualIncomparable,
3279 "{}": notEqualIncomparable,
3280 "{ valueOf: undefined }": notEqualIncomparable,
3281 "[]": notEqualLessThan,
3282 '[""]': notEqualLessThan,
3283 '["a"]': notEqualIncomparable,
3284 "[0]": notEqualLessThan
3285 },
3286 "JSVAL_INT_MIN":
3287 {
3288 "undefined": notEqualIncomparable,
3289 "null": notEqualLessThan,
3290 "true": notEqualLessThan,
3291 "false": notEqualLessThan,
3292 '""': notEqualLessThan,
3293 '"a"': notEqualIncomparable,
3294 '"Z"': notEqualIncomparable,
3295 "0": notEqualLessThan,
3296 "-0": notEqualLessThan,
3297 "1": notEqualLessThan,
3298 "Math.E": notEqualLessThan,
3299 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3300 "JSVAL_INT_MIN": strictlyEqual,
3301 "JSVAL_INT_MIN + 1": notEqualLessThan,
3302 "JSVAL_INT_MAX - 1": notEqualLessThan,
3303 "JSVAL_INT_MAX": notEqualLessThan,
3304 "JSVAL_INT_MAX + 1": notEqualLessThan,
3305 "Infinity": notEqualLessThan,
3306 "-Infinity": notEqualGreaterThan,
3307 "NaN": notEqualIncomparable,
3308 "{}": notEqualIncomparable,
3309 "{ valueOf: undefined }": notEqualIncomparable,
3310 "[]": notEqualLessThan,
3311 '[""]': notEqualLessThan,
3312 '["a"]': notEqualIncomparable,
3313 "[0]": notEqualLessThan
3314 },
3315 "JSVAL_INT_MIN + 1":
3316 {
3317 "undefined": notEqualIncomparable,
3318 "null": notEqualLessThan,
3319 "true": notEqualLessThan,
3320 "false": notEqualLessThan,
3321 '""': notEqualLessThan,
3322 '"a"': notEqualIncomparable,
3323 '"Z"': notEqualIncomparable,
3324 "0": notEqualLessThan,
3325 "-0": notEqualLessThan,
3326 "1": notEqualLessThan,
3327 "Math.E": notEqualLessThan,
3328 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3329 "JSVAL_INT_MIN": notEqualGreaterThan,
3330 "JSVAL_INT_MIN + 1": strictlyEqual,
3331 "JSVAL_INT_MAX - 1": notEqualLessThan,
3332 "JSVAL_INT_MAX": notEqualLessThan,
3333 "JSVAL_INT_MAX + 1": notEqualLessThan,
3334 "Infinity": notEqualLessThan,
3335 "-Infinity": notEqualGreaterThan,
3336 "NaN": notEqualIncomparable,
3337 "{}": notEqualIncomparable,
3338 "{ valueOf: undefined }": notEqualIncomparable,
3339 "[]": notEqualLessThan,
3340 '[""]': notEqualLessThan,
3341 '["a"]': notEqualIncomparable,
3342 "[0]": notEqualLessThan
3343 },
3344 "JSVAL_INT_MAX - 1":
3345 {
3346 "undefined": notEqualIncomparable,
3347 "null": notEqualGreaterThan,
3348 "true": notEqualGreaterThan,
3349 "false": notEqualGreaterThan,
3350 '""': notEqualGreaterThan,
3351 '"a"': notEqualIncomparable,
3352 '"Z"': notEqualIncomparable,
3353 "0": notEqualGreaterThan,
3354 "-0": notEqualGreaterThan,
3355 "1": notEqualGreaterThan,
3356 "Math.E": notEqualGreaterThan,
3357 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3358 "JSVAL_INT_MIN": notEqualGreaterThan,
3359 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3360 "JSVAL_INT_MAX - 1": strictlyEqual,
3361 "JSVAL_INT_MAX": notEqualLessThan,
3362 "JSVAL_INT_MAX + 1": notEqualLessThan,
3363 "Infinity": notEqualLessThan,
3364 "-Infinity": notEqualGreaterThan,
3365 "NaN": notEqualIncomparable,
3366 "{}": notEqualIncomparable,
3367 "{ valueOf: undefined }": notEqualIncomparable,
3368 "[]": notEqualGreaterThan,
3369 '[""]': notEqualGreaterThan,
3370 '["a"]': notEqualIncomparable,
3371 "[0]": notEqualGreaterThan
3372 },
3373 "JSVAL_INT_MAX":
3374 {
3375 "undefined": notEqualIncomparable,
3376 "null": notEqualGreaterThan,
3377 "true": notEqualGreaterThan,
3378 "false": notEqualGreaterThan,
3379 '""': notEqualGreaterThan,
3380 '"a"': notEqualIncomparable,
3381 '"Z"': notEqualIncomparable,
3382 "0": notEqualGreaterThan,
3383 "-0": notEqualGreaterThan,
3384 "1": notEqualGreaterThan,
3385 "Math.E": notEqualGreaterThan,
3386 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3387 "JSVAL_INT_MIN": notEqualGreaterThan,
3388 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3389 "JSVAL_INT_MAX - 1": notEqualGreaterThan,
3390 "JSVAL_INT_MAX": strictlyEqual,
3391 "JSVAL_INT_MAX + 1": notEqualLessThan,
3392 "Infinity": notEqualLessThan,
3393 "-Infinity": notEqualGreaterThan,
3394 "NaN": notEqualIncomparable,
3395 "{}": notEqualIncomparable,
3396 "{ valueOf: undefined }": notEqualIncomparable,
3397 "[]": notEqualGreaterThan,
3398 '[""]': notEqualGreaterThan,
3399 '["a"]': notEqualIncomparable,
3400 "[0]": notEqualGreaterThan
3401 },
3402 "JSVAL_INT_MAX + 1":
3403 {
3404 "undefined": notEqualIncomparable,
3405 "null": notEqualGreaterThan,
3406 "true": notEqualGreaterThan,
3407 "false": notEqualGreaterThan,
3408 '""': notEqualGreaterThan,
3409 '"a"': notEqualIncomparable,
3410 '"Z"': notEqualIncomparable,
3411 "0": notEqualGreaterThan,
3412 "-0": notEqualGreaterThan,
3413 "1": notEqualGreaterThan,
3414 "Math.E": notEqualGreaterThan,
3415 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3416 "JSVAL_INT_MIN": notEqualGreaterThan,
3417 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3418 "JSVAL_INT_MAX - 1": notEqualGreaterThan,
3419 "JSVAL_INT_MAX": notEqualGreaterThan,
3420 "JSVAL_INT_MAX + 1": strictlyEqual,
3421 "Infinity": notEqualLessThan,
3422 "-Infinity": notEqualGreaterThan,
3423 "NaN": notEqualIncomparable,
3424 "{}": notEqualIncomparable,
3425 "{ valueOf: undefined }": notEqualIncomparable,
3426 "[]": notEqualGreaterThan,
3427 '[""]': notEqualGreaterThan,
3428 '["a"]': notEqualIncomparable,
3429 "[0]": notEqualGreaterThan
3430 },
3431 "Infinity":
3432 {
3433 "undefined": notEqualIncomparable,
3434 "null": notEqualGreaterThan,
3435 "true": notEqualGreaterThan,
3436 "false": notEqualGreaterThan,
3437 '""': notEqualGreaterThan,
3438 '"a"': notEqualIncomparable,
3439 '"Z"': notEqualIncomparable,
3440 "0": notEqualGreaterThan,
3441 "-0": notEqualGreaterThan,
3442 "1": notEqualGreaterThan,
3443 "Math.E": notEqualGreaterThan,
3444 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3445 "JSVAL_INT_MIN": notEqualGreaterThan,
3446 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3447 "JSVAL_INT_MAX - 1": notEqualGreaterThan,
3448 "JSVAL_INT_MAX": notEqualGreaterThan,
3449 "JSVAL_INT_MAX + 1": notEqualGreaterThan,
3450 "Infinity": strictlyEqual,
3451 "-Infinity": notEqualGreaterThan,
3452 "NaN": notEqualIncomparable,
3453 "{}": notEqualIncomparable,
3454 "{ valueOf: undefined }": notEqualIncomparable,
3455 "[]": notEqualGreaterThan,
3456 '[""]': notEqualGreaterThan,
3457 '["a"]': notEqualIncomparable,
3458 "[0]": notEqualGreaterThan
3459 },
3460 "-Infinity":
3461 {
3462 "undefined": notEqualIncomparable,
3463 "null": notEqualLessThan,
3464 "true": notEqualLessThan,
3465 "false": notEqualLessThan,
3466 '""': notEqualLessThan,
3467 '"a"': notEqualIncomparable,
3468 '"Z"': notEqualIncomparable,
3469 "0": notEqualLessThan,
3470 "-0": notEqualLessThan,
3471 "1": notEqualLessThan,
3472 "Math.E": notEqualLessThan,
3473 "JSVAL_INT_MIN - 1": notEqualLessThan,
3474 "JSVAL_INT_MIN": notEqualLessThan,
3475 "JSVAL_INT_MIN + 1": notEqualLessThan,
3476 "JSVAL_INT_MAX - 1": notEqualLessThan,
3477 "JSVAL_INT_MAX": notEqualLessThan,
3478 "JSVAL_INT_MAX + 1": notEqualLessThan,
3479 "Infinity": notEqualLessThan,
3480 "-Infinity": strictlyEqual,
3481 "NaN": notEqualIncomparable,
3482 "{}": notEqualIncomparable,
3483 "{ valueOf: undefined }": notEqualIncomparable,
3484 "[]": notEqualLessThan,
3485 '[""]': notEqualLessThan,
3486 '["a"]': notEqualIncomparable,
3487 "[0]": notEqualLessThan
3488 },
3489 "NaN":
3490 {
3491 "undefined": notEqualIncomparable,
3492 "null": notEqualIncomparable,
3493 "true": notEqualIncomparable,
3494 "false": notEqualIncomparable,
3495 '""': notEqualIncomparable,
3496 '"a"': notEqualIncomparable,
3497 '"Z"': notEqualIncomparable,
3498 "0": notEqualIncomparable,
3499 "-0": notEqualIncomparable,
3500 "1": notEqualIncomparable,
3501 "Math.E": notEqualIncomparable,
3502 "JSVAL_INT_MIN - 1": notEqualIncomparable,
3503 "JSVAL_INT_MIN": notEqualIncomparable,
3504 "JSVAL_INT_MIN + 1": notEqualIncomparable,
3505 "JSVAL_INT_MAX - 1": notEqualIncomparable,
3506 "JSVAL_INT_MAX": notEqualIncomparable,
3507 "JSVAL_INT_MAX + 1": notEqualIncomparable,
3508 "Infinity": notEqualIncomparable,
3509 "-Infinity": notEqualIncomparable,
3510 "NaN": notEqualIncomparable,
3511 "{}": notEqualIncomparable,
3512 "{ valueOf: undefined }": notEqualIncomparable,
3513 "[]": notEqualIncomparable,
3514 '[""]': notEqualIncomparable,
3515 '["a"]': notEqualIncomparable,
3516 "[0]": notEqualIncomparable
3517 },
3518 "{}": comparingObjectOrObjectWithValueUndefined,
3519 "{ valueOf: undefined }": comparingObjectOrObjectWithValueUndefined,
3520 "[]":
3521 {
3522 "undefined": notEqualIncomparable,
3523 "null": notEqualNorDifferent,
3524 "true": notEqualLessThan,
3525 "false": looselyEqual,
3526 '""': looselyEqual,
3527 '"a"': notEqualLessThan,
3528 '"Z"': notEqualLessThan,
3529 "0": looselyEqual,
3530 "-0": looselyEqual,
3531 "1": notEqualLessThan,
3532 "Math.E": notEqualLessThan,
3533 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3534 "JSVAL_INT_MIN": notEqualGreaterThan,
3535 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3536 "JSVAL_INT_MAX - 1": notEqualLessThan,
3537 "JSVAL_INT_MAX": notEqualLessThan,
3538 "JSVAL_INT_MAX + 1": notEqualLessThan,
3539 "Infinity": notEqualLessThan,
3540 "-Infinity": notEqualGreaterThan,
3541 "NaN": notEqualIncomparable,
3542 "{}": notEqualLessThan,
3543 "{ valueOf: undefined }": notEqualLessThan,
3544 "[]": notEqualNorDifferent,
3545 '[""]': notEqualNorDifferent,
3546 '["a"]': notEqualLessThan,
3547 "[0]": notEqualLessThan
3548 },
3549 '[""]':
3550 {
3551 "undefined": notEqualIncomparable,
3552 "null": notEqualNorDifferent,
3553 "true": notEqualLessThan,
3554 "false": looselyEqual,
3555 '""': looselyEqual,
3556 '"a"': notEqualLessThan,
3557 '"Z"': notEqualLessThan,
3558 "0": looselyEqual,
3559 "-0": looselyEqual,
3560 "1": notEqualLessThan,
3561 "Math.E": notEqualLessThan,
3562 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3563 "JSVAL_INT_MIN": notEqualGreaterThan,
3564 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3565 "JSVAL_INT_MAX - 1": notEqualLessThan,
3566 "JSVAL_INT_MAX": notEqualLessThan,
3567 "JSVAL_INT_MAX + 1": notEqualLessThan,
3568 "Infinity": notEqualLessThan,
3569 "-Infinity": notEqualGreaterThan,
3570 "NaN": notEqualIncomparable,
3571 "{}": notEqualLessThan,
3572 "{ valueOf: undefined }": notEqualLessThan,
3573 "[]": notEqualNorDifferent,
3574 '[""]': notEqualNorDifferent,
3575 '["a"]': notEqualLessThan,
3576 "[0]": notEqualLessThan
3577 },
3578 '["a"]':
3579 {
3580 "undefined": notEqualIncomparable,
3581 "null": notEqualIncomparable,
3582 "true": notEqualIncomparable,
3583 "false": notEqualIncomparable,
3584 '""': notEqualGreaterThan,
3585 '"a"': looselyEqual,
3586 '"Z"': notEqualGreaterThan,
3587 "0": notEqualIncomparable,
3588 "-0": notEqualIncomparable,
3589 "1": notEqualIncomparable,
3590 "Math.E": notEqualIncomparable,
3591 "JSVAL_INT_MIN - 1": notEqualIncomparable,
3592 "JSVAL_INT_MIN": notEqualIncomparable,
3593 "JSVAL_INT_MIN + 1": notEqualIncomparable,
3594 "JSVAL_INT_MAX - 1": notEqualIncomparable,
3595 "JSVAL_INT_MAX": notEqualIncomparable,
3596 "JSVAL_INT_MAX + 1": notEqualIncomparable,
3597 "Infinity": notEqualIncomparable,
3598 "-Infinity": notEqualIncomparable,
3599 "NaN": notEqualIncomparable,
3600 "{}": notEqualGreaterThan,
3601 "{ valueOf: undefined }": notEqualGreaterThan,
3602 "[]": notEqualGreaterThan,
3603 '[""]': notEqualGreaterThan,
3604 '["a"]': notEqualNorDifferent,
3605 "[0]": notEqualGreaterThan
3606 },
3607 "[0]":
3608 {
3609 "undefined": notEqualIncomparable,
3610 "null": notEqualNorDifferent,
3611 "true": notEqualLessThan,
3612 "false": looselyEqual,
3613 '""': notEqualGreaterThan,
3614 '"a"': notEqualLessThan,
3615 '"Z"': notEqualLessThan,
3616 "0": looselyEqual,
3617 "-0": looselyEqual,
3618 "1": notEqualLessThan,
3619 "Math.E": notEqualLessThan,
3620 "JSVAL_INT_MIN - 1": notEqualGreaterThan,
3621 "JSVAL_INT_MIN": notEqualGreaterThan,
3622 "JSVAL_INT_MIN + 1": notEqualGreaterThan,
3623 "JSVAL_INT_MAX - 1": notEqualLessThan,
3624 "JSVAL_INT_MAX": notEqualLessThan,
3625 "JSVAL_INT_MAX + 1": notEqualLessThan,
3626 "Infinity": notEqualLessThan,
3627 "-Infinity": notEqualGreaterThan,
3628 "NaN": notEqualIncomparable,
3629 "{}": notEqualLessThan,
3630 "{ valueOf: undefined }": notEqualLessThan,
3631 "[]": notEqualGreaterThan,
3632 '[""]': notEqualGreaterThan,
3633 '["a"]': notEqualLessThan,
3634 "[0]": notEqualNorDifferent
3635 }
3636 };
3637
3638
3639
3640 var failures = [];
3641 function fail(a, ta, b, tb, ex, ac, op)
3642 {
3643 failures.push("(" + a + " " + op + " " + b + ") wrong: " +
3644 "expected " + ex + ", got " + ac +
3645 " (types " + types[ta] + ", " + types[tb] + ")");
3646 }
3647
3648 var result = false;
3649 for (var i in values)
3650 {
3651 for (var j in values)
3652 {
3653 // Constants, so hoist to help JIT know that
3654 var vala = values[i], valb = values[j];
3655 var a = vala.value(), b = valb.value();
3656
3657 for (var opname in orderOps)
3658 {
3659 var op = orderOps[opname];
3660 var expect = expected[i][j].order[opname];
3661 var failed = false;
3662
3663 for (var iter = 0; iter < 5; iter++)
3664 {
3665 result = op(a, b);
3666 failed = failed || result !== expect;
3667 }
3668
3669 if (failed)
3670 fail(i, vala.type, j, valb.type, expect, result, opname);
3671 }
3672
3673 for (var opname in eqOps)
3674 {
3675 var op = eqOps[opname];
3676 var expect = expected[i][j].eq[opname];
3677 var failed = false;
3678
3679 for (var iter = 0; iter < 5; iter++)
3680 {
3681 result = op(a, b);
3682 failed = failed || result !== expect;
3683 }
3684
3685 if (failed)
3686 fail(i, vala.type, j, valb.type, expect, result, opname);
3687 }
3688 }
3689 }
3690
3691 if (failures.length == 0)
3692 return "no failures reported!";
3693
3694 return "\n" + failures.join(",\n");
3695 }
3696 testComparisons.expected = "no failures reported!";
3697 test(testComparisons);
3698
3699 function testCaseAbort()
3700 {
3701 var four = "4";
3702 var r = 0;
3703 for (var i = 0; i < 5; i++)
3704 {
3705 switch (i)
3706 {
3707 case four: r += 1; break;
3708 default: r += 2; break;
3709 }
3710 }
3711
3712 return "" + r;
3713 }
3714 testCaseAbort.expected = "10";
3715 testCaseAbort.jitstats = {
3716 recorderAborted: 0
3717 };
3718 test(testCaseAbort);
3719
3720 function testApplyCallHelper(f) {
3721 var r = [];
3722 for (var i = 0; i < 10; ++i) f.call();
3723 r.push(x);
3724 for (var i = 0; i < 10; ++i) f.call(this);
3725 r.push(x);
3726 for (var i = 0; i < 10; ++i) f.apply(this);
3727 r.push(x);
3728 for (var i = 0; i < 10; ++i) f.call(this,0);
3729 r.push(x);
3730 for (var i = 0; i < 10; ++i) f.apply(this,[0]);
3731 r.push(x);
3732 for (var i = 0; i < 10; ++i) f.call(this,0,1);
3733 r.push(x);
3734 for (var i = 0; i < 10; ++i) f.apply(this,[0,1]);
3735 r.push(x);
3736 for (var i = 0; i < 10; ++i) f.call(this,0,1,2);
3737 r.push(x);
3738 for (var i = 0; i < 10; ++i) f.apply(this,[0,1,2]);
3739 r.push(x);
3740 for (var i = 0; i < 10; ++i) f.call(this,0,1,2,3);
3741 r.push(x);
3742 for (var i = 0; i < 10; ++i) f.apply(this,[0,1,2,3]);
3743 r.push(x);
3744 for (var i = 0; i < 10; ++i) f.call(this,0,1,2,3,4);
3745 r.push(x);
3746 for (var i = 0; i < 10; ++i) f.apply(this,[0,1,2,3,4]);
3747 r.push(x);
3748 for (var i = 0; i < 10; ++i) f.call(this,0,1,2,3,4,5);
3749 r.push(x);
3750 for (var i = 0; i < 10; ++i) f.apply(this,[0,1,2,3,4,5])
3751 r.push(x);
3752 return(r.join(","));
3753 }
3754 function testApplyCall() {
3755 var r = testApplyCallHelper(function (a0,a1,a2,a3,a4,a5,a6,a7) { x = [a0,a1,a2,a3,a4,a5,a6,a7]; });
3756 r += testApplyCallHelper(function (a0,a1,a2,a3,a4,a5,a6,a7) { x = [a0,a1,a2,a3,a4,a5,a6,a7]; });
3757 return r;
3758 }
3759 testApplyCall.expected =
3760 ",,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,,,,,,,,0,1,,,,,,,0,1,,,,,,,0,1,2,,,,,,0,1,2,,,,,,0,1,2,3,,,,,0,1,2,3,,,,,0,1,2,3,4,,,,0,1,2,3,4,,,,0,1,2,3,4,5,,,0,1,2,3,4,5,," +
3761 ",,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,,,,,,,,0,1,,,,,,,0,1,,,,,,,0,1,2,,,,,,0,1,2,,,,,,0,1,2,3,,,,,0,1,2,3,,,,,0,1,2,3,4,,,,0,1,2,3,4,,,,0,1,2,3,4,5,,,0,1,2,3,4,5,,";
3762 test(testApplyCall);
3763
3764 function testApplyUnboxHelper(f,a) {
3765 var q;
3766 for (var i = 0; i < 10; ++i)
3767 q = f.apply(f,a);
3768 return q;
3769 }
3770 function testApplyUnbox() {
3771 var f = function(x) { return x; }
3772 return [testApplyUnboxHelper(f,[1]), testApplyUnboxHelper(f,[true])].join(",");
3773 }
3774 testApplyUnbox.expected = "1,true";
3775 test(testApplyUnbox);
3776
3777 function testCallPick() {
3778 function g(x,a) {
3779 x.f();
3780 }
3781
3782 var x = [];
3783 x.f = function() { }
3784
3785 var y = [];
3786 y.f = function() { }
3787
3788 var z = [x,x,x,x,x,y,y,y,y,y];
3789
3790 for (var i = 0; i < 10; ++i)
3791 g.call(this, z[i], "");
3792 return true;
3793 }
3794 testCallPick.expected = true;
3795 test(testCallPick);
3796
3797 function testInvertNullAfterNegateNull()
3798 {
3799 for (var i = 0; i < 5; i++) !null;
3800 for (var i = 0; i < 5; i++) -null;
3801 return "no assertion";
3802 }
3803 testInvertNullAfterNegateNull.expected = "no assertion";
3804 test(testInvertNullAfterNegateNull);
3805
3806 function testUnaryImacros()
3807 {
3808 function checkArg(x)
3809 {
3810 return 1;
3811 }
3812
3813 var o = { valueOf: checkArg, toString: null };
3814 var count = 0;
3815 var v = 0;
3816 for (var i = 0; i < 5; i++)
3817 v += +o + -(-o);
3818
3819 var results = [v === 10 ? "valueOf passed" : "valueOf failed"];
3820
3821 o.valueOf = null;
3822 o.toString = checkArg;
3823
3824 for (var i = 0; i < 5; i++)
3825 v += +o + -(-o);
3826
3827 results.push(v === 20 ? "toString passed" : "toString failed");
3828
3829 return results.join(", ");
3830 }
3831 testUnaryImacros.expected = "valueOf passed, toString passed";
3832 test(testUnaryImacros);
3833
3834 function testAddAnyInconvertibleObject()
3835 {
3836 var count = 0;
3837 function toString() { ++count; if (count == 95) return {}; return "" + count; }
3838
3839 var threw = false;
3840 try
3841 {
3842 for (var i = 0; i < 100; i++)
3843 {
3844 var o = {valueOf: undefined, toString: toString};
3845 var q = 5 + o;
3846 }
3847 }
3848 catch (e)
3849 {
3850 threw = true;
3851 if (i !== 94)
3852 return "expected i === 94, got " + i;
3853 if (q !== "594")
3854 return "expected q === '594', got " + q + " (type " + typeof q + ")";
3855 if (count !== 95)
3856 return "expected count === 95, got " + count;
3857 }
3858 if (!threw)
3859 return "expected throw with 5 + o"; // hey, a rhyme!
3860
3861 return "pass";
3862 }
3863 testAddAnyInconvertibleObject.expected = "pass";
3864 testAddAnyInconvertibleObject.jitstats = {
3865 recorderStarted: 1,
3866 recorderAborted: 0,
3867 sideExitIntoInterpreter: 93
3868 };
3869 test(testAddAnyInconvertibleObject);
3870
3871 function testAddInconvertibleObjectAny()
3872 {
3873 var count = 0;
3874 function toString()
3875 {
3876 ++count;
3877 if (count == 95)
3878 return {};
3879 return "" + count;
3880 }
3881
3882 var threw = false;
3883 try
3884 {
3885 for (var i = 0; i < 100; i++)
3886 {
3887 var o = {valueOf: undefined, toString: toString};
3888 var q = o + 5;
3889 }
3890 }
3891 catch (e)
3892 {
3893 threw = true;
3894 if (i !== 94)
3895 return "expected i === 94, got " + i;
3896 if (q !== "945")
3897 return "expected q === '945', got " + q + " (type " + typeof q + ")";
3898 if (count !== 95)
3899 return "expected count === 95, got " + count;
3900 }
3901 if (!threw)
3902 return "expected throw with o + 5";
3903
3904 return "pass";
3905 }
3906 testAddInconvertibleObjectAny.expected = "pass";
3907 testAddInconvertibleObjectAny.jitstats = {
3908 recorderStarted: 1,
3909 recorderAborted: 0,
3910 sideExitIntoInterpreter: 93
3911 };
3912 test(testAddInconvertibleObjectAny);
3913
3914 function testAddInconvertibleObjectInconvertibleObject()
3915 {
3916 var count1 = 0;
3917 function toString1() { ++count1; if (count1 == 95) return {}; return "" + count1; }
3918 var count2 = 0;
3919 function toString2() { ++count2; if (count2 == 95) return {}; return "" + count2; }
3920
3921 var threw = false;
3922 try
3923 {
3924 for (var i = 0; i < 100; i++)
3925 {
3926 var o1 = {valueOf: undefined, toString: toString1};
3927 var o2 = {valueOf: undefined, toString: toString2};
3928 var q = o1 + o2;
3929 }
3930 }
3931 catch (e)
3932 {
3933 threw = true;
3934 if (i !== 94)
3935 return "expected i === 94, got " + i;
3936 if (q !== "9494")
3937 return "expected q === '9494', got " + q + " (type " + typeof q + ")";
3938 if (count1 !== 95)
3939 return "expected count1 === 95, got " + count1;
3940 if (count2 !== 94)
3941 return "expected count2 === 94, got " + count2;
3942 }
3943 if (!threw)
3944 return "expected throw with o1 + o2";
3945
3946 return "pass";
3947 }
3948 testAddInconvertibleObjectInconvertibleObject.expected = "pass";
3949 testAddInconvertibleObjectInconvertibleObject.jitstats = {
3950 recorderStarted: 1,
3951 recorderAborted: 0,
3952 sideExitIntoInterpreter: 93
3953 };
3954 test(testAddInconvertibleObjectInconvertibleObject);
3955
3956 function testBitOrAnyInconvertibleObject()
3957 {
3958 var count = 0;
3959 function toString() { ++count; if (count == 95) return {}; return count; }
3960
3961 var threw = false;
3962 try
3963 {
3964 for (var i = 0; i < 100; i++)
3965 {
3966 var o = {valueOf: undefined, toString: toString};
3967 var q = 1 | o;
3968 }
3969 }
3970 catch (e)
3971 {
3972 threw = true;
3973 if (i !== 94)
3974 return "expected i === 94, got " + i;
3975 if (q !== 95)
3976 return "expected q === 95, got " + q;
3977 if (count !== 95)
3978 return "expected count === 95, got " + count;
3979 }
3980 if (!threw)
3981 return "expected throw with 2 | o"; // hey, a rhyme!
3982
3983 return "pass";
3984 }
3985 testBitOrAnyInconvertibleObject.expected = "pass";
3986 testBitOrAnyInconvertibleObject.jitstats = {
3987 recorderStarted: 1,
3988 recorderAborted: 0,
3989 sideExitIntoInterpreter: 93
3990 };
3991 test(testBitOrAnyInconvertibleObject);
3992
3993 function testBitOrInconvertibleObjectAny()
3994 {
3995 var count = 0;
3996 function toString() { ++count; if (count == 95) return {}; return count; }
3997
3998 var threw = false;
3999 try
4000 {
4001 for (var i = 0; i < 100; i++)
4002 {
4003 var o = {valueOf: undefined, toString: toString};
4004 var q = o | 1;
4005 }
4006 }
4007 catch (e)
4008 {
4009 threw = true;
4010 if (i !== 94)
4011 return "expected i === 94, got " + i;
4012 if (q !== 95)
4013 return "expected q === 95, got " + q;
4014 if (count !== 95)
4015 return "expected count === 95, got " + count;
4016 }
4017 if (!threw)
4018 return "expected throw with o | 2";
4019
4020 return "pass";
4021 }
4022 testBitOrInconvertibleObjectAny.expected = "pass";
4023 testBitOrInconvertibleObjectAny.jitstats = {
4024 recorderStarted: 1,
4025 recorderAborted: 0,
4026 sideExitIntoInterpreter: 93
4027 };
4028 test(testBitOrInconvertibleObjectAny);
4029
4030 function testBitOrInconvertibleObjectInconvertibleObject()
4031 {
4032 var count1 = 0;
4033 function toString1() { ++count1; if (count1 == 95) return {}; return count1; }
4034 var count2 = 0;
4035 function toString2() { ++count2; if (count2 == 95) return {}; return count2; }
4036
4037 var threw = false;
4038 try
4039 {
4040 for (var i = 0; i < 100; i++)
4041 {
4042 var o1 = {valueOf: undefined, toString: toString1};
4043 var o2 = {valueOf: undefined, toString: toString2};
4044 var q = o1 | o2;
4045 }
4046 }
4047 catch (e)
4048 {
4049 threw = true;
4050 if (i !== 94)
4051 return "expected i === 94, got " + i;
4052 if (q !== 94)
4053 return "expected q === 94, got " + q;
4054 if (count1 !== 95)
4055 return "expected count1 === 95, got " + count1;
4056 if (count2 !== 94)
4057 return "expected count2 === 94, got " + count2;
4058 }
4059 if (!threw)
4060 return "expected throw with o1 | o2";
4061
4062 return "pass";
4063 }
4064 testBitOrInconvertibleObjectInconvertibleObject.expected = "pass";
4065 testBitOrInconvertibleObjectInconvertibleObject.jitstats = {
4066 recorderStarted: 1,
4067 recorderAborted: 0,
4068 sideExitIntoInterpreter: 93
4069 };
4070 test(testBitOrInconvertibleObjectInconvertibleObject);
4071
4072 function testCaseTypeMismatchBadness()
4073 {
4074 for (var z = 0; z < 3; ++z)
4075 {
4076 switch ("")
4077 {
4078 default:
4079 case 9:
4080 break;
4081
4082 case "":
4083 case <x/>:
4084 break;
4085 }
4086 }
4087
4088 return "no crash";
4089 }
4090 testCaseTypeMismatchBadness.expected = "no crash";
4091 testCaseTypeMismatchBadness.jitstats = {
4092 recorderAborted: 0
4093 };
4094 test(testCaseTypeMismatchBadness);
4095
4096 function testDoubleComparison()
4097 {
4098 for (var i = 0; i < 500000; ++i)
4099 {
4100 switch (1 / 0)
4101 {
4102 case Infinity:
4103 }
4104 }
4105
4106 return "finished";
4107 }
4108 testDoubleComparison.expected = "finished";
4109 testDoubleComparison.jitstats = {
4110 sideExitIntoInterpreter: 1
4111 };
4112 test(testDoubleComparison);
4113
4114 function testLirBufOOM()
4115 {
4116 var a = [
4117 "12345678901234",
4118 "123456789012",
4119 "1234567890123456789012345678",
4120 "12345678901234567890123456789012345678901234567890123456",
4121 "f",
4122 "$",
4123 "",
4124 "f()",
4125 "(\\*)",
4126 "b()",
4127 "()",
4128 "(#)",
4129 "ABCDEFGHIJK",
4130 "ABCDEFGHIJKLM",
4131 "ABCDEFGHIJKLMNOPQ",
4132 "ABCDEFGH",
4133 "(.)",
4134 "(|)",
4135 "()$",
4136 "/()",
4137 "(.)$"
4138 ];
4139
4140 for (var j = 0; j < 200; ++j) {
4141 var js = "" + j;
4142 for (var i = 0; i < a.length; i++)
4143 "".match(a[i] + js)
4144 }
4145 return "ok";
4146 }
4147 testLirBufOOM.expected = "ok";
4148 test(testLirBufOOM);
4149
4150 function testStringResolve() {
4151 var x = 0;
4152 for each (let d in [new String('q'), new String('q'), new String('q')]) {
4153 if (("" + (0 in d)) === "true")
4154 x++;
4155 }
4156 return x;
4157 }
4158 testStringResolve.expected = 3;
4159 test(testStringResolve);
4160
4161 //test no multitrees assert
4162 function testGlobalMultitrees1() {
4163 (function() {
4164 for (var j = 0; j < 4; ++j) {
4165 for each (e in ['A', 1, 'A']) {
4166 }
4167 }
4168 })();
4169 return true;
4170 }
4171 testGlobalMultitrees1.expected = true;
4172 test(testGlobalMultitrees1);
4173
4174 var q = [];
4175 for each (b in [0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF]) {
4176 for each (let e in [{}, {}, {}, "", {}]) {
4177 b = (b | 0x40000000) + 1;
4178 q.push(b);
4179 }
4180 }
4181 function testLetWithUnstableGlobal() {
4182 return q.join(",");
4183 }
4184 testLetWithUnstableGlobal.expected = "2147483648,-1073741823,-1073741822,-1073741821,-1073741820,2147483648,-1073741823,-1073741822,-1073741821,-1073741820,2147483648,-1073741823,-1073741822,-1073741821,-1073741820";
4185 test(testLetWithUnstableGlobal);
4186 delete b;
4187 delete q;
4188
4189 for each (testBug474769_b in [1, 1, 1, 1.5, 1, 1]) {
4190 (function() { for each (let testBug474769_h in [0, 0, 1.4, ""]) {} })()
4191 }
4192 function testBug474769() {
4193 return testBug474769_b;
4194 }
4195 testBug474769.expected = 1;
4196 test(testBug474769);
4197
4198 function testReverseArgTypes() {
4199 for (var j = 0; j < 4; ++j) ''.replace('', /x/);
4200 return 1;
4201 }
4202 testReverseArgTypes.expected = 1;
4203 test(testReverseArgTypes);
4204
4205 function testBug458838() {
4206 var a = 1;
4207 function g() {
4208 var b = 0
4209 for (var i = 0; i < 10; ++i) {
4210 b += a;
4211 }
4212 return b;
4213 }
4214
4215 return g();
4216 }
4217 testBug458838.expected = 10;
4218 testBug458838.jitstats = {
4219 recorderStarted: 1,
4220 recorderAborted: 0,
4221 traceCompleted: 1
4222 };
4223 test(testBug458838);
4224
4225 function testInterpreterReentry() {
4226 this.__defineSetter__('x', function(){})
4227 for (var j = 0; j < 5; ++j) { x = 3; }
4228 return 1;
4229 }
4230 testInterpreterReentry.expected = 1;
4231 test(testInterpreterReentry);
4232
4233 function testInterpreterReentry2() {
4234 var a = false;
4235 var b = {};
4236 var c = false;
4237 var d = {};
4238 this.__defineGetter__('e', function(){});
4239 for (let f in this) print(f);
4240 [1 for each (g in this) for each (h in [])]
4241 return 1;
4242 }
4243 testInterpreterReentry2.expected = 1;
4244 test(testInterpreterReentry2);
4245
4246 function testInterpreterReentry3() {
4247 for (let i=0;i<5;++i) this["y" + i] = function(){};
4248 this.__defineGetter__('e', function (x2) { yield; });
4249 [1 for each (a in this) for (b in {})];
4250 return 1;
4251 }
4252 testInterpreterReentry3.expected = 1;
4253 test(testInterpreterReentry3);
4254
4255 function testInterpreterReentry4() {
4256 var obj = {a:1, b:1, c:1, d:1, get e() 1000 };
4257 for (var p in obj)
4258 obj[p];
4259 }
4260 test(testInterpreterReentry4);
4261
4262 function testInterpreterReentry5() {
4263 var arr = [0, 1, 2, 3, 4];
4264 arr.__defineGetter__("4", function() 1000);
4265 for (var i = 0; i < 5; i++)
4266 arr[i];
4267 for (var p in arr)
4268 arr[p];
4269 }
4270 test(testInterpreterReentry5);
4271
4272 function testInterpreterReentry6() {
4273 var obj = {a:1, b:1, c:1, d:1, set e(x) { this._e = x; }};
4274 for (var p in obj)
4275 obj[p] = "grue";
4276 return obj._e;
4277 }
4278 testInterpreterReentry6.expected = "grue";
4279 test(testInterpreterReentry6);
4280
4281 function testInterpreterReentry7() {
4282 var arr = [0, 1, 2, 3, 4];
4283 arr.__defineSetter__("4", function(x) { this._4 = x; });
4284 for (var i = 0; i < 5; i++)
4285 arr[i] = "grue";
4286 var tmp = arr._4;
4287 for (var p in arr)
4288 arr[p] = "bleen";
4289 return tmp + " " + arr._4;
4290 }
4291 testInterpreterReentry7.expected = "grue bleen";
4292 test(testInterpreterReentry7);
4293
4294 // Bug 462027 comment 54.
4295 function testInterpreterReentery8() {
4296 var e = <x><y/></x>;
4297 for (var j = 0; j < 4; ++j) { +[e]; }
4298 }
4299 test(testInterpreterReentery8);
4300
4301 function testHolePushing() {
4302 var a = ["foobar", "baz"];
4303 for (var i = 0; i < 5; i++)
4304 a = [, "overwritten", "new"];
4305 var s = "[";
4306 for (i = 0; i < a.length; i++) {
4307 s += (i in a) ? a[i] : "<hole>";
4308 if (i != a.length - 1)
4309 s += ",";
4310 }
4311 return s + "], " + (0 in a);
4312 }
4313 testHolePushing.expected = "[<hole>,overwritten,new], false";
4314 test(testHolePushing);
4315
4316 function testDeepBail1() {
4317 var y = <z/>;
4318 for (var i = 0; i < RUNLOOP; i++)
4319 "" in y;
4320 }
4321 test(testDeepBail1);
4322
4323 /* Array comprehension tests */
4324
4325 function Range(start, stop) {
4326 this.i = start;
4327 this.stop = stop;
4328 }
4329 Range.prototype = {
4330 __iterator__: function() this,
4331 next: function() {
4332 if (this.i >= this.stop)
4333 throw StopIteration;
4334 return this.i++;
4335 }
4336 };
4337
4338 function range(start, stop) {
4339 return new Range(start, stop);
4340 }
4341
4342 function testArrayComp1() {
4343 return [a for (a in range(0, 10))].join('');
4344 }
4345 testArrayComp1.expected='0123456789';
4346 test(testArrayComp1);
4347
4348 function testArrayComp2() {
4349 return [a + b for (a in range(0, 5)) for (b in range(0, 5))].join('');
4350 }
4351 testArrayComp2.expected='0123412345234563456745678';
4352 test(testArrayComp2);
4353
4354 function testSwitchUndefined()
4355 {
4356 var x = undefined;
4357 var y = 0;
4358 for (var i = 0; i < 5; i++)
4359 {
4360 switch (x)
4361 {
4362 default:
4363 y++;
4364 }
4365 }
4366 return y;
4367 }
4368 testSwitchUndefined.expected = 5;
4369 test(testSwitchUndefined);
4370
4371 function testGeneratorDeepBail() {
4372 function g() { yield 2; }
4373 var iterables = [[1], [], [], [], g()];
4374
4375 var total = 0;
4376 for (let i = 0; i < iterables.length; i++)
4377 for each (let j in iterables[i])
4378 total += j;
4379 return total;
4380 }
4381 testGeneratorDeepBail.expected = 3;
4382 test(testGeneratorDeepBail);
4383
4384 function testRegexpGet() {
4385 var re = /hi/;
4386 var a = [];
4387 for (let i = 0; i < 5; ++i)
4388 a.push(re.source);
4389 return a.toString();
4390 }
4391 testRegexpGet.expected = "hi,hi,hi,hi,hi";
4392 test(testRegexpGet);
4393
4394 function testThrowingObjectEqUndefined()
4395 {
4396 try
4397 {
4398 var obj = { toString: function() { throw 0; } };
4399 for (var i = 0; i < 5; i++)
4400 "" + (obj == undefined);
4401 return i === 5;
4402 }
4403 catch (e)
4404 {
4405 return "" + e;
4406 }
4407 }
4408 testThrowingObjectEqUndefined.expected = true;
4409 testThrowingObjectEqUndefined.jitstats = {
4410 sideExitIntoInterpreter: 1
4411 };
4412 test(testThrowingObjectEqUndefined);
4413
4414 function x4(v) { return "" + v + v + v + v; }
4415 function testConvertibleObjectEqUndefined()
4416 {
4417 var compares =
4418 [
4419 false, false, false, false,
4420 undefined, undefined, undefined, undefined,
4421 false, false, false, false,
4422 undefined, undefined, undefined, undefined,
4423 false, false, false, false,
4424 undefined, undefined, undefined, undefined,
4425 false, false, false, false,
4426 undefined, undefined, undefined, undefined,
4427 false, false, false, false,
4428 undefined, undefined, undefined, undefined,
4429 ];
4430 var count = 0;
4431 var obj = { valueOf: function() { count++; return 1; } };
4432 var results = compares.map(function(v) { return "unwritten"; });
4433
4434 for (var i = 0, sz = compares.length; i < sz; i++)
4435 results[i] = compares[i] == obj;
4436
4437 return results.join("") + count;
4438 }
4439 testConvertibleObjectEqUndefined.expected =
4440 x4(false) + x4(false) + x4(false) + x4(false) + x4(false) + x4(false) +
4441 x4(false) + x4(false) + x4(false) + x4(false) + "20";
4442 testConvertibleObjectEqUndefined.jitstats = {
4443 sideExitIntoInterpreter: 3
4444 };
4445 test(testConvertibleObjectEqUndefined);
4446
4447 function testUndefinedPropertyAccess() {
4448 var x = [1,2,3];
4449 var y = {};
4450 var a = { foo: 1 };
4451 y.__proto__ = x;
4452 var z = [x, x, x, y, y, y, y, a, a, a];
4453 var s = "";
4454 for (var i = 0; i < z.length; ++i)
4455 s += z[i].foo;
4456 return s;
4457 }
4458 testUndefinedPropertyAccess.expected = "undefinedundefinedundefinedundefinedundefinedundefinedundefined111";
4459 testUndefinedPropertyAccess.jitstats = {
4460 traceCompleted: 3
4461 };
4462 test(testUndefinedPropertyAccess);
4463
4464 q = "";
4465 function g() { q += "g"; }
4466 function h() { q += "h"; }
4467 a = [g, g, g, g, h];
4468 for (i=0; i<5; i++) { f = a[i]; f(); }
4469
4470 function testRebranding() {
4471 return q;
4472 }
4473 testRebranding.expected = "ggggh";
4474 test(testRebranding);
4475 delete q;
4476 delete g;
4477 delete h;
4478 delete a;
4479 delete f;
4480
4481 function testLambdaCtor() {
4482 var a = [];
4483 for (var x = 0; x < RUNLOOP; ++x) {
4484 var f = function(){};
4485 a[a.length] = new f;
4486 }
4487
4488 // This prints false until the upvar2 bug is fixed:
4489 // print(a[HOTLOOP].__proto__ !== a[HOTLOOP-1].__proto__);
4490
4491 // Assert that the last f was properly constructed.
4492 return a[RUNLOOP-1].__proto__ === f.prototype;
4493 }
4494
4495 testLambdaCtor.expected = true;
4496 test(testLambdaCtor);
4497
4498 function testNonStubGetter() {
4499 let ([] = false) { (this.watch("x", /a/g)); };
4500 (function () { (eval("(function(){for each (x in [1, 2, 2]);});"))(); })();
4501 this.unwatch("x");
4502 return "ok";
4503 }
4504 testNonStubGetter.expected = "ok";
4505 test(testNonStubGetter);
4506
4507 function testString() {
4508 var q;
4509 for (var i = 0; i <= RUNLOOP; ++i) {
4510 q = [];
4511 q.push(String(void 0));
4512 q.push(String(true));
4513 q.push(String(5));
4514 q.push(String(5.5));
4515 q.push(String("5"));
4516 q.push(String([5]));
4517 }
4518 return q.join(",");
4519 }
4520 testString.expected = "undefined,true,5,5.5,5,5";
4521 testString.jitstats = {
4522 recorderStarted: 1,
4523 sideExitIntoInterpreter: 1
4524 };
4525 test(testString);
4526
4527 function testToStringBeforeValueOf()
4528 {
4529 var o = {toString: function() { return "s"; }, valueOf: function() { return "v"; } };
4530 var a = [];
4531 for (var i = 0; i < 10; i++)
4532 a.push(String(o));
4533 return a.join(",");
4534 }
4535 testToStringBeforeValueOf.expected = "s,s,s,s,s,s,s,s,s,s";
4536 testToStringBeforeValueOf.jitstats = {
4537 recorderStarted: 1,
4538 sideExitIntoInterpreter: 1
4539 };
4540 test(testToStringBeforeValueOf);
4541
4542 function testNullToString()
4543 {
4544 var a = [];
4545 for (var i = 0; i < 10; i++)
4546 a.push(String(null));
4547 for (i = 0; i < 10; i++) {
4548 var t = typeof a[i];
4549 if (t != "string")
4550 a.push(t);
4551 }
4552 return a.join(",");
4553 }
4554 testNullToString.expected = "null,null,null,null,null,null,null,null,null,null";
4555 testNullToString.jitstats = {
4556 recorderStarted: 2,
4557 sideExitIntoInterpreter: 2,
4558 recorderAborted: 0
4559 };
4560 test(testNullToString);
4561
4562 function testAddNull()
4563 {
4564 var rv;
4565 for (var x = 0; x < HOTLOOP + 1; ++x)
4566 rv = null + [,,];
4567 return rv;
4568 }
4569 testAddNull.expected = "null,";
4570 testAddNull.jitstats = {
4571 recorderStarted: 1,
4572 sideExitIntoInterpreter: 1,
4573 recorderAborted: 0
4574 };
4575 test(testAddNull);
4576
4577 function testClosures()
4578 {
4579 function MyObject(id) {
4580 var thisObject = this;
4581 this.id = id;
4582 this.toString = str;
4583
4584 function str() {
4585 return "" + this.id + thisObject.id;
4586 }
4587 }
4588
4589 var a = [];
4590 for (var i = 0; i < 5; i++)
4591 a.push(new MyObject(i));
4592 return a.toString();
4593 }
4594 testClosures.expected = "00,11,22,33,44";
4595 test(testClosures);
4596
4597 function testMoreClosures() {
4598 var f = {}, max = 3;
4599
4600 var hello = function(n) {
4601 function howdy() { return n * n }
4602 f.test = howdy;
4603 };
4604
4605 for (var i = 0; i <= max; i++)
4606 hello(i);
4607
4608 return f.test();
4609 }
4610 testMoreClosures.expected = 9;
4611 test(testMoreClosures);
4612
4613 function testLambdaInitedVar() {
4614 var jQuery = function (a, b) {
4615 return jQuery && jQuery.length;
4616 }
4617 return jQuery();
4618 }
4619
4620 testLambdaInitedVar.expected = 2;
4621 test(testLambdaInitedVar);
4622
4623 function testNestedEscapingLambdas()
4624 {
4625 try {
4626 return (function() {
4627 var a = [], r = [];
4628 function setTimeout(f, t) {
4629 a.push(f);
4630 }
4631
4632 function runTimeouts() {
4633 for (var i = 0; i < a.length; i++)
4634 a[i]();
4635 }
4636
4637 var $foo = "#nothiddendiv";
4638 setTimeout(function(){
4639 r.push($foo);
4640 setTimeout(function(){
4641 r.push($foo);
4642 }, 100);
4643 }, 100);
4644
4645 runTimeouts();
4646
4647 return r.join("");
4648 })();
4649 } catch (e) {
4650 return e;
4651 }
4652 }
4653 testNestedEscapingLambdas.expected = "#nothiddendiv#nothiddendiv";
4654 test(testNestedEscapingLambdas);
4655
4656 function testPropagatedFunArgs()
4657 {
4658 var win = this;
4659 var res = [], q = [];
4660 function addEventListener(name, func, flag) {
4661 q.push(func);
4662 }
4663
4664 var pageInfo, obs;
4665 addEventListener("load", handleLoad, true);
4666
4667 var observer = {
4668 observe: function(win, topic, data) {
4669 // obs.removeObserver(observer, "page-info-dialog-loaded");
4670 handlePageInfo();
4671 }
4672 };
4673
4674 function handleLoad() {
4675 pageInfo = { toString: function() { return "pageInfo"; } };
4676 obs = { addObserver: function (obs, topic, data) { obs.observe(win, topic, data); } };
4677 obs.addObserver(observer, "page-info-dialog-loaded", false);
4678 }
4679
4680 function handlePageInfo() {
4681 res.push(pageInfo);
4682 function $(aId) { res.push(pageInfo); };
4683 var feedTab = $("feedTab");
4684 }
4685
4686 q[0]();
4687 return res.join(',');
4688 }
4689 testPropagatedFunArgs.expected = "pageInfo,pageInfo";
4690 test(testPropagatedFunArgs);
4691
4692 // Second testPropagatedFunArgs test -- this is a crash-test.
4693 (function () {
4694 var escapee;
4695
4696 function testPropagatedFunArgs()
4697 {
4698 const magic = 42;
4699
4700 var win = this;
4701 var res = [], q = [];
4702 function addEventListener(name, func, flag) {
4703 q.push(func);
4704 }
4705
4706 var pageInfo = "pageInfo", obs;
4707 addEventListener("load", handleLoad, true);
4708
4709 var observer = {
4710 observe: function(win, topic, data) {
4711 // obs.removeObserver(observer, "page-info-dialog-loaded");
4712 handlePageInfo();
4713 }
4714 };
4715
4716 function handleLoad() {
4717 //pageInfo = { toString: function() { return "pageInfo"; } };
4718 obs = { addObserver: function (obs, topic, data) { obs.observe(win, topic, data); } };
4719 obs.addObserver(observer, "page-info-dialog-loaded", false);
4720 }
4721
4722 function handlePageInfo() {
4723 res.push(pageInfo);
4724 function $(aId) {
4725 function notSafe() {
4726 return magic;
4727 }
4728 notSafe();
4729 res.push(pageInfo);
4730 };
4731 var feedTab = $("feedTab");
4732 }
4733
4734 escapee = q[0];
4735 return res.join(',');
4736 }
4737
4738 testPropagatedFunArgs();
4739
4740 escapee();
4741 })();
4742
4743 function testStringLengthNoTinyId()
4744 {
4745 var x = "unset";
4746 var t = new String("");
4747 for (var i = 0; i < 5; i++)
4748 x = t["-1"];
4749
4750 var r = "t['-1'] is " + x;
4751 t["-1"] = "foo";
4752 r += " when unset, '" + t["-1"] + "' when set";
4753 return r;
4754 }
4755 testStringLengthNoTinyId.expected = "t['-1'] is undefined when unset, 'foo' when set";
4756 test(testStringLengthNoTinyId);
4757
4758 function testLengthInString()
4759 {
4760 var s = new String();
4761 var res = "length" in s;
4762 for (var i = 0; i < 5; i++)
4763 res = res && ("length" in s);
4764 res = res && s.hasOwnProperty("length");
4765 for (var i = 0; i < 5; i++)
4766 res = res && s.hasOwnProperty("length");
4767 return res;
4768 }
4769 testLengthInString.expected = true;
4770 test(testLengthInString);
4771
4772 function testSlowArrayLength()
4773 {
4774 var counter = 0;
4775 var a = [];
4776 a[10000000 - 1] = 0;
4777 for (var i = 0; i < a.length; i++)
4778 counter++;
4779 return counter;
4780 }
4781 testSlowArrayLength.expected = 10000000;
4782 testSlowArrayLength.jitstats = {
4783 recorderStarted: 1,
4784 recorderAborted: 0,
4785 sideExitIntoInterpreter: 1
4786 };
4787 test(testSlowArrayLength);
4788
4789 function testObjectLength()
4790 {
4791 var counter = 0;
4792 var a = {};
4793 a.length = 10000000;
4794 for (var i = 0; i < a.length; i++)
4795 counter++;
4796 return counter;
4797 }
4798 testObjectLength.expected = 10000000;
4799 testObjectLength.jitstats = {
4800 recorderStarted: 1,
4801 recorderAborted: 0,
4802 sideExitIntoInterpreter: 1
4803 };
4804 test(testObjectLength);
4805
4806 function testChangingObjectWithLength()
4807 {
4808 var obj = { length: 10 };
4809 var dense = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
4810 var slow = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; slow.slow = 5;
4811
4812 /*
4813 * The elements of objs constitute a De Bruijn sequence repeated 4x to trace
4814 * and run native code for every object and transition.
4815 */
4816 var objs = [obj, obj, obj, obj,
4817 obj, obj, obj, obj,
4818 dense, dense, dense, dense,
4819 obj, obj, obj, obj,
4820 slow, slow, slow, slow,
4821 dense, dense, dense, dense,
4822 dense, dense, dense, dense,
4823 slow, slow, slow, slow,
4824 slow, slow, slow, slow,
4825 obj, obj, obj, obj];
4826
4827 var counter = 0;
4828
4829 for (var i = 0, sz = objs.length; i < sz; i++)
4830 {
4831 var o = objs[i];
4832 for (var j = 0; j < o.length; j++)
4833 counter++;
4834 }
4835
4836 return counter;
4837 }
4838 testChangingObjectWithLength.expected = 400;
4839 testChangingObjectWithLength.jitstats = {
4840 recorderAborted: 0,
4841 sideExitIntoInterpreter: 15 // empirically determined
4842 };
4843 test(testChangingObjectWithLength);
4844
4845 function testNEWINIT()
4846 {
4847 var a;
4848 for (var i = 0; i < 10; ++i)
4849 a = [{}];
4850 return uneval(a);
4851 }
4852 testNEWINIT.expected = "[{}]";
4853 test(testNEWINIT);
4854
4855 function testNEWINIT_DOUBLE()
4856 {
4857 for (var z = 0; z < 2; ++z) { ({ 0.1: null })}
4858 return "ok";
4859 }
4860 testNEWINIT_DOUBLE.expected = "ok";
4861 test(testNEWINIT_DOUBLE);
4862
4863 function testIntOverflow() {
4864 // int32_max - 7
4865 var ival = 2147483647 - 7;
4866 for (var i = 0; i < 30; i++) {
4867 ival += 2;
4868 }
4869 return (ival < 2147483647);
4870 }
4871 testIntOverflow.expected = false;
4872 testIntOverflow.jitstats = {
4873 recorderStarted: 2,
4874 recorderAborted: 0,
4875 traceCompleted: 2,
4876 traceTriggered: 2,
4877 };
4878 test(testIntOverflow);
4879
4880 function testIntUnderflow() {
4881 // int32_min + 8
4882 var ival = -2147483648 + 8;
4883 for (var i = 0; i < 30; i++) {
4884 ival -= 2;
4885 }
4886 return (ival > -2147483648);
4887 }
4888 testIntUnderflow.expected = false;
4889 testIntUnderflow.jitstats = {
4890 recorderStarted: 2,
4891 recorderAborted: 0,
4892 traceCompleted: 2,
4893 traceTriggered: 2,
4894 };
4895 test(testIntUnderflow);
4896
4897 function testCALLELEM()
4898 {
4899 function f() {
4900 return 5;
4901 }
4902
4903 function g() {
4904 return 7;
4905 }
4906
4907 var x = [f,f,f,f,g];
4908 var y = 0;
4909 for (var i = 0; i < 5; ++i)
4910 y = x[i]();
4911 return y;
4912 }
4913 testCALLELEM.expected = 7;
4914 test(testCALLELEM);
4915
4916 function testNewString()
4917 {
4918 var o = { toString: function() { return "string"; } };
4919 var r = [];
4920 for (var i = 0; i < 5; i++)
4921 r.push(typeof new String(o));
4922 for (var i = 0; i < 5; i++)
4923 r.push(typeof new String(3));
4924 for (var i = 0; i < 5; i++)
4925 r.push(typeof new String(2.5));
4926 for (var i = 0; i < 5; i++)
4927 r.push(typeof new String("string"));
4928 for (var i = 0; i < 5; i++)
4929 r.push(typeof new String(null));
4930 for (var i = 0; i < 5; i++)
4931 r.push(typeof new String(true));
4932 for (var i = 0; i < 5; i++)
4933 r.push(typeof new String(undefined));
4934 return r.length === 35 && r.every(function(v) { return v === "object"; });
4935 }
4936 testNewString.expected = true;
4937 testNewString.jitstats = {
4938 recorderStarted: 7,
4939 recorderAborted: 0,
4940 traceCompleted: 7,
4941 sideExitIntoInterpreter: 7
4942 };
4943 test(testNewString);
4944
4945 function testWhileObjectOrNull()
4946 {
4947 try
4948 {
4949 for (var i = 0; i < 3; i++)
4950 {
4951 var o = { p: { p: null } };
4952 while (o.p)
4953 o = o.p;
4954 }
4955 return "pass";
4956 }
4957 catch (e)
4958 {
4959 return "threw exception: " + e;
4960 }
4961 }
4962 testWhileObjectOrNull.expected = "pass";
4963 test(testWhileObjectOrNull);
4964
4965 function testDenseArrayProp()
4966 {
4967 [].__proto__.x = 1;
4968 ({}).__proto__.x = 2;
4969 var a = [[],[],[],({}).__proto__];
4970 for (var i = 0; i < a.length; ++i)
4971 uneval(a[i].x);
4972 delete [].__proto__.x;
4973 delete ({}).__proto__.x;
4974 return "ok";
4975 }
4976 testDenseArrayProp.expected = "ok";
4977 test(testDenseArrayProp);
4978
4979 function testNewWithNonNativeProto()
4980 {
4981 function f() { }
4982 var a = f.prototype = [];
4983 for (var i = 0; i < 5; i++)
4984 var o = new f();
4985 return Object.getPrototypeOf(o) === a && o.splice === Array.prototype.splice;
4986 }
4987 testNewWithNonNativeProto.expected = true;
4988 testNewWithNonNativeProto.jitstats = {
4989 recorderStarted: 1,
4990 recorderAborted: 0,
4991 sideExitIntoInterpreter: 1
4992 };
4993 test(testNewWithNonNativeProto);
4994
4995 function testLengthOnNonNativeProto()
4996 {
4997 var o = {};
4998 o.__proto__ = [3];
4999 for (var j = 0; j < 5; j++)
5000 o[0];
5001
5002 var o2 = {};
5003 o2.__proto__ = [];
5004 for (var j = 0; j < 5; j++)
5005 o2.length;
5006
5007 function foo() { }
5008 foo.__proto__ = [];
5009 for (var j = 0; j < 5; j++)
5010 foo.length;
5011
5012 return "no assertion";
5013 }
5014 testLengthOnNonNativeProto.expected = "no assertion";
5015 test(testLengthOnNonNativeProto);
5016
5017 function testDeepPropertyShadowing()
5018 {
5019 function h(node) {
5020 var x = 0;
5021 while (node) {
5022 x++;
5023 node = node.parent;
5024 }
5025 return x;
5026 }
5027 var tree = {__proto__: {__proto__: {parent: null}}};
5028 h(tree);
5029 h(tree);
5030 tree.parent = {};
5031 assertEq(h(tree), 2);
5032 }
5033 test(testDeepPropertyShadowing);
5034
5035 // Complicated whitebox test for bug 487845.
5036 function testGlobalShapeChangeAfterDeepBail() {
5037 function f(name) {
5038 this[name] = 1; // may change global shape
5039 for (var i = 0; i < 4; i++)
5040 ; // MonitorLoopEdge eventually triggers assertion
5041 }
5042
5043 // When i==3, deep-bail, then change global shape enough times to exhaust
5044 // the array of GlobalStates.
5045 var arr = [[], [], [], ["bug0", "bug1", "bug2", "bug3", "bug4"]];
5046 for (var i = 0; i < arr.length; i++)
5047 arr[i].forEach(f);
5048 }
5049 test(testGlobalShapeChangeAfterDeepBail);
5050 for (let i = 0; i < 5; i++)
5051 delete this["bug" + i];
5052
5053 function testFunctionIdentityChange()
5054 {
5055 function a() {}
5056 function b() {}
5057
5058 var o = { a: a, b: b };
5059
5060 for (var prop in o)
5061 {
5062 for (var i = 0; i < 1000; i++)
5063 o[prop]();
5064 }
5065
5066 return true;
5067 }
5068 testFunctionIdentityChange.expected = true;
5069 testFunctionIdentityChange.jitstats = {
5070 recorderStarted: 2,
5071 traceCompleted: 2,
5072 sideExitIntoInterpreter: 3
5073 };
5074 test(testFunctionIdentityChange);
5075
5076 function testStringObjectLength() {
5077 var x = new String("foo"), y = 0;
5078 for (var i = 0; i < 10; ++i)
5079 y = x.length;
5080 return y;
5081 }
5082 testStringObjectLength.expected = 3;
5083 test(testStringObjectLength);
5084
5085 var _quit;
5086 function testNestedDeepBail()
5087 {
5088 _quit = false;
5089 function loop() {
5090 for (var i = 0; i < 4; i++)
5091 ;
5092 }
5093 loop();
5094
5095 function f() {
5096 loop();
5097 _quit = true;
5098 }
5099 var stk = [[1], [], [], [], []];
5100 while (!_quit)
5101 stk.pop().forEach(f);
5102 }
5103 test(testNestedDeepBail);
5104 delete _quit;
5105
5106 function testSlowNativeCtor() {
5107 for (var i = 0; i < 4; i++)
5108 new Date().valueOf();
5109 }
5110 test(testSlowNativeCtor);
5111
5112 function testSlowNativeBail() {
5113 var a = ['0', '1', '2', '3', '+'];
5114 try {
5115 for (var i = 0; i < a.length; i++)
5116 new RegExp(a[i]);
5117 } catch (exc) {
5118 assertEq(""+exc.stack.match(/^RegExp/), "RegExp");
5119 }
5120 }
5121 test(testSlowNativeBail);
5122
5123 /* Test the proper operation of the left shift operator. This is especially
5124 * important on ARM as an explicit mask is required at the native instruction
5125 * level. */
5126 function testShiftLeft()
5127 {
5128 var r = [];
5129 var i = 0;
5130 var j = 0;
5131
5132 var shifts = [0,1,7,8,15,16,23,24,31];
5133
5134 /* Samples from the simple shift range. */
5135 for (i = 0; i < shifts.length; i++)
5136 r[j++] = 1 << shifts[i];
5137
5138 /* Samples outside the normal shift range. */
5139 for (i = 0; i < shifts.length; i++)
5140 r[j++] = 1 << (shifts[i] + 32);
5141
5142 /* Samples far outside the normal shift range. */
5143 for (i = 0; i < shifts.length; i++)
5144 r[j++] = 1 << (shifts[i] + 224);
5145 for (i = 0; i < shifts.length; i++)
5146 r[j++] = 1 << (shifts[i] + 256);
5147
5148 return r.join(",");
5149 }
5150 testShiftLeft.expected =
5151 "1,2,128,256,32768,65536,8388608,16777216,-2147483648,"+
5152 "1,2,128,256,32768,65536,8388608,16777216,-2147483648,"+
5153 "1,2,128,256,32768,65536,8388608,16777216,-2147483648,"+
5154 "1,2,128,256,32768,65536,8388608,16777216,-2147483648";
5155 test(testShiftLeft);
5156
5157 /* Test the proper operation of the logical right shift operator. This is
5158 * especially important on ARM as an explicit mask is required at the native
5159 * instruction level. */
5160 function testShiftRightLogical()
5161 {
5162 var r = [];
5163 var i = 0;
5164 var j = 0;
5165
5166 var shifts = [0,1,7,8,15,16,23,24,31];
5167
5168 /* Samples from the simple shift range. */
5169 for (i = 0; i < shifts.length; i++)
5170 r[j++] = -2147483648 >>> shifts[i];
5171
5172 /* Samples outside the normal shift range. */
5173 for (i = 0; i < shifts.length; i++)
5174 r[j++] = -2147483648 >>> (shifts[i] + 32);
5175
5176 /* Samples far outside the normal shift range. */
5177 for (i = 0; i < shifts.length; i++)
5178 r[j++] = -2147483648 >>> (shifts[i] + 224);
5179 for (i = 0; i < shifts.length; i++)
5180 r[j++] = -2147483648 >>> (shifts[i] + 256);
5181
5182 return r.join(",");
5183 }
5184 /* Note: Arguments to the ">>>" operator are converted to unsigned 32-bit
5185 * integers during evaluation. As a result, -2147483648 >>> 0 evaluates to the
5186 * unsigned interpretation of the same value, which is 2147483648. */
5187 testShiftRightLogical.expected =
5188 "2147483648,1073741824,16777216,8388608,65536,32768,256,128,1,"+
5189 "2147483648,1073741824,16777216,8388608,65536,32768,256,128,1,"+
5190 "2147483648,1073741824,16777216,8388608,65536,32768,256,128,1,"+
5191 "2147483648,1073741824,16777216,8388608,65536,32768,256,128,1";
5192 test(testShiftRightLogical);
5193
5194 /* Test the proper operation of the arithmetic right shift operator. This is
5195 * especially important on ARM as an explicit mask is required at the native
5196 * instruction level. */
5197 function testShiftRightArithmetic()
5198 {
5199 var r = [];
5200 var i = 0;
5201 var j = 0;
5202
5203 var shifts = [0,1,7,8,15,16,23,24,31];
5204
5205 /* Samples from the simple shift range. */
5206 for (i = 0; i < shifts.length; i++)
5207 r[j++] = -2147483648 >> shifts[i];
5208
5209 /* Samples outside the normal shift range. */
5210 for (i = 0; i < shifts.length; i++)
5211 r[j++] = -2147483648 >> (shifts[i] + 32);
5212
5213 /* Samples far outside the normal shift range. */
5214 for (i = 0; i < shifts.length; i++)
5215 r[j++] = -2147483648 >> (shifts[i] + 224);
5216 for (i = 0; i < shifts.length; i++)
5217 r[j++] = -2147483648 >> (shifts[i] + 256);
5218
5219 return r.join(",");
5220 }
5221 testShiftRightArithmetic.expected =
5222 "-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+
5223 "-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+
5224 "-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+
5225 "-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1";
5226 test(testShiftRightArithmetic);
5227
5228 function testStringConstructorWithExtraArg() {
5229 for (let i = 0; i < 5; ++i)
5230 new String(new String(), 2);
5231 return "ok";
5232 }
5233 testStringConstructorWithExtraArg.expected = "ok";
5234 test(testStringConstructorWithExtraArg);
5235
5236 function testConstructorBail() {
5237 for (let i = 0; i < 5; ++i) new Number(/x/);
5238 }
5239 test(testConstructorBail);
5240
5241 function testNewArrayCount()
5242 {
5243 var a = [];
5244 for (var i = 0; i < 5; i++)
5245 a = [0];
5246 assertEq(a.__count__, 1);
5247 for (var i = 0; i < 5; i++)
5248 a = [0, , 2];
5249 assertEq(a.__count__, 2);
5250 }
5251 test(testNewArrayCount);
5252
5253 function testNewArrayCount2() {
5254 var x = 0;
5255 for (var i = 0; i < 10; ++i)
5256 x = new Array(1,2,3).__count__;
5257 return x;
5258 }
5259 testNewArrayCount2.expected = 3;
5260 test(testNewArrayCount2);
5261
5262 /*****************************************************************************
5263 * *
5264 * _____ _ _ _____ ______ _____ _______ *
5265 * |_ _| \ | |/ ____| ____| __ \__ __| *
5266 * | | | \| | (___ | |__ | |__) | | | *
5267 * | | | . ` |\___ \| __| | _ / | | *
5268 * _| |_| |\ |____) | |____| | \ \ | | *
5269 * |_____|_| \_|_____/|______|_| \_\ |_| *
5270 * *
5271 * *
5272 * _______ ______ _____ _______ _____ *
5273 * |__ __| ____|/ ____|__ __/ ____| *
5274 * | | | |__ | (___ | | | (___ *
5275 * | | | __| \___ \ | | \___ \ *
5276 * | | | |____ ____) | | | ____) | *
5277 * |_| |______|_____/ |_| |_____/ *
5278 * *
5279 * *
5280 * ____ ______ ______ ____ _____ ______ _ _ ______ _____ ______ *
5281 * | _ \| ____| ____/ __ \| __ \| ____| | | | | ____| __ \| ____| *
5282 * | |_) | |__ | |__ | | | | |__) | |__ | |__| | |__ | |__) | |__ *
5283 * | _ <| __| | __|| | | | _ /| __| | __ | __| | _ /| __| *
5284 * | |_) | |____| | | |__| | | \ \| |____ | | | | |____| | \ \| |____ *
5285 * |____/|______|_| \____/|_| \_\______| |_| |_|______|_| \_\______| *
5286 * *
5287 *****************************************************************************/
5288
5289 // math-trace-tests.js is a separate file here.
5290
5291 // MANDELBROT STUFF deleted
5292
5293 /*****************************************************************************
5294 * _ _ ____ _ __ ____ _____ ______ *
5295 * | \ | |/ __ \ | \/ |/ __ \| __ \| ____| *
5296 * | \| | | | | | \ / | | | | |__) | |__ *
5297 * | . ` | | | | | |\/| | | | | _ /| __| *
5298 * | |\ | |__| | | | | | |__| | | \ \| |____ *
5299 * |_| \_|\____/ |_| |_|\____/|_| \_\______| *
5300 * *
5301 * _______ ______ _____ _______ _____ *
5302 * |__ __| ____|/ ____|__ __/ ____| *
5303 * | | | |__ | (___ | | | (___ *
5304 * | | | __| \___ \ | | \___ \ *
5305 * | | | |____ ____) | | | ____) | *
5306 * |_| |______|_____/ |_| |_____/ *
5307 * *
5308 * ______ _______ ______ _____ _ _ ______ _____ ______ _ *
5309 * /\ | ____|__ __| ____| __ \ | | | | ____| __ \| ____| | *
5310 * / \ | |__ | | | |__ | |__) | | |__| | |__ | |__) | |__ | | *
5311 * / /\ \ | __| | | | __| | _ / | __ | __| | _ /| __| | | *
5312 * / ____ \| | | | | |____| | \ \ | | | | |____| | \ \| |____|_| *
5313 * /_/ \_\_| |_| |______|_| \_\ |_| |_|______|_| \_\______(_) *
5314 * *
5315 *****************************************************************************/
5316
5317 /* NOTE: Keep this test last, since it screws up all for...in loops after it. */
5318 function testGlobalProtoAccess() {
5319 return "ok";
5320 }
5321 this.__proto__.a = 3; for (var j = 0; j < 4; ++j) { [a]; }
5322 testGlobalProtoAccess.expected = "ok";
5323 test(testGlobalProtoAccess);
5324
5325 jit(false);
5326
5327 /* Keep these at the end so that we can see the summary after the trace-debug spew. */
5328 if (gReportSummary) {
5329 print("\npassed:", passes.length && passes.join(","));
5330 print("\nFAILED:", fails.length && fails.join(","));
5331 }