test/script/basic/JDK-8077955.js

Thu, 16 Apr 2015 17:31:32 +0200

author
hannesw
date
Thu, 16 Apr 2015 17:31:32 +0200
changeset 1329
63fe48ca8630
permissions
-rw-r--r--

8077955: Undeclared globals in eval code should not be handled as fast scope
Reviewed-by: lagergren, attila

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

mercurial