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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     2 // Test various code paths associated with fused getprop/poly inlining.
     4 function A(a) { this.a = a; }
     5 A.prototype.foo = function (x) { return (x % 3) + this.a; };
     7 function B(b) { this.b = b; }
     8 B.prototype.foo = function (x) { return (x % 3) + this.b + 1; };
    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;
    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 }
    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 }
    46 // Make an array of instance.
    47 var resultArray = [0];
    48 var arr = makeArray(30000);
    50 // Run runner for a bit with C.prototype.foo being C_foo1
    51 runner(arr, resultArray, 100);
    53 // Run runner for a bit with C.prototype.foo being C_foo2
    54 C.prototype.foo = C_foo2;
    55 runner(arr, resultArray, 100);
    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 }
    66 // Check results.
    67 assertEq(gotError, true);
    68 assertEq(resultArray[0], 108859);

mercurial