regress-1624.js revision 5d4cdbf7a67d3662fa0bee4efdb7edd8daec9b0b
1// Copyright 2012 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// Test that global eval calls of strict code (independent from whether being
29// direct or indirect) have their own lexical and variable environment.
30
31var evil = eval;
32
33// Test global direct strict eval.
34// Expects new environment.
35var no_touch = 0;
36eval('"use strict"; var no_touch = 1;');
37assertSame(0, no_touch);
38
39// Test global indirect strict eval.
40// Expects new environment.
41var no_touch = 0;
42evil('"use strict"; var no_touch = 2;');
43assertSame(0, no_touch);
44
45// Test global direct non-strict eval.
46// Expects global environment.
47var no_touch = 0;
48eval('var no_touch = 3;');
49assertSame(3, no_touch);
50
51// Test global indirect non-strict eval.
52// Expects global environment.
53var no_touch = 0;
54evil('var no_touch = 4;');
55assertSame(4, no_touch);
56
57// Test non-global direct strict eval in non-strict function.
58// Expects new environment.
59var no_touch = 0;
60(function() {
61  var no_touch = 0;
62  eval('"use strict"; var no_touch = 5;');
63  assertSame(0, no_touch);
64})()
65assertSame(0, no_touch);
66
67// Test non-global indirect strict eval in non-strict function.
68// Expects new environment.
69var no_touch = 0;
70(function() {
71  var no_touch = 0;
72  evil('"use strict"; var no_touch = 6;');
73  assertSame(0, no_touch);
74})()
75assertSame(0, no_touch);
76
77// Test non-global direct non-strict eval in non-strict function.
78// Expects function environment.
79var no_touch = 0;
80(function() {
81  var no_touch = 0;
82  eval('var no_touch = 7;');
83  assertSame(7, no_touch);
84})()
85assertSame(0, no_touch);
86
87// Test non-global indirect non-strict eval in non-strict function.
88// Expects global environment.
89var no_touch = 0;
90(function() {
91  var no_touch = 0;
92  evil('var no_touch = 8;');
93  assertSame(0, no_touch);
94})()
95assertSame(8, no_touch);
96
97// Test non-global direct strict eval in strict function.
98// Expects new environment.
99var no_touch = 0;
100(function() {
101  "use strict";
102  var no_touch = 0;
103  eval('"use strict"; var no_touch = 9;');
104  assertSame(0, no_touch);
105})()
106assertSame(0, no_touch);
107
108// Test non-global indirect strict eval in strict function.
109// Expects new environment.
110var no_touch = 0;
111(function() {
112  "use strict";
113  var no_touch = 0;
114  evil('"use strict"; var no_touch = 10;');
115  assertSame(0, no_touch);
116})()
117assertSame(0, no_touch);
118
119// Test non-global direct non-strict eval in strict function.
120// Expects new environment.
121var no_touch = 0;
122(function() {
123  "use strict";
124  var no_touch = 0;
125  eval('var no_touch = 11;');
126  assertSame(0, no_touch);
127})()
128assertSame(0, no_touch);
129
130// Test non-global indirect non-strict eval in strict function.
131// Expects global environment.
132var no_touch = 0;
133(function() {
134  "use strict";
135  var no_touch = 0;
136  evil('var no_touch = 12;');
137  assertSame(0, no_touch);
138})()
139assertSame(12, no_touch);
140