1 // Copyright 2009 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
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.
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.
28 // Test handling of const variables in various settings.
33 x = 42; // should be ignored
34 return x; // force x into context
36 x = 43; // should be ignored
37 assertEquals(undefined, g());
38 x = 44; // should be ignored
40 x = 45; // should be ignored
51 x = 42; // should be ignored
52 return x; // force x into context
55 x = 43; // should be ignored
56 assertEquals(undefined, g());
57 x = 44; // should be ignored
59 x = 45; // should be ignored
70 return x; // force x into context
72 x = 43; // should be ignored
73 assertEquals(undefined, g("x = 42;"));
74 x = 44; // should be ignored
76 x = 45; // should be ignored
77 assertEquals(0, g("x = 46;"));
88 return x; // force x into context
91 x = 43; // should be ignored
92 assertEquals(undefined, g("x = 42;"));
93 x = 44; // should be ignored
95 x = 45; // should be ignored
96 assertEquals(0, g("x = 46;"));
105 x = 42; // assign to global x, or to const x
108 x = 43; // declare global x
109 assertEquals(42, g());
110 x = 44; // assign to global x
112 x = 45; // should be ignored (assign to const x)
113 assertEquals(0, g());
123 x = 42; // assign to global x, or to const x
127 x = 43; // declare global x
128 assertEquals(42, g());
129 x = 44; // assign to global x
131 x = 45; // should be ignored (assign to const x)
132 assertEquals(0, g());
144 x = 43; // declare global x
145 assertEquals(42, g("x = 42;"));
146 x = 44; // assign to global x
148 x = 45; // should be ignored (assign to const x)
149 assertEquals(0, g("x = 46;"));
163 x = 43; // declare global x
164 assertEquals(42, g("x = 42;"));
165 x = 44; // assign to global x
167 x = 45; // should be ignored (assign to const x)
168 assertEquals(0, g("x = 46;"));