8009757: Package access clean up and refactoring
Reviewed-by: jlaskey, lagergren, attila
This commit is contained in:
parent
61cac54a92
commit
bb6c34adc7
nashorn
docs
make
src/jdk/nashorn
api/scripting
internal
test
script
basic
sandbox
trusted
src/jdk/nashorn
api/scripting
internal/runtime
test/models
@ -533,9 +533,8 @@ with (SwingGui) {
|
||||
<hr>
|
||||
<a name="jsarrays" id="jsarrays"></a>
|
||||
<h3>Creating, Converting and Using Java Arrays</h3>
|
||||
<p>While creating a Java object is the same as in Java, to create
|
||||
Java arrays in JavaScript we can use Java reflection
|
||||
explicitly. But once created the element access or length access is
|
||||
<p>
|
||||
Array element access or length access is
|
||||
the same as in Java. Also, a script array can be used when a Java
|
||||
method expects a Java array (auto conversion). So in most cases we
|
||||
don't have to create Java arrays explicitly.</p>
|
||||
@ -543,7 +542,8 @@ don't have to create Java arrays explicitly.</p>
|
||||
// <a href="source/javaarray.js">javaarray.js</a>
|
||||
|
||||
// create Java String array of 5 elements
|
||||
var a = java.lang.reflect.Array.newInstance(java.lang.String.class, 5);
|
||||
var StringArray = Java.type("java.lang.String[]");
|
||||
var a = new StringArray(5);
|
||||
|
||||
// Accessing elements and length access is by usual Java syntax
|
||||
a[0] = "scripting is great!";
|
||||
|
@ -30,7 +30,8 @@
|
||||
*/
|
||||
|
||||
// create Java String array of 5 elements
|
||||
var a = java.lang.reflect.Array.newInstance(java.lang.String.class, 5);
|
||||
var StringArray = Java.type("java.lang.String[]");
|
||||
var a = new StringArray(5);
|
||||
|
||||
// Accessing elements and length access is by usual Java syntax
|
||||
a[0] = "scripting is great!";
|
||||
|
@ -191,12 +191,12 @@
|
||||
|
||||
<!-- tests that check nashorn internals and internal API -->
|
||||
<jar jarfile="${nashorn.internal.tests.jar}">
|
||||
<fileset dir="${build.test.classes.dir}" excludes="**/api/*"/>
|
||||
<fileset dir="${build.test.classes.dir}" excludes="**/api/**"/>
|
||||
</jar>
|
||||
|
||||
<!-- tests that check nashorn script engine (jsr-223) API -->
|
||||
<jar jarfile="${nashorn.api.tests.jar}">
|
||||
<fileset dir="${build.test.classes.dir}" includes="**/api/*"/>
|
||||
<fileset dir="${build.test.classes.dir}" includes="**/api/**"/>
|
||||
</jar>
|
||||
|
||||
</target>
|
||||
|
@ -3,7 +3,7 @@
|
||||
# We ensure that by overriding "package.access" security property.
|
||||
|
||||
# The following "package.access" value was copied from default java.security
|
||||
# of jre/lib/security and appended with nashorn IR, Codegen and Parser packages.
|
||||
# of jre/lib/security and appended with nashorn sensitive packages.
|
||||
|
||||
#
|
||||
# List of comma-separated packages that start with or equal this string
|
||||
@ -11,4 +11,4 @@
|
||||
# passed to checkPackageAccess unless the
|
||||
# corresponding RuntimePermission ("accessClassInPackage."+package) has
|
||||
# been granted.
|
||||
package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.glassfish.external.,com.sun.org.glassfish.gmbal.,jdk.internal.,jdk.nashorn.internal.ir., jdk.nashorn.internal.codegen., jdk.nashorn.internal.lookup., jdk.nashorn.internal.parser.
|
||||
package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.glassfish.external.,com.sun.org.glassfish.gmbal.,jdk.internal.,jdk.nashorn.internal.,jdk.nashorn.tools.
|
||||
|
@ -147,6 +147,7 @@ public final class NashornScriptEngineFactory implements ScriptEngineFactory {
|
||||
* @return newly created script engine.
|
||||
*/
|
||||
public ScriptEngine getScriptEngine(final ClassLoader appLoader) {
|
||||
checkConfigPermission();
|
||||
return new NashornScriptEngine(this, appLoader);
|
||||
}
|
||||
|
||||
@ -157,6 +158,7 @@ public final class NashornScriptEngineFactory implements ScriptEngineFactory {
|
||||
* @return newly created script engine.
|
||||
*/
|
||||
public ScriptEngine getScriptEngine(final String[] args) {
|
||||
checkConfigPermission();
|
||||
return new NashornScriptEngine(this, args, getAppClassLoader());
|
||||
}
|
||||
|
||||
@ -168,11 +170,19 @@ public final class NashornScriptEngineFactory implements ScriptEngineFactory {
|
||||
* @return newly created script engine.
|
||||
*/
|
||||
public ScriptEngine getScriptEngine(final String[] args, final ClassLoader appLoader) {
|
||||
checkConfigPermission();
|
||||
return new NashornScriptEngine(this, args, appLoader);
|
||||
}
|
||||
|
||||
// -- Internals only below this point
|
||||
|
||||
private void checkConfigPermission() {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("nashorn.setConfig"));
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<String> names;
|
||||
private static final List<String> mimeTypes;
|
||||
private static final List<String> extensions;
|
||||
|
48
nashorn/src/jdk/nashorn/api/scripting/ScriptUtils.java
Normal file
48
nashorn/src/jdk/nashorn/api/scripting/ScriptUtils.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.scripting;
|
||||
|
||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||
|
||||
/**
|
||||
* Utilities that are to be called from script code
|
||||
*/
|
||||
public final class ScriptUtils {
|
||||
private ScriptUtils() {}
|
||||
|
||||
/**
|
||||
* Returns AST as JSON compatible string. This is used to
|
||||
* implement "parse" function in resources/parse.js script.
|
||||
*
|
||||
* @param code code to be parsed
|
||||
* @param name name of the code source (used for location)
|
||||
* @param includeLoc tells whether to include location information for nodes or not
|
||||
* @return JSON string representation of AST of the supplied code
|
||||
*/
|
||||
public static String parse(final String code, final String name, final boolean includeLoc) {
|
||||
return ScriptRuntime.parse(code, name, includeLoc);
|
||||
}
|
||||
}
|
@ -34,6 +34,9 @@ import java.io.PrintWriter;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -1503,8 +1506,10 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
|
||||
addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
|
||||
|
||||
// Nashorn extension: global.$OPTIONS (scripting-mode-only)
|
||||
value = context.getEnv();
|
||||
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, value);
|
||||
final ScriptObject options = newEmptyInstance();
|
||||
final ScriptEnvironment scriptEnv = context.getEnv();
|
||||
copyOptions(options, scriptEnv);
|
||||
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
|
||||
|
||||
// Nashorn extension: global.$ENV (scripting-mode-only)
|
||||
if (System.getSecurityManager() == null) {
|
||||
@ -1523,6 +1528,21 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
|
||||
addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
|
||||
}
|
||||
|
||||
private void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
public Void run() {
|
||||
for (Field f : scriptEnv.getClass().getFields()) {
|
||||
try {
|
||||
options.set(f.getName(), f.get(scriptEnv), false);
|
||||
} catch (final IllegalArgumentException | IllegalAccessException exp) {
|
||||
throw new RuntimeException(exp);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initTypedArray() {
|
||||
this.builtinArrayBuffer = initConstructor("ArrayBuffer");
|
||||
this.builtinInt8Array = initConstructor("Int8Array");
|
||||
|
@ -66,7 +66,7 @@ public final class NativeDebug extends ScriptObject {
|
||||
public static Object getContext(final Object self) {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("getNashornContext"));
|
||||
sm.checkPermission(new RuntimePermission("nashorn.getContext"));
|
||||
}
|
||||
return Global.getThisContext();
|
||||
}
|
||||
|
@ -222,6 +222,23 @@ public final class NativeJava {
|
||||
return simpleType(typeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of a java type {@link StaticClass}.
|
||||
* @param self not used
|
||||
* @param type the type whose name is returned
|
||||
* @return name of the given type
|
||||
*/
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
|
||||
public static Object typeName(final Object self, final Object type) {
|
||||
if (type instanceof StaticClass) {
|
||||
return ((StaticClass)type).getRepresentedClass().getName();
|
||||
} else if (type instanceof Class) {
|
||||
return ((Class<?>)type).getName();
|
||||
} else {
|
||||
return UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a JavaScript array and a Java type, returns a Java array with the same initial contents, and with the
|
||||
* specified component type. Example:
|
||||
|
@ -39,10 +39,13 @@ import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.CodeSigner;
|
||||
import java.security.CodeSource;
|
||||
import java.security.Permissions;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.ProtectionDomain;
|
||||
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||
import jdk.internal.org.objectweb.asm.util.CheckClassAdapter;
|
||||
import jdk.nashorn.internal.codegen.Compiler;
|
||||
@ -123,7 +126,7 @@ public final class Context {
|
||||
if (callerLoader != myLoader &&
|
||||
!(callerLoader instanceof StructureLoader) &&
|
||||
!(JavaAdapterFactory.isAdapterClass(caller))) {
|
||||
sm.checkPermission(new RuntimePermission("getNashornGlobal"));
|
||||
sm.checkPermission(new RuntimePermission("nashorn.getGlobal"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +140,7 @@ public final class Context {
|
||||
public static void setGlobal(final ScriptObject global) {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("setNashornGlobal"));
|
||||
sm.checkPermission(new RuntimePermission("nashorn.setGlobal"));
|
||||
}
|
||||
|
||||
if (global != null && !(global instanceof GlobalObject)) {
|
||||
@ -154,7 +157,7 @@ public final class Context {
|
||||
public static Context getContext() {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("getNashornContext"));
|
||||
sm.checkPermission(new RuntimePermission("nashorn.getContext"));
|
||||
}
|
||||
return getContextTrusted();
|
||||
}
|
||||
@ -267,7 +270,7 @@ public final class Context {
|
||||
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader) {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("createNashornContext"));
|
||||
sm.checkPermission(new RuntimePermission("nashorn.createContext"));
|
||||
}
|
||||
|
||||
this.env = new ScriptEnvironment(options, out, err);
|
||||
@ -533,7 +536,13 @@ public final class Context {
|
||||
if (index != -1) {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPackageAccess(fullName.substring(0, index));
|
||||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
@Override
|
||||
public Void run() {
|
||||
sm.checkPackageAccess(fullName.substring(0, index));
|
||||
return null;
|
||||
}
|
||||
}, createNoPermissionsContext());
|
||||
}
|
||||
}
|
||||
|
||||
@ -599,7 +608,7 @@ public final class Context {
|
||||
public ScriptObject newGlobal() {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("createNashornGlobal"));
|
||||
sm.checkPermission(new RuntimePermission("nashorn.newGlobal"));
|
||||
}
|
||||
|
||||
return newGlobalTrusted();
|
||||
@ -676,6 +685,10 @@ public final class Context {
|
||||
return (context != null) ? context : Context.getContextTrusted();
|
||||
}
|
||||
|
||||
private static AccessControlContext createNoPermissionsContext() {
|
||||
return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) });
|
||||
}
|
||||
|
||||
private Object evaluateSource(final Source source, final ScriptObject scope, final ScriptObject thiz) {
|
||||
ScriptFunction script = null;
|
||||
|
||||
|
@ -30,6 +30,10 @@ import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.security.CodeSource;
|
||||
import java.security.Permission;
|
||||
import java.security.PermissionCollection;
|
||||
import java.security.Permissions;
|
||||
import java.security.SecureClassLoader;
|
||||
import jdk.nashorn.tools.Shell;
|
||||
|
||||
@ -40,6 +44,28 @@ import jdk.nashorn.tools.Shell;
|
||||
*
|
||||
*/
|
||||
abstract class NashornLoader extends SecureClassLoader {
|
||||
private static final String OBJECTS_PKG = "jdk.nashorn.internal.objects";
|
||||
private static final String RUNTIME_PKG = "jdk.nashorn.internal.runtime";
|
||||
private static final String RUNTIME_LINKER_PKG = "jdk.nashorn.internal.runtime.linker";
|
||||
private static final String SCRIPTS_PKG = "jdk.nashorn.internal.scripts";
|
||||
|
||||
private static final Permission[] SCRIPT_PERMISSIONS;
|
||||
static {
|
||||
SCRIPT_PERMISSIONS = new Permission[4];
|
||||
|
||||
/*
|
||||
* Generated classes get access to runtime, runtime.linker, objects, scripts packages.
|
||||
* Note that the actual scripts can not access these because Java.type, Packages
|
||||
* prevent these restricted packages. And Java reflection and JSR292 access is prevented
|
||||
* for scripts. In other words, nashorn generated portions of script classes can access
|
||||
* clases in these implementation packages.
|
||||
*/
|
||||
SCRIPT_PERMISSIONS[0] = new RuntimePermission("accessClassInPackage." + RUNTIME_PKG);
|
||||
SCRIPT_PERMISSIONS[1] = new RuntimePermission("accessClassInPackage." + RUNTIME_LINKER_PKG);
|
||||
SCRIPT_PERMISSIONS[2] = new RuntimePermission("accessClassInPackage." + OBJECTS_PKG);
|
||||
SCRIPT_PERMISSIONS[3] = new RuntimePermission("accessClassInPackage." + SCRIPTS_PKG);
|
||||
}
|
||||
|
||||
private final Context context;
|
||||
|
||||
final Context getContext() {
|
||||
@ -68,11 +94,30 @@ abstract class NashornLoader extends SecureClassLoader {
|
||||
if (i != -1) {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPackageAccess(name.substring(0, i));
|
||||
final String pkgName = name.substring(0, i);
|
||||
switch (pkgName) {
|
||||
case RUNTIME_PKG:
|
||||
case RUNTIME_LINKER_PKG:
|
||||
case OBJECTS_PKG:
|
||||
case SCRIPTS_PKG:
|
||||
// allow it.
|
||||
break;
|
||||
default:
|
||||
sm.checkPackageAccess(pkgName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PermissionCollection getPermissions(CodeSource codesource) {
|
||||
final Permissions permCollection = new Permissions();
|
||||
for (final Permission perm : SCRIPT_PERMISSIONS) {
|
||||
permCollection.add(perm);
|
||||
}
|
||||
return permCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a secure URL class loader for the given classpath
|
||||
* @param classPath classpath for the loader to search from
|
||||
|
@ -26,6 +26,7 @@
|
||||
package jdk.nashorn.internal.runtime;
|
||||
|
||||
import java.security.CodeSource;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
/**
|
||||
* Responsible for loading script generated classes.
|
||||
@ -57,6 +58,10 @@ final class ScriptLoader extends NashornLoader {
|
||||
* @return Installed class.
|
||||
*/
|
||||
synchronized Class<?> installClass(final String name, final byte[] data, final CodeSource cs) {
|
||||
return defineClass(name, data, 0, data.length, cs);
|
||||
if (cs == null) {
|
||||
return defineClass(name, data, 0, data.length, new ProtectionDomain(null, getPermissions(null)));
|
||||
} else {
|
||||
return defineClass(name, data, 0, data.length, cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import java.security.CodeSigner;
|
||||
import java.security.CodeSource;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.security.ProtectionDomain;
|
||||
import jdk.nashorn.internal.codegen.ObjectClassGenerator;
|
||||
|
||||
/**
|
||||
@ -129,6 +130,6 @@ final class StructureLoader extends NashornLoader {
|
||||
}
|
||||
|
||||
final byte[] code = new ObjectClassGenerator(context).generate(descriptor);
|
||||
return defineClass(name, code, 0, code.length);
|
||||
return defineClass(name, code, 0, code.length, new ProtectionDomain(null, getPermissions(null)));
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public final class Bootstrap {
|
||||
static {
|
||||
final DynamicLinkerFactory factory = new DynamicLinkerFactory();
|
||||
factory.setPrioritizedLinkers(new NashornLinker(), new NashornPrimitiveLinker(), new NashornStaticClassLinker(),
|
||||
new JSObjectLinker());
|
||||
new JSObjectLinker(), new ReflectionCheckLinker());
|
||||
factory.setFallbackLinkers(new BeansLinker(), new NashornBottomLinker());
|
||||
factory.setSyncOnRelink(true);
|
||||
final int relinkThreshold = Options.getIntProperty("nashorn.unstable.relink.threshold", -1);
|
||||
|
@ -54,6 +54,7 @@ import java.security.CodeSigner;
|
||||
import java.security.CodeSource;
|
||||
import java.security.Permissions;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.security.SecureClassLoader;
|
||||
import java.security.SecureRandom;
|
||||
@ -410,9 +411,13 @@ public final class JavaAdapterFactory {
|
||||
*/
|
||||
public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType) throws Exception {
|
||||
final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType });
|
||||
return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(NashornCallSiteDescriptor.get(
|
||||
"dyn:new", MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false,
|
||||
adapterClass, null)).getInvocation(), adapterClass);
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<MethodHandle>() {
|
||||
public MethodHandle run() throws Exception {
|
||||
return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl(NashornCallSiteDescriptor.get(
|
||||
"dyn:new", MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false,
|
||||
adapterClass, null)).getInvocation(), adapterClass);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -456,8 +461,25 @@ public final class JavaAdapterFactory {
|
||||
private static ClassLoader createClassLoader(final ClassLoader parentLoader, final String className,
|
||||
final byte[] classBytes, final String privilegedActionClassName) {
|
||||
return new AdapterLoader(parentLoader) {
|
||||
private final ClassLoader myLoader = getClass().getClassLoader();
|
||||
private final ProtectionDomain myProtectionDomain = getClass().getProtectionDomain();
|
||||
|
||||
@Override
|
||||
public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
|
||||
try {
|
||||
return super.loadClass(name, resolve);
|
||||
} catch (final SecurityException se) {
|
||||
// we may be implementing an interface or extending a class that was
|
||||
// loaded by a loader that prevents package.access. If so, it'd throw
|
||||
// SecurityException for nashorn's classes!. For adapter's to work, we
|
||||
// should be able to refer to nashorn classes.
|
||||
if (name.startsWith("jdk.nashorn.internal.")) {
|
||||
return myLoader.loadClass(name);
|
||||
}
|
||||
throw se;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> findClass(final String name) throws ClassNotFoundException {
|
||||
if(name.equals(className)) {
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.runtime.linker;
|
||||
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
import jdk.internal.dynalink.linker.LinkRequest;
|
||||
import jdk.internal.dynalink.linker.LinkerServices;
|
||||
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
|
||||
|
||||
/**
|
||||
* Check java reflection permission for java reflective and java.lang.invoke access from scripts
|
||||
*/
|
||||
final class ReflectionCheckLinker implements TypeBasedGuardingDynamicLinker{
|
||||
@Override
|
||||
public boolean canLinkType(final Class<?> type) {
|
||||
return canLinkTypeStatic(type);
|
||||
}
|
||||
|
||||
private static boolean canLinkTypeStatic(final Class<?> type) {
|
||||
if (type == Class.class || ClassLoader.class.isAssignableFrom(type)) {
|
||||
return true;
|
||||
}
|
||||
final String name = type.getName();
|
||||
return name.startsWith("java.lang.reflect.") || name.startsWith("java.lang.invoke.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuardedInvocation getGuardedInvocation(final LinkRequest origRequest, final LinkerServices linkerServices)
|
||||
throws Exception {
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("nashorn.JavaReflection"));
|
||||
}
|
||||
// let the next linker deal with actual linking
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
@ -34,7 +34,7 @@ Object.defineProperty(this, "JavaAdapter", {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError("JavaAdapter requires atleast two arguments");
|
||||
}
|
||||
|
||||
|
||||
var types = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
|
||||
var NewType = Java.extend.apply(Java, types);
|
||||
return new NewType(arguments[arguments.length - 1]);
|
||||
@ -56,10 +56,10 @@ Object.defineProperty(this, "importPackage", {
|
||||
return type;
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
|
||||
return oldNoSuchProperty? oldNoSuchProperty(name) : undefined;
|
||||
}
|
||||
|
||||
|
||||
var prefix = "[JavaPackage ";
|
||||
return function() {
|
||||
for (var i in arguments) {
|
||||
@ -343,7 +343,9 @@ Object.defineProperty(this, "importClass", {
|
||||
configurable: true, enumerable: false, writable: true,
|
||||
value: function(clazz) {
|
||||
if (Java.isType(clazz)) {
|
||||
this[clazz.class.getSimpleName()] = clazz;
|
||||
var className = Java.typeName(clazz);
|
||||
var simpleName = className.substring(className.lastIndexOf('.') + 1);
|
||||
this[simpleName] = clazz;
|
||||
} else {
|
||||
throw new TypeError(clazz + " is not a Java class");
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
@ -47,7 +47,7 @@ function parse(/*code, [name], [location]*/) {
|
||||
code = arguments[0];
|
||||
}
|
||||
|
||||
var jsonStr = Packages.jdk.nashorn.internal.runtime.ScriptRuntime.parse(code, name, location);
|
||||
var jsonStr = Packages.jdk.nashorn.api.scripting.ScriptUtils.parse(code, name, location);
|
||||
return JSON.parse(jsonStr,
|
||||
function (prop, value) {
|
||||
if (typeof(value) == 'string' && prop == "value") {
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
var File = Java.type("java.io.File");
|
||||
var FilenameFilter = Java.type("java.io.FilenameFilter");
|
||||
var Source = Java.type("jdk.nashorn.internal.runtime.Source")
|
||||
var SourceHelper = Java.type("jdk.nashorn.test.models.SourceHelper")
|
||||
|
||||
// Filter out non .js files
|
||||
var files = new File(__DIR__).listFiles(new FilenameFilter() {
|
||||
@ -44,5 +44,5 @@ load("nashorn:parser.js");
|
||||
|
||||
// parse each file to make sure it does not result in exception
|
||||
for each (var f in files) {
|
||||
parse(new Source(f.toString(), f).getString());
|
||||
parse(SourceHelper.readFully(f));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
* @run
|
||||
*/
|
||||
|
||||
var t = new Packages.jdk.nashorn.internal.runtime.Nashorn401TestSubject();
|
||||
var t = new Packages.jdk.nashorn.test.models.Nashorn401TestSubject();
|
||||
|
||||
print(t.method2(10));
|
||||
print(t.method2(10.2));
|
||||
|
@ -37,4 +37,4 @@ list.add(String(new String(str + "2"))); // String() called as function with
|
||||
list.add((str + "3").toString()); // toString() called on primitive string
|
||||
list.add(new String(str + "4").toString()); // toString() called on String object
|
||||
|
||||
Packages.jdk.nashorn.internal.test.models.StringArgs.checkString(list);
|
||||
Packages.jdk.nashorn.test.models.StringArgs.checkString(list);
|
||||
|
@ -41,8 +41,8 @@ print(file + " : " + __LINE__);
|
||||
load(__DIR__ + "loadedfile.js");
|
||||
|
||||
// Add check for base part of a URL. We can't test __DIR__ inside
|
||||
// a script that is downloaded from a URL. check for Source.baseURL
|
||||
// a script that is downloaded from a URL. check for SourceHelper.baseURL
|
||||
// which is exposed as __DIR__ for URL case.
|
||||
|
||||
var url = new java.net.URL("http://www.acme.com:8080/foo/bar.js");
|
||||
print(Packages.jdk.nashorn.internal.runtime.Source.baseURL(url));
|
||||
print(Packages.jdk.nashorn.test.models.SourceHelper.baseURL(url));
|
||||
|
@ -29,25 +29,25 @@
|
||||
*/
|
||||
|
||||
// Do it with Java.type()
|
||||
var outer = new (Java.type("jdk.nashorn.internal.test.models.OuterClass"))("apple")
|
||||
var outer = new (Java.type("jdk.nashorn.test.models.OuterClass"))("apple")
|
||||
print(outer)
|
||||
var innerStatic = new (Java.type("jdk.nashorn.internal.test.models.OuterClass$InnerStaticClass"))("orange")
|
||||
var innerStatic = new (Java.type("jdk.nashorn.test.models.OuterClass$InnerStaticClass"))("orange")
|
||||
print(innerStatic)
|
||||
var innerNonStatic = new (Java.type("jdk.nashorn.internal.test.models.OuterClass$InnerNonStaticClass"))(outer, "pear")
|
||||
var innerNonStatic = new (Java.type("jdk.nashorn.test.models.OuterClass$InnerNonStaticClass"))(outer, "pear")
|
||||
print(innerNonStatic)
|
||||
|
||||
// Now do it with Packages and explicit $ names
|
||||
var outer = new Packages.jdk.nashorn.internal.test.models.OuterClass("red")
|
||||
var outer = new Packages.jdk.nashorn.test.models.OuterClass("red")
|
||||
print(outer)
|
||||
var innerStatic = new Packages.jdk.nashorn.internal.test.models.OuterClass$InnerStaticClass("green")
|
||||
var innerStatic = new Packages.jdk.nashorn.test.models.OuterClass$InnerStaticClass("green")
|
||||
print(innerStatic)
|
||||
var innerNonStatic = new Packages.jdk.nashorn.internal.test.models.OuterClass$InnerNonStaticClass(outer, "blue")
|
||||
var innerNonStatic = new Packages.jdk.nashorn.test.models.OuterClass$InnerNonStaticClass(outer, "blue")
|
||||
print(innerNonStatic)
|
||||
|
||||
// Now do it with Packages and nested properties
|
||||
var outer = new Packages.jdk.nashorn.internal.test.models.OuterClass("sweet")
|
||||
var outer = new Packages.jdk.nashorn.test.models.OuterClass("sweet")
|
||||
print(outer)
|
||||
var innerStatic = new Packages.jdk.nashorn.internal.test.models.OuterClass.InnerStaticClass("sour")
|
||||
var innerStatic = new Packages.jdk.nashorn.test.models.OuterClass.InnerStaticClass("sour")
|
||||
print(innerStatic)
|
||||
var innerNonStatic = new Packages.jdk.nashorn.internal.test.models.OuterClass.InnerNonStaticClass(outer, "bitter")
|
||||
var innerNonStatic = new Packages.jdk.nashorn.test.models.OuterClass.InnerNonStaticClass(outer, "bitter")
|
||||
print(innerNonStatic)
|
||||
|
@ -28,7 +28,7 @@
|
||||
* @run
|
||||
*/
|
||||
var l = new java.util.ArrayList();
|
||||
print("l.class.name=" + l.class.name) // Has "class" property like any POJO
|
||||
print("l.class.name=" + Java.typeName(l.class)) // Has "class" property like any POJO
|
||||
|
||||
l.add("foo")
|
||||
l.add("bar")
|
||||
|
@ -28,7 +28,7 @@
|
||||
* @run
|
||||
*/
|
||||
var m = new (Java.type("java.util.LinkedHashMap"));
|
||||
print("m.class.name=" + m.class.name) // Has "class" property like any POJO
|
||||
print("m.class.name=" + Java.typeName(m.class)) // Has "class" property like any POJO
|
||||
|
||||
var empty_key = "empty"
|
||||
|
||||
|
@ -28,8 +28,8 @@
|
||||
* @run
|
||||
*/
|
||||
|
||||
print(java.lang.System.in.class.name);
|
||||
print(Java.typeName(java.lang.System.in.class));
|
||||
var prop = "in";
|
||||
print(java.lang.System[prop].class.name);
|
||||
print(java.lang.System["in"].class.name);
|
||||
print(Java.typeName(java.lang.System[prop].class));
|
||||
print(Java.typeName(java.lang.System["in"].class));
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
function model(n) {
|
||||
return Java.type("jdk.nashorn.internal.test.models." + n)
|
||||
return Java.type("jdk.nashorn.test.models." + n)
|
||||
}
|
||||
|
||||
// Can't extend a final class
|
||||
|
@ -1,6 +1,6 @@
|
||||
TypeError: Can not extend final class jdk.nashorn.internal.test.models.FinalClass.
|
||||
TypeError: Can not extend class jdk.nashorn.internal.test.models.NoAccessibleConstructorClass as it has no public or protected constructors.
|
||||
TypeError: Can not extend/implement non-public class/interface jdk.nashorn.internal.test.models.NonPublicClass.
|
||||
TypeError: Can not extend final class jdk.nashorn.test.models.FinalClass.
|
||||
TypeError: Can not extend class jdk.nashorn.test.models.NoAccessibleConstructorClass as it has no public or protected constructors.
|
||||
TypeError: Can not extend/implement non-public class/interface jdk.nashorn.test.models.NonPublicClass.
|
||||
TypeError: Can not extend multiple classes java.lang.Number and java.lang.Thread. At most one of the specified types can be a class, the rest must all be interfaces.
|
||||
abcdabcd
|
||||
run-object
|
||||
|
@ -30,9 +30,7 @@
|
||||
*/
|
||||
|
||||
function check(e) {
|
||||
if (e instanceof java.lang.SecurityException) {
|
||||
print(e);
|
||||
} else {
|
||||
if (! (e instanceof java.lang.SecurityException)) {
|
||||
fail("expected SecurityException, got " + e);
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
|
@ -30,9 +30,7 @@
|
||||
*/
|
||||
|
||||
function check(e) {
|
||||
if (e instanceof java.lang.SecurityException) {
|
||||
print(e);
|
||||
} else {
|
||||
if (! (e instanceof java.lang.SecurityException)) {
|
||||
fail("expected SecurityException, got " + e);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.misc")
|
||||
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.misc")
|
||||
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun")
|
||||
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
|
@ -9,7 +9,7 @@ var URLReader = Java.type("jdk.nashorn.api.scripting.URLReader");
|
||||
var URL = Java.type("java.net.URL");
|
||||
var File = Java.type("java.io.File");
|
||||
var JString = Java.type("java.lang.String");
|
||||
var Source = Java.type("jdk.nashorn.internal.runtime.Source");
|
||||
var SourceHelper = Java.type("jdk.nashorn.test.models.SourceHelper");
|
||||
|
||||
var url = new File(__FILE__).toURI().toURL();
|
||||
var reader = new URLReader(url);
|
||||
@ -19,9 +19,9 @@ var reader = new URLReader(url);
|
||||
|
||||
// check URL read
|
||||
// read URL content by directly reading from URL
|
||||
var str = new Source(url.toString(), url).getString();
|
||||
var str = SourceHelper.readFully(url);
|
||||
// read URL content via URLReader
|
||||
var content = new JString(Source.readFully(reader));
|
||||
var content = new JString(SourceHelper.readFully(reader));
|
||||
|
||||
// assert that the content is same
|
||||
Assert.assertEquals(str, content);
|
||||
|
@ -47,7 +47,6 @@ import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import javax.script.SimpleScriptContext;
|
||||
import jdk.nashorn.internal.runtime.Version;
|
||||
import netscape.javascript.JSObject;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
@ -129,7 +128,6 @@ public class ScriptEngineTest {
|
||||
assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
|
||||
assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
|
||||
assertEquals(fac.getEngineName(), "Oracle Nashorn");
|
||||
assertEquals(fac.getEngineVersion(), Version.version());
|
||||
assertEquals(fac.getOutputStatement("context"), "print(context)");
|
||||
assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
|
||||
assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
|
||||
@ -313,27 +311,6 @@ public class ScriptEngineTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static void alert(final Object msg) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exposeMethodTest() {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
|
||||
try {
|
||||
final Method alert = ScriptEngineTest.class.getMethod("alert", Object.class);
|
||||
// expose a Method object as global var.
|
||||
e.put("alert", alert);
|
||||
// call the global var.
|
||||
e.eval("alert.invoke(null, 'alert! alert!!')");
|
||||
} catch (final NoSuchMethodException | SecurityException | ScriptException exp) {
|
||||
exp.printStackTrace();
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putGlobalFunctionTest() {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
@ -592,13 +569,6 @@ public class ScriptEngineTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void versionTest() {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
assertEquals(e.getFactory().getEngineVersion(), Version.version());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noEnumerablePropertiesTest() {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
@ -874,26 +844,4 @@ public class ScriptEngineTest {
|
||||
fail(se.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryOptionsTest() {
|
||||
final ScriptEngineManager sm = new ScriptEngineManager();
|
||||
for (ScriptEngineFactory fac : sm.getEngineFactories()) {
|
||||
if (fac instanceof NashornScriptEngineFactory) {
|
||||
final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
|
||||
// specify --no-syntax-extensions flag
|
||||
final String[] options = new String[] { "--no-syntax-extensions" };
|
||||
final ScriptEngine e = nfac.getScriptEngine(options);
|
||||
try {
|
||||
// try nashorn specific extension
|
||||
e.eval("var f = funtion(x) 2*x;");
|
||||
fail("should have thrown exception!");
|
||||
} catch (final ScriptException se) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fail("Cannot find nashorn factory!");
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
package jdk.nashorn.internal.runtime;
|
||||
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
@ -40,6 +40,13 @@ import org.testng.annotations.Test;
|
||||
* Tests for trusted client usage of nashorn script engine factory extension API
|
||||
*/
|
||||
public class TrustedScriptEngineTest {
|
||||
@Test
|
||||
public void versionTest() {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
assertEquals(e.getFactory().getEngineVersion(), Version.version());
|
||||
}
|
||||
|
||||
private static class MyClassLoader extends ClassLoader {
|
||||
// to check if script engine uses the specified class loader
|
||||
private final boolean[] reached = new boolean[1];
|
||||
@ -116,4 +123,26 @@ public class TrustedScriptEngineTest {
|
||||
|
||||
fail("Cannot find nashorn factory!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryOptionsTest() {
|
||||
final ScriptEngineManager sm = new ScriptEngineManager();
|
||||
for (ScriptEngineFactory fac : sm.getEngineFactories()) {
|
||||
if (fac instanceof NashornScriptEngineFactory) {
|
||||
final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
|
||||
// specify --no-syntax-extensions flag
|
||||
final String[] options = new String[] { "--no-syntax-extensions" };
|
||||
final ScriptEngine e = nfac.getScriptEngine(options);
|
||||
try {
|
||||
// try nashorn specific extension
|
||||
e.eval("var f = funtion(x) 2*x;");
|
||||
fail("should have thrown exception!");
|
||||
} catch (final ScriptException se) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fail("Cannot find nashorn factory!");
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public abstract class ConstructorWithArgument {
|
||||
private final String token;
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public interface DessertTopping {
|
||||
public String pourOnDessert();
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public class DessertToppingFloorWaxDriver {
|
||||
public void decorateDessert(DessertTopping dt) {
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public final class FinalClass {
|
||||
//empty
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public interface FloorWax {
|
||||
public String shineUpTheFloor();
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.runtime;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public class Nashorn401TestSubject {
|
||||
public String method2(int arg) {
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public class NoAccessibleConstructorClass {
|
||||
NoAccessibleConstructorClass() { }
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
class NonPublicClass {
|
||||
public NonPublicClass() { }
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public class OuterClass {
|
||||
private final String value;
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public interface OverloadedSam {
|
||||
public void sam(String s);
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public class OverrideObject {
|
||||
@Override
|
55
nashorn/test/src/jdk/nashorn/test/models/SourceHelper.java
Normal file
55
nashorn/test/src/jdk/nashorn/test/models/SourceHelper.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import jdk.nashorn.internal.runtime.Source;
|
||||
|
||||
/**
|
||||
* Helper class to facilitate script access of nashorn Source class.
|
||||
*/
|
||||
public final class SourceHelper {
|
||||
private SourceHelper() {}
|
||||
|
||||
public static String baseURL(final URL url) {
|
||||
return Source.baseURL(url);
|
||||
}
|
||||
|
||||
public static String readFully(final File file) throws IOException {
|
||||
return new String(Source.readFully(file));
|
||||
}
|
||||
|
||||
public static String readFully(final URL url) throws IOException {
|
||||
return new Source(url.toString(), url).getString();
|
||||
}
|
||||
|
||||
public static String readFully(final Reader reader) throws IOException {
|
||||
return new String(Source.readFully(reader));
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.internal.test.models;
|
||||
package jdk.nashorn.test.models;
|
||||
|
||||
public abstract class Toothpaste {
|
||||
public void applyToBrush() {
|
Loading…
x
Reference in New Issue
Block a user