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
40function first(x, y) { return x; }
41var y = 0;
42var o = {};
43o.x = 0;
44o[0] = 0;
45
46// Assignment to global variable.
47x0 = 0;
48function test0() { return first((y = 1, typeof x0), 2); }
49// Call the function once to compile it.
50assertEquals('number', test0());
51// Delete to force deoptimization on the next call.
52delete x0;
53assertEquals('undefined', test0());
54
55// Compound assignment to global variable.
56x1 = 0;
57function test1() { return first((y += 1, typeof x1), 2); }
58assertEquals('number', test1(), 'test1 before');
59delete x1;
60assertEquals('undefined', test1(), 'test1 after');
61
62// Pre and post-increment of global variable.
63x2 = 0;
64function test2() { return first((++y, typeof x2), 2); }
65assertEquals('number', test2(), 'test2 before');
66delete x2;
67assertEquals('undefined', test2(), 'test2 after');
68
69x3 = 0;
70function test3() { return first((y++, typeof x3), 2); }
71assertEquals('number', test3(), 'test3 before');
72delete x3;
73assertEquals('undefined', test3(), 'test3 after');
74
75
76// Assignment, compound assignment, and pre and post-increment of named
77// properties.
78x4 = 0;
79function test4() { return first((o.x = 1, typeof x4), 2); }
80assertEquals('number', test4());
81delete x4;
82assertEquals('undefined', test4());
83
84x5 = 0;
85function test5() { return first((o.x += 1, typeof x5), 2); }
86assertEquals('number', test5());
87delete x5;
88assertEquals('undefined', test5());
89
90x6 = 0;
91function test6() { return first((++o.x, typeof x6), 2); }
92assertEquals('number', test6());
93delete x6;
94assertEquals('undefined', test6());
95
96x7 = 0;
97function test7() { return first((o.x++, typeof x7), 2); }
98assertEquals('number', test7());
99delete x7;
100assertEquals('undefined', test7());
101
102
103// Assignment, compound assignment, and pre and post-increment of indexed
104// properties.
105x8 = 0;
106function test8(index) { return first((o[index] = 1, typeof x8), 2); }
107assertEquals('number', test8());
108delete x8;
109assertEquals('undefined', test8());
110
111x9 = 0;
112function test9(index) { return first((o[index] += 1, typeof x9), 2); }
113assertEquals('number', test9());
114delete x9;
115assertEquals('undefined', test9());
116
117x10 = 0;
118function test10(index) { return first((++o[index], typeof x10), 2); }
119assertEquals('number', test10());
120delete x10;
121assertEquals('undefined', test10());
122
123x11 = 0;
124function test11(index) { return first((o[index]++, typeof x11), 2); }
125assertEquals('number', test11());
126delete x11;
127assertEquals('undefined', test11());
128