tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / js / script-tests / array-type-speculation.js
1 description(
2 "This tests that storing into something that is not array does not crash."
3 );
4
5 theCode = "\n\
6 function storeFooByValOrDoArithmetic(o, p1, p2, v) {\n\
7     var x;\n\
8     if (p1) {\n\
9         x = o.foo;\n\
10     } else {\n\
11         x = v;\n\
12         if (p2) {\n\
13             x--;\n\
14         } else {\n\
15             x++;\n\
16         }\n\
17     }\n\
18     x[5] = \"foo\";\n\
19 }\n\
20 \n\
21 function runTheTest(p1, p2) {\n\
22     var o = new Object();\n\
23     o.foo = new Object();\n\
24     storeFooByValOrDoArithmetic(o, p1, p2, 1);\n\
25     return o.foo[5];\n\
26 }\n";
27
28 function runWithPredicates(predicateArray) {
29     var myCode = theCode;
30     
31     for (var i = 0; i < predicateArray.length; ++i) {
32         myCode += "result = runTheTest(" + predicateArray[i][0] + ", " + predicateArray[i][1] + ");\n";
33         myCode += "shouldBe(\"result\", " + predicateArray[i][2] + ");\n";
34     }
35     
36     eval(myCode);
37 }
38
39 runWithPredicates([[true, true, "\"\\\"foo\\\"\""], [true, false, "\"\\\"foo\\\"\""], [false, true, "\"undefined\""], [false, false, "\"undefined\""]]);
40 runWithPredicates([[false, false, "\"undefined\""], [true, false, "\"\\\"foo\\\"\""], [false, true, "\"undefined\""], [true, true, "\"\\\"foo\\\"\""]]);
41 runWithPredicates([[true, true, "\"\\\"foo\\\"\""], [false, true, "\"undefined\""], [true, false, "\"\\\"foo\\\"\""], [false, false, "\"undefined\""]]);
42 runWithPredicates([[false, false, "\"undefined\""], [false, true, "\"undefined\""], [true, false, "\"\\\"foo\\\"\""], [true, true, "\"\\\"foo\\\"\""]]);