sundar@99: /* sundar@99: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. sundar@99: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@962: * sundar@99: * This code is free software; you can redistribute it and/or modify it sundar@99: * under the terms of the GNU General Public License version 2 only, as sundar@99: * published by the Free Software Foundation. attila@962: * sundar@99: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@99: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@99: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@99: * version 2 for more details (a copy is included in the LICENSE file that sundar@99: * accompanied this code). attila@962: * sundar@99: * You should have received a copy of the GNU General Public License version sundar@99: * 2 along with this work; if not, write to the Free Software Foundation, sundar@99: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@962: * sundar@99: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@99: * or visit www.oracle.com if you need additional information or have any sundar@99: * questions. sundar@99: */ sundar@99: sundar@99: /** sundar@99: * JDK-8008305: ScriptEngine.eval should offer the ability to provide a codebase * sundar@99: * @test sundar@99: * @run sundar@99: */ sundar@99: sundar@99: var URLReader = Java.type("jdk.nashorn.api.scripting.URLReader"); sundar@99: var File = Java.type("java.io.File"); sundar@99: var FileReader = Java.type("java.io.FileReader"); sundar@99: var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager"); sundar@99: var SecurityException = Java.type("java.lang.SecurityException"); sundar@99: sundar@99: var m = new ScriptEngineManager(); sundar@99: var e = m.getEngineByName("nashorn"); sundar@99: sundar@99: sundar@99: // subtest script file sundar@99: var scriptFile = new File(__DIR__ + "JDK-8008305_subtest.js"); sundar@99: sundar@99: // evaluate the subtest via a URLReader sundar@99: var res = e.eval(new URLReader(scriptFile.toURI().toURL())); sundar@99: sundar@99: // subtest should execute with AllPermission and so return absolute path sundar@99: if (! res.equals(new File(".").getAbsolutePath())) { sundar@99: fail("eval result is not equal to expected value"); sundar@99: } sundar@99: sundar@99: // try same subtest without URLReader and so it runs with null code source sundar@99: try { sundar@99: e.eval(new FileReader(scriptFile)); sundar@99: fail("Expected SecurityException from script!"); sundar@99: } catch (e) { sundar@99: if (! (e instanceof SecurityException)) { sundar@560: fail("Expected SecurityException, but got " + e); sundar@99: } sundar@99: }