author | sundar |
Wed, 06 May 2015 20:04:42 +0530 | |
changeset 30394 | 72a59e4dffea |
parent 25242 | ac1d21c4d61d |
permissions | -rw-r--r-- |
25242
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
1 |
/* |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
4 |
* |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
8 |
* |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
14 |
* |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
18 |
* |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
21 |
* questions. |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
22 |
*/ |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
23 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
24 |
/** |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
25 |
* JDK-8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
26 |
* |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
27 |
* @test |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
28 |
* @run |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
29 |
*/ |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
30 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
31 |
function func() { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
32 |
var x = 1; |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
33 |
with ({ eval: this.eval }) { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
34 |
eval("var x = 23"); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
35 |
} |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
36 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
37 |
return x; |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
38 |
} |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
39 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
40 |
print(func()); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
41 |
print("typeof x? " + typeof x); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
42 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
43 |
print((function(global){ |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
44 |
var x = 1; |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
45 |
with(global) { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
46 |
eval("eval('var x=0')"); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
47 |
} |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
48 |
return x; |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
49 |
})(this)); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
50 |
print("typeof x? " + typeof x); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
51 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
52 |
print((function(global){ |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
53 |
var x = 1; |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
54 |
with({eval: global.eval}) { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
55 |
eval("eval('var x=0')"); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
56 |
} |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
57 |
return x; |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
58 |
})(this)); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
59 |
print("typeof x? " + typeof x); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
60 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
61 |
// not-builtin eval cases |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
62 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
63 |
(function () { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
64 |
function eval(str) { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
65 |
print("local eval called: " + str); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
66 |
print(this); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
67 |
} |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
68 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
69 |
with({}) { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
70 |
eval("hello"); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
71 |
} |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
72 |
})(); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
73 |
|
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
74 |
(function () { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
75 |
with({ |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
76 |
eval:function(str) { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
77 |
print("with's eval called: " + str); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
78 |
print("this = " + this); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
79 |
print("this.foo = " + this.foo); |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
80 |
}, |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
81 |
foo: 42 |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
82 |
}) { |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
83 |
eval("hello") |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
84 |
} |
ac1d21c4d61d
8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval
sundar
parents:
diff
changeset
|
85 |
})(); |