Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/tests/Bug783797Test.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.javascript.tests;
6
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertSame;
9 import static org.mozilla.javascript.tests.Utils.runWithAllOptimizationLevels;
10
11 import org.junit.Test;
12 import org.mozilla.javascript.Context;
13 import org.mozilla.javascript.ContextAction;
14 import org.mozilla.javascript.Scriptable;
15 import org.mozilla.javascript.ScriptableObject;
16
17 /**
18 * @author André Bargull
19 *
20 */
21 public class Bug783797Test {
22 private interface Action {
23 void run(Context cx, ScriptableObject scope1, ScriptableObject scope2);
24 }
25
26 private static ContextAction action(final String fn, final Action a) {
27 return new ContextAction() {
28 public Object run(Context cx) {
29 ScriptableObject scope1 = cx.initStandardObjects();
30 ScriptableObject scope2 = cx.initStandardObjects();
31 scope1.put("scope2", scope1, scope2);
32
33 eval(cx, scope2, fn);
34 a.run(cx, scope1, scope2);
35
36 return null;
37 }
38 };
39 }
40
41 private static Object eval(Context cx, Scriptable scope, String source) {
42 return cx.evaluateString(scope, source, "<eval>", 1, null);
43 }
44
45 private static void assertTRUE(Object actual) {
46 assertSame(Boolean.TRUE, actual);
47 }
48
49 private static void assertFALSE(Object actual) {
50 assertSame(Boolean.FALSE, actual);
51 }
52
53 @Test
54 public void test_getElem() {
55 String fn = "function test(){ return ''['foo'] }";
56 runWithAllOptimizationLevels(action(fn, new Action() {
57 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
58 eval(cx, scope1, "String.prototype.foo = 'scope1'");
59 eval(cx, scope2, "String.prototype.foo = 'scope2'");
60
61 assertEquals("scope2", eval(cx, scope2, "test()"));
62 assertEquals("scope2", eval(cx, scope1, "scope2.test()"));
63 assertEquals("scope2", eval(cx, scope1, "scope2.test.call(null)"));
64 assertEquals("scope2", eval(cx, scope1, "var t=scope2.test; t()"));
65 assertEquals("scope2", eval(cx, scope1, "var t=scope2.test; t.call(null)"));
66 }
67 }));
68 }
69
70 @Test
71 public void test_getProp() {
72 String fn = "function test(){ return ''.foo }";
73 runWithAllOptimizationLevels(action(fn, new Action() {
74 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
75 eval(cx, scope1, "String.prototype.foo = 'scope1'");
76 eval(cx, scope2, "String.prototype.foo = 'scope2'");
77
78 assertEquals("scope2", eval(cx, scope2, "test()"));
79 assertEquals("scope2", eval(cx, scope1, "scope2.test()"));
80 assertEquals("scope2", eval(cx, scope1, "scope2.test.call(null)"));
81 assertEquals("scope2", eval(cx, scope1, "var t=scope2.test; t()"));
82 assertEquals("scope2", eval(cx, scope1, "var t=scope2.test; t.call(null)"));
83 }
84 }));
85 }
86
87 @Test
88 public void test_getPropNoWarn1() {
89 String fn = "function test(){ if (''.foo) return true; return false; }";
90 runWithAllOptimizationLevels(action(fn, new Action() {
91 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
92 eval(cx, scope1, "String.prototype.foo = 'scope1'");
93
94 assertFALSE(eval(cx, scope2, "test()"));
95 assertFALSE(eval(cx, scope1, "scope2.test()"));
96 assertFALSE(eval(cx, scope1, "scope2.test.call(null)"));
97 assertFALSE(eval(cx, scope1, "var t=scope2.test; t()"));
98 assertFALSE(eval(cx, scope1, "var t=scope2.test; t.call(null)"));
99 }
100 }));
101 }
102
103 @Test
104 public void test_getPropNoWarn2() {
105 String fn = "function test(){ if (''.foo) return true; return false; }";
106 runWithAllOptimizationLevels(action(fn, new Action() {
107 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
108 eval(cx, scope2, "String.prototype.foo = 'scope2'");
109
110 assertTRUE(eval(cx, scope2, "test()"));
111 assertTRUE(eval(cx, scope1, "scope2.test()"));
112 assertTRUE(eval(cx, scope1, "scope2.test.call(null)"));
113 assertTRUE(eval(cx, scope1, "var t=scope2.test; t()"));
114 assertTRUE(eval(cx, scope1, "var t=scope2.test; t.call(null)"));
115 }
116 }));
117 }
118
119 @Test
120 public void test_setElem() {
121 String fn = "function test(){ ''['foo'] = '_' }";
122 runWithAllOptimizationLevels(action(fn, new Action() {
123 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
124 String code = "";
125 code += "String.prototype.c = 0;";
126 code += "Object.defineProperty(String.prototype, 'foo', {"
127 + " set: function(v){ this.__proto__.c++ }})";
128 eval(cx, scope1, code);
129 eval(cx, scope2, code);
130
131 eval(cx, scope2, "test()");
132 eval(cx, scope1, "scope2.test()");
133 eval(cx, scope1, "scope2.test.call(null)");
134 eval(cx, scope1, "var t=scope2.test; t()");
135 eval(cx, scope1, "var t=scope2.test; t.call(null)");
136
137 assertTRUE(eval(cx, scope1, "0 == String.prototype.c"));
138 assertTRUE(eval(cx, scope2, "5 == String.prototype.c"));
139 }
140 }));
141 }
142
143 @Test
144 public void test_setProp() {
145 String fn = "function test(){ ''.foo = '_' }";
146 runWithAllOptimizationLevels(action(fn, new Action() {
147 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
148 String code = "";
149 code += "String.prototype.c = 0;";
150 code += "Object.defineProperty(String.prototype, 'foo', {"
151 + " set: function(v){ this.__proto__.c++ }})";
152 eval(cx, scope1, code);
153 eval(cx, scope2, code);
154
155 eval(cx, scope2, "test()");
156 eval(cx, scope1, "scope2.test()");
157 eval(cx, scope1, "scope2.test.call(null)");
158 eval(cx, scope1, "var t=scope2.test; t()");
159 eval(cx, scope1, "var t=scope2.test; t.call(null)");
160
161 assertTRUE(eval(cx, scope1, "0 == String.prototype.c"));
162 assertTRUE(eval(cx, scope2, "5 == String.prototype.c"));
163 }
164 }));
165 }
166
167 @Test
168 public void test_setElemIncDec() {
169 String fn = "function test(){ ''['foo']++ }";
170 runWithAllOptimizationLevels(action(fn, new Action() {
171 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
172 String code = "";
173 code += "String.prototype.c = 0;";
174 code += "Object.defineProperty(String.prototype, 'foo', {"
175 + " set: function(v){ this.__proto__.c++ }})";
176 eval(cx, scope1, code);
177 eval(cx, scope2, code);
178
179 eval(cx, scope2, "test()");
180 eval(cx, scope1, "scope2.test()");
181 eval(cx, scope1, "scope2.test.call(null)");
182 eval(cx, scope1, "var t=scope2.test; t()");
183 eval(cx, scope1, "var t=scope2.test; t.call(null)");
184
185 assertTRUE(eval(cx, scope1, "0 == String.prototype.c"));
186 assertTRUE(eval(cx, scope2, "5 == String.prototype.c"));
187 }
188 }));
189 }
190
191 @Test
192 public void test_setPropIncDec() {
193 String fn = "function test(){ ''.foo++ }";
194 runWithAllOptimizationLevels(action(fn, new Action() {
195 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
196 String code = "";
197 code += "String.prototype.c = 0;";
198 code += "Object.defineProperty(String.prototype, 'foo', {"
199 + " set: function(v){ this.__proto__.c++ }})";
200 eval(cx, scope1, code);
201 eval(cx, scope2, code);
202
203 eval(cx, scope2, "test()");
204 eval(cx, scope1, "scope2.test()");
205 eval(cx, scope1, "scope2.test.call(null)");
206 eval(cx, scope1, "var t=scope2.test; t()");
207 eval(cx, scope1, "var t=scope2.test; t.call(null)");
208
209 assertTRUE(eval(cx, scope1, "0 == String.prototype.c"));
210 assertTRUE(eval(cx, scope2, "5 == String.prototype.c"));
211 }
212 }));
213 }
214
215 @Test
216 public void test_setElemOp1() {
217 String fn = "function test(){ return ''['foo'] += '_' }";
218 runWithAllOptimizationLevels(action(fn, new Action() {
219 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
220 String code = "";
221 code += "String.prototype.c = 0;";
222 code += "Object.defineProperty(String.prototype, 'foo', {"
223 + " set: function(v){ this.__proto__.c++ }})";
224 eval(cx, scope1, code);
225 eval(cx, scope2, code);
226
227 eval(cx, scope2, "test()");
228 eval(cx, scope1, "scope2.test()");
229 eval(cx, scope1, "scope2.test.call(null)");
230 eval(cx, scope1, "var t=scope2.test; t()");
231 eval(cx, scope1, "var t=scope2.test; t.call(null)");
232
233 assertTRUE(eval(cx, scope1, "0 == String.prototype.c"));
234 assertTRUE(eval(cx, scope2, "5 == String.prototype.c"));
235 }
236 }));
237 }
238
239 @Test
240 public void test_setPropOp1() {
241 String fn = "function test(){ return ''.foo += '_' }";
242 runWithAllOptimizationLevels(action(fn, new Action() {
243 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
244 String code = "";
245 code += "String.prototype.c = 0;";
246 code += "String.prototype.d = 0;";
247 code += "Object.defineProperty(String.prototype, 'foo', {"
248 + " set: function(v){ this.__proto__.c++ },"
249 + " get: function(v){ this.__proto__.d++ }})";
250 eval(cx, scope1, code);
251 eval(cx, scope2, code);
252
253 eval(cx, scope2, "test()");
254 eval(cx, scope1, "scope2.test()");
255 eval(cx, scope1, "scope2.test.call(null)");
256 eval(cx, scope1, "var t=scope2.test; t()");
257 eval(cx, scope1, "var t=scope2.test; t.call(null)");
258
259 assertTRUE(eval(cx, scope1, "0 == String.prototype.c"));
260 assertTRUE(eval(cx, scope2, "5 == String.prototype.c"));
261 assertTRUE(eval(cx, scope1, "0 == String.prototype.d"));
262 assertTRUE(eval(cx, scope2, "5 == String.prototype.d"));
263 }
264 }));
265 }
266
267 @Test
268 public void test_setElemOp2() {
269 String fn = "function test(){ return ''['foo'] += '_' }";
270 runWithAllOptimizationLevels(action(fn, new Action() {
271 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
272 String code = "";
273 code += "String.prototype.c = 0;";
274 code += "String.prototype.d = 0;";
275 code += "Object.defineProperty(String.prototype, 'foo', {"
276 + " set: function(v){ this.__proto__.c++ },"
277 + " get: function(v){ this.__proto__.d++ }})";
278 eval(cx, scope1, code);
279 eval(cx, scope2, code);
280
281 eval(cx, scope2, "test()");
282 eval(cx, scope1, "scope2.test()");
283 eval(cx, scope1, "scope2.test.call(null)");
284 eval(cx, scope1, "var t=scope2.test; t()");
285 eval(cx, scope1, "var t=scope2.test; t.call(null)");
286
287 assertTRUE(eval(cx, scope1, "0 == String.prototype.c"));
288 assertTRUE(eval(cx, scope2, "5 == String.prototype.c"));
289 assertTRUE(eval(cx, scope1, "0 == String.prototype.d"));
290 assertTRUE(eval(cx, scope2, "5 == String.prototype.d"));
291 }
292 }));
293 }
294
295 @Test
296 public void test_setPropOp2() {
297 String fn = "function test(){ return ''.foo += '_' }";
298 runWithAllOptimizationLevels(action(fn, new Action() {
299 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
300 eval(cx, scope1, "String.prototype.foo = 'scope1'");
301 eval(cx, scope2, "String.prototype.foo = 'scope2'");
302
303 assertEquals("scope2_", eval(cx, scope2, "test()"));
304 assertEquals("scope2_", eval(cx, scope1, "scope2.test()"));
305 assertEquals("scope2_", eval(cx, scope1, "scope2.test.call(null)"));
306 assertEquals("scope2_", eval(cx, scope1, "var t=scope2.test; t()"));
307 assertEquals("scope2_", eval(cx, scope1, "var t=scope2.test; t.call(null)"));
308 }
309 }));
310 }
311
312 @Test
313 public void test_getElemCall() {
314 String fn = "function test(){ return ''['foo']() }";
315 runWithAllOptimizationLevels(action(fn, new Action() {
316 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
317 eval(cx, scope1, "String.prototype.foo = function(){ return 'scope1' }");
318 eval(cx, scope2, "String.prototype.foo = function(){ return 'scope2' }");
319
320 assertEquals("scope2", eval(cx, scope2, "test()"));
321 assertEquals("scope2", eval(cx, scope1, "scope2.test()"));
322 assertEquals("scope2", eval(cx, scope1, "scope2.test.call(null)"));
323 assertEquals("scope2", eval(cx, scope1, "var t=scope2.test; t()"));
324 assertEquals("scope2", eval(cx, scope1, "var t=scope2.test; t.call(null)"));
325 }
326 }));
327 }
328
329 @Test
330 public void test_getPropCall() {
331 String fn = "function test(){ return ''.foo() }";
332 runWithAllOptimizationLevels(action(fn, new Action() {
333 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
334 eval(cx, scope1, "String.prototype.foo = function(){ return 'scope1' }");
335 eval(cx, scope2, "String.prototype.foo = function(){ return 'scope2' }");
336
337 assertEquals("scope2", eval(cx, scope2, "test()"));
338 assertEquals("scope2", eval(cx, scope1, "scope2.test()"));
339 assertEquals("scope2", eval(cx, scope1, "scope2.test.call(null)"));
340 assertEquals("scope2", eval(cx, scope1, "var t=scope2.test; t()"));
341 assertEquals("scope2", eval(cx, scope1, "var t=scope2.test; t.call(null)"));
342 }
343 }));
344 }
345
346 @Test
347 public void test_Enum1() {
348 String fn = "function test(){ for (var k in '') if (k == 'foo') return true; return false; }";
349 runWithAllOptimizationLevels(action(fn, new Action() {
350 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
351 eval(cx, scope1, "String.prototype.foo = 'scope1'");
352
353 assertFALSE(eval(cx, scope2, "test()"));
354 assertFALSE(eval(cx, scope1, "scope2.test()"));
355 assertFALSE(eval(cx, scope1, "scope2.test.call(null)"));
356 assertFALSE(eval(cx, scope1, "var t=scope2.test; t()"));
357 assertFALSE(eval(cx, scope1, "var t=scope2.test; t.call(null)"));
358 }
359 }));
360 }
361
362 @Test
363 public void test_Enum2() {
364 String fn = "function test(){ for (var k in '') if (k == 'foo') return true; return false; }";
365 runWithAllOptimizationLevels(action(fn, new Action() {
366 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
367 eval(cx, scope2, "String.prototype.foo = 'scope1'");
368
369 assertTRUE(eval(cx, scope2, "test()"));
370 assertTRUE(eval(cx, scope1, "scope2.test()"));
371 assertTRUE(eval(cx, scope1, "scope2.test.call(null)"));
372 assertTRUE(eval(cx, scope1, "var t=scope2.test; t()"));
373 assertTRUE(eval(cx, scope1, "var t=scope2.test; t.call(null)"));
374 }
375 }));
376 }
377
378 @Test
379 public void test_Parent() {
380 String fn = "function test(){}";
381 runWithAllOptimizationLevels(action(fn, new Action() {
382 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
383 assertSame(scope2, eval(cx, scope2, "test.__parent__"));
384 assertSame(scope2, eval(cx, scope1, "scope2.test.__parent__"));
385 assertSame(scope2, eval(cx, scope1, "var t=scope2.test; t.__parent__"));
386 }
387 }));
388 }
389
390 @Test
391 public void test_ReturnThis() {
392 String fn = "function test(){ return this }";
393 runWithAllOptimizationLevels(action(fn, new Action() {
394 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
395 assertSame(scope2, eval(cx, scope2, "test()"));
396 assertSame(scope2, eval(cx, scope2, "test.call(null)"));
397 assertSame(scope2, eval(cx, scope1, "scope2.test()"));
398 assertSame(scope1, eval(cx, scope1, "scope2.test.call(null)"));
399 assertSame(scope1, eval(cx, scope1, "var t=scope2.test; t()"));
400 assertSame(scope1, eval(cx, scope1, "var t=scope2.test; t.call(null)"));
401 }
402 }));
403 }
404
405 @Test
406 public void test_ReturnThisNested() {
407 String fn = "function test(){ return (function(){ return this })() }";
408 runWithAllOptimizationLevels(action(fn, new Action() {
409 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
410 assertSame(scope2, eval(cx, scope2, "test()"));
411 assertSame(scope2, eval(cx, scope2, "test.call(null)"));
412 assertSame(scope2, eval(cx, scope1, "scope2.test()"));
413 assertSame(scope2, eval(cx, scope1, "scope2.test.call(null)"));
414 assertSame(scope2, eval(cx, scope1, "var t=scope2.test; t()"));
415 assertSame(scope2, eval(cx, scope1, "var t=scope2.test; t.call(null)"));
416 }
417 }));
418 }
419
420 @Test
421 public void test_ReturnThisNestedCall() {
422 String fn = "function test(o){ return (function(){ return this }).call(o) }";
423 runWithAllOptimizationLevels(action(fn, new Action() {
424 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
425 assertSame(scope2, eval(cx, scope2, "test()"));
426 assertSame(scope2, eval(cx, scope2, "test(null)"));
427 assertSame(scope2, eval(cx, scope2, "test.call(null)"));
428 assertSame(scope2, eval(cx, scope2, "test.call(null, null)"));
429
430 assertSame(scope1, eval(cx, scope1, "scope2.test()"));
431 assertSame(scope1, eval(cx, scope1, "scope2.test(null)"));
432 assertSame(scope1, eval(cx, scope1, "scope2.test.call(null)"));
433 assertSame(scope1, eval(cx, scope1, "scope2.test.call(null, null)"));
434
435 assertSame(scope1, eval(cx, scope1, "var t=scope2.test; t()"));
436 assertSame(scope1, eval(cx, scope1, "var t=scope2.test; t(null)"));
437 assertSame(scope1, eval(cx, scope1, "var t=scope2.test; t.call(null)"));
438 assertSame(scope1, eval(cx, scope1, "var t=scope2.test; t.call(null, null)"));
439 }
440 }));
441 }
442
443 @Test
444 public void test_NameStringPrototype() {
445 String fn = "function test(){ return String.prototype }";
446 runWithAllOptimizationLevels(action(fn, new Action() {
447 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
448 assertTRUE(eval(cx, scope2, "String.prototype === test()"));
449 assertTRUE(eval(cx, scope2, "String.prototype === test.call(null)"));
450 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test()"));
451 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test.call(null)"));
452 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t()"));
453 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t.call(null)"));
454 }
455 }));
456 }
457
458 @Test
459 public void test_NameStringPrototypeNested() {
460 String fn = "function test(){ return (function(){ return String.prototype })() }";
461 runWithAllOptimizationLevels(action(fn, new Action() {
462 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
463 assertTRUE(eval(cx, scope2, "String.prototype === test()"));
464 assertTRUE(eval(cx, scope2, "String.prototype === test.call(null)"));
465 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test()"));
466 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test.call(null)"));
467 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t()"));
468 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t.call(null)"));
469 }
470 }));
471 }
472
473 @Test
474 public void test_ThisStringPrototype() {
475 String fn = "function test(){ return this.String.prototype }";
476 runWithAllOptimizationLevels(action(fn, new Action() {
477 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
478 assertTRUE(eval(cx, scope2, "String.prototype === test()"));
479 assertTRUE(eval(cx, scope2, "String.prototype === test.call(null)"));
480 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test()"));
481 assertTRUE(eval(cx, scope1, "String.prototype === scope2.test.call(null)"));
482 assertTRUE(eval(cx, scope1, "var t=scope2.test; String.prototype === t()"));
483 assertTRUE(eval(cx, scope1, "var t=scope2.test; String.prototype === t.call(null)"));
484 }
485 }));
486 }
487
488 @Test
489 public void test_ThisProto() {
490 String fn = "function test(){ return this.__proto__ }";
491 runWithAllOptimizationLevels(action(fn, new Action() {
492 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
493 assertTRUE(eval(cx, scope2, "String.prototype === test.call('')"));
494 assertTRUE(eval(cx, scope1, "String.prototype === scope2.test.call('')"));
495 assertTRUE(eval(cx, scope1, "var t=scope2.test; String.prototype === t.call('')"));
496 }
497 }));
498 }
499
500 @Test
501 public void test_StringLiteralProto() {
502 String fn = "function test(){ return ''.__proto__ }";
503 runWithAllOptimizationLevels(action(fn, new Action() {
504 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
505 assertTRUE(eval(cx, scope2, "String.prototype === test()"));
506 assertTRUE(eval(cx, scope2, "String.prototype === test.call(null)"));
507 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test()"));
508 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test.call(null)"));
509 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t()"));
510 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t.call(null)"));
511 }
512 }));
513 }
514
515 @Test
516 public void test_ThisProtoNested() {
517 String fn = "function test(){ return (function(){ return this.__proto__ }).call('') }";
518 runWithAllOptimizationLevels(action(fn, new Action() {
519 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
520 assertTRUE(eval(cx, scope2, "String.prototype === test()"));
521 assertTRUE(eval(cx, scope2, "String.prototype === test.call(null)"));
522 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test()"));
523 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test.call(null)"));
524 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t()"));
525 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t.call(null)"));
526 }
527 }));
528 }
529
530 @Test
531 public void test_StringLiteralProtoNested() {
532 String fn = "function test(){ return (function(){ return ''.__proto__ })() }";
533 runWithAllOptimizationLevels(action(fn, new Action() {
534 public void run(Context cx, ScriptableObject scope1, ScriptableObject scope2) {
535 assertTRUE(eval(cx, scope2, "String.prototype === test()"));
536 assertTRUE(eval(cx, scope2, "String.prototype === test.call(null)"));
537 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test()"));
538 assertFALSE(eval(cx, scope1, "String.prototype === scope2.test.call(null)"));
539 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t()"));
540 assertFALSE(eval(cx, scope1, "var t=scope2.test; String.prototype === t.call(null)"));
541 }
542 }));
543 }
544
545 }