提交 7de8a938 编写于 作者: L lana

Merge

......@@ -236,6 +236,10 @@
<fileset dir="${test.src.dir}/META-INF/services/"/>
</copy>
<copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/resources">
<fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/resources"/>
</copy>
<!-- tests that check nashorn internals and internal API -->
<jar jarfile="${nashorn.internal.tests.jar}">
<fileset dir="${build.test.classes.dir}" excludes="**/api/**"/>
......@@ -245,6 +249,7 @@
<jar jarfile="${nashorn.api.tests.jar}">
<fileset dir="${build.test.classes.dir}" includes="**/api/**"/>
<fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
<fileset dir="${build.test.classes.dir}" includes="**/resources/*.js"/>
</jar>
</target>
......
# We would like to avoid references from anywhere outside nashorn
# to codegen, IR and parser packages, in particular script generated classes.
# 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 sensitive packages.
#
# List of comma-separated packages that start with or equal this string
# will cause a security exception to be thrown when
# 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.,jdk.nashorn.tools.
......@@ -234,7 +234,7 @@ run.test.jvmargs.main=${run.test.jvmargs.common} -ea
#-XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M
run.test.jvmargs.octane.main=${run.test.jvmargs.common}
run.test.jvmsecurityargs=-Xverify:all -Djava.security.properties=${basedir}/make/java.security.override -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
# VM options for script tests with @fork option
test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}
......
......@@ -313,7 +313,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
if (! Modifier.isPublic(clazz.getModifiers())) {
throw new SecurityException(getMessage("implementing.non.public.interface", clazz.getName()));
}
Context.checkPackageAccess(clazz.getName());
Context.checkPackageAccess(clazz);
}
ScriptObject realSelf = null;
......
......@@ -1082,24 +1082,6 @@ final class Attr extends NodeOperatorVisitor<LexicalContext> {
private boolean enterAssignmentNode(final BinaryNode binaryNode) {
start(binaryNode);
final Node lhs = binaryNode.lhs();
if (lhs instanceof IdentNode) {
final Block block = lc.getCurrentBlock();
final IdentNode ident = (IdentNode)lhs;
final String name = ident.getName();
Symbol symbol = findSymbol(block, name);
if (symbol == null) {
symbol = defineSymbol(block, name, IS_GLOBAL);
} else {
maybeForceScope(symbol);
}
addLocalDef(name);
}
return true;
}
......@@ -1112,20 +1094,33 @@ final class Attr extends NodeOperatorVisitor<LexicalContext> {
* @param binaryNode assignment node
*/
private Node leaveAssignmentNode(final BinaryNode binaryNode) {
BinaryNode newBinaryNode = binaryNode;
final Expression lhs = binaryNode.lhs();
final Expression rhs = binaryNode.rhs();
final Type type;
if (lhs instanceof IdentNode) {
final Block block = lc.getCurrentBlock();
final IdentNode ident = (IdentNode)lhs;
final String name = ident.getName();
final Symbol symbol = findSymbol(block, name);
if (symbol == null) {
defineSymbol(block, name, IS_GLOBAL);
} else {
maybeForceScope(symbol);
}
addLocalDef(name);
}
if (rhs.getType().isNumeric()) {
type = Type.widest(binaryNode.lhs().getType(), binaryNode.rhs().getType());
type = Type.widest(lhs.getType(), rhs.getType());
} else {
type = Type.OBJECT; //force lhs to be an object if not numeric assignment, e.g. strings too.
}
newType(lhs.getSymbol(), type);
return end(ensureSymbol(type, newBinaryNode));
return end(ensureSymbol(type, binaryNode));
}
private boolean isLocal(FunctionNode function, Symbol symbol) {
......
......@@ -1827,6 +1827,8 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
}
if (cases.isEmpty()) {
// still evaluate expression for side-effects.
load(expression).pop();
method.label(breakLabel);
return false;
}
......@@ -1956,7 +1958,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
final Expression expression = throwNode.getExpression();
final int position = throwNode.position();
final int line = source.getLine(position);
final int line = throwNode.getLineNumber();
final int column = source.getColumn(position);
load(expression);
......
......@@ -88,8 +88,8 @@ final class FoldConstants extends NodeVisitor<LexicalContext> {
@Override
public Node leaveIfNode(final IfNode ifNode) {
final Node test = ifNode.getTest();
if (test instanceof LiteralNode) {
final Block shortCut = ((LiteralNode<?>)test).isTrue() ? ifNode.getPass() : ifNode.getFail();
if (test instanceof LiteralNode.PrimitiveLiteralNode) {
final Block shortCut = ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue() ? ifNode.getPass() : ifNode.getFail();
if (shortCut != null) {
return new BlockStatement(ifNode.getLineNumber(), shortCut);
}
......@@ -101,8 +101,8 @@ final class FoldConstants extends NodeVisitor<LexicalContext> {
@Override
public Node leaveTernaryNode(final TernaryNode ternaryNode) {
final Node test = ternaryNode.getTest();
if (test instanceof LiteralNode) {
return ((LiteralNode<?>)test).isTrue() ? ternaryNode.getTrueExpression() : ternaryNode.getFalseExpression();
if (test instanceof LiteralNode.PrimitiveLiteralNode) {
return ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue() ? ternaryNode.getTrueExpression() : ternaryNode.getFalseExpression();
}
return ternaryNode;
}
......
......@@ -40,9 +40,10 @@ import jdk.nashorn.internal.ir.visitor.NodeVisitor;
*/
@Immutable
public final class IdentNode extends Expression implements PropertyKey, TypeOverride<IdentNode>, FunctionCall {
private static final int PROPERTY_NAME = 1 << 0;
private static final int INITIALIZED_HERE = 1 << 1;
private static final int FUNCTION = 1 << 2;
private static final int PROPERTY_NAME = 1 << 0;
private static final int INITIALIZED_HERE = 1 << 1;
private static final int FUNCTION = 1 << 2;
private static final int FUTURESTRICT_NAME = 1 << 3;
/** Identifier. */
private final String name;
......@@ -196,6 +197,25 @@ public final class IdentNode extends Expression implements PropertyKey, TypeOver
return new IdentNode(this, name, callSiteType, flags | PROPERTY_NAME);
}
/**
* Check if this IdentNode is a future strict name
* @return true if this is a future strict name
*/
public boolean isFutureStrictName() {
return (flags & FUTURESTRICT_NAME) != 0;
}
/**
* Flag this IdentNode as a future strict name
* @return a node equivalent to this one except for the requested change.
*/
public IdentNode setIsFutureStrictName() {
if (isFutureStrictName()) {
return this;
}
return new IdentNode(this, name, callSiteType, flags | FUTURESTRICT_NAME);
}
/**
* Helper function for local def analysis.
* @return true if IdentNode is initialized on creation
......
......@@ -587,11 +587,11 @@ public class LexicalContext {
final FunctionNode fn = (FunctionNode)node;
final Source source = fn.getSource();
String src = source.toString();
if (src.indexOf(File.pathSeparator) != -1) {
if (src.contains(File.pathSeparator)) {
src = src.substring(src.lastIndexOf(File.pathSeparator));
}
src += ' ';
src += source.getLine(fn.getStart());
src += fn.getLineNumber();
sb.append(src);
}
sb.append(' ');
......
......@@ -96,14 +96,6 @@ public abstract class LiteralNode<T> extends Expression implements PropertyKey {
return value == null;
}
/**
* Check if the literal value is boolean true
* @return true if literal value is boolean true
*/
public boolean isTrue() {
return JSType.toBoolean(value);
}
@Override
public Type getType() {
return Type.typeFor(value.getClass());
......@@ -259,8 +251,31 @@ public abstract class LiteralNode<T> extends Expression implements PropertyKey {
return new NullLiteralNode(parent.getToken(), parent.getFinish());
}
/**
* Super class for primitive (side-effect free) literals.
*
* @param <T> the literal type
*/
public static class PrimitiveLiteralNode<T> extends LiteralNode<T> {
private PrimitiveLiteralNode(final long token, final int finish, final T value) {
super(token, finish, value);
}
private PrimitiveLiteralNode(final PrimitiveLiteralNode<T> literalNode) {
super(literalNode);
}
/**
* Check if the literal value is boolean true
* @return true if literal value is boolean true
*/
public boolean isTrue() {
return JSType.toBoolean(value);
}
}
@Immutable
private static final class BooleanLiteralNode extends LiteralNode<Boolean> {
private static final class BooleanLiteralNode extends PrimitiveLiteralNode<Boolean> {
private BooleanLiteralNode(final long token, final int finish, final boolean value) {
super(Token.recast(token, value ? TokenType.TRUE : TokenType.FALSE), finish, value);
......@@ -312,7 +327,7 @@ public abstract class LiteralNode<T> extends Expression implements PropertyKey {
}
@Immutable
private static final class NumberLiteralNode extends LiteralNode<Number> {
private static final class NumberLiteralNode extends PrimitiveLiteralNode<Number> {
private final Type type = numberGetType(value);
......@@ -374,7 +389,7 @@ public abstract class LiteralNode<T> extends Expression implements PropertyKey {
return new NumberLiteralNode(parent.getToken(), parent.getFinish(), value);
}
private static class UndefinedLiteralNode extends LiteralNode<Undefined> {
private static class UndefinedLiteralNode extends PrimitiveLiteralNode<Undefined> {
private UndefinedLiteralNode(final long token, final int finish) {
super(Token.recast(token, TokenType.OBJECT), finish, ScriptRuntime.UNDEFINED);
}
......@@ -410,7 +425,7 @@ public abstract class LiteralNode<T> extends Expression implements PropertyKey {
}
@Immutable
private static class StringLiteralNode extends LiteralNode<String> {
private static class StringLiteralNode extends PrimitiveLiteralNode<String> {
private StringLiteralNode(final long token, final int finish, final String value) {
super(Token.recast(token, TokenType.STRING), finish, value);
}
......@@ -522,7 +537,7 @@ public abstract class LiteralNode<T> extends Expression implements PropertyKey {
return POSTSET_MARKER;
}
private static final class NullLiteralNode extends LiteralNode<Object> {
private static final class NullLiteralNode extends PrimitiveLiteralNode<Object> {
private NullLiteralNode(final long token, final int finish) {
super(Token.recast(token, TokenType.OBJECT), finish, null);
......
......@@ -819,8 +819,15 @@ public final class NativeArray extends ScriptObject {
if (bulkable(sobj)) {
sobj.getArray().shiftLeft(1);
} else {
boolean hasPrevious = true;
for (long k = 1; k < len; k++) {
sobj.set(k - 1, sobj.get(k), true);
boolean hasCurrent = sobj.has(k);
if (hasCurrent) {
sobj.set(k - 1, sobj.get(k), true);
} else if (hasPrevious) {
sobj.delete(k - 1, true);
}
hasPrevious = hasCurrent;
}
}
sobj.delete(--len, true);
......@@ -860,9 +867,12 @@ public final class NativeArray extends ScriptObject {
return new NativeArray(sobj.getArray().slice(k, finale));
}
final NativeArray copy = new NativeArray(0);
// Construct array with proper length to have a deleted filter on undefined elements
final NativeArray copy = new NativeArray(finale - k);
for (long n = 0; k < finale; n++, k++) {
copy.defineOwnProperty(ArrayIndex.getArrayIndex(n), sobj.get(k));
if (sobj.has(k)) {
copy.defineOwnProperty(ArrayIndex.getArrayIndex(n), sobj.get(k));
}
}
return copy;
......
......@@ -37,10 +37,12 @@ import jdk.nashorn.internal.objects.annotations.Function;
import jdk.nashorn.internal.objects.annotations.Property;
import jdk.nashorn.internal.objects.annotations.ScriptClass;
import jdk.nashorn.internal.objects.annotations.Where;
import jdk.nashorn.internal.objects.ScriptFunctionImpl;
import jdk.nashorn.internal.runtime.ECMAException;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptRuntime;
/**
......@@ -138,7 +140,10 @@ public final class NativeError extends ScriptObject {
Global.checkObject(errorObj);
final ScriptObject sobj = (ScriptObject)errorObj;
final ECMAException exp = new ECMAException(sobj, null);
sobj.set("stack", getScriptStackString(sobj, exp), false);
sobj.delete("stack", false);
final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK);
final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK);
sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
return UNDEFINED;
}
......
......@@ -221,6 +221,7 @@ public final class NativeFunction {
final StringBuilder sb = new StringBuilder();
sb.append("(function (");
final String funcBody;
if (args.length > 0) {
final StringBuilder paramListBuf = new StringBuilder();
for (int i = 0; i < args.length - 1; i++) {
......@@ -230,15 +231,20 @@ public final class NativeFunction {
}
}
// now convert function body to a string
funcBody = JSType.toString(args[args.length - 1]);
final String paramList = paramListBuf.toString();
if (! paramList.isEmpty()) {
checkFunctionParameters(paramList);
sb.append(paramList);
}
} else {
funcBody = null;
}
sb.append(") {\n");
if (args.length > 0) {
final String funcBody = JSType.toString(args[args.length - 1]);
checkFunctionBody(funcBody);
sb.append(funcBody);
sb.append('\n');
......
......@@ -378,7 +378,7 @@ public abstract class AbstractParser {
next();
// Create IDENT node.
return new IdentNode(identToken, finish, ident);
return new IdentNode(identToken, finish, ident).setIsFutureStrictName();
}
// Get IDENT.
......
......@@ -909,6 +909,10 @@ loop:
default:
break;
}
if (ident.isFutureStrictName()) {
throw error(AbstractParser.message("strict.name", ident.getName(), contextString), ident.getToken());
}
}
}
......@@ -2436,7 +2440,7 @@ loop:
// name is null, generate anonymous name
boolean isAnonymous = false;
if (name == null) {
final String tmpName = "_L" + source.getLine(Token.descPosition(token));
final String tmpName = "_L" + functionLine;
name = new IdentNode(functionToken, Token.descPosition(functionToken), tmpName);
isAnonymous = true;
}
......
......@@ -48,6 +48,7 @@ final class CompiledFunction implements Comparable<CompiledFunction> {
}
CompiledFunction(final MethodType type, final MethodHandle invoker, final MethodHandle constructor) {
assert type != null;
this.type = type;
this.invoker = invoker;
this.constructor = constructor;
......@@ -80,7 +81,37 @@ final class CompiledFunction implements Comparable<CompiledFunction> {
@Override
public int compareTo(final CompiledFunction o) {
return weight() - o.weight();
return compareMethodTypes(type(), o.type());
}
private static int compareMethodTypes(final MethodType ownType, final MethodType otherType) {
// Comparable interface demands that compareTo() should only return 0 if objects are equal.
// Failing to meet this requirement causes same weight functions to replace each other in TreeSet,
// so we go some lengths to come up with an ordering between same weight functions,
// first falling back to parameter count and then to hash code.
if (ownType.equals(otherType)) {
return 0;
}
final int diff = weight(ownType) - weight(otherType);
if (diff != 0) {
return diff;
}
if (ownType.parameterCount() != otherType.parameterCount()) {
return ownType.parameterCount() - otherType.parameterCount();
}
// We're just interested in not returning 0 here, not correct ordering
return ownType.hashCode() - otherType.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof CompiledFunction && type().equals(((CompiledFunction)obj).type());
}
@Override
public int hashCode() {
return type().hashCode();
}
private int weight() {
......@@ -119,14 +150,14 @@ final class CompiledFunction implements Comparable<CompiledFunction> {
* a semantically equivalent linkage can be performed.
*
* @param mt type to check against
* @return
* @return true if types are compatible
*/
boolean typeCompatible(final MethodType mt) {
final Class<?>[] wantedParams = mt.parameterArray();
final Class<?>[] existingParams = type().parameterArray();
final int wantedParamCount = mt.parameterCount();
final int existingParamCount = type.parameterCount();
//if we are not examining a varargs type, the number of parameters must be the same
if (wantedParams.length != existingParams.length && !isVarArgsType(mt)) {
if (wantedParamCount != existingParamCount && !isVarArgsType(mt)) {
return false;
}
......@@ -134,10 +165,10 @@ final class CompiledFunction implements Comparable<CompiledFunction> {
//parameters lengths do not match is if our type ends with a varargs argument.
//then every trailing parameter in the given callsite can be folded into it, making
//us compatible (albeit slower than a direct specialization)
final int lastParamIndex = Math.min(wantedParams.length, existingParams.length);
final int lastParamIndex = Math.min(wantedParamCount, existingParamCount);
for (int i = 0; i < lastParamIndex; i++) {
final Type w = Type.typeFor(wantedParams[i]);
final Type e = Type.typeFor(existingParams[i]);
final Type w = Type.typeFor(mt.parameterType(i));
final Type e = Type.typeFor(type.parameterType(i));
//don't specialize on booleans, we have the "true" vs int 1 ambiguity in resolution
//we also currently don't support boolean as a javascript function callsite type.
......
......@@ -91,6 +91,11 @@ public final class Context {
*/
public static final String NASHORN_JAVA_REFLECTION = "nashorn.JavaReflection";
// nashorn load psuedo URL prefixes
private static final String LOAD_CLASSPATH = "classpath:";
private static final String LOAD_FX = "fx:";
private static final String LOAD_NASHORN = "nashorn:";
/* Force DebuggerSupport to be loaded. */
static {
DebuggerSupport.FORCELOAD = true;
......@@ -501,21 +506,26 @@ public final class Context {
// or a ScriptObject that has "name" and "source" (string valued) properties.
if (src instanceof String) {
final String srcStr = (String)src;
final File file = new File(srcStr);
if (srcStr.indexOf(':') != -1) {
if ((source = loadInternal(srcStr, "nashorn:", "resources/")) == null &&
(source = loadInternal(srcStr, "fx:", "resources/fx/")) == null) {
URL url;
try {
//check for malformed url. if malformed, it may still be a valid file
url = new URL(srcStr);
} catch (final MalformedURLException e) {
url = file.toURI().toURL();
if (srcStr.startsWith(LOAD_CLASSPATH)) {
URL url = getResourceURL(srcStr.substring(LOAD_CLASSPATH.length()));
source = (url != null)? new Source(url.toString(), url) : null;
} else {
final File file = new File(srcStr);
if (srcStr.indexOf(':') != -1) {
if ((source = loadInternal(srcStr, LOAD_NASHORN, "resources/")) == null &&
(source = loadInternal(srcStr, LOAD_FX, "resources/fx/")) == null) {
URL url;
try {
//check for malformed url. if malformed, it may still be a valid file
url = new URL(srcStr);
} catch (final MalformedURLException e) {
url = file.toURI().toURL();
}
source = new Source(url.toString(), url);
}
source = new Source(url.toString(), url);
} else if (file.isFile()) {
source = new Source(srcStr, file);
}
} else if (file.isFile()) {
source = new Source(srcStr, file);
}
} else if (src instanceof File && ((File)src).isFile()) {
final File file = (File)src;
......@@ -609,37 +619,54 @@ public final class Context {
return Class.forName(fullName, true, sharedLoader);
}
/**
* Checks that the given Class can be accessed from no permissions context.
*
* @param clazz Class object
* @throw SecurityException if not accessible
*/
public static void checkPackageAccess(final Class clazz) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
Class bottomClazz = clazz;
while(bottomClazz.isArray()) {
bottomClazz = bottomClazz.getComponentType();
}
checkPackageAccess(sm, bottomClazz.getName());
}
}
/**
* Checks that the given package can be accessed from no permissions context.
*
* @param sm current security manager instance
* @param fullName fully qualified package name
* @throw SecurityException if not accessible
*/
public static void checkPackageAccess(final String fullName) {
private static void checkPackageAccess(final SecurityManager sm, final String fullName) {
sm.getClass(); // null check
final int index = fullName.lastIndexOf('.');
if (index != -1) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
sm.checkPackageAccess(fullName.substring(0, index));
return null;
}
}, NO_PERMISSIONS_ACC_CTXT);
}
final String pkgName = fullName.substring(0, index);
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
sm.checkPackageAccess(pkgName);
return null;
}
}, NO_PERMISSIONS_ACC_CTXT);
}
}
/**
* Checks that the given package can be accessed from no permissions context.
* Checks that the given Class can be accessed from no permissions context.
*
* @param fullName fully qualified package name
* @param clazz Class object
* @return true if package is accessible, false otherwise
*/
public static boolean isAccessiblePackage(final String fullName) {
private static boolean isAccessiblePackage(final Class clazz) {
try {
checkPackageAccess(fullName);
checkPackageAccess(clazz);
return true;
} catch (final SecurityException se) {
return false;
......@@ -653,7 +680,7 @@ public final class Context {
* @return true if Class is accessible, false otherwise
*/
public static boolean isAccessibleClass(final Class<?> clazz) {
return Modifier.isPublic(clazz.getModifiers()) && Context.isAccessiblePackage(clazz.getName());
return Modifier.isPublic(clazz.getModifiers()) && Context.isAccessiblePackage(clazz);
}
/**
......@@ -667,8 +694,16 @@ public final class Context {
* @throws ClassNotFoundException if class cannot be resolved
*/
public Class<?> findClass(final String fullName) throws ClassNotFoundException {
if (fullName.indexOf('[') != -1 || fullName.indexOf('/') != -1) {
// don't allow array class names or internal names.
throw new ClassNotFoundException(fullName);
}
// check package access as soon as possible!
checkPackageAccess(fullName);
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkPackageAccess(sm, fullName);
}
// try the script -classpath loader, if that is set
if (classPathLoader != null) {
......@@ -803,6 +838,18 @@ public final class Context {
return Context.getContextTrusted();
}
private URL getResourceURL(final String resName) throws IOException {
// try the classPathLoader if we have and then
// try the appLoader if non-null.
if (classPathLoader != null) {
return classPathLoader.getResource(resName);
} else if (appLoader != null) {
return appLoader.getResource(resName);
}
return null;
}
private Object evaluateSource(final Source source, final ScriptObject scope, final ScriptObject thiz) {
ScriptFunction script = null;
......
......@@ -132,7 +132,7 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData {
if (source != null) {
sb.append(source.getName())
.append(':')
.append(source.getLine(Token.descPosition(token)))
.append(functionNode.getLineNumber())
.append(' ');
}
......
......@@ -272,6 +272,10 @@ public final class Source {
/**
* Return line number of character position.
*
* <p>This method can be expensive for large sources as it iterates through
* all characters up to {@code position}.</p>
*
* @param position Position of character in source content.
* @return Line number.
*/
......
......@@ -109,7 +109,7 @@ public final class JavaAdapterFactory {
if (sm != null) {
for (Class<?> type : types) {
// check for restricted package access
Context.checkPackageAccess(type.getName());
Context.checkPackageAccess(type);
}
}
return getAdapterInfo(types).getAdapterClassFor(classOverrides);
......
......@@ -70,7 +70,7 @@ final class NashornStaticClassLinker implements TypeBasedGuardingDynamicLinker {
// We intercept "new" on StaticClass instances to provide additional capabilities
if ("new".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
// make sure new is on accessible Class
Context.checkPackageAccess(receiverClass.getName());
Context.checkPackageAccess(receiverClass);
// Is the class abstract? (This includes interfaces.)
if (NashornLinker.isAbstractClass(receiverClass)) {
......
......@@ -33,7 +33,6 @@ var JFX_SWING_CLASSES = [];
var JFX_SWT_CLASSES = [];
function LOAD_FX_CLASSES(clsList) {
for each (var cls in clsList) {
// Ex. Stage = Java.type("javafx.stage.Stage");
this[cls[cls.length - 1]] = Java.type(cls.join("."));
......@@ -146,3 +145,5 @@ function LOAD_FX_CLASSES(clsList) {
}
}
})();
LOAD_FX_CLASSES(JFX_BASE_CLASSES);
......@@ -48,7 +48,7 @@ function checkIterations(obj) {
function(x) x*x));
}
var array = new (Java.type("[I"))(4);
var array = new (Java.type("int[]"))(4);
for (var i in array) {
array[i] = i;
}
......
/*
* 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.
*/
/**
* JDK-8025213: Assignment marks variable as defined too early
*
* @test
* @run
*/
function test() {
if (String("")) {
var foo = 42;
}
foo = foo + 1;
print(foo);
}
test();
/*
* 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.
*/
/**
* JDK-8025488: Error.captureStackTrace should not format error stack
*
* @test
* @run
*/
function MyError () {
Error.call(this);
Error.captureStackTrace(this);
this.arr = {};
};
MyError.prototype.toString = function() {
return this.arr.toString();
}
var e = new MyError();
print(e.stack);
[object Object]
at MyError (test/script/basic/JDK-8025488.js:34)
at <program> (test/script/basic/JDK-8025488.js:42)
/*
* 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.
*/
/**
* JDK-8025515: Performance issues with Source.getLine()
*
* @test
* @run
*/
// Make sure synthetic names of anonymous functions have correct line numbers
function testMethodName(f, expected) {
try {
f();
fail("expected error");
} catch (e) {
var stack = e.getStackTrace();
if (stack[0].methodName !== expected) {
fail("got " + stack[0].methodName + ", expected " + expected);
}
}
}
testMethodName(function() {
return a.b.c;
}, "_L45");
testMethodName(function() { throw new Error() }, "_L49");
var f = (function() {
return function() { a.b.c; };
})();
testMethodName(f, "_L51$_L52");
testMethodName((function() {
return function() { return a.b.c; };
})(), "_L56$_L57");
/*
* 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.
*/
/**
* JDK-8025520: Array.prototype.slice should only copy defined elements
*
* @test
* @run
*/
var s = Array.prototype.slice.call({length: 6, 3: 1}, 2, 5);
if (s.length != 3) {
fail("s.length != 3");
}
if (0 in s) {
fail("0 in s");
}
if (s.hasOwnProperty(0)) {
fail("s.hasOwnProperty(0)");
}
if (s[1] !== 1) {
fail("s[1] !== 1");
}
if (2 in s) {
fail("2 in s");
}
if (s.hasOwnProperty(2)) {
fail("s.hasOwnProperty(2)");
}
/*
* 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.
*/
/**
* JDK-8025589: Array.prototype.shift should only copy defined elements in generic mode
*
* @test
* @run
*/
var s = {length: 4, 2: 1};
Array.prototype.shift.call(s);
if (s.length != 3) {
fail("s.length != 3");
}
if (0 in s) {
fail("0 in s");
}
if (s.hasOwnProperty(0)) {
fail("s.hasOwnProperty(0)");
}
if (s[1] !== 1) {
fail("s[1] !== 1");
}
if (2 in s) {
fail("2 in s");
}
if (s.hasOwnProperty(2)) {
fail("s.hasOwnProperty(2)");
}
/*
* 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.
*/
/**
* JDK-8026033: Switch should load expression even when there are no cases in it
*
* @test
* @run
*/
try {
(function() { switch(x) {} })();
fail("Should have thrown ReferenceError");
} catch (e) {
if (! (e instanceof ReferenceError)) {
fail("ReferenceError expected, got " + e);
}
print(e);
}
/*
* 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.
*/
/**
* JDK-8026042: FoldConstants need to guard against ArrayLiteralNode
*
* @test
* @run
*/
try {
if ([a]) {
print("fail");
}
} catch (e) {
print(e);
}
try {
[a] ? print(1) : print(2);
} catch (e) {
print(e);
}
ReferenceError: "a" is not defined
ReferenceError: "a" is not defined
/*
* 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.
*/
/**
* JDK-8026048: Function constructor should convert arguments to String before performing any syntax checks
*
* @test
* @run
*/
try {
Function("-", {toString:function(){throw "err"}})
} catch (e) {
if (e !== "err") {
fail("err xpected, got " + e);
}
}
/*
* 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.
*/
/**
* JDK-8026039: future strict names are allowed as function name and argument name of a strict function
*
* @test/compile-error
*/
function public() {"use strict"}
function f(public) {"use strict"}
test/script/error/JDK-8026039.js:30:9 "public" cannot be used as function name in strict mode
function public() {"use strict"}
^
test/script/error/JDK-8026039.js:32:11 Expected ident but found public
function f(public) {"use strict"}
^
test/script/error/JDK-8026039.js:33:0 Expected } but found eof
^
/*
* 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.
*/
/**
* Try to access array class of a sensitive class like Unsafe.
*
* @test
* @security
* @run
*/
try {
var unsafeArr = Java.type("[Lsun.misc.Unsafe;");
fail("No Exception for [Lsun.misc.Unsafe;");
} catch (e) {
print(e);
}
java.lang.ClassNotFoundException: [Lsun.misc.Unsafe;
/*
* 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.
*/
/**
* JDK-8025629: load function should support a way to load scripts from classpath
*
* @test
* @run
*/
load("classpath:jdk/nashorn/internal/runtime/resources/load_test.js")
Assert.assertEquals(loadedFunc("hello"), "HELLO");
/*
* 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.
*/
function loadedFunc(arg) {
return arg.toUpperCase();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册