test/script/basic/JDK-8114838.js

Tue, 21 Mar 2017 13:41:57 -0700

author
asaha
date
Tue, 21 Mar 2017 13:41:57 -0700
changeset 2160
1df40fe54cd6
parent 1511
c6e9453ed5ef
permissions
-rw-r--r--

Merge

sundar@1511 1 /*
sundar@1511 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
sundar@1511 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sundar@1511 4 *
sundar@1511 5 * This code is free software; you can redistribute it and/or modify it
sundar@1511 6 * under the terms of the GNU General Public License version 2 only, as
sundar@1511 7 * published by the Free Software Foundation.
sundar@1511 8 *
sundar@1511 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sundar@1511 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sundar@1511 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sundar@1511 12 * version 2 for more details (a copy is included in the LICENSE file that
sundar@1511 13 * accompanied this code).
sundar@1511 14 *
sundar@1511 15 * You should have received a copy of the GNU General Public License version
sundar@1511 16 * 2 along with this work; if not, write to the Free Software Foundation,
sundar@1511 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sundar@1511 18 *
sundar@1511 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sundar@1511 20 * or visit www.oracle.com if you need additional information or have any
sundar@1511 21 * questions.
sundar@1511 22 */
sundar@1511 23
sundar@1511 24 /**
sundar@1511 25 * JDK-8114838: Anonymous functions escape to surrounding scope when defined under "with" statement
sundar@1511 26 *
sundar@1511 27 * @test
sundar@1511 28 * @run
sundar@1511 29 */
sundar@1511 30
sundar@1511 31 // do *not* introduce new lines! The next line should be 32
sundar@1511 32 with({}) { function () {} }
sundar@1511 33 if (typeof this["L:32"] != 'undefined') {
sundar@1511 34 throw new Error("anonymous name spills into global scope");
sundar@1511 35 }
sundar@1511 36
sundar@1511 37 var func = eval("function() {}");
sundar@1511 38 if (typeof func != 'function') {
sundar@1511 39 throw new Error("eval of anonymous function does not work!");
sundar@1511 40 }
sundar@1511 41
sundar@1511 42 var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager");
sundar@1511 43 var engine = new ScriptEngineManager().getEngineByName("nashorn");
sundar@1511 44 var func2 = engine.eval("function() {}");
sundar@1511 45 if (typeof func2 != 'function') {
sundar@1511 46 throw new Error("eval of anonymous function does not work from script engine!");
sundar@1511 47 }

mercurial