This commit is contained in:
Athijegannathan Sundararajan 2013-07-29 10:28:03 +05:30
commit 95f14173b8
38 changed files with 438 additions and 318 deletions

View file

@ -152,14 +152,14 @@ public class ClassGenerator {
} }
static MethodGenerator makeStaticInitializer(final ClassVisitor cv, final String name) { static MethodGenerator makeStaticInitializer(final ClassVisitor cv, final String name) {
final int access = ACC_PUBLIC | ACC_STATIC; final int access = ACC_PUBLIC | ACC_STATIC;
final String desc = DEFAULT_INIT_DESC; final String desc = DEFAULT_INIT_DESC;
final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null); final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
return new MethodGenerator(mv, access, name, desc); return new MethodGenerator(mv, access, name, desc);
} }
static MethodGenerator makeConstructor(final ClassVisitor cv) { static MethodGenerator makeConstructor(final ClassVisitor cv) {
final int access = ACC_PUBLIC; final int access = 0;
final String name = INIT; final String name = INIT;
final String desc = DEFAULT_INIT_DESC; final String desc = DEFAULT_INIT_DESC;
final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null); final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);

View file

@ -25,6 +25,7 @@
package jdk.nashorn.internal.tools.nasgen; package jdk.nashorn.internal.tools.nasgen;
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_FINAL;
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC; import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER; import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKESTATIC; import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKESTATIC;
@ -80,7 +81,7 @@ public class ConstructorGenerator extends ClassGenerator {
byte[] getClassBytes() { byte[] getClassBytes() {
// new class extensing from ScriptObject // new class extensing from ScriptObject
final String superClass = (constructor != null)? SCRIPTFUNCTIONIMPL_TYPE : SCRIPTOBJECT_TYPE; final String superClass = (constructor != null)? SCRIPTFUNCTIONIMPL_TYPE : SCRIPTOBJECT_TYPE;
cw.visit(V1_7, ACC_PUBLIC | ACC_SUPER, className, null, superClass, null); cw.visit(V1_7, ACC_FINAL, className, null, superClass, null);
if (memberCount > 0) { if (memberCount > 0) {
// add fields // add fields
emitFields(); emitFields();

View file

@ -25,6 +25,7 @@
package jdk.nashorn.internal.tools.nasgen; package jdk.nashorn.internal.tools.nasgen;
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_FINAL;
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC; import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER; import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
import static jdk.internal.org.objectweb.asm.Opcodes.V1_7; import static jdk.internal.org.objectweb.asm.Opcodes.V1_7;
@ -60,7 +61,7 @@ public class PrototypeGenerator extends ClassGenerator {
byte[] getClassBytes() { byte[] getClassBytes() {
// new class extensing from ScriptObject // new class extensing from ScriptObject
cw.visit(V1_7, ACC_PUBLIC | ACC_SUPER, className, null, PROTOTYPEOBJECT_TYPE, null); cw.visit(V1_7, ACC_FINAL | ACC_SUPER, className, null, PROTOTYPEOBJECT_TYPE, null);
if (memberCount > 0) { if (memberCount > 0) {
// add fields // add fields
emitFields(); emitFields();

View file

@ -47,10 +47,10 @@
<!-- check if testng.jar is avaiable --> <!-- check if testng.jar is avaiable -->
<available property="testng.available" file="${file.reference.testng.jar}"/> <available property="testng.available" file="${file.reference.testng.jar}"/>
<!-- enable/disable make code coverage --> <!-- enable/disable make code coverage -->
<condition property="cc.enabled"> <condition property="cc.enabled">
<istrue value="${make.code.coverage}" /> <istrue value="${make.code.coverage}" />
</condition> </condition>
<!-- exclude tests in exclude lists --> <!-- exclude tests in exclude lists -->
<condition property="exclude.list" value="./exclude/exclude_list_cc.txt" else="./exclude/exclude_list.txt"> <condition property="exclude.list" value="./exclude/exclude_list_cc.txt" else="./exclude/exclude_list.txt">
@ -60,9 +60,9 @@
<target name="init" depends="init-conditions, init-cc"> <target name="init" depends="init-conditions, init-cc">
<!-- extends jvm args --> <!-- extends jvm args -->
<property name="run.test.jvmargs" value="${run.test.jvmargs.main} ${run.test.cc.jvmargs}"/> <property name="run.test.jvmargs" value="${run.test.jvmargs.main} ${run.test.cc.jvmargs}"/>
<property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main} ${run.test.cc.jvmargs}" /> <property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main} ${run.test.cc.jvmargs}" />
<echo message="run.test.jvmargs=${run.test.jvmargs}"/> <echo message="run.test.jvmargs=${run.test.jvmargs}"/>
<echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/> <echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/>
@ -294,19 +294,6 @@ grant codeBase "file:/${basedir}/test/script/basic/classloader.js" {
</target> </target>
<target name="test" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> <target name="test" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
<java classname="${nashorn.shell.tool}" fork="true" dir="${test.script.dir}/representations" output="${build.dir}/output1.log" error="${build.dir}/err.log">
<jvmarg line="${ext.class.path}"/>
<jvmarg line="-Dnashorn.fields.dual=true"/>
<arg value="NASHORN-592a.js"/>
</java>
<java classname="${nashorn.shell.tool}" fork="true" dir="${test.script.dir}/representations" output="${build.dir}/output2.log" error="${build.dir}/err.log">
<jvmarg line="${ext.class.path}"/>
<arg value="NASHORN-592a.js"/>
</java>
<condition property="representation-ok">
<filesmatch file1="${build.dir}/output1.log" file2="${build.dir}/output2.log"/>
</condition>
<fail unless="representation-ok">Representation test failed - output differs!</fail>
<fileset id="test.classes" dir="${build.test.classes.dir}"> <fileset id="test.classes" dir="${build.test.classes.dir}">
<include name="**/api/javaaccess/*Test.class"/> <include name="**/api/javaaccess/*Test.class"/>
<include name="**/api/scripting/*Test.class"/> <include name="**/api/scripting/*Test.class"/>

View file

@ -223,7 +223,6 @@ run.test.user.language=tr
run.test.user.country=TR run.test.user.country=TR
# -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMethods # -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMethods
# add '-Dtest.js.outofprocess' to run each test in a new sub-process
run.test.jvmargs.main=-server -Xmx${run.test.xmx} -XX:+TieredCompilation -ea -Dfile.encoding=UTF-8 -Duser.language=${run.test.user.language} -Duser.country=${run.test.user.country} run.test.jvmargs.main=-server -Xmx${run.test.xmx} -XX:+TieredCompilation -ea -Dfile.encoding=UTF-8 -Duser.language=${run.test.user.language} -Duser.country=${run.test.user.country}
#-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M #-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M
@ -231,6 +230,9 @@ run.test.jvmargs.octane.main=-Xms${run.test.xms} ${run.test.jvmargs.main}
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.properties=${basedir}/make/java.security.override -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} ${run.test.jvmsecurityargs}
# path of rhino.jar for benchmarks # path of rhino.jar for benchmarks
rhino.jar= rhino.jar=

View file

@ -35,7 +35,7 @@ import jdk.nashorn.internal.runtime.ScriptRuntime;
* must track their {@code [[TargetFunction]]} property for purposes of correctly implementing {@code [[HasInstance]]}; * must track their {@code [[TargetFunction]]} property for purposes of correctly implementing {@code [[HasInstance]]};
* see {@link ScriptFunction#isInstance(ScriptObject)}. * see {@link ScriptFunction#isInstance(ScriptObject)}.
*/ */
class BoundScriptFunctionImpl extends ScriptFunctionImpl { final class BoundScriptFunctionImpl extends ScriptFunctionImpl {
private final ScriptFunction targetFunction; private final ScriptFunction targetFunction;
BoundScriptFunctionImpl(ScriptFunctionData data, ScriptFunction targetFunction) { BoundScriptFunctionImpl(ScriptFunctionData data, ScriptFunction targetFunction) {

View file

@ -75,7 +75,7 @@ public class PrototypeObject extends ScriptObject {
* *
* @param map property map * @param map property map
*/ */
public PrototypeObject(final PropertyMap map) { PrototypeObject(final PropertyMap map) {
this(Global.instance(), map); this(Global.instance(), map);
} }
@ -89,7 +89,7 @@ public class PrototypeObject extends ScriptObject {
* @param self self reference * @param self self reference
* @return constructor, probably, but not necessarily, a {@link ScriptFunction} * @return constructor, probably, but not necessarily, a {@link ScriptFunction}
*/ */
public static Object getConstructor(final Object self) { static Object getConstructor(final Object self) {
return (self instanceof PrototypeObject) ? return (self instanceof PrototypeObject) ?
((PrototypeObject)self).getConstructor() : ((PrototypeObject)self).getConstructor() :
UNDEFINED; UNDEFINED;
@ -100,7 +100,7 @@ public class PrototypeObject extends ScriptObject {
* @param self self reference * @param self self reference
* @param constructor constructor, probably, but not necessarily, a {@link ScriptFunction} * @param constructor constructor, probably, but not necessarily, a {@link ScriptFunction}
*/ */
public static void setConstructor(final Object self, final Object constructor) { static void setConstructor(final Object self, final Object constructor) {
if (self instanceof PrototypeObject) { if (self instanceof PrototypeObject) {
((PrototypeObject)self).setConstructor(constructor); ((PrototypeObject)self).setConstructor(constructor);
} }

View file

@ -51,7 +51,7 @@ import jdk.nashorn.internal.lookup.MethodHandleFactory;
* An AccessorProperty is the most generic property type. An AccessorProperty is * An AccessorProperty is the most generic property type. An AccessorProperty is
* represented as fields in a ScriptObject class. * represented as fields in a ScriptObject class.
*/ */
public class AccessorProperty extends Property { public final class AccessorProperty extends Property {
private static final MethodHandles.Lookup lookup = MethodHandles.lookup(); private static final MethodHandles.Lookup lookup = MethodHandles.lookup();
private static final MethodHandle REPLACE_MAP = findOwnMH("replaceMap", Object.class, Object.class, PropertyMap.class, String.class, Class.class, Class.class); private static final MethodHandle REPLACE_MAP = findOwnMH("replaceMap", Object.class, Object.class, PropertyMap.class, String.class, Class.class, Class.class);
@ -149,7 +149,7 @@ public class AccessorProperty extends Property {
* @param property accessor property to rebind * @param property accessor property to rebind
* @param delegate delegate object to rebind receiver to * @param delegate delegate object to rebind receiver to
*/ */
public AccessorProperty(final AccessorProperty property, final Object delegate) { AccessorProperty(final AccessorProperty property, final Object delegate) {
super(property); super(property);
this.primitiveGetter = bindTo(property.primitiveGetter, delegate); this.primitiveGetter = bindTo(property.primitiveGetter, delegate);
@ -185,7 +185,7 @@ public class AccessorProperty extends Property {
* @param getter the property getter * @param getter the property getter
* @param setter the property setter or null if non writable, non configurable * @param setter the property setter or null if non writable, non configurable
*/ */
public AccessorProperty(final String key, final int flags, final int slot, final MethodHandle getter, final MethodHandle setter) { AccessorProperty(final String key, final int flags, final int slot, final MethodHandle getter, final MethodHandle setter) {
super(key, flags, slot); super(key, flags, slot);
// we don't need to prep the setters these will never be invalidated as this is a nasgen // we don't need to prep the setters these will never be invalidated as this is a nasgen

View file

@ -33,7 +33,7 @@ import java.lang.invoke.MethodHandle;
* This is a subclass that represents a script function that may not be regenerated. * This is a subclass that represents a script function that may not be regenerated.
* This is used for example for bound functions and builtins. * This is used for example for bound functions and builtins.
*/ */
public final class FinalScriptFunctionData extends ScriptFunctionData { final class FinalScriptFunctionData extends ScriptFunctionData {
/** /**
* Constructor - used for bind * Constructor - used for bind

View file

@ -47,7 +47,7 @@ import jdk.nashorn.internal.runtime.linker.InvokeByName;
* operations respectively, while {@link #addLast(Object)} and {@link #removeLast()} will translate to {@code push} and * operations respectively, while {@link #addLast(Object)} and {@link #removeLast()} will translate to {@code push} and
* {@code pop}. * {@code pop}.
*/ */
public class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { public final class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> {
// These add to the back and front of the list // These add to the back and front of the list
private static final InvokeByName PUSH = new InvokeByName("push", ScriptObject.class, void.class, Object.class); private static final InvokeByName PUSH = new InvokeByName("push", ScriptObject.class, void.class, Object.class);
private static final InvokeByName UNSHIFT = new InvokeByName("unshift", ScriptObject.class, void.class, Object.class); private static final InvokeByName UNSHIFT = new InvokeByName("unshift", ScriptObject.class, void.class, Object.class);

View file

@ -100,7 +100,7 @@ public abstract class Property {
* @param flags property flags * @param flags property flags
* @param slot property field number or spill slot * @param slot property field number or spill slot
*/ */
public Property(final String key, final int flags, final int slot) { Property(final String key, final int flags, final int slot) {
assert key != null; assert key != null;
this.key = key; this.key = key;
this.flags = flags; this.flags = flags;
@ -112,7 +112,7 @@ public abstract class Property {
* *
* @param property source property * @param property source property
*/ */
protected Property(final Property property) { Property(final Property property) {
this.key = property.key; this.key = property.key;
this.flags = property.flags; this.flags = property.flags;
this.slot = property.slot; this.slot = property.slot;
@ -123,7 +123,7 @@ public abstract class Property {
* *
* @return cloned property * @return cloned property
*/ */
protected abstract Property copy(); abstract Property copy();
/** /**
* Property flag utility method for {@link PropertyDescriptor}s. Given two property descriptors, * Property flag utility method for {@link PropertyDescriptor}s. Given two property descriptors,

View file

@ -32,6 +32,7 @@ import java.util.WeakHashMap;
* Helper class to manage property listeners and notification. * Helper class to manage property listeners and notification.
*/ */
public class PropertyListenerManager implements PropertyListener { public class PropertyListenerManager implements PropertyListener {
PropertyListenerManager() {}
/** property listeners for this object. */ /** property listeners for this object. */
private Map<PropertyListener,Boolean> listeners; private Map<PropertyListener,Boolean> listeners;

View file

@ -67,7 +67,7 @@ public abstract class ScriptFunctionData {
* @param isBuiltin is the function built in * @param isBuiltin is the function built in
* @param isConstructor is the function a constructor * @param isConstructor is the function a constructor
*/ */
protected ScriptFunctionData(final String name, final int arity, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) { ScriptFunctionData(final String name, final int arity, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) {
this.name = name; this.name = name;
this.arity = arity; this.arity = arity;
this.code = new CompiledFunctions(); this.code = new CompiledFunctions();

View file

@ -83,7 +83,7 @@ public final class UserAccessorProperty extends Property {
* @param getterSlot getter slot, starting at first embed * @param getterSlot getter slot, starting at first embed
* @param setterSlot setter slot, starting at first embed * @param setterSlot setter slot, starting at first embed
*/ */
public UserAccessorProperty(final String key, final int flags, final int getterSlot, final int setterSlot) { UserAccessorProperty(final String key, final int flags, final int getterSlot, final int setterSlot) {
super(key, flags, -1); super(key, flags, -1);
this.getterSlot = getterSlot; this.getterSlot = getterSlot;
this.setterSlot = setterSlot; this.setterSlot = setterSlot;

View file

@ -57,7 +57,7 @@ public final class WithObject extends ScriptObject implements Scope {
* @param scope scope object * @param scope scope object
* @param expression with expression * @param expression with expression
*/ */
public WithObject(final ScriptObject scope, final Object expression) { WithObject(final ScriptObject scope, final Object expression) {
super(scope, null); super(scope, null);
setIsScope(); setIsScope();
this.expression = expression; this.expression = expression;

View file

@ -26,7 +26,7 @@
package jdk.nashorn.internal.runtime.linker; package jdk.nashorn.internal.runtime.linker;
@SuppressWarnings("serial") @SuppressWarnings("serial")
class AdaptationException extends Exception { final class AdaptationException extends Exception {
private final AdaptationResult adaptationResult; private final AdaptationResult adaptationResult;
AdaptationException(final AdaptationResult.Outcome outcome, final String classList) { AdaptationException(final AdaptationResult.Outcome outcome, final String classList) {

View file

@ -32,7 +32,7 @@ import jdk.nashorn.internal.runtime.ECMAException;
* A result of generating an adapter for a class. A tuple of an outcome and - in case of an error outcome - a list of * A result of generating an adapter for a class. A tuple of an outcome and - in case of an error outcome - a list of
* classes that caused the error. * classes that caused the error.
*/ */
class AdaptationResult { final class AdaptationResult {
/** /**
* Contains various outcomes for attempting to generate an adapter class. These are stored in AdapterInfo instances. * Contains various outcomes for attempting to generate an adapter class. These are stored in AdapterInfo instances.
* We have a successful outcome (adapter class was generated) and four possible error outcomes: superclass is final, * We have a successful outcome (adapter class was generated) and four possible error outcomes: superclass is final,

View file

@ -58,7 +58,7 @@ import java.lang.invoke.MethodHandle;
* you dynamically invoke a function with the same name from multiple places in your code, it is advisable to create a * you dynamically invoke a function with the same name from multiple places in your code, it is advisable to create a
* separate instance of this class for every place. * separate instance of this class for every place.
*/ */
public class InvokeByName { public final class InvokeByName {
private final String name; private final String name;
private final MethodHandle getter; private final MethodHandle getter;
private final MethodHandle invoker; private final MethodHandle invoker;

View file

@ -56,7 +56,6 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random;
import java.util.Set; import java.util.Set;
import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Label; import jdk.internal.org.objectweb.asm.Label;

View file

@ -37,7 +37,7 @@ import jdk.nashorn.internal.runtime.Undefined;
/** /**
* Provides static utility services to generated Java adapter classes. * Provides static utility services to generated Java adapter classes.
*/ */
public class JavaAdapterServices { public final class JavaAdapterServices {
private static final ThreadLocal<ScriptObject> classOverrides = new ThreadLocal<>(); private static final ThreadLocal<ScriptObject> classOverrides = new ThreadLocal<>();
private JavaAdapterServices() { private JavaAdapterServices() {

View file

@ -42,7 +42,7 @@ import jdk.nashorn.internal.runtime.ScriptObject;
* Utility class shared by {@code NashornLinker} and {@code NashornPrimitiveLinker} for converting JS values to Java * Utility class shared by {@code NashornLinker} and {@code NashornPrimitiveLinker} for converting JS values to Java
* types. * types.
*/ */
public class JavaArgumentConverters { final class JavaArgumentConverters {
private static final MethodHandle TO_BOOLEAN = findOwnMH("toBoolean", Boolean.class, Object.class); private static final MethodHandle TO_BOOLEAN = findOwnMH("toBoolean", Boolean.class, Object.class);
private static final MethodHandle TO_STRING = findOwnMH("toString", String.class, Object.class); private static final MethodHandle TO_STRING = findOwnMH("toString", String.class, Object.class);

View file

@ -39,7 +39,7 @@ import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
* we can have a more compact representation, as we know that we're always only using {@code "dyn:*"} operations; also * we can have a more compact representation, as we know that we're always only using {@code "dyn:*"} operations; also
* we're storing flags in an additional primitive field. * we're storing flags in an additional primitive field.
*/ */
public class NashornCallSiteDescriptor extends AbstractCallSiteDescriptor { public final class NashornCallSiteDescriptor extends AbstractCallSiteDescriptor {
/** Flags that the call site references a scope variable (it's an identifier reference or a var declaration, not a /** Flags that the call site references a scope variable (it's an identifier reference or a var declaration, not a
* property access expression. */ * property access expression. */
public static final int CALLSITE_SCOPE = 0x01; public static final int CALLSITE_SCOPE = 0x01;

View file

@ -46,7 +46,7 @@ import jdk.nashorn.internal.runtime.Undefined;
* This is the main dynamic linker for Nashorn. It is used for linking all {@link ScriptObject} and its subclasses (this * This is the main dynamic linker for Nashorn. It is used for linking all {@link ScriptObject} and its subclasses (this
* includes {@link ScriptFunction} and its subclasses) as well as {@link Undefined}. * includes {@link ScriptFunction} and its subclasses) as well as {@link Undefined}.
*/ */
public final class NashornLinker implements TypeBasedGuardingDynamicLinker, GuardingTypeConverterFactory, ConversionComparator { final class NashornLinker implements TypeBasedGuardingDynamicLinker, GuardingTypeConverterFactory, ConversionComparator {
/** /**
* Returns true if {@code ScriptObject} is assignable from {@code type}, or it is {@code Undefined}. * Returns true if {@code ScriptObject} is assignable from {@code type}, or it is {@code Undefined}.
*/ */

View file

@ -25,7 +25,6 @@
package jdk.nashorn.internal.runtime.linker; package jdk.nashorn.internal.runtime.linker;
import jdk.nashorn.internal.lookup.Lookup;
import static jdk.nashorn.internal.lookup.Lookup.MH; import static jdk.nashorn.internal.lookup.Lookup.MH;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
@ -35,6 +34,7 @@ import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.support.CallSiteDescriptorFactory; import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.Guards; import jdk.internal.dynalink.support.Guards;
import jdk.nashorn.internal.lookup.Lookup;
import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptObject;
/** /**
@ -42,7 +42,7 @@ import jdk.nashorn.internal.runtime.ScriptObject;
* numbers). This class is only public so it can be accessed by classes in the {@code jdk.nashorn.internal.objects} * numbers). This class is only public so it can be accessed by classes in the {@code jdk.nashorn.internal.objects}
* package. * package.
*/ */
public class PrimitiveLookup { public final class PrimitiveLookup {
private PrimitiveLookup() { private PrimitiveLookup() {
} }

View file

@ -36,7 +36,7 @@ import java.util.StringTokenizer;
* *
* {@code --log=module1:level1,module2:level2... } * {@code --log=module1:level1,module2:level2... }
*/ */
public class KeyValueOption extends Option<String> { public final class KeyValueOption extends Option<String> {
/** /**
* Map of keys given * Map of keys given
*/ */

View file

@ -34,7 +34,7 @@ import jdk.nashorn.internal.runtime.QuotedStringTokenizer;
* bundle file. Metainfo such as parameters and description is here as well * bundle file. Metainfo such as parameters and description is here as well
* for context sensitive help generation. * for context sensitive help generation.
*/ */
public class OptionTemplate implements Comparable<OptionTemplate> { public final class OptionTemplate implements Comparable<OptionTemplate> {
/** Resource, e.g. "nashorn" for this option */ /** Resource, e.g. "nashorn" for this option */
private final String resource; private final String resource;

View file

@ -0,0 +1,34 @@
/*
* 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.
*/
/**
* NASHORN-592-dual: test all combos of field types and getters and setters
* This time use dual field representation
*
* @test
* @option -Dnashorn.fields.dual=true
* @fork
* @run/ignore-std-error
*/
load(__DIR__ + 'NASHORN-592.js');

View file

@ -0,0 +1,44 @@
0
0
NaN
undefinedhej!
17
8
34
17hej!
17
8
34.9422
17.4711hej!
0
0
NaN
Fame and fortune Salamander Yahoo!hej!
24
11111
23.23
23
23
Have some pie!
4711.17
17172
23
23.23
23
23
Have some pie!
4711.17
23
111
4711.16
I like cake!
0
NaN
0
I like cake!
17
17.4711
salamander
4711.17
axolotl
lizard

View file

@ -0,0 +1,32 @@
/*
* 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.
*/
/**
* @test
* @option -Dnashorn.compiler.splitter.threshold=1000
* @fork
* @runif external.octane
*/
compile_only = true;
load(__DIR__ + 'run-octane.js');

View file

@ -0,0 +1,13 @@
Compiled OK: box2d
Compiled OK: code-load
Compiled OK: crypto
Compiled OK: deltablue
Compiled OK: earley-boyer
Compiled OK: gbemu
Compiled OK: mandreel
Compiled OK: navier-stokes
Compiled OK: pdfjs
Compiled OK: raytrace
Compiled OK: regexp
Compiled OK: richards
Compiled OK: splay

View file

@ -1,21 +1,21 @@
/* /*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* This code is distributed in the hope that it will be useful, but WITHOUT * This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * 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 * version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code). * accompanied this code).
* *
* You should have received a copy of the GNU General Public License version * 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, * 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 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 * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
@ -33,7 +33,7 @@
function assertEq(a, b) { function assertEq(a, b) {
if (a !== b) { if (a !== b) {
throw "ASSERTION FAILED: " + a + " should be " + b; throw "ASSERTION FAILED: " + a + " should be " + b;
} }
} }
@ -44,19 +44,19 @@ var total_time = 0;
function runbench(name) { function runbench(name) {
var filename = name.split("/").pop(); var filename = name.split("/").pop();
if (verbose_run) { if (verbose_run) {
print("Running " + filename); print("Running " + filename);
} }
var start = new Date; var start = new Date;
for (var i = 0; i < iterations__; i++) { for (var i = 0; i < iterations__; i++) {
load(name); load(name);
} }
var stop = new Date - start; var stop = new Date - start;
total_time += stop; total_time += stop;
if (verbose_run) { if (verbose_run) {
print(filename + " done in " + stop + " ms"); print(filename + " done in " + stop + " ms");
} }
runs++; runs++;
} }
@ -73,27 +73,23 @@ function pseudorandom() {
function runsuite(tests) { function runsuite(tests) {
var changed = false; var changed = false;
var oldRandom = Math.random; var oldRandom = Math.random;
Math.random = pseudorandom; Math.random = pseudorandom;
try { try {
for (var n = 0; n < tests.length; n++) { for (var n = 0; n < tests.length; n++) {
runbench(tests[n].name); path = dir + '../external/sunspider/tests/sunspider-1.0/' + tests[n].name
if (typeof tests[n].actual !== 'undefined') { runbench(path);
assertEq(tests[n].actual(), tests[n].expected()); if (typeof tests[n].actual !== 'undefined') {
} assertEq(tests[n].actual(), tests[n].expected());
changed = true; }
} changed = true;
} catch (e) { }
print("error: " + e.printStackTrace()); // no scripting or something, silently fail
if (e.toString().indexOf(tests) == 1) {
throw e;
}
// no scripting or something, silently fail
} finally { } finally {
Math.random = oldRandom;
} }
Math.random = oldRandom;
return changed; return changed;
} }
@ -103,211 +99,211 @@ function hash(str) {
var h = 0; var h = 0;
var off = 0; var off = 0;
for (var i = 0; i < s.length; i++) { for (var i = 0; i < s.length; i++) {
h = 31 * h + s.charCodeAt(off++); h = 31 * h + s.charCodeAt(off++);
h &= 0x7fffffff; h &= 0x7fffffff;
} }
return h ^ s.length; return h ^ s.length;
} }
var tests = [ var tests = [
{ name: 'string-base64.js', { name: 'string-base64.js',
actual: function() { actual: function() {
return hash(str); return hash(str);
}, },
expected: function() { expected: function() {
return 1544571068; return 1544571068;
} }
}, },
{ name: 'string-validate-input.js', { name: 'string-validate-input.js',
actual: function() { actual: function() {
return hash(endResult); return hash(endResult);
}, },
expected: function() { expected: function() {
return 2016572373; return 2016572373;
} }
}, },
{ name: 'date-format-xparb.js', { name: 'date-format-xparb.js',
actual: function() { actual: function() {
return shortFormat + longFormat; return shortFormat + longFormat;
}, },
expected: function() { expected: function() {
return "2017-09-05Tuesday, September 05, 2017 8:43:48 AM"; return "2017-09-05Tuesday, September 05, 2017 8:43:48 AM";
} }
}, },
{ name: '3d-morph.js', { name: '3d-morph.js',
actual: function() { actual: function() {
var acceptableDelta = 4e-15; var acceptableDelta = 4e-15;
return (testOutput - 6.394884621840902e-14) < acceptableDelta; return (testOutput - 6.394884621840902e-14) < acceptableDelta;
}, },
expected: function() { expected: function() {
return true; return true;
} }
}, },
{ name: 'crypto-aes.js', { name: 'crypto-aes.js',
actual: function() { actual: function() {
return plainText; return plainText;
}, },
expected: function() { expected: function() {
return decryptedText; return decryptedText;
} }
}, },
{ name: 'crypto-md5.js', { name: 'crypto-md5.js',
actual: function() { actual: function() {
return md5Output; return md5Output;
}, },
expected: function() { expected: function() {
return "a831e91e0f70eddcb70dc61c6f82f6cd"; return "a831e91e0f70eddcb70dc61c6f82f6cd";
} }
}, },
{ name: 'crypto-sha1.js', { name: 'crypto-sha1.js',
actual: function() { actual: function() {
return sha1Output; return sha1Output;
}, },
expected: function() { expected: function() {
return "2524d264def74cce2498bf112bedf00e6c0b796d"; return "2524d264def74cce2498bf112bedf00e6c0b796d";
} }
}, },
{ name: 'bitops-bitwise-and.js', { name: 'bitops-bitwise-and.js',
actual: function() { actual: function() {
return result; return result;
}, },
expected: function() { expected: function() {
return 0; return 0;
} }
}, },
{ name: 'bitops-bits-in-byte.js', { name: 'bitops-bits-in-byte.js',
actual: function() { actual: function() {
return result; return result;
}, },
expected: function() { expected: function() {
return 358400; return 358400;
} }
}, },
{ name: 'bitops-nsieve-bits.js', { name: 'bitops-nsieve-bits.js',
actual: function() { actual: function() {
var ret = 0; var ret = 0;
for (var i = 0; i < result.length; ++i) { for (var i = 0; i < result.length; ++i) {
ret += result[i]; ret += result[i];
} }
ret += result.length; ret += result.length;
return ret; return ret;
}, },
expected: function() { expected: function() {
return -1286749539853; return -1286749539853;
} }
}, },
{ name: 'bitops-3bit-bits-in-byte.js', { name: 'bitops-3bit-bits-in-byte.js',
actual: function() { actual: function() {
return sum; return sum;
}, },
expected: function() { expected: function() {
return 512000; return 512000;
} }
}, },
{ name: 'access-nbody.js', { name: 'access-nbody.js',
actual: function() { actual: function() {
return ret; return ret;
}, },
expected: function() { expected: function() {
return -0.16906933525822856; return -1.3524862408537381;
} }
}, },
{ name: 'access-binary-trees.js', { name: 'access-binary-trees.js',
actual: function() { actual: function() {
return ret; return ret;
}, },
expected: function() { expected: function() {
return -1; return -4;
} }
}, },
{ name: 'access-fannkuch.js', { name: 'access-fannkuch.js',
actual: function() { actual: function() {
return ret; return ret;
}, },
expected: function() { expected: function() {
return 22; return 22;
} }
}, },
{ name: 'math-spectral-norm.js', { name: 'math-spectral-norm.js',
actual: function() { actual: function() {
var ret = ''; var ret = '';
for (var i = 6; i <= 48; i *= 2) { for (var i = 6; i <= 48; i *= 2) {
ret += spectralnorm(i) + ','; ret += spectralnorm(i) + ',';
} }
return ret; return ret;
}, },
expected: function() { expected: function() {
return "1.2657786149754053,1.2727355112619148,1.273989979775574,1.274190125290389,"; return "1.2657786149754053,1.2727355112619148,1.273989979775574,1.274190125290389,";
} }
}, },
{ name: '3d-raytrace.js', { name: '3d-raytrace.js',
actual: function() { actual: function() {
return hash(testOutput); return hash(testOutput);
}, },
expected: function() { expected: function() {
return 230692593; return 230692593;
} }
}, },
{ name: 'regexp-dna.js', { name: 'regexp-dna.js',
actual: function() { actual: function() {
return dnaOutputString; return dnaOutputString;
}, },
expected: function() { expected: function() {
return "undefinedagggtaaa|tttaccct 0\n[cgt]gggtaaa|tttaccc[acg] 9\na[act]ggtaaa|tttacc[agt]t 27\nag[act]gtaaa|tttac[agt]ct 24\nagg[act]taaa|ttta[agt]cct 30\naggg[acg]aaa|ttt[cgt]ccct 9\nagggt[cgt]aa|tt[acg]accct 12\nagggta[cgt]a|t[acg]taccct 9\nagggtaa[cgt]|[acg]ttaccct 15\n"; return "agggtaaa|tttaccct 0\n[cgt]gggtaaa|tttaccc[acg] 9\na[act]ggtaaa|tttacc[agt]t 27\nag[act]gtaaa|tttac[agt]ct 24\nagg[act]taaa|ttta[agt]cct 30\naggg[acg]aaa|ttt[cgt]ccct 9\nagggt[cgt]aa|tt[acg]accct 12\nagggta[cgt]a|t[acg]taccct 9\nagggtaa[cgt]|[acg]ttaccct 15\n";
} }
}, },
{ name: 'math-cordic.js', { name: 'math-cordic.js',
actual: function() { actual: function() {
return total; return total;
}, },
expected: function() { expected: function() {
return 10362.570468755888; return 10362.570468755888;
} }
}, },
{ name: 'controlflow-recursive.js', { name: 'controlflow-recursive.js',
actual: function() { actual: function() {
var ret = 0; var ret = 0;
for (var i = 3; i <= 5; i++) { for (var i = 3; i <= 5; i++) {
ret += ack(3,i); ret += ack(3,i);
ret += fib(17.0+i); ret += fib(17.0+i);
ret += tak(3*i+3,2*i+2,i+1); ret += tak(3*i+3,2*i+2,i+1);
} }
return ret; return ret;
}, },
expected: function() { expected: function() {
return 57775; return 57775;
} }
}, },
{ name: 'date-format-tofte.js', { name: 'date-format-tofte.js',
actual: function() { actual: function() {
return shortFormat + longFormat; return shortFormat + longFormat;
}, },
expected: function() { expected: function() {
return "2008-05-01Thursday, May 01, 2008 6:31:22 PM"; return "2008-05-01Thursday, May 01, 2008 6:31:22 PM";
} }
}, },
{ name: 'string-tagcloud.js', { name: 'string-tagcloud.js',
actual: function() { actual: function() {
// The result string embeds floating-point numbers, which can vary a bit on different platforms, // The result string embeds floating-point numbers, which can vary a bit on different platforms,
// so we truncate them a bit before comparing. // so we truncate them a bit before comparing.
var tagcloud_norm = tagcloud.replace(/([0-9.]+)px/g, function(str, p1) { return p1.substr(0, 10) + 'px' }) var tagcloud_norm = tagcloud.replace(/([0-9.]+)px/g, function(str, p1) { return p1.substr(0, 10) + 'px' })
return tagcloud_norm.length; return tagcloud_norm.length;
}, },
expected: function() { expected: function() {
return 295906; return 295906;
} }
}, },
{ name: 'string-unpack-code.js', { name: 'string-unpack-code.js',
actual: function() { actual: function() {
return decompressedMochiKit.length == 106415 && return decompressedMochiKit.length == 106415 &&
decompressedMochiKit[2000] == '5' && decompressedMochiKit[2000] == '5' &&
decompressedMochiKit[12000] == '_' && decompressedMochiKit[12000] == '_' &&
decompressedMochiKit[82556] == '>'; decompressedMochiKit[82556] == '>';
}, },
expected: function() { expected: function() {
return true; return true;
} }
}, },
//TODO no easy way to sanity check result //TODO no easy way to sanity check result
{ name: 'string-fasta.js' }, { name: 'string-fasta.js' },
//TODO no easy way to sanity check result //TODO no easy way to sanity check result
@ -315,17 +311,13 @@ var tests = [
//TODO no easy way to sanity check result //TODO no easy way to sanity check result
{ name: 'access-nsieve.js' }, { name: 'access-nsieve.js' },
//TODO no easy way to sanity check result //TODO no easy way to sanity check result
{ name: '3d-cube.js' }, { name: '3d-cube.js' },
]; ];
// handle the case this script may be run by a JS engine that doesn't // handle the case this script may be run by a JS engine that doesn't
// support __DIR__ global variable. // support __DIR__ global variable.
var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__; var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;
for (i in tests) {
tests[i].name = dir + '../external/sunspider/tests/sunspider-1.0/' + tests[i].name;
}
var verbose_run = false; var verbose_run = false;
var args = []; var args = [];
@ -333,12 +325,12 @@ if (typeof $ARGS !== 'undefined') {
args = $ARGS; args = $ARGS;
} else if (typeof arguments !== 'undefined' && arguments.length != 0) { } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
args = arguments; args = arguments;
} }
for (i in args) { for (i in args) {
if (args[i] === '--verbose') { if (args[i] === '--verbose') {
verbose_run = true; verbose_run = true;
break; break;
} }
} }

View file

@ -0,0 +1,36 @@
/*
* 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.
*/
/**
* Test various scripts with low splitter threshold
*
* @test
* @option -Dnashorn.compiler.splitter.threshold=200
* @run
* @fork
*/
load(__DIR__ + 'prototype.js');
load(__DIR__ + 'yui.js');
load(__DIR__ + 'NASHORN-689.js');
load(__DIR__ + 'NASHORN-58.js');

View file

@ -0,0 +1,76 @@
parsed and compiled ok prototype.js
parsed and compiled ok yui-min.js
parsed and compiled ok yui.js
a=10
a=9
a=8
a=7
a=6
a=5
a=4
a=3
a=2
a=1
a=0
10
a=0
a=1
a=2
a=3
a=4
a=5
a=6
a=7
a=8
a=9
a=10
ok
a=0
a=1
a=2
a=3
a=4
a=5
a=6
a=7
a=8
a=9
a=10
done
no arg
x=0
x=1
x=2
x=3
x=4
x=5
x=6
x=7
x=8
x=9
x=10
ok
done
try
finally
3
try
finally
2
3
1
2
3
4
5
5
6
6
1
2
3
4
6
Error: testing
finally
SUCCESS

View file

@ -1,122 +0,0 @@
/*
* 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.
*/
/**
* NASHORN-592a: test all combos of field types and getters and setters
* This time use dual field representation
*
* @test
* @option --dual-fields
* @run
*/
//fortype undefined
var a;
print(a & 0xff);
print(a >>> 1);
print(a * 2);
print(a + "hej!");
var b;
b = 17; //set undefined->int
print(b & 0xff);
print(b >>> 1);
print(b * 2);
print(b + "hej!");
var c;
c = 17.4711 //set undefined->double
print(c & 0xff);
print(c >>> 1);
print(c * 2);
print(c + "hej!");
var d; // set undefined->double
d = "Fame and fortune Salamander Yahoo!";
print(d & 0xff);
print(d >>> 1);
print(d * 2);
print(d + "hej!");
// now we have exhausted all getters and undefined->everything setters.
var e = 23; // int to everything setters,
e = 24; //int to int
print(e);
e = (22222 >>> 1); //int to long;
print(e);
e = 23.23; //int to double
print(e);
e = 23; //double to int - still double
print(e);
print(e & 0xff);
e = "Have some pie!" //double to string
print(e);
e = 4711.17;
print(e); //still an object not a double
var f = (23222 >>> 1); // long to everything setters,
f = 34344 >>> 1; //long to long
print(f);
f = 23; //long to int - still long
print(f);
f = 23.23; //long to double
print(f);
f = 23; //double to int - still double
print(f);
print(f & 0xff);
f = "Have some pie!" //double to string
print(f);
f = 4711.17;
print(f); //still an object not a double
var g = 4811.16;
g = 23; //still double
print(g);
g = (222 >>> 1); //still double
print(g);
g = 4711.16; //double->double
print(g);
g = "I like cake!";
print(g); //object to various
print(g & 0xff);
print(g * 2);
print(g >>> 2);
print(g);
var h = {x:17, y:17.4711, z:"salamander"};
print(h.x);
print(h.y);
print(h.z);
h.x = 4711.17;
h.y = "axolotl";
h.z = "lizard";
print(h.x);
print(h.y);
print(h.z);

View file

@ -29,6 +29,7 @@ import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_CHECK_COMPI
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_COMPARE; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_COMPARE;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_COMPILE_FAIL; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_COMPILE_FAIL;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_RUN_FAIL; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_RUN_FAIL;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_FORK;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_IGNORE_STD_ERROR; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_IGNORE_STD_ERROR;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_RUN; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_RUN;
import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_FAIL_LIST; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_FAIL_LIST;
@ -68,6 +69,8 @@ public abstract class AbstractScriptRunnable {
protected final boolean checkCompilerMsg; protected final boolean checkCompilerMsg;
// .EXPECTED file compared for this or test? // .EXPECTED file compared for this or test?
protected final boolean compare; protected final boolean compare;
// should test run in a separate process?
protected final boolean fork;
// ignore stderr output? // ignore stderr output?
protected final boolean ignoreStdError; protected final boolean ignoreStdError;
// Foo.js.OUTPUT file where test stdout messages go // Foo.js.OUTPUT file where test stdout messages go
@ -98,6 +101,7 @@ public abstract class AbstractScriptRunnable {
this.checkCompilerMsg = testOptions.containsKey(OPTIONS_CHECK_COMPILE_MSG); this.checkCompilerMsg = testOptions.containsKey(OPTIONS_CHECK_COMPILE_MSG);
this.ignoreStdError = testOptions.containsKey(OPTIONS_IGNORE_STD_ERROR); this.ignoreStdError = testOptions.containsKey(OPTIONS_IGNORE_STD_ERROR);
this.compare = testOptions.containsKey(OPTIONS_COMPARE); this.compare = testOptions.containsKey(OPTIONS_COMPARE);
this.fork = testOptions.containsKey(OPTIONS_FORK);
final String testName = testFile.getName(); final String testName = testFile.getName();
this.outputFileName = buildDir + File.separator + testName + ".OUTPUT"; this.outputFileName = buildDir + File.separator + testName + ".OUTPUT";
@ -105,7 +109,6 @@ public abstract class AbstractScriptRunnable {
this.copyExpectedFileName = buildDir + File.separator + testName + ".EXPECTED"; this.copyExpectedFileName = buildDir + File.separator + testName + ".EXPECTED";
this.expectedFileName = testFile.getPath() + ".EXPECTED"; this.expectedFileName = testFile.getPath() + ".EXPECTED";
final String failListString = System.getProperty(TEST_JS_FAIL_LIST);
if (failListString != null) { if (failListString != null) {
final String[] failedTests = failListString.split(" "); final String[] failedTests = failListString.split(" ");
for (final String failedTest : failedTests) { for (final String failedTest : failedTests) {
@ -147,10 +150,15 @@ public abstract class AbstractScriptRunnable {
} }
// shared context or not? // shared context or not?
protected static final boolean sharedContext; protected static final boolean sharedContext = Boolean.getBoolean(TEST_JS_SHARED_CONTEXT);
protected static final String failListString = System.getProperty(TEST_JS_FAIL_LIST);
// VM options when a @fork test is executed by a separate process
protected static final String[] forkJVMOptions;
static { static {
sharedContext = Boolean.getBoolean(TEST_JS_SHARED_CONTEXT); String vmOptions = System.getProperty(TestConfig.TEST_FORK_JVM_OPTIONS);
forkJVMOptions = (vmOptions != null)? vmOptions.split(" ") : new String[0];
} }
private static ThreadLocal<ScriptEvaluator> evaluators = new ThreadLocal<>(); private static ThreadLocal<ScriptEvaluator> evaluators = new ThreadLocal<>();
/** /**

View file

@ -43,6 +43,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import jdk.nashorn.tools.Shell;
import org.testng.Assert; import org.testng.Assert;
import org.testng.ITest; import org.testng.ITest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -53,9 +55,6 @@ import org.testng.annotations.Test;
* corresponding .EXPECTED file. * corresponding .EXPECTED file.
*/ */
public final class ScriptRunnable extends AbstractScriptRunnable implements ITest { public final class ScriptRunnable extends AbstractScriptRunnable implements ITest {
// when test is run in a separate process, this is the command line
protected final ArrayList<String> separateProcessArgs;
public ScriptRunnable(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) { public ScriptRunnable(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
super(framework, testFile, engineOptions, testOptions, scriptArguments); super(framework, testFile, engineOptions, testOptions, scriptArguments);
@ -63,9 +62,6 @@ public final class ScriptRunnable extends AbstractScriptRunnable implements ITes
// add --dump-on-error option always so that we can get detailed error msg. // add --dump-on-error option always so that we can get detailed error msg.
engineOptions.add("-doe"); engineOptions.add("-doe");
} }
final String separateProcess = System.getProperty("test.js.separateprocess");
this.separateProcessArgs = separateProcess == null ? null : new ArrayList<>(Arrays.asList(separateProcess.split(" ")));
} }
@Override @Override
@ -81,7 +77,7 @@ public final class ScriptRunnable extends AbstractScriptRunnable implements ITes
@Override @Override
protected void execute() { protected void execute() {
if (separateProcessArgs != null) { if (fork) {
executeInNewProcess(); executeInNewProcess();
} else { } else {
executeInThisProcess(); executeInThisProcess();
@ -172,15 +168,24 @@ public final class ScriptRunnable extends AbstractScriptRunnable implements ITes
} }
private void executeInNewProcess() { private void executeInNewProcess() {
final List<String> args = separateProcessArgs;
final String separator = System.getProperty("file.separator");
final List<String> cmd = new ArrayList<>();
cmd.add(System.getProperty("java.home") + separator + "bin" + separator + "java");
cmd.add("-Djava.ext.dirs=dist");
for (String str : forkJVMOptions) {
cmd.add(str);
}
cmd.add(Shell.class.getName());
// now add the rest of the "in process" runtime arguments // now add the rest of the "in process" runtime arguments
args.addAll(getRuntimeArgs()); cmd.addAll(getRuntimeArgs());
final File outputFileHandle = new File(outputFileName); final File outputFileHandle = new File(outputFileName);
final File errorFileHandle = new File(errorFileName); final File errorFileHandle = new File(errorFileName);
try { try {
final ProcessBuilder pb = new ProcessBuilder(args); final ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectOutput(outputFileHandle); pb.redirectOutput(outputFileHandle);
pb.redirectError(errorFileHandle); pb.redirectError(errorFileHandle);
final Process process = pb.start(); final Process process = pb.start();

View file

@ -36,6 +36,7 @@ public interface TestConfig {
public static final String OPTIONS_EXPECT_RUN_FAIL = "expect-run-fail"; public static final String OPTIONS_EXPECT_RUN_FAIL = "expect-run-fail";
public static final String OPTIONS_IGNORE_STD_ERROR = "ignore-std-error"; public static final String OPTIONS_IGNORE_STD_ERROR = "ignore-std-error";
public static final String OPTIONS_COMPARE = "compare"; public static final String OPTIONS_COMPARE = "compare";
public static final String OPTIONS_FORK = "fork";
// System property names used for various test configurations // System property names used for various test configurations
@ -73,6 +74,8 @@ public interface TestConfig {
// shared context mode or not // shared context mode or not
static final String TEST_JS_SHARED_CONTEXT = "test.js.shared.context"; static final String TEST_JS_SHARED_CONTEXT = "test.js.shared.context";
static final String TEST_FORK_JVM_OPTIONS = "test.fork.jvm.options";
// file for storing last run's failed tests // file for storing last run's failed tests
static final String TEST_FAILED_LIST_FILE = "test.failed.list.file"; static final String TEST_FAILED_LIST_FILE = "test.failed.list.file";
} }

View file

@ -29,6 +29,7 @@ import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_CHECK_COMPI
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_COMPARE; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_COMPARE;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_COMPILE_FAIL; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_COMPILE_FAIL;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_RUN_FAIL; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_RUN_FAIL;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_FORK;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_IGNORE_STD_ERROR; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_IGNORE_STD_ERROR;
import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_RUN; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_RUN;
import static jdk.nashorn.internal.test.framework.TestConfig.TEST_FAILED_LIST_FILE; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_FAILED_LIST_FILE;
@ -208,6 +209,7 @@ final class TestFinder {
boolean checkCompilerMsg = false; boolean checkCompilerMsg = false;
boolean noCompare = false; boolean noCompare = false;
boolean ignoreStdError = false; boolean ignoreStdError = false;
boolean fork = false;
final List<String> engineOptions = new ArrayList<>(); final List<String> engineOptions = new ArrayList<>();
final List<String> scriptArguments = new ArrayList<>(); final List<String> scriptArguments = new ArrayList<>();
@ -284,6 +286,9 @@ final class TestFinder {
case "@option": case "@option":
engineOptions.add(scanner.next()); engineOptions.add(scanner.next());
break; break;
case "@fork":
fork = true;
break;
} }
// negative tests are expected to fail at runtime only // negative tests are expected to fail at runtime only
@ -324,6 +329,9 @@ final class TestFinder {
if (ignoreStdError) { if (ignoreStdError) {
testOptions.put(OPTIONS_IGNORE_STD_ERROR, "true"); testOptions.put(OPTIONS_IGNORE_STD_ERROR, "true");
} }
if (fork) {
testOptions.put(OPTIONS_FORK, "true");
}
tests.add(factory.createTest(framework, testFile.toFile(), engineOptions, testOptions, scriptArguments)); tests.add(factory.createTest(framework, testFile.toFile(), engineOptions, testOptions, scriptArguments));
} else if (!isNotTest) { } else if (!isNotTest) {