JDK-8048071.js revision 909:a8bab91498c2
1169689Skan/* 2169689Skan * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3169689Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4169689Skan * 5169689Skan * This code is free software; you can redistribute it and/or modify it 6169689Skan * under the terms of the GNU General Public License version 2 only, as 7169689Skan * published by the Free Software Foundation. 8169689Skan * 9169689Skan * This code is distributed in the hope that it will be useful, but WITHOUT 10169689Skan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11169689Skan * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12169689Skan * version 2 for more details (a copy is included in the LICENSE file that 13169689Skan * accompanied this code). 14169689Skan * 15169689Skan * You should have received a copy of the GNU General Public License version 16169689Skan * 2 along with this work; if not, write to the Free Software Foundation, 17169689Skan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18169689Skan * 19169689Skan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20169689Skan * or visit www.oracle.com if you need additional information or have any 21169689Skan * questions. 22169689Skan */ 23169689Skan 24169689Skan/** 25169689Skan * JDK-8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval 26169689Skan * 27169689Skan * @test 28169689Skan * @run 29169689Skan */ 30169689Skan 31169689Skanfunction func() { 32169689Skan var x = 1; 33169689Skan with ({ eval: this.eval }) { 34169689Skan eval("var x = 23"); 35169689Skan } 36169689Skan 37169689Skan return x; 38169689Skan} 39169689Skan 40169689Skanprint(func()); 41169689Skanprint("typeof x? " + typeof x); 42169689Skan 43169689Skanprint((function(global){ 44169689Skan var x = 1; 45169689Skan with(global) { 46169689Skan eval("eval('var x=0')"); 47169689Skan } 48169689Skan return x; 49169689Skan})(this)); 50169689Skanprint("typeof x? " + typeof x); 51169689Skan 52169689Skanprint((function(global){ 53169689Skan var x = 1; 54169689Skan with({eval: global.eval}) { 55169689Skan eval("eval('var x=0')"); 56169689Skan } 57169689Skan return x; 58169689Skan})(this)); 59169689Skanprint("typeof x? " + typeof x); 60169689Skan 61169689Skan// not-builtin eval cases 62169689Skan 63169689Skan(function () { 64169689Skan function eval(str) { 65169689Skan print("local eval called: " + str); 66169689Skan print(this); 67169689Skan } 68169689Skan 69169689Skan with({}) { 70169689Skan eval("hello"); 71169689Skan } 72169689Skan})(); 73169689Skan 74169689Skan(function () { 75169689Skan with({ 76169689Skan eval:function(str) { 77169689Skan print("with's eval called: " + str); 78169689Skan print("this = " + this); 79169689Skan print("this.foo = " + this.foo); 80169689Skan }, 81169689Skan foo: 42 82169689Skan }) { 83169689Skan eval("hello") 84169689Skan } 85169689Skan})(); 86169689Skan