yan@970: /* yan@970: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. yan@970: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. yan@970: * yan@970: * This code is free software; you can redistribute it and/or modify it yan@970: * under the terms of the GNU General Public License version 2 only, as yan@970: * published by the Free Software Foundation. yan@970: * yan@970: * This code is distributed in the hope that it will be useful, but WITHOUT yan@970: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or yan@970: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License yan@970: * version 2 for more details (a copy is included in the LICENSE file that yan@970: * accompanied this code). yan@970: * yan@970: * You should have received a copy of the GNU General Public License version yan@970: * 2 along with this work; if not, write to the Free Software Foundation, yan@970: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. yan@970: * yan@970: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA yan@970: * or visit www.oracle.com if you need additional information or have any yan@970: * questions. yan@970: */ yan@970: yan@970: /** yan@970: * @test yan@970: * @bug 8036987 yan@970: * @run yan@970: */ yan@970: yan@970: var factory = Java.type('jdk.nashorn.api.scripting.NashornScriptEngineFactory') yan@970: var engine = new factory().getScriptEngine(function(str){ yan@970: return str.indexOf('java.util') != -1; yan@970: }) yan@970: yan@970: load("nashorn:mozilla_compat.js"); yan@970: engine.eval("load('nashorn:mozilla_compat.js');") yan@970: yan@970: function tryEval (str) { yan@970: try { yan@970: print(eval(str)) yan@970: print(engine.eval(str)) yan@970: } catch (exc) { yan@970: print(exc.message) yan@970: } yan@970: } yan@970: yan@970: tryEval("new JavaAdapter(javax.script.ScriptContext){}.class") yan@970: tryEval("new JavaAdapter(java.util.ArrayList){}.class") yan@970: tryEval("importClass(java.lang.Integer); Integer") yan@970: tryEval("importClass(java.util.HashSet); HashSet") yan@970: tryEval("importPackage(java.lang); Integer") yan@970: tryEval("importPackage(java.util); HashMap")