Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / v8 / test / mjsunit / regress / poly_count_operation.js
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Flags: --allow-natives-syntax --turbo-deoptimization
29
30 var o1 = {x:1};
31 var o2 = {};
32 var deopt_getter = false;
33 var deopt_setter = false;
34
35 function f_mono(o) {
36   return 5 + o.x++;
37 }
38
39 var to_deopt = f_mono;
40
41 var v = 1;
42 var g = 0;
43 var s = 0;
44
45 Object.defineProperty(o2, "x",
46     {get:function() {
47        g++;
48        if (deopt_getter) {
49          deopt_getter = false;
50          %DeoptimizeFunction(to_deopt);
51        }
52        return v;
53      },
54      set:function(new_v) {
55        v = new_v;
56        s++;
57        if (deopt_setter) {
58          deopt_setter = false;
59          %DeoptimizeFunction(to_deopt);
60        }
61      }});
62
63 assertEquals(6, f_mono(o2));
64 assertEquals(1, g);
65 assertEquals(1, s);
66 assertEquals(7, f_mono(o2));
67 assertEquals(2, g);
68 assertEquals(2, s);
69 %OptimizeFunctionOnNextCall(f_mono);
70 deopt_setter = true;
71 assertEquals(8, f_mono(o2));
72 assertEquals(3, g);
73 assertEquals(3, s);
74
75 function f_poly(o) {
76   return 5 + o.x++;
77 }
78
79 v = 1;
80 to_deopt = f_poly;
81
82 f_poly(o1);
83 f_poly(o1);
84 assertEquals(6, f_poly(o2));
85 assertEquals(4, g);
86 assertEquals(4, s);
87 assertEquals(7, f_poly(o2));
88 assertEquals(5, g);
89 assertEquals(5, s);
90 %OptimizeFunctionOnNextCall(f_poly);
91 deopt_setter = true;
92 assertEquals(8, f_poly(o2));
93 assertEquals(6, g);
94 assertEquals(6, s);
95
96 %OptimizeFunctionOnNextCall(f_poly);
97 v = undefined;
98 assertEquals(NaN, f_poly(o2));
99 assertEquals(7, g);
100 assertEquals(7, s);
101
102 function f_pre(o) {
103   return 5 + ++o.x;
104 }
105
106 v = 1;
107 to_deopt = f_pre;
108
109 f_pre(o1);
110 f_pre(o1);
111 assertEquals(7, f_pre(o2));
112 assertEquals(8, g);
113 assertEquals(8, s);
114 assertEquals(8, f_pre(o2));
115 assertEquals(9, g);
116 assertEquals(9, s);
117 %OptimizeFunctionOnNextCall(f_pre);
118 deopt_setter = true;
119 assertEquals(9, f_pre(o2));
120 assertEquals(10, g);
121 assertEquals(10, s);
122
123 %OptimizeFunctionOnNextCall(f_pre);
124 v = undefined;
125 assertEquals(NaN, f_pre(o2));
126 assertEquals(11, g);
127 assertEquals(11, s);
128
129
130 function f_get(o) {
131   return 5 + o.x++;
132 }
133
134 v = 1;
135 to_deopt = f_get;
136
137 f_get(o1);
138 f_get(o1);
139 assertEquals(6, f_get(o2));
140 assertEquals(12, g);
141 assertEquals(12, s);
142 assertEquals(7, f_get(o2));
143 assertEquals(13, g);
144 assertEquals(13, s);
145 %OptimizeFunctionOnNextCall(f_get);
146 deopt_getter = true;
147 assertEquals(8, f_get(o2));
148 assertEquals(14, g);
149 assertEquals(14, s);
150
151 %OptimizeFunctionOnNextCall(f_get);
152 v = undefined;
153 assertEquals(NaN, f_get(o2));
154 assertEquals(15, g);
155 assertEquals(15, s);