Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset 7c756d901f9a
sundar@1058 | 1 | /* |
sundar@1058 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
sundar@1058 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sundar@1058 | 4 | * |
sundar@1058 | 5 | * This code is free software; you can redistribute it and/or modify it |
sundar@1058 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sundar@1058 | 7 | * published by the Free Software Foundation. |
sundar@1058 | 8 | * |
sundar@1058 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sundar@1058 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sundar@1058 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sundar@1058 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sundar@1058 | 13 | * accompanied this code). |
sundar@1058 | 14 | * |
sundar@1058 | 15 | * You should have received a copy of the GNU General Public License version |
sundar@1058 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sundar@1058 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sundar@1058 | 18 | * |
sundar@1058 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sundar@1058 | 20 | * or visit www.oracle.com if you need additional information or have any |
sundar@1058 | 21 | * questions. |
sundar@1058 | 22 | */ |
sundar@1058 | 23 | |
sundar@1058 | 24 | /** |
sundar@1058 | 25 | * JDK-8060688: Nashorn: Generated script class name fails --verify-code for names with special chars |
sundar@1058 | 26 | * |
sundar@1058 | 27 | * @test |
sundar@1058 | 28 | * @run |
sundar@1058 | 29 | */ |
sundar@1058 | 30 | |
sundar@1058 | 31 | var NashornEngineFactory = Java.type("jdk.nashorn.api.scripting.NashornScriptEngineFactory"); |
sundar@1058 | 32 | var ScriptEngine = Java.type("javax.script.ScriptEngine"); |
sundar@1058 | 33 | var ScriptContext = Java.type("javax.script.ScriptContext"); |
sundar@1058 | 34 | |
sundar@1058 | 35 | var factory = new NashornEngineFactory(); |
sundar@1058 | 36 | |
sundar@1058 | 37 | var e = factory.getScriptEngine("--verify-code"); |
sundar@1058 | 38 | |
sundar@1058 | 39 | function evalAndCheck(code) { |
sundar@1058 | 40 | try { |
sundar@1058 | 41 | e.eval(code); |
sundar@1058 | 42 | } catch (exp) { |
sundar@1058 | 43 | exp.printStackTrace(); |
sundar@1058 | 44 | } |
sundar@1058 | 45 | } |
sundar@1058 | 46 | |
sundar@1058 | 47 | // check default name |
sundar@1058 | 48 | evalAndCheck("var a = 3"); |
sundar@1058 | 49 | // check few names with special chars |
sundar@1058 | 50 | var scontext = e.context; |
sundar@1058 | 51 | scontext.setAttribute(ScriptEngine.FILENAME, "<myscript>", ScriptContext.ENGINE_SCOPE); |
sundar@1058 | 52 | evalAndCheck("var h = 'hello'"); |
sundar@1058 | 53 | scontext.setAttribute(ScriptEngine.FILENAME, "[myscript]", ScriptContext.ENGINE_SCOPE); |
sundar@1058 | 54 | evalAndCheck("var foo = 'world'"); |
sundar@1058 | 55 | scontext.setAttribute(ScriptEngine.FILENAME, ";/\\$.", ScriptContext.ENGINE_SCOPE); |
sundar@1058 | 56 | evalAndCheck("var foo = 'helloworld'"); |