summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/eval/exhaustive-fun-strictcaller-indirect-normalcode.js
blob: 8b3016d2ea4ad7b8f18c73c6b8e2b13b90dd7943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/

//-----------------------------------------------------------------------------
var BUGNUMBER = 514568;
var summary = "eval in all its myriad flavors";

print(BUGNUMBER + ": " + summary);

/**************
 * BEGIN TEST *
 **************/

var x = 17;
function globalX() { return x; }
var y = 42;
function globalY() { return y; }

var ev = eval;

function testX()
{
  "use strict";

  var x = 2;
  var xcode =
    "var x = 4;" +
    "function actX(action)" +
    "{" +
    "  switch (action)" +
    "  {" +
    "    case 'get':" +
    "      return x;" +
    "    case 'set1':" +
    "      x = 9;" +
    "      return;" +
    "    case 'set2':" +
    "      x = 23;" +
    "      return;" +
    "    case 'delete':" +
    "      try { return eval('delete x'); }" +
    "      catch (e) { return e.name; }" +
    "  }" +
    "}" +
    "actX;";

  var local0 = x;
  var global0 = globalX();

  var f = ev(xcode);

  var inner1 = f("get");
  var local1 = x;
  var global1 = globalX();

  x = 7;
  var inner2 = f("get");
  var local2 = x;
  var global2 = globalX();

  f("set1");
  var inner3 = f("get");
  var local3 = x;
  var global3 = globalX();

  var del = f("delete");
  var inner4 = f("get");
  var local4 = x;
  var global4 = globalX();

  f("set2");
  var inner5 = f("get");
  var local5 = x;
  var global5 = globalX();

  return {
           local0: local0, global0: global0,
           inner1: inner1, local1: local1, global1: global1,
           inner2: inner2, local2: local2, global2: global2,
           inner3: inner3, local3: local3, global3: global3,
           del: del,
           inner4: inner4, local4: local4, global4: global4,
           inner5: inner5, local5: local5, global5: global5,
         };
}

var resultsX = testX();

assertEq(resultsX.local0, 2);
assertEq(resultsX.global0, 17);

assertEq(resultsX.inner1, 4);
assertEq(resultsX.local1, 2);
assertEq(resultsX.global1, 4);

assertEq(resultsX.inner2, 4);
assertEq(resultsX.local2, 7);
assertEq(resultsX.global2, 4);

assertEq(resultsX.inner3, 9);
assertEq(resultsX.local3, 7);
assertEq(resultsX.global3, 9);

assertEq(resultsX.del, false);

assertEq(resultsX.inner4, 9);
assertEq(resultsX.local4, 7);
assertEq(resultsX.global4, 9);

assertEq(resultsX.inner5, 23);
assertEq(resultsX.local5, 7);
assertEq(resultsX.global5, 23);


function testY()
{
  "use strict";

  var ycode =
    "var y = 5;" +
    "function actY(action)" +
    "{" +
    "  switch (action)" +
    "  {" +
    "    case 'get':" +
    "      return y;" +
    "    case 'set1':" +
    "      y = 2;" +
    "      return;" +
    "    case 'set2':" +
    "      y = 71;" +
    "      return;" +
    "    case 'delete':" +
    "      try { return eval('delete y'); }" +
    "      catch (e) { return e.name; }" +
    "  }" +
    "}" +
    "actY;";

  var local0 = y;
  var global0 = globalY();

  var f = ev(ycode);

  var inner1 = f("get");
  var local1 = y;
  var global1 = globalY();

  y = 8;
  var inner2 = f("get");
  var local2 = y;
  var global2 = globalY();

  f("set1");
  var inner3 = f("get");
  var local3 = y;
  var global3 = globalY();

  var del = f("delete");
  var inner4 = f("get");
  var local4 = y;
  var global4 = globalY();

  f("set2");
  var inner5 = f("get");
  var local5 = y;
  var global5 = globalY();

  return {
           local0: local0, global0: global0,
           inner1: inner1, local1: local1, global1: global1,
           inner2: inner2, local2: local2, global2: global2,
           inner3: inner3, local3: local3, global3: global3,
           del: del,
           inner4: inner4, local4: local4, global4: global4,
           inner5: inner5, local5: local5, global5: global5,
         };
}

var resultsY = testY();

assertEq(resultsY.local0, 42);
assertEq(resultsY.global0, 42);

assertEq(resultsY.inner1, 5);
assertEq(resultsY.local1, 5);
assertEq(resultsY.global1, 5);

assertEq(resultsY.inner2, 8);
assertEq(resultsY.local2, 8);
assertEq(resultsY.global2, 8);

assertEq(resultsY.inner3, 2);
assertEq(resultsY.local3, 2);
assertEq(resultsY.global3, 2);

assertEq(resultsY.del, false);

assertEq(resultsY.inner4, 2);
assertEq(resultsY.local4, 2);
assertEq(resultsY.global4, 2);

assertEq(resultsY.inner5, 71);
assertEq(resultsY.local5, 71);
assertEq(resultsY.global5, 71);

/******************************************************************************/

if (typeof reportCompare === "function")
  reportCompare(true, true);

print("Tests complete!");