author | jmanson |
Tue, 12 May 2015 14:39:36 -0700 | |
changeset 30445 | e1e28b9abbe5 |
parent 29941 | 4da7ab19348e |
permissions | -rw-r--r-- |
29941
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
1 |
/* |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
4 |
* |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
8 |
* |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
13 |
* accompanied this code). |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
14 |
* |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
18 |
* |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
21 |
* questions. |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
22 |
*/ |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
23 |
|
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
24 |
/** |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
25 |
* JDK-8077955: Undeclared globals in eval code should not be handled as fast scope |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
26 |
* |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
27 |
* @test |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
28 |
* @run |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
29 |
* @fork |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
30 |
* @option -Dnashorn.fields.objects |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
31 |
*/ |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
32 |
|
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
33 |
var m = new javax.script.ScriptEngineManager(); |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
34 |
var e = m.getEngineByName('js'); |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
35 |
|
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
36 |
// leave the whitespace - need both eval("e") at same column for this test! |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
37 |
|
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
38 |
e.eval('function f(e) { eval("e") } f()'); |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
39 |
e.eval('function f() { var e = 33; eval("e") } f()'); |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
40 |
|
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
41 |
function f() { |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
42 |
Function.call.call(function x() { eval("x") }); eval("x") |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
43 |
} |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
44 |
|
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
45 |
try { |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
46 |
f(); |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
47 |
fail("Should have thrown ReferenceError"); |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
48 |
} catch (e) { |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
49 |
if (! (e instanceof ReferenceError)) { |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
50 |
fail("ReferenceError expected but got " + e); |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
51 |
} |
4da7ab19348e
8077955: Undeclared globals in eval code should not be handled as fast scope
hannesw
parents:
diff
changeset
|
52 |
} |