aboutsummaryrefslogtreecommitdiff
path: root/src/jdk
diff options
context:
space:
mode:
Diffstat (limited to 'src/jdk')
-rw-r--r--src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java10
-rw-r--r--src/jdk/nashorn/api/scripting/ScriptUtils.java48
-rw-r--r--src/jdk/nashorn/internal/objects/Global.java24
-rw-r--r--src/jdk/nashorn/internal/objects/NativeDebug.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeJava.java17
-rw-r--r--src/jdk/nashorn/internal/runtime/Context.java25
-rw-r--r--src/jdk/nashorn/internal/runtime/NashornLoader.java47
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptLoader.java7
-rw-r--r--src/jdk/nashorn/internal/runtime/StructureLoader.java3
-rw-r--r--src/jdk/nashorn/internal/runtime/linker/Bootstrap.java2
-rw-r--r--src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java28
-rw-r--r--src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java60
-rw-r--r--src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js18
-rw-r--r--src/jdk/nashorn/internal/runtime/resources/parser.js10
14 files changed, 272 insertions, 29 deletions
diff --git a/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java b/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java
index 47a0c595..4672f6a0 100644
--- a/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java
+++ b/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java
@@ -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;
diff --git a/src/jdk/nashorn/api/scripting/ScriptUtils.java b/src/jdk/nashorn/api/scripting/ScriptUtils.java
new file mode 100644
index 00000000..63358bd7
--- /dev/null
+++ b/src/jdk/nashorn/api/scripting/ScriptUtils.java
@@ -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);
+ }
+}
diff --git a/src/jdk/nashorn/internal/objects/Global.java b/src/jdk/nashorn/internal/objects/Global.java
index b89d2073..a9835f6f 100644
--- a/src/jdk/nashorn/internal/objects/Global.java
+++ b/src/jdk/nashorn/internal/objects/Global.java
@@ -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");
diff --git a/src/jdk/nashorn/internal/objects/NativeDebug.java b/src/jdk/nashorn/internal/objects/NativeDebug.java
index 3d6fcbc8..8188f426 100644
--- a/src/jdk/nashorn/internal/objects/NativeDebug.java
+++ b/src/jdk/nashorn/internal/objects/NativeDebug.java
@@ -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();
}
diff --git a/src/jdk/nashorn/internal/objects/NativeJava.java b/src/jdk/nashorn/internal/objects/NativeJava.java
index fc16962e..2519c028 100644
--- a/src/jdk/nashorn/internal/objects/NativeJava.java
+++ b/src/jdk/nashorn/internal/objects/NativeJava.java
@@ -223,6 +223,23 @@ public final class NativeJava {
}
/**
+ * 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:
* <pre>
diff --git a/src/jdk/nashorn/internal/runtime/Context.java b/src/jdk/nashorn/internal/runtime/Context.java
index 1c4a08c8..516c0a79 100644
--- a/src/jdk/nashorn/internal/runtime/Context.java
+++ b/src/jdk/nashorn/internal/runtime/Context.java
@@ -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;
diff --git a/src/jdk/nashorn/internal/runtime/NashornLoader.java b/src/jdk/nashorn/internal/runtime/NashornLoader.java
index 80a0b8e6..5ce31008 100644
--- a/src/jdk/nashorn/internal/runtime/NashornLoader.java
+++ b/src/jdk/nashorn/internal/runtime/NashornLoader.java
@@ -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
diff --git a/src/jdk/nashorn/internal/runtime/ScriptLoader.java b/src/jdk/nashorn/internal/runtime/ScriptLoader.java
index d6321662..adecd8a3 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptLoader.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptLoader.java
@@ -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);
+ }
}
}
diff --git a/src/jdk/nashorn/internal/runtime/StructureLoader.java b/src/jdk/nashorn/internal/runtime/StructureLoader.java
index da64655f..35786b0b 100644
--- a/src/jdk/nashorn/internal/runtime/StructureLoader.java
+++ b/src/jdk/nashorn/internal/runtime/StructureLoader.java
@@ -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)));
}
}
diff --git a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java
index 3c5e2d81..6b55656b 100644
--- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java
+++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java
@@ -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);
diff --git a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java
index a9e4bd01..ba599da1 100644
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java
+++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java
@@ -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,9 +461,26 @@ 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)) {
final byte[] bytes = classBytes;
diff --git a/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java b/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
new file mode 100644
index 00000000..eb8837a8
--- /dev/null
+++ b/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
@@ -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;
+ }
+}
diff --git a/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js b/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js
index 15c67f94..0b967d69 100644
--- a/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js
+++ b/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js
@@ -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");
}
diff --git a/src/jdk/nashorn/internal/runtime/resources/parser.js b/src/jdk/nashorn/internal/runtime/resources/parser.js
index b89f7e12..8671d365 100644
--- a/src/jdk/nashorn/internal/runtime/resources/parser.js
+++ b/src/jdk/nashorn/internal/runtime/resources/parser.js
@@ -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") {