Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: mozilla-tests/js1_8_1/trace/trace-test.js

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

Powered by Google App Engine
This is Rietveld 408576698