Home | History | Annotate | Download | only in webkit
      1 // Copyright 2013 the V8 project authors. All rights reserved.
      2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions
      6 // are met:
      7 // 1.  Redistributions of source code must retain the above copyright
      8 //     notice, this list of conditions and the following disclaimer.
      9 // 2.  Redistributions in binary form must reproduce the above copyright
     10 //     notice, this list of conditions and the following disclaimer in the
     11 //     documentation and/or other materials provided with the distribution.
     12 //
     13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
     14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 
     24 description(
     25 "This tests that the static analysis we use to infer if a variable should be a double doesn't crash."
     26 );
     27 
     28 var grandResult = 0;
     29 
     30 for (var i = 0; i < 256; ++i) {
     31     code  = "function foo(o, a, b) {\n";
     32     code += "    var x = 0;\n";
     33     code += "    var c = a + b;\n";
     34     for (var j = 0; j < 8; ++j)
     35         code += "    var " + String.fromCharCode("d".charCodeAt(0) + j) + " = " + ((i & (1 << ((j / 2) | 0))) ? "0.5" : "0") + ";\n";
     36     code += "    for (var __i = 0; __i < 10; ++__i) {\n";
     37     code += "        if (a + b + 1 > __i) {\n";
     38     code += "            c = d;\n";
     39     code += "            x += c;\n";
     40     code += "        }\n";
     41     code += "        if (a + b + 2 > __i) {\n";
     42     code += "            c = e;\n";
     43     code += "            x += c;\n";
     44     code += "        }\n";
     45     code += "        if (a + b + 3 > __i) {\n";
     46     code += "            c = f;\n";
     47     code += "            x += c;\n";
     48     code += "        }\n";
     49     code += "        if (a + b + 4 > __i) {\n";
     50     code += "            c = g;\n";
     51     code += "            x += c;\n";
     52     code += "        }\n";
     53     code += "        if (a + b + 5 > __i) {\n";
     54     code += "            c = h;\n";
     55     code += "            x += c;\n";
     56     code += "        }\n";
     57     code += "        if (a + b + 6 > __i) {\n";
     58     code += "            c = i;\n";
     59     code += "            x += c;\n";
     60     code += "        }\n";
     61     code += "        if (a + b + 7 > __i) {\n";
     62     code += "            c = j;\n";
     63     code += "            x += c;\n";
     64     code += "        }\n";
     65     code += "        if (a + b + 8 > __i) {\n";
     66     code += "            c = k;\n";
     67     code += "            x += c;\n";
     68     code += "        }\n";
     69     for (var j = 0; j < 8; ++j) {
     70         code += "        if (a + b + " + (9 + j) + " > __i)\n";
     71         code += "            " + String.fromCharCode("d".charCodeAt(0) + j) + " = __i + " + j + " + " + ((i & (1 << (((j / 2) | 0) + 4))) ? "0.5" : "0") + ";\n";
     72     }
     73     code += "    }\n";
     74     code += "    return x + c;\n";
     75     code += "}\n";
     76     code += "\n";
     77     code += "var result = 0;\n"
     78     code += "for (var __j = 0; __j < 100; ++__j) {\n";
     79     code += "    result += foo({}, __j, __j + 1);\n";
     80     code += "}\n";
     81     code += "\n";
     82     code += "result";
     83 
     84     var theResult = eval(code);
     85     debug("Result value is " + theResult);
     86     grandResult += theResult;
     87 }
     88 
     89 shouldBe("grandResult", "14578304");
     90