OLD | NEW |
| (Empty) |
1 // Copyright 2010 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 // Regression test for bugs when deoptimizing after assignments in effect | |
29 // contexts. | |
30 | |
31 // Bug 989 is that there was an extra value on the expression stack when | |
32 // deoptimizing after an assignment in effect context (the value of the | |
33 // assignment was lingering). This is hard to observe in the unoptimized | |
34 // code. | |
35 // | |
36 // This test uses comma expressions to put assignments in effect contexts, | |
37 // references to deleted global variables to force deoptimization, and | |
38 // function calls to observe an extra value. | |
39 | |
40 function first(x, y) { return x; } | |
41 var y = 0; | |
42 var o = {}; | |
43 o.x = 0; | |
44 o[0] = 0; | |
45 | |
46 // Assignment to global variable. | |
47 x0 = 0; | |
48 function test0() { return first((y = 1, typeof x0), 2); } | |
49 // Call the function once to compile it. | |
50 assertEquals('number', test0()); | |
51 // Delete to force deoptimization on the next call. | |
52 delete x0; | |
53 assertEquals('undefined', test0()); | |
54 | |
55 // Compound assignment to global variable. | |
56 x1 = 0; | |
57 function test1() { return first((y += 1, typeof x1), 2); } | |
58 assertEquals('number', test1(), 'test1 before'); | |
59 delete x1; | |
60 assertEquals('undefined', test1(), 'test1 after'); | |
61 | |
62 // Pre and post-increment of global variable. | |
63 x2 = 0; | |
64 function test2() { return first((++y, typeof x2), 2); } | |
65 assertEquals('number', test2(), 'test2 before'); | |
66 delete x2; | |
67 assertEquals('undefined', test2(), 'test2 after'); | |
68 | |
69 x3 = 0; | |
70 function test3() { return first((y++, typeof x3), 2); } | |
71 assertEquals('number', test3(), 'test3 before'); | |
72 delete x3; | |
73 assertEquals('undefined', test3(), 'test3 after'); | |
74 | |
75 | |
76 // Assignment, compound assignment, and pre and post-increment of named | |
77 // properties. | |
78 x4 = 0; | |
79 function test4() { return first((o.x = 1, typeof x4), 2); } | |
80 assertEquals('number', test4()); | |
81 delete x4; | |
82 assertEquals('undefined', test4()); | |
83 | |
84 x5 = 0; | |
85 function test5() { return first((o.x += 1, typeof x5), 2); } | |
86 assertEquals('number', test5()); | |
87 delete x5; | |
88 assertEquals('undefined', test5()); | |
89 | |
90 x6 = 0; | |
91 function test6() { return first((++o.x, typeof x6), 2); } | |
92 assertEquals('number', test6()); | |
93 delete x6; | |
94 assertEquals('undefined', test6()); | |
95 | |
96 x7 = 0; | |
97 function test7() { return first((o.x++, typeof x7), 2); } | |
98 assertEquals('number', test7()); | |
99 delete x7; | |
100 assertEquals('undefined', test7()); | |
101 | |
102 | |
103 // Assignment, compound assignment, and pre and post-increment of indexed | |
104 // properties. | |
105 x8 = 0; | |
106 function test8(index) { return first((o[index] = 1, typeof x8), 2); } | |
107 assertEquals('number', test8()); | |
108 delete x8; | |
109 assertEquals('undefined', test8()); | |
110 | |
111 x9 = 0; | |
112 function test9(index) { return first((o[index] += 1, typeof x9), 2); } | |
113 assertEquals('number', test9()); | |
114 delete x9; | |
115 assertEquals('undefined', test9()); | |
116 | |
117 x10 = 0; | |
118 function test10(index) { return first((++o[index], typeof x10), 2); } | |
119 assertEquals('number', test10()); | |
120 delete x10; | |
121 assertEquals('undefined', test10()); | |
122 | |
123 x11 = 0; | |
124 function test11(index) { return first((o[index]++, typeof x11), 2); } | |
125 assertEquals('number', test11()); | |
126 delete x11; | |
127 assertEquals('undefined', test11()); | |
OLD | NEW |