js/src/jit-test/tests/ion/bug-770309-mcall-bailout.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:fdf15c35c676
1
2 // Test various code paths associated with fused getprop/poly inlining.
3
4 function A(a) { this.a = a; }
5 A.prototype.foo = function (x) { return (x % 3) + this.a; };
6
7 function B(b) { this.b = b; }
8 B.prototype.foo = function (x) { return (x % 3) + this.b + 1; };
9
10 // c.foo() for some (c instanceof C) should always hit the fallback
11 // path of any fused poly inline cache created for it.
12 function C(c) { this.c = c; }
13 var GLOBX = {'x': function (x) {
14 if (x > 29500)
15 throw new Error("ERROR");
16 return 2;
17 }};
18 function C_foo1(x) {
19 return (x % 3) + this.c + GLOBX.x(x) + 1;
20 }
21 function C_foo2(x) {
22 return (x % 3) + this.c + GLOBX.x(x) + 2;
23 }
24 C.prototype.foo = C_foo1;
25
26 // Create an array of As, Bs, and Cs.
27 function makeArray(n) {
28 var classes = [A, B, C];
29 var arr = [];
30 for (var i = 0; i < n; i++) {
31 arr.push(new classes[i % 3](i % 3));
32 }
33 return arr;
34 }
35
36 // Call foo on them, sum up results into first elem of resultArray
37 function runner(arr, resultArray, len) {
38 for (var i = 0; i < len; i++) {
39 // This changes the type of returned value from C.foo(), leading to
40 // a bailout fater the call obj.foo() below.
41 var obj = arr[i];
42 resultArray[0] += obj.foo(i);
43 }
44 }
45
46 // Make an array of instance.
47 var resultArray = [0];
48 var arr = makeArray(30000);
49
50 // Run runner for a bit with C.prototype.foo being C_foo1
51 runner(arr, resultArray, 100);
52
53 // Run runner for a bit with C.prototype.foo being C_foo2
54 C.prototype.foo = C_foo2;
55 runner(arr, resultArray, 100);
56
57 // Run runner for a bit longer to force GLOBX.x to raise
58 // an error inside a call to C.prototype.foo within runner.
59 var gotError = false;
60 try {
61 runner(arr, resultArray, 30000);
62 } catch(err) {
63 gotError = true;
64 }
65
66 // Check results.
67 assertEq(gotError, true);
68 assertEq(resultArray[0], 108859);

mercurial