8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code

Mon, 11 Feb 2013 21:26:06 +0530

author
sundar
date
Mon, 11 Feb 2013 21:26:06 +0530
changeset 82
abea4ba28901
parent 81
5ead5333fa59
child 83
774a0f349cc0

8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
Reviewed-by: lagergren, jlaskey, attila

bin/jjssecure file | annotate | diff | comparison | revisions
bin/jjssecure.bat file | annotate | diff | comparison | revisions
bin/nashornsecure file | annotate | diff | comparison | revisions
bin/nashornsecure.bat file | annotate | diff | comparison | revisions
make/Makefile file | annotate | diff | comparison | revisions
make/build.xml file | annotate | diff | comparison | revisions
make/java.security.override file | annotate | diff | comparison | revisions
make/project.properties file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/codegen/Attr.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/codegen/CodeGenerator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/codegen/Compiler.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/codegen/RuntimeCallSite.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/Symbol.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/debug/JSONWriter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeArray.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeArrayBuffer.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeDebug.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeError.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeEvalError.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeFloat32Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeFloat64Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeFunction.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeInt16Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeInt32Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeInt8Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeJSAdapter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeJSON.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeJava.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeJavaImporter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeRangeError.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeReferenceError.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeRegExp.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeString.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeSyntaxError.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeTypeError.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeURIError.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint16Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint32Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint8Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/parser/AbstractParser.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/parser/Lexer.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/parser/RegExp.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/parser/RegExpScanner.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ArgumentSetter.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/BitVector.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ConsString.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Context.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Debug.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/DebugLogger.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/GlobalFunctions.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/JSONFunctions.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Logging.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/NashornLoader.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/NativeJavaPackage.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/RegExp.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/RegExpScanner.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptFunction.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptFunctionData.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptLoader.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptRuntime.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptingFunctions.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/SetMethodCreator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/StructureLoader.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/WithObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/arrays/EmptyArrayLikeIterator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/arrays/MapIterator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/Bootstrap.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/resources/parser.js file | annotate | diff | comparison | revisions
test/script/sandbox/nashorninternals.js file | annotate | diff | comparison | revisions
test/script/trusted/JDK-8006529.js file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/javaaccess/Person.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/javaaccess/SharedObject.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/BooleanAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/MethodAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/NumberAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/NumberBoxingTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/ObjectAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/Person.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/SharedObject.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/access/StringAccessTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/codegen/CompilerAccess.java file | annotate | diff | comparison | revisions
     1.1 --- a/bin/jjssecure	Sat Feb 09 16:58:48 2013 +0100
     1.2 +++ b/bin/jjssecure	Mon Feb 11 21:26:06 2013 +0530
     1.3 @@ -26,4 +26,4 @@
     1.4  
     1.5  [ -z "$JAVA_HOME" ] && echo "Please set JAVA_HOME" && exit 1;
     1.6  
     1.7 -$JAVA_HOME/bin/java -Xms2G -Xmx2G -XX:-TieredCompilation -server -esa -ea -Djava.ext.dirs=$JAVA_HOME/jre/lib/ext:`dirname $0`/../dist -XX:+HeapDumpOnOutOfMemoryError -Dnashorn.debug=true -Djava.lang.invoke.MethodHandle.DEBUG_NAMES=true -Dnashorn.home=`dirname $0`/.. -Djava.security.manager jdk.nashorn.tools.Shell $*
     1.8 +$JAVA_HOME/bin/java -Xms2G -Xmx2G -XX:-TieredCompilation -server -esa -ea -Djava.security.properties=`dirname $0`/../make/java.security.override -Djava.ext.dirs=$JAVA_HOME/jre/lib/ext:`dirname $0`/../dist -XX:+HeapDumpOnOutOfMemoryError -Dnashorn.debug=true -Djava.lang.invoke.MethodHandle.DEBUG_NAMES=true -Dnashorn.home=`dirname $0`/.. -Djava.security.manager jdk.nashorn.tools.Shell $*
     2.1 --- a/bin/jjssecure.bat	Sat Feb 09 16:58:48 2013 +0100
     2.2 +++ b/bin/jjssecure.bat	Mon Feb 11 21:26:06 2013 +0530
     2.3 @@ -24,4 +24,4 @@
     2.4  rem
     2.5  @echo off
     2.6  
     2.7 -java -Xms2G -Xmx2G -XX:-TieredCompilation -server -esa -ea -Djava.ext.dirs=%~dp0\..\dist -XX:+HeapDumpOnOutOfMemoryError -Dnashorn.debug=true -Djava.lang.invoke.MethodHandle.DEBUG_NAMES=false -Dnashorn.home=%~dp0\.. -Djava.security.manager jdk.nashorn.tools.Shell
     2.8 +java -Xms2G -Xmx2G -XX:-TieredCompilation -server -esa -ea -Djava.security.properties=%~dp0\..\make\java.security.override -Djava.ext.dirs=%~dp0\..\dist -XX:+HeapDumpOnOutOfMemoryError -Dnashorn.debug=true -Djava.lang.invoke.MethodHandle.DEBUG_NAMES=false -Dnashorn.home=%~dp0\.. -Djava.security.manager jdk.nashorn.tools.Shell
     3.1 --- a/bin/nashornsecure	Sat Feb 09 16:58:48 2013 +0100
     3.2 +++ b/bin/nashornsecure	Mon Feb 11 21:26:06 2013 +0530
     3.3 @@ -26,4 +26,4 @@
     3.4  
     3.5  [ -z "$JAVA_HOME" ] && echo "Please set JAVA_HOME" && exit 1;
     3.6  
     3.7 -$JAVA_HOME/bin/jrunscript -J-Djava.security.manager -J-Xms2G -J-Xmx2G -J-XX:-TieredCompilation -J-server -J-esa -J-ea -J-Djava.ext.dirs=$JAVA_HOME/jre/lib/ext:`dirname $0`/../dist -J-XX:+HeapDumpOnOutOfMemoryError -J-Djava.lang.invoke.MethodHandle.DEBUG_NAMES=false -J-Dnashorn.debug=true -l nashorn $*
     3.8 +$JAVA_HOME/bin/jrunscript -J-Djava.security.properties=`dirname $0`/../make/java.security.override -J-Djava.security.manager -J-Xms2G -J-Xmx2G -J-XX:-TieredCompilation -J-server -J-esa -J-ea -J-Djava.ext.dirs=$JAVA_HOME/jre/lib/ext:`dirname $0`/../dist -J-XX:+HeapDumpOnOutOfMemoryError -J-Djava.lang.invoke.MethodHandle.DEBUG_NAMES=false -J-Dnashorn.debug=true -l nashorn $*
     4.1 --- a/bin/nashornsecure.bat	Sat Feb 09 16:58:48 2013 +0100
     4.2 +++ b/bin/nashornsecure.bat	Mon Feb 11 21:26:06 2013 +0530
     4.3 @@ -24,4 +24,4 @@
     4.4  rem
     4.5  @echo off
     4.6  
     4.7 -jrunscript -J-Djava.security.manager -J-Xms2G -J-Xmx2G -J-XX:-TieredCompilation -J-server -J-esa -J-ea -J-Djava.ext.dirs=%~dp0\..\dist -J-XX:+HeapDumpOnOutOfMemoryError -J-Dnashorn.debug=true -J-Djava.lang.invoke.MethodHandle.DEBUG_NAMES=false -l nashorn
     4.8 +jrunscript -J-Djava.security.properties=%~dp0\..\make\java.security.override -J-Djava.security.manager -J-Xms2G -J-Xmx2G -J-XX:-TieredCompilation -J-server -J-esa -J-ea -J-Djava.ext.dirs=%~dp0\..\dist -J-XX:+HeapDumpOnOutOfMemoryError -J-Dnashorn.debug=true -J-Djava.lang.invoke.MethodHandle.DEBUG_NAMES=false -l nashorn
     5.1 --- a/make/Makefile	Sat Feb 09 16:58:48 2013 +0100
     5.2 +++ b/make/Makefile	Mon Feb 11 21:26:06 2013 +0530
     5.3 @@ -181,7 +181,7 @@
     5.4  endif
     5.5  
     5.6  # Default target and expected 'do everything' target
     5.7 -all: test docs
     5.8 +all: test
     5.9  
    5.10  # Standard make clobber target
    5.11  clobber: clean
     6.1 --- a/make/build.xml	Sat Feb 09 16:58:48 2013 +0100
     6.2 +++ b/make/build.xml	Mon Feb 11 21:26:06 2013 +0530
     6.3 @@ -201,12 +201,12 @@
     6.4  
     6.5      <!-- tests that check nashorn internals and internal API -->
     6.6      <jar jarfile="${nashorn.internal.tests.jar}">
     6.7 -      <fileset dir="${build.test.classes.dir}" excludes="**/api/scripting/*"/>
     6.8 +      <fileset dir="${build.test.classes.dir}" excludes="**/api/*"/>
     6.9      </jar>
    6.10  
    6.11      <!-- tests that check nashorn script engine (jsr-223) API -->
    6.12      <jar jarfile="${nashorn.api.tests.jar}">
    6.13 -      <fileset dir="${build.test.classes.dir}" includes="**/api/scripting/*"/>
    6.14 +      <fileset dir="${build.test.classes.dir}" includes="**/api/*"/>
    6.15      </jar>
    6.16  
    6.17    </target>
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/make/java.security.override	Mon Feb 11 21:26:06 2013 +0530
     7.3 @@ -0,0 +1,14 @@
     7.4 +# We would like to avoid references from anywhere outside nashorn
     7.5 +# to codegen, IR and parser packages, in particular script generated classes.
     7.6 +# We ensure that by overriding "package.access" security property.
     7.7 +
     7.8 +# The following "package.access" value was copied from  default java.security 
     7.9 +# of jre/lib/security and appended with nashorn IR, Codegen and Parser packages.
    7.10 +
    7.11 +#
    7.12 +# List of comma-separated packages that start with or equal this string
    7.13 +# will cause a security exception to be thrown when
    7.14 +# passed to checkPackageAccess unless the
    7.15 +# corresponding RuntimePermission ("accessClassInPackage."+package) has
    7.16 +# been granted.
    7.17 +package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.glassfish.external.,com.sun.org.glassfish.gmbal.,jdk.internal.,jdk.nashorn.internal.ir., jdk.nashorn.internal.codegen., jdk.nashorn.internal.parser.
     8.1 --- a/make/project.properties	Sat Feb 09 16:58:48 2013 +0100
     8.2 +++ b/make/project.properties	Mon Feb 11 21:26:06 2013 +0530
     8.3 @@ -225,7 +225,7 @@
     8.4  #-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M  
     8.5  run.test.jvmargs.octane=-Xms${run.test.xms} ${run.test.jvmargs}
     8.6  
     8.7 -run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
     8.8 +run.test.jvmsecurityargs=-Xverify:all -Djava.security.properties=${basedir}/make/java.security.override -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
     8.9  
    8.10  # path of rhino.jar for benchmarks
    8.11  rhino.jar=
     9.1 --- a/src/jdk/nashorn/internal/codegen/Attr.java	Sat Feb 09 16:58:48 2013 +0100
     9.2 +++ b/src/jdk/nashorn/internal/codegen/Attr.java	Mon Feb 11 21:26:06 2013 +0530
     9.3 @@ -415,6 +415,7 @@
     9.4              symbol.setIsScope();
     9.5          }
     9.6  
     9.7 +        assert symbol != null;
     9.8          if(symbol.isGlobal()) {
     9.9              getCurrentFunctionNode().setUsesGlobalSymbol();
    9.10          } else if(symbol.isScope()) {
    10.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Sat Feb 09 16:58:48 2013 +0100
    10.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Mon Feb 11 21:26:06 2013 +0530
    10.3 @@ -3183,6 +3183,7 @@
    10.4                  @Override
    10.5                  public Node enter(final IdentNode node) {
    10.6                      final Symbol symbol = node.getSymbol();
    10.7 +                    assert symbol != null;
    10.8                      if (symbol.isScope()) {
    10.9                          if (symbol.isFastScope(currentFunction)) {
   10.10                              storeFastScopeVar(node.getType(), symbol, CALLSITE_SCOPE | getCallSiteFlags());
   10.11 @@ -3190,7 +3191,6 @@
   10.12                              method.dynamicSet(node.getType(), node.getName(), CALLSITE_SCOPE | getCallSiteFlags());
   10.13                          }
   10.14                      } else {
   10.15 -                        assert symbol != null;
   10.16                          method.store(symbol);
   10.17                      }
   10.18                      return null;
    11.1 --- a/src/jdk/nashorn/internal/codegen/Compiler.java	Sat Feb 09 16:58:48 2013 +0100
    11.2 +++ b/src/jdk/nashorn/internal/codegen/Compiler.java	Mon Feb 11 21:26:06 2013 +0530
    11.3 @@ -108,6 +108,9 @@
    11.4      /** Name of the objects package */
    11.5      public static final String OBJECTS_PACKAGE = "jdk/nashorn/internal/objects";
    11.6  
    11.7 +    /** Name of the runtime package */
    11.8 +    public static final String RUNTIME_PACKAGE = "jdk/nashorn/internal/runtime";
    11.9 +
   11.10      /** Name of the Global object, cannot be referred to as .class, @see CodeGenerator */
   11.11      public static final String GLOBAL_OBJECT = OBJECTS_PACKAGE + '/' + "Global";
   11.12  
    12.1 --- a/src/jdk/nashorn/internal/codegen/RuntimeCallSite.java	Sat Feb 09 16:58:48 2013 +0100
    12.2 +++ b/src/jdk/nashorn/internal/codegen/RuntimeCallSite.java	Mon Feb 11 21:26:06 2013 +0530
    12.3 @@ -42,6 +42,7 @@
    12.4  import jdk.nashorn.internal.ir.RuntimeNode;
    12.5  import jdk.nashorn.internal.ir.RuntimeNode.Request;
    12.6  import jdk.nashorn.internal.runtime.ScriptRuntime;
    12.7 +import jdk.nashorn.internal.runtime.linker.Bootstrap;
    12.8  import jdk.nashorn.internal.runtime.linker.Lookup;
    12.9  import jdk.nashorn.internal.runtime.linker.MethodHandleFactory;
   12.10  
   12.11 @@ -55,8 +56,8 @@
   12.12   * {@code Object a === int b} is a good idea to specialize to {@code ((Integer)a).intValue() == b}
   12.13   * surrounded by catch blocks that will try less narrow specializations
   12.14   */
   12.15 -public class RuntimeCallSite extends MutableCallSite {
   12.16 -    static final Call BOOTSTRAP = staticCallNoLookup(RuntimeCallSite.class, "bootstrap", CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
   12.17 +public final class RuntimeCallSite extends MutableCallSite {
   12.18 +    static final Call BOOTSTRAP = staticCallNoLookup(Bootstrap.class, "runtimeBootstrap", CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
   12.19  
   12.20      private static final MethodHandle NEXT = findOwnMH("next",  MethodHandle.class);
   12.21  
   12.22 @@ -200,26 +201,13 @@
   12.23       * @param type method type for call site
   12.24       * @param name name of runtime call
   12.25       */
   12.26 -    RuntimeCallSite(final MethodType type, final String name) {
   12.27 +    public RuntimeCallSite(final MethodType type, final String name) {
   12.28          super(type);
   12.29          this.name    = name;
   12.30          this.request = Request.valueOf(name.substring(0, name.indexOf(SpecializedRuntimeNode.REQUEST_SEPARATOR)));
   12.31          setTarget(makeMethod(name));
   12.32      }
   12.33  
   12.34 -    /**
   12.35 -     * Bootstrapper for a specialized Runtime call
   12.36 -     *
   12.37 -     * @param lookup       lookup
   12.38 -     * @param initialName  initial name for callsite
   12.39 -     * @param type         method type for call site
   12.40 -     *
   12.41 -     * @return callsite for a runtime node
   12.42 -     */
   12.43 -    public static CallSite bootstrap(final MethodHandles.Lookup lookup, final String initialName, final MethodType type) {
   12.44 -        return new RuntimeCallSite(type, initialName);
   12.45 -    }
   12.46 -
   12.47      private String nextName(final String requestName) {
   12.48          if (requestName.equals(request.toString())) {
   12.49              return null;
    13.1 --- a/src/jdk/nashorn/internal/ir/Symbol.java	Sat Feb 09 16:58:48 2013 +0100
    13.2 +++ b/src/jdk/nashorn/internal/ir/Symbol.java	Mon Feb 11 21:26:06 2013 +0530
    13.3 @@ -660,7 +660,7 @@
    13.4          if (TRACE_SYMBOLS != null && (TRACE_SYMBOLS.isEmpty() || TRACE_SYMBOLS.contains(name))) {
    13.5              Context.err("SYMBOL: '" + name + "' " + desc);
    13.6              if (TRACE_SYMBOLS_STACKTRACE != null && (TRACE_SYMBOLS_STACKTRACE.isEmpty() || TRACE_SYMBOLS_STACKTRACE.contains(name))) {
    13.7 -                new Throwable().printStackTrace(Context.getContext().getErr());
    13.8 +                new Throwable().printStackTrace(Context.getCurrentErr());
    13.9              }
   13.10          }
   13.11      }
    14.1 --- a/src/jdk/nashorn/internal/ir/debug/JSONWriter.java	Sat Feb 09 16:58:48 2013 +0100
    14.2 +++ b/src/jdk/nashorn/internal/ir/debug/JSONWriter.java	Mon Feb 11 21:26:06 2013 +0530
    14.3 @@ -80,19 +80,13 @@
    14.4      /**
    14.5       * Returns AST as JSON compatible string.
    14.6       *
    14.7 +     * @param context nashorn context to use
    14.8       * @param code code to be parsed
    14.9       * @param name name of the code source (used for location)
   14.10       * @param includeLoc tells whether to include location information for nodes or not
   14.11       * @return JSON string representation of AST of the supplied code
   14.12       */
   14.13 -    public static String parse(final String code, final String name, final boolean includeLoc) {
   14.14 -        final Context      context    = AccessController.doPrivileged(
   14.15 -                new PrivilegedAction<Context>() {
   14.16 -                    @Override
   14.17 -                    public Context run() {
   14.18 -                        return Context.getContext();
   14.19 -                    }
   14.20 -                });
   14.21 +    public static String parse(final Context context, final String code, final String name, final boolean includeLoc) {
   14.22          final Compiler     compiler   = Compiler.compiler(new Source(name, code), context, new Context.ThrowErrorManager(), context._strict);
   14.23          final Parser       parser     = new Parser(compiler, context._strict);
   14.24          final JSONWriter   jsonWriter = new JSONWriter(includeLoc);
    15.1 --- a/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java	Sat Feb 09 16:58:48 2013 +0100
    15.2 +++ b/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java	Mon Feb 11 21:26:06 2013 +0530
    15.3 @@ -138,7 +138,7 @@
    15.4  
    15.5      @Override
    15.6      public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    15.7 -        final boolean strict = getContext()._strict;
    15.8 +        final boolean strict = isStrictContext();
    15.9  
   15.10          if (sobj.has(CONFIGURABLE)) {
   15.11              this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    16.1 --- a/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java	Sat Feb 09 16:58:48 2013 +0100
    16.2 +++ b/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java	Mon Feb 11 21:26:06 2013 +0530
    16.3 @@ -136,7 +136,7 @@
    16.4  
    16.5      @Override
    16.6      public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    16.7 -        final boolean strict = getContext()._strict;
    16.8 +        final boolean strict = isStrictContext();
    16.9          if (sobj.has(CONFIGURABLE)) {
   16.10              this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
   16.11          } else {
    17.1 --- a/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java	Sat Feb 09 16:58:48 2013 +0100
    17.2 +++ b/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java	Mon Feb 11 21:26:06 2013 +0530
    17.3 @@ -124,7 +124,7 @@
    17.4  
    17.5      @Override
    17.6      public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    17.7 -        final boolean strict = getContext()._strict;
    17.8 +        final boolean strict = isStrictContext();
    17.9          if (sobj.has(CONFIGURABLE)) {
   17.10              this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
   17.11          } else {
    18.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Sat Feb 09 16:58:48 2013 +0100
    18.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Mon Feb 11 21:26:06 2013 +0530
    18.3 @@ -347,10 +347,13 @@
    18.4      private static final MethodHandle LOAD    = findOwnMH("load",    Object.class, Object.class, Object.class);
    18.5      private static final MethodHandle EXIT    = findOwnMH("exit",    Object.class, Object.class, Object.class);
    18.6  
    18.7 +    private final Context context;
    18.8 +
    18.9      /**
   18.10       * Constructor
   18.11       */
   18.12 -    public Global() {
   18.13 +    public Global(final Context context) {
   18.14 +        this.context = context;
   18.15          this.setIsScope();
   18.16          /*
   18.17           * Duplicate global's map and use it. This way the initial Map filled
   18.18 @@ -359,19 +362,23 @@
   18.19           */
   18.20          this.setMap(getMap().duplicate());
   18.21  
   18.22 -        final int cacheSize = getContext()._class_cache_size;
   18.23 +        final int cacheSize = context._class_cache_size;
   18.24          if (cacheSize > 0) {
   18.25              classCache = new ClassCache(cacheSize);
   18.26          }
   18.27      }
   18.28  
   18.29      /**
   18.30 -     * Script access to unique context specific Global instance
   18.31 +     * Script access to "current" Global instance
   18.32       *
   18.33       * @return the global singleton
   18.34       */
   18.35      public static Global instance() {
   18.36 -        return (Global)Context.getGlobal();
   18.37 +        ScriptObject global = Context.getGlobal();
   18.38 +        if (! (global instanceof Global)) {
   18.39 +            throw new IllegalStateException("no current global instance");
   18.40 +        }
   18.41 +        return (Global)global;
   18.42      }
   18.43  
   18.44      /**
   18.45 @@ -380,7 +387,7 @@
   18.46       * @return the context
   18.47       */
   18.48      static Context getThisContext() {
   18.49 -        return instance().getContext();
   18.50 +        return instance().context;
   18.51      }
   18.52  
   18.53      /**
   18.54 @@ -569,7 +576,7 @@
   18.55      public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) {
   18.56          final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set);
   18.57  
   18.58 -        final boolean strict = getContext()._strict;
   18.59 +        final boolean strict = context._strict;
   18.60  
   18.61          if (get == null) {
   18.62              desc.delete(PropertyDescriptor.GET, strict);
   18.63 @@ -658,7 +665,7 @@
   18.64          final Global global = Global.instance();
   18.65          final ScriptObject scope = (self instanceof ScriptObject) ? (ScriptObject)self : global;
   18.66  
   18.67 -        return global.getContext().eval(scope, str.toString(), callThis, location, Boolean.TRUE.equals(strict));
   18.68 +        return global.context.eval(scope, str.toString(), callThis, location, Boolean.TRUE.equals(strict));
   18.69      }
   18.70  
   18.71      /**
   18.72 @@ -698,7 +705,7 @@
   18.73      public static Object load(final Object self, final Object source) throws IOException {
   18.74          final Global global = Global.instance();
   18.75          final ScriptObject scope = (self instanceof ScriptObject) ? (ScriptObject)self : global;
   18.76 -        return global.getContext().load(scope, source);
   18.77 +        return global.context.load(scope, source);
   18.78      }
   18.79  
   18.80      /**
   18.81 @@ -1344,7 +1351,7 @@
   18.82          this.decodeURIComponent = ScriptFunctionImpl.makeFunction("decodeURIComponent", GlobalFunctions.DECODE_URICOMPONENT);
   18.83          this.escape             = ScriptFunctionImpl.makeFunction("escape",     GlobalFunctions.ESCAPE);
   18.84          this.unescape           = ScriptFunctionImpl.makeFunction("unescape",   GlobalFunctions.UNESCAPE);
   18.85 -        this.print              = ScriptFunctionImpl.makeFunction("print",      getContext()._print_no_newline ? PRINT : PRINTLN);
   18.86 +        this.print              = ScriptFunctionImpl.makeFunction("print",      context._print_no_newline ? PRINT : PRINTLN);
   18.87          this.load               = ScriptFunctionImpl.makeFunction("load",       LOAD);
   18.88          this.exit               = ScriptFunctionImpl.makeFunction("exit",       EXIT);
   18.89          this.quit               = ScriptFunctionImpl.makeFunction("quit",       EXIT);
   18.90 @@ -1387,7 +1394,7 @@
   18.91  
   18.92          initTypedArray();
   18.93  
   18.94 -        if (getContext()._scripting) {
   18.95 +        if (context._scripting) {
   18.96              initScripting();
   18.97          }
   18.98  
   18.99 @@ -1403,11 +1410,11 @@
  18.100          this.__LINE__ = 0.0;
  18.101  
  18.102          // expose script (command line) arguments as "arguments" property of global
  18.103 -        final List<String> arguments = getContext().getOptions().getArguments();
  18.104 +        final List<String> arguments = context.getOptions().getArguments();
  18.105          final Object argsObj = wrapAsObject(arguments.toArray());
  18.106  
  18.107          addOwnProperty("arguments", Attribute.NOT_ENUMERABLE, argsObj);
  18.108 -        if (getContext()._scripting) {
  18.109 +        if (context._scripting) {
  18.110              // synonym for "arguments" in scripting mode
  18.111              addOwnProperty("$ARG", Attribute.NOT_ENUMERABLE, argsObj);
  18.112          }
  18.113 @@ -1485,7 +1492,7 @@
  18.114          addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);
  18.115  
  18.116          // Nashorn extension: global.$OPTIONS (scripting-mode-only)
  18.117 -        value = new OptionsObject(this.getContext());
  18.118 +        value = new OptionsObject(context);
  18.119          addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, value);
  18.120  
  18.121          // Nashorn extension: global.$ENV (scripting-mode-only)
    19.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java	Sat Feb 09 16:58:48 2013 +0100
    19.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java	Mon Feb 11 21:26:06 2013 +0530
    19.3 @@ -118,7 +118,7 @@
    19.4              if (value == ScriptRuntime.EMPTY) {
    19.5                  arrayData = arrayData.delete(index);
    19.6              } else {
    19.7 -                arrayData = arrayData.set(index, value, getContext()._strict);
    19.8 +                arrayData = arrayData.set(index, value, isStrictContext());
    19.9              }
   19.10          }
   19.11  
   19.12 @@ -644,7 +644,7 @@
   19.13              if (bulkable(sobj)) {
   19.14                  final NativeArray nativeArray = (NativeArray)sobj;
   19.15                  if (nativeArray.getArray().length() + args.length <= JSType.MAX_UINT) {
   19.16 -                    final ArrayData newData = nativeArray.getArray().push(nativeArray.getContext()._strict, args);
   19.17 +                    final ArrayData newData = nativeArray.getArray().push(nativeArray.isStrictContext(), args);
   19.18                      nativeArray.setArray(newData);
   19.19                      return newData.length();
   19.20                  }
    20.1 --- a/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Sat Feb 09 16:58:48 2013 +0100
    20.2 +++ b/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Mon Feb 11 21:26:06 2013 +0530
    20.3 @@ -36,7 +36,7 @@
    20.4  import jdk.nashorn.internal.runtime.ScriptRuntime;
    20.5  
    20.6  @ScriptClass("ArrayBuffer")
    20.7 -class NativeArrayBuffer extends ScriptObject {
    20.8 +final class NativeArrayBuffer extends ScriptObject {
    20.9      private final byte[] buffer;
   20.10  
   20.11      @Constructor(arity = 1)
    21.1 --- a/src/jdk/nashorn/internal/objects/NativeDebug.java	Sat Feb 09 16:58:48 2013 +0100
    21.2 +++ b/src/jdk/nashorn/internal/objects/NativeDebug.java	Mon Feb 11 21:26:06 2013 +0530
    21.3 @@ -46,7 +46,7 @@
    21.4   *
    21.5   */
    21.6  @ScriptClass("Debug")
    21.7 -public class NativeDebug extends ScriptObject {
    21.8 +public final class NativeDebug extends ScriptObject {
    21.9      NativeDebug() {
   21.10          this.setProto(Global.objectPrototype());
   21.11      }
   21.12 @@ -64,6 +64,10 @@
   21.13       */
   21.14      @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   21.15      public static Object getContext(final Object self) {
   21.16 +        final SecurityManager sm = System.getSecurityManager();
   21.17 +        if (sm != null) {
   21.18 +            sm.checkPermission(new RuntimePermission("getNashornContext"));
   21.19 +        }
   21.20          return Global.getThisContext();
   21.21      }
   21.22  
    22.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java	Sat Feb 09 16:58:48 2013 +0100
    22.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java	Mon Feb 11 21:26:06 2013 +0530
    22.3 @@ -47,7 +47,7 @@
    22.4   * ECMA 15.11 Error Objects
    22.5   */
    22.6  @ScriptClass("Error")
    22.7 -public class NativeError extends ScriptObject {
    22.8 +public final class NativeError extends ScriptObject {
    22.9  
   22.10      static final MethodHandle GET_COLUMNNUMBER = findOwnMH("getColumnNumber", Object.class, Object.class);
   22.11      static final MethodHandle SET_COLUMNNUMBER = findOwnMH("setColumnNumber", Object.class, Object.class, Object.class);
    23.1 --- a/src/jdk/nashorn/internal/objects/NativeEvalError.java	Sat Feb 09 16:58:48 2013 +0100
    23.2 +++ b/src/jdk/nashorn/internal/objects/NativeEvalError.java	Mon Feb 11 21:26:06 2013 +0530
    23.3 @@ -40,7 +40,7 @@
    23.4   *
    23.5   */
    23.6  @ScriptClass("Error")
    23.7 -public class NativeEvalError extends ScriptObject {
    23.8 +public final class NativeEvalError extends ScriptObject {
    23.9  
   23.10      /** message property in instance */
   23.11      @Property(name = NativeError.MESSAGE)
    24.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat32Array.java	Sat Feb 09 16:58:48 2013 +0100
    24.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat32Array.java	Mon Feb 11 21:26:06 2013 +0530
    24.3 @@ -37,7 +37,7 @@
    24.4   * Float32 array for the TypedArray extension
    24.5   */
    24.6  @ScriptClass("Float32Array")
    24.7 -public class NativeFloat32Array extends ArrayBufferView {
    24.8 +public final class NativeFloat32Array extends ArrayBufferView {
    24.9      private static final int BYTES_PER_ELEMENT = 4;
   24.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   24.11          @Override
    25.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat64Array.java	Sat Feb 09 16:58:48 2013 +0100
    25.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat64Array.java	Mon Feb 11 21:26:06 2013 +0530
    25.3 @@ -37,7 +37,7 @@
    25.4   * Float64 array for the TypedArray extension
    25.5   */
    25.6  @ScriptClass("Float64Array")
    25.7 -public class NativeFloat64Array extends ArrayBufferView {
    25.8 +public final class NativeFloat64Array extends ArrayBufferView {
    25.9      private static final int BYTES_PER_ELEMENT = 8;
   25.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   25.11          @Override
    26.1 --- a/src/jdk/nashorn/internal/objects/NativeFunction.java	Sat Feb 09 16:58:48 2013 +0100
    26.2 +++ b/src/jdk/nashorn/internal/objects/NativeFunction.java	Mon Feb 11 21:26:06 2013 +0530
    26.3 @@ -168,7 +168,7 @@
    26.4              arguments = ScriptRuntime.EMPTY_ARRAY;
    26.5          }
    26.6  
    26.7 -        return ((ScriptFunction)self).makeBoundFunction(thiz, arguments);
    26.8 +        return ((ScriptFunctionImpl)self).makeBoundFunction(thiz, arguments);
    26.9      }
   26.10  
   26.11      /**
    27.1 --- a/src/jdk/nashorn/internal/objects/NativeInt16Array.java	Sat Feb 09 16:58:48 2013 +0100
    27.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt16Array.java	Mon Feb 11 21:26:06 2013 +0530
    27.3 @@ -36,7 +36,7 @@
    27.4   * Int16 array for the TypedArray extension
    27.5   */
    27.6  @ScriptClass("Int16Array")
    27.7 -public class NativeInt16Array extends ArrayBufferView {
    27.8 +public final class NativeInt16Array extends ArrayBufferView {
    27.9      private static final int BYTES_PER_ELEMENT = 2;
   27.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   27.11          @Override
    28.1 --- a/src/jdk/nashorn/internal/objects/NativeInt32Array.java	Sat Feb 09 16:58:48 2013 +0100
    28.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt32Array.java	Mon Feb 11 21:26:06 2013 +0530
    28.3 @@ -36,7 +36,7 @@
    28.4   * Int32 array for the TypedArray extension
    28.5   */
    28.6  @ScriptClass("Int32Array")
    28.7 -public class NativeInt32Array extends ArrayBufferView {
    28.8 +public final class NativeInt32Array extends ArrayBufferView {
    28.9      private static final int BYTES_PER_ELEMENT = 4;
   28.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   28.11          @Override
    29.1 --- a/src/jdk/nashorn/internal/objects/NativeInt8Array.java	Sat Feb 09 16:58:48 2013 +0100
    29.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt8Array.java	Mon Feb 11 21:26:06 2013 +0530
    29.3 @@ -36,7 +36,7 @@
    29.4   * Int8Array for the TypedArray extension
    29.5   */
    29.6  @ScriptClass("Int8Array")
    29.7 -public class NativeInt8Array extends ArrayBufferView {
    29.8 +public final class NativeInt8Array extends ArrayBufferView {
    29.9      private static final int BYTES_PER_ELEMENT = 1;
   29.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   29.11          @Override
    30.1 --- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java	Sat Feb 09 16:58:48 2013 +0100
    30.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java	Mon Feb 11 21:26:06 2013 +0530
    30.3 @@ -617,7 +617,7 @@
    30.4          case "getMethod":
    30.5              final FindProperty find = adaptee.findProperty(__call__, true);
    30.6              if (find != null) {
    30.7 -                final ScriptFunction func = (ScriptFunction)getObjectValue(find);
    30.8 +                final ScriptFunctionImpl func = (ScriptFunctionImpl)getObjectValue(find);
    30.9                  // TODO: It's a shame we need to produce a function bound to this and name, when we'd only need it bound
   30.10                  // to name. Probably not a big deal, but if we can ever make it leaner, it'd be nice.
   30.11                  return new GuardedInvocation(MH.dropArguments(MH.constant(Object.class,
    31.1 --- a/src/jdk/nashorn/internal/objects/NativeJSON.java	Sat Feb 09 16:58:48 2013 +0100
    31.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSON.java	Mon Feb 11 21:26:06 2013 +0530
    31.3 @@ -25,7 +25,6 @@
    31.4  
    31.5  package jdk.nashorn.internal.objects;
    31.6  
    31.7 -import static jdk.nashorn.internal.runtime.ECMAErrors.syntaxError;
    31.8  import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
    31.9  import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
   31.10  
   31.11 @@ -36,25 +35,15 @@
   31.12  import java.util.Iterator;
   31.13  import java.util.List;
   31.14  import java.util.Map;
   31.15 -import jdk.nashorn.internal.ir.LiteralNode;
   31.16 -import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
   31.17 -import jdk.nashorn.internal.ir.Node;
   31.18 -import jdk.nashorn.internal.ir.ObjectNode;
   31.19 -import jdk.nashorn.internal.ir.PropertyNode;
   31.20 -import jdk.nashorn.internal.ir.UnaryNode;
   31.21  import jdk.nashorn.internal.objects.annotations.Attribute;
   31.22  import jdk.nashorn.internal.objects.annotations.Function;
   31.23  import jdk.nashorn.internal.objects.annotations.ScriptClass;
   31.24  import jdk.nashorn.internal.objects.annotations.Where;
   31.25 -import jdk.nashorn.internal.parser.JSONParser;
   31.26 -import jdk.nashorn.internal.parser.TokenType;
   31.27  import jdk.nashorn.internal.runtime.ConsString;
   31.28 -import jdk.nashorn.internal.runtime.Context;
   31.29 +import jdk.nashorn.internal.runtime.JSONFunctions;
   31.30  import jdk.nashorn.internal.runtime.JSType;
   31.31 -import jdk.nashorn.internal.runtime.ParserException;
   31.32  import jdk.nashorn.internal.runtime.ScriptFunction;
   31.33  import jdk.nashorn.internal.runtime.ScriptObject;
   31.34 -import jdk.nashorn.internal.runtime.Source;
   31.35  import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator;
   31.36  import jdk.nashorn.internal.runtime.linker.Bootstrap;
   31.37  import jdk.nashorn.internal.runtime.linker.InvokeByName;
   31.38 @@ -68,8 +57,6 @@
   31.39      private static final InvokeByName TO_JSON = new InvokeByName("toJSON", ScriptObject.class, Object.class, Object.class);
   31.40      private static final MethodHandle REPLACER_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class,
   31.41              ScriptFunction.class, ScriptObject.class, Object.class, Object.class);
   31.42 -    private static final MethodHandle REVIVER_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class,
   31.43 -            ScriptFunction.class, ScriptObject.class, String.class, Object.class);
   31.44  
   31.45  
   31.46      NativeJSON() {
   31.47 @@ -87,27 +74,7 @@
   31.48       */
   31.49      @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   31.50      public static Object parse(final Object self, final Object text, final Object reviver) {
   31.51 -        final String     str     = JSType.toString(text);
   31.52 -        final Context    context = Global.getThisContext();
   31.53 -        final JSONParser parser  = new JSONParser(
   31.54 -                new Source("<json>", str),
   31.55 -                new Context.ThrowErrorManager(),
   31.56 -                (context != null) ?
   31.57 -                    context._strict :
   31.58 -                    false);
   31.59 -
   31.60 -        Node node;
   31.61 -
   31.62 -        try {
   31.63 -            node = parser.parse();
   31.64 -        } catch (final ParserException e) {
   31.65 -            syntaxError(e, "invalid.json", e.getMessage());
   31.66 -            return UNDEFINED;
   31.67 -        }
   31.68 -
   31.69 -        final Object unfiltered = convertNode(node);
   31.70 -
   31.71 -        return applyReviver(unfiltered, reviver);
   31.72 +        return JSONFunctions.parse(text, reviver);
   31.73      }
   31.74  
   31.75      /**
   31.76 @@ -198,136 +165,6 @@
   31.77  
   31.78      // -- Internals only below this point
   31.79  
   31.80 -    // parse helpers
   31.81 -
   31.82 -    // apply 'reviver' function if available
   31.83 -    private static Object applyReviver(final Object unfiltered, final Object reviver) {
   31.84 -        if (reviver instanceof ScriptFunction) {
   31.85 -            final ScriptObject root = Global.newEmptyInstance();
   31.86 -            root.set("", unfiltered, Global.isStrict());
   31.87 -            return walk(root, "", (ScriptFunction)reviver);
   31.88 -        }
   31.89 -        return unfiltered;
   31.90 -    }
   31.91 -
   31.92 -    // This is the abstract "Walk" operation from the spec.
   31.93 -    private static Object walk(final ScriptObject holder, final Object name, final ScriptFunction reviver) {
   31.94 -        final Object val = holder.get(name);
   31.95 -        if (val == UNDEFINED) {
   31.96 -            return val;
   31.97 -        } else if (val instanceof ScriptObject) {
   31.98 -            final ScriptObject     valueObj = (ScriptObject)val;
   31.99 -            final boolean          strict   = Global.isStrict();
  31.100 -            final Iterator<String> iter     = valueObj.propertyIterator();
  31.101 -
  31.102 -            while (iter.hasNext()) {
  31.103 -                final String key        = iter.next();
  31.104 -                final Object newElement = walk(valueObj, key, reviver);
  31.105 -
  31.106 -                if (newElement == UNDEFINED) {
  31.107 -                    valueObj.delete(key, strict);
  31.108 -                } else {
  31.109 -                    valueObj.set(key, newElement, strict);
  31.110 -                }
  31.111 -            }
  31.112 -
  31.113 -            return valueObj;
  31.114 -        } else if (isArray(val)) {
  31.115 -            final NativeArray      valueArray = (NativeArray)val;
  31.116 -            final boolean          strict     = Global.isStrict();
  31.117 -            final Iterator<String> iter       = valueArray.propertyIterator();
  31.118 -
  31.119 -            while (iter.hasNext()) {
  31.120 -                final String key        = iter.next();
  31.121 -                final Object newElement = walk(valueArray, valueArray.get(key), reviver);
  31.122 -
  31.123 -                if (newElement == UNDEFINED) {
  31.124 -                    valueArray.delete(key, strict);
  31.125 -                } else {
  31.126 -                    valueArray.set(key, newElement, strict);
  31.127 -                }
  31.128 -            }
  31.129 -            return valueArray;
  31.130 -        } else {
  31.131 -            try {
  31.132 -                // Object.class, ScriptFunction.class, ScriptObject.class, String.class, Object.class);
  31.133 -                return REVIVER_INVOKER.invokeExact(reviver, holder, JSType.toString(name), val);
  31.134 -            } catch(Error|RuntimeException t) {
  31.135 -                throw t;
  31.136 -            } catch(final Throwable t) {
  31.137 -                throw new RuntimeException(t);
  31.138 -            }
  31.139 -        }
  31.140 -    }
  31.141 -
  31.142 -    // Converts IR node to runtime value
  31.143 -    private static Object convertNode(final Node node) {
  31.144 -
  31.145 -       if (node instanceof LiteralNode) {
  31.146 -            // check for array literal
  31.147 -            if (node.tokenType() == TokenType.ARRAY) {
  31.148 -                assert node instanceof ArrayLiteralNode;
  31.149 -                final Node[] elements = ((ArrayLiteralNode)node).getValue();
  31.150 -
  31.151 -                // NOTE: We cannot use LiteralNode.isNumericArray() here as that
  31.152 -                // method uses symbols of element nodes. Since we don't do lower
  31.153 -                // pass, there won't be any symbols!
  31.154 -                if (isNumericArray(elements)) {
  31.155 -                    final double[] values = new double[elements.length];
  31.156 -                    int   index = 0;
  31.157 -
  31.158 -                    for (final Node elem : elements) {
  31.159 -                        values[index++] = JSType.toNumber(convertNode(elem));
  31.160 -                    }
  31.161 -                    return Global.allocate(values);
  31.162 -                }
  31.163 -
  31.164 -                final Object[] values = new Object[elements.length];
  31.165 -                int   index = 0;
  31.166 -
  31.167 -                for (final Node elem : elements) {
  31.168 -                    values[index++] = convertNode(elem);
  31.169 -                }
  31.170 -
  31.171 -                return Global.allocate(values);
  31.172 -            }
  31.173 -
  31.174 -            return ((LiteralNode<?>)node).getValue();
  31.175 -
  31.176 -        } else if (node instanceof ObjectNode) {
  31.177 -            final ObjectNode   objNode  = (ObjectNode) node;
  31.178 -            final ScriptObject object   = Global.newEmptyInstance();
  31.179 -            final boolean      strict   = Global.isStrict();
  31.180 -            final List<Node>   elements = objNode.getElements();
  31.181 -
  31.182 -            for (final Node elem : elements) {
  31.183 -                final PropertyNode pNode     = (PropertyNode) elem;
  31.184 -                final Node         valueNode = pNode.getValue();
  31.185 -
  31.186 -                object.set(pNode.getKeyName(), convertNode(valueNode), strict);
  31.187 -            }
  31.188 -
  31.189 -            return object;
  31.190 -        } else if (node instanceof UnaryNode) {
  31.191 -            // UnaryNode used only to represent negative number JSON value
  31.192 -            final UnaryNode unaryNode = (UnaryNode)node;
  31.193 -            return -((LiteralNode<?>)unaryNode.rhs()).getNumber();
  31.194 -        } else {
  31.195 -            return null;
  31.196 -        }
  31.197 -    }
  31.198 -
  31.199 -    // does the given IR node represent a numeric array?
  31.200 -    private static boolean isNumericArray(final Node[] values) {
  31.201 -        for (final Node node : values) {
  31.202 -            if (node instanceof LiteralNode && ((LiteralNode<?>)node).getValue() instanceof Number) {
  31.203 -                continue;
  31.204 -            }
  31.205 -            return false;
  31.206 -        }
  31.207 -        return true;
  31.208 -    }
  31.209 -
  31.210      // stringify helpers.
  31.211  
  31.212      private static class StringifyState {
  31.213 @@ -380,9 +217,9 @@
  31.214          }
  31.215  
  31.216          if (value instanceof String) {
  31.217 -            return JSONParser.quote((String)value);
  31.218 +            return JSONFunctions.quote((String)value);
  31.219          } else if (value instanceof ConsString) {
  31.220 -            return JSONParser.quote(value.toString());
  31.221 +            return JSONFunctions.quote(value.toString());
  31.222          }
  31.223  
  31.224          if (value instanceof Number) {
  31.225 @@ -421,7 +258,7 @@
  31.226              if (strP != UNDEFINED) {
  31.227                  final StringBuilder member = new StringBuilder();
  31.228  
  31.229 -                member.append(JSONParser.quote(p.toString())).append(':');
  31.230 +                member.append(JSONFunctions.quote(p.toString())).append(':');
  31.231                  if (!state.gap.isEmpty()) {
  31.232                      member.append(' ');
  31.233                  }
    32.1 --- a/src/jdk/nashorn/internal/objects/NativeJava.java	Sat Feb 09 16:58:48 2013 +0100
    32.2 +++ b/src/jdk/nashorn/internal/objects/NativeJava.java	Mon Feb 11 21:26:06 2013 +0530
    32.3 @@ -47,7 +47,7 @@
    32.4   * arrays, and so forth.
    32.5   */
    32.6  @ScriptClass("Java")
    32.7 -public class NativeJava {
    32.8 +public final class NativeJava {
    32.9  
   32.10      private NativeJava() {
   32.11      }
    33.1 --- a/src/jdk/nashorn/internal/objects/NativeJavaImporter.java	Sat Feb 09 16:58:48 2013 +0100
    33.2 +++ b/src/jdk/nashorn/internal/objects/NativeJavaImporter.java	Mon Feb 11 21:26:06 2013 +0530
    33.3 @@ -52,7 +52,7 @@
    33.4   * {@link NativeJava#type(Object, Object) Java.type()} method.
    33.5   */
    33.6  @ScriptClass("JavaImporter")
    33.7 -public class NativeJavaImporter extends ScriptObject {
    33.8 +public final class NativeJavaImporter extends ScriptObject {
    33.9      private final Object[] args;
   33.10  
   33.11      NativeJavaImporter(final Object[] args) {
   33.12 @@ -121,7 +121,7 @@
   33.13          final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
   33.14          final Object value = createProperty(name);
   33.15          if(value != null) {
   33.16 -            set(name, value, getContext()._strict);
   33.17 +            set(name, value, isStrictContext());
   33.18              return true;
   33.19          }
   33.20          return false;
    34.1 --- a/src/jdk/nashorn/internal/objects/NativeRangeError.java	Sat Feb 09 16:58:48 2013 +0100
    34.2 +++ b/src/jdk/nashorn/internal/objects/NativeRangeError.java	Mon Feb 11 21:26:06 2013 +0530
    34.3 @@ -40,7 +40,7 @@
    34.4   *
    34.5   */
    34.6  @ScriptClass("Error")
    34.7 -public class NativeRangeError extends ScriptObject {
    34.8 +public final class NativeRangeError extends ScriptObject {
    34.9  
   34.10      /** message property in instance */
   34.11      @Property(name = NativeError.MESSAGE)
    35.1 --- a/src/jdk/nashorn/internal/objects/NativeReferenceError.java	Sat Feb 09 16:58:48 2013 +0100
    35.2 +++ b/src/jdk/nashorn/internal/objects/NativeReferenceError.java	Mon Feb 11 21:26:06 2013 +0530
    35.3 @@ -40,7 +40,7 @@
    35.4   *
    35.5   */
    35.6  @ScriptClass("Error")
    35.7 -public class NativeReferenceError extends ScriptObject {
    35.8 +public final class NativeReferenceError extends ScriptObject {
    35.9  
   35.10      /** message property in instance */
   35.11      @Property(name = NativeError.MESSAGE)
    36.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java	Sat Feb 09 16:58:48 2013 +0100
    36.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java	Mon Feb 11 21:26:06 2013 +0530
    36.3 @@ -41,10 +41,10 @@
    36.4  import jdk.nashorn.internal.objects.annotations.ScriptClass;
    36.5  import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
    36.6  import jdk.nashorn.internal.objects.annotations.Where;
    36.7 -import jdk.nashorn.internal.parser.RegExp;
    36.8  import jdk.nashorn.internal.runtime.BitVector;
    36.9  import jdk.nashorn.internal.runtime.JSType;
   36.10  import jdk.nashorn.internal.runtime.ParserException;
   36.11 +import jdk.nashorn.internal.runtime.RegExp;
   36.12  import jdk.nashorn.internal.runtime.RegExpMatch;
   36.13  import jdk.nashorn.internal.runtime.ScriptFunction;
   36.14  import jdk.nashorn.internal.runtime.ScriptObject;
    37.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java	Sat Feb 09 16:58:48 2013 +0100
    37.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java	Mon Feb 11 21:26:06 2013 +0530
    37.3 @@ -40,7 +40,7 @@
    37.4   * RegExp.prototype.exec method.
    37.5   */
    37.6  @ScriptClass("RegExpExecResult")
    37.7 -public class NativeRegExpExecResult extends ScriptObject {
    37.8 +public final class NativeRegExpExecResult extends ScriptObject {
    37.9      /** index property */
   37.10      @Property
   37.11      public Object index;
    38.1 --- a/src/jdk/nashorn/internal/objects/NativeString.java	Sat Feb 09 16:58:48 2013 +0100
    38.2 +++ b/src/jdk/nashorn/internal/objects/NativeString.java	Mon Feb 11 21:26:06 2013 +0530
    38.3 @@ -47,7 +47,6 @@
    38.4  import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
    38.5  import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
    38.6  import jdk.nashorn.internal.objects.annotations.Where;
    38.7 -import jdk.nashorn.internal.parser.Lexer;
    38.8  import jdk.nashorn.internal.runtime.ConsString;
    38.9  import jdk.nashorn.internal.runtime.JSType;
   38.10  import jdk.nashorn.internal.runtime.ScriptFunction;
   38.11 @@ -1034,10 +1033,10 @@
   38.12          int start = 0;
   38.13          int end   = len - 1;
   38.14  
   38.15 -        while (start <= end && Lexer.isJSWhitespace(str.charAt(start))) {
   38.16 +        while (start <= end && ScriptRuntime.isJSWhitespace(str.charAt(start))) {
   38.17              start++;
   38.18          }
   38.19 -        while (end > start && Lexer.isJSWhitespace(str.charAt(end))) {
   38.20 +        while (end > start && ScriptRuntime.isJSWhitespace(str.charAt(end))) {
   38.21              end--;
   38.22          }
   38.23  
    39.1 --- a/src/jdk/nashorn/internal/objects/NativeSyntaxError.java	Sat Feb 09 16:58:48 2013 +0100
    39.2 +++ b/src/jdk/nashorn/internal/objects/NativeSyntaxError.java	Mon Feb 11 21:26:06 2013 +0530
    39.3 @@ -40,7 +40,7 @@
    39.4   *
    39.5   */
    39.6  @ScriptClass("Error")
    39.7 -public class NativeSyntaxError extends ScriptObject {
    39.8 +public final class NativeSyntaxError extends ScriptObject {
    39.9  
   39.10      /** message property in instance */
   39.11      @Property(name = NativeError.MESSAGE)
    40.1 --- a/src/jdk/nashorn/internal/objects/NativeTypeError.java	Sat Feb 09 16:58:48 2013 +0100
    40.2 +++ b/src/jdk/nashorn/internal/objects/NativeTypeError.java	Mon Feb 11 21:26:06 2013 +0530
    40.3 @@ -40,7 +40,7 @@
    40.4   *
    40.5   */
    40.6  @ScriptClass("Error")
    40.7 -public class NativeTypeError extends ScriptObject {
    40.8 +public final class NativeTypeError extends ScriptObject {
    40.9  
   40.10      /** message property in instance */
   40.11      @Property(name = NativeError.MESSAGE)
    41.1 --- a/src/jdk/nashorn/internal/objects/NativeURIError.java	Sat Feb 09 16:58:48 2013 +0100
    41.2 +++ b/src/jdk/nashorn/internal/objects/NativeURIError.java	Mon Feb 11 21:26:06 2013 +0530
    41.3 @@ -39,7 +39,7 @@
    41.4   * ECMA 15.11.6.6 URIError
    41.5   */
    41.6  @ScriptClass("Error")
    41.7 -public class NativeURIError extends ScriptObject {
    41.8 +public final class NativeURIError extends ScriptObject {
    41.9  
   41.10      /** message property in instance */
   41.11      @Property(name = NativeError.MESSAGE)
    42.1 --- a/src/jdk/nashorn/internal/objects/NativeUint16Array.java	Sat Feb 09 16:58:48 2013 +0100
    42.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint16Array.java	Mon Feb 11 21:26:06 2013 +0530
    42.3 @@ -36,7 +36,7 @@
    42.4   * Uint16 array for TypedArray extension
    42.5   */
    42.6  @ScriptClass("Uint16Array")
    42.7 -public class NativeUint16Array extends ArrayBufferView {
    42.8 +public final class NativeUint16Array extends ArrayBufferView {
    42.9      private static final int BYTES_PER_ELEMENT = 2;
   42.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   42.11          @Override
    43.1 --- a/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Sat Feb 09 16:58:48 2013 +0100
    43.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Mon Feb 11 21:26:06 2013 +0530
    43.3 @@ -36,7 +36,7 @@
    43.4   * Uint32 array for TypedArray extension
    43.5   */
    43.6  @ScriptClass("Uint32Array")
    43.7 -public class NativeUint32Array extends ArrayBufferView {
    43.8 +public final class NativeUint32Array extends ArrayBufferView {
    43.9      private static final int BYTES_PER_ELEMENT = 4;
   43.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   43.11          @Override
    44.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8Array.java	Sat Feb 09 16:58:48 2013 +0100
    44.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8Array.java	Mon Feb 11 21:26:06 2013 +0530
    44.3 @@ -36,7 +36,7 @@
    44.4   * Uint8 array for TypedArray extension
    44.5   */
    44.6  @ScriptClass("Uint8Array")
    44.7 -public class NativeUint8Array extends ArrayBufferView {
    44.8 +public final class NativeUint8Array extends ArrayBufferView {
    44.9      private static final int BYTES_PER_ELEMENT = 1;
   44.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   44.11          @Override
    45.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Sat Feb 09 16:58:48 2013 +0100
    45.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Mon Feb 11 21:26:06 2013 +0530
    45.3 @@ -37,7 +37,7 @@
    45.4   * Uint8 clamped array for TypedArray extension
    45.5   */
    45.6  @ScriptClass("Uint8ClampedArray")
    45.7 -public class NativeUint8ClampedArray extends ArrayBufferView {
    45.8 +public final class NativeUint8ClampedArray extends ArrayBufferView {
    45.9      private static final int BYTES_PER_ELEMENT = 1;
   45.10      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   45.11          @Override
    46.1 --- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Sat Feb 09 16:58:48 2013 +0100
    46.2 +++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Mon Feb 11 21:26:06 2013 +0530
    46.3 @@ -30,12 +30,12 @@
    46.4  
    46.5  import java.lang.invoke.MethodHandle;
    46.6  import java.lang.invoke.MethodHandles;
    46.7 -import jdk.nashorn.internal.codegen.objects.FunctionObjectCreator;
    46.8 +
    46.9 +import jdk.nashorn.internal.runtime.ScriptFunctionData;
   46.10  import jdk.nashorn.internal.runtime.GlobalFunctions;
   46.11  import jdk.nashorn.internal.runtime.Property;
   46.12  import jdk.nashorn.internal.runtime.PropertyMap;
   46.13  import jdk.nashorn.internal.runtime.ScriptFunction;
   46.14 -import jdk.nashorn.internal.runtime.ScriptFunctionData;
   46.15  import jdk.nashorn.internal.runtime.ScriptObject;
   46.16  import jdk.nashorn.internal.runtime.ScriptRuntime;
   46.17  import jdk.nashorn.internal.runtime.linker.Lookup;
   46.18 @@ -184,7 +184,7 @@
   46.19       * @param strict are we in strict mode
   46.20       * @return new ScriptFunction
   46.21       */
   46.22 -    public static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle, final MethodHandle[] specs, final boolean strict) {
   46.23 +    static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle, final MethodHandle[] specs, final boolean strict) {
   46.24          final ScriptFunctionImpl func = new ScriptFunctionImpl(name, methodHandle, null, specs, strict, true);
   46.25          func.setConstructHandle(null);
   46.26          func.setPrototype(UNDEFINED);
   46.27 @@ -200,7 +200,7 @@
   46.28       * @param specs  specialized versions of function if available, null otherwise
   46.29       * @return new ScriptFunction
   46.30       */
   46.31 -    public static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle, final MethodHandle[] specs) {
   46.32 +    static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle, final MethodHandle[] specs) {
   46.33          return makeFunction(name, methodHandle, specs, false);
   46.34      }
   46.35  
   46.36 @@ -211,7 +211,7 @@
   46.37       * @param methodHandle handle for invocation
   46.38       * @return new ScriptFunction
   46.39       */
   46.40 -    public static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle) {
   46.41 +    static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle) {
   46.42          return makeFunction(name, methodHandle, null);
   46.43      }
   46.44  
   46.45 @@ -223,7 +223,7 @@
   46.46       * @param args arguments to bind
   46.47       */
   46.48      @Override
   46.49 -    public ScriptFunction makeBoundFunction(final Object thiz, final Object[] args) {
   46.50 +    protected ScriptFunction makeBoundFunction(final Object thiz, final Object[] args) {
   46.51          Object[] allArgs = args;
   46.52  
   46.53          if (allArgs == null) {
    47.1 --- a/src/jdk/nashorn/internal/parser/AbstractParser.java	Sat Feb 09 16:58:48 2013 +0100
    47.2 +++ b/src/jdk/nashorn/internal/parser/AbstractParser.java	Mon Feb 11 21:26:06 2013 +0530
    47.3 @@ -37,6 +37,7 @@
    47.4  import jdk.nashorn.internal.runtime.ErrorManager;
    47.5  import jdk.nashorn.internal.runtime.JSErrorType;
    47.6  import jdk.nashorn.internal.runtime.ParserException;
    47.7 +import jdk.nashorn.internal.runtime.RegExp;
    47.8  import jdk.nashorn.internal.runtime.Source;
    47.9  
   47.10  /**
    48.1 --- a/src/jdk/nashorn/internal/parser/Lexer.java	Sat Feb 09 16:58:48 2013 +0100
    48.2 +++ b/src/jdk/nashorn/internal/parser/Lexer.java	Mon Feb 11 21:26:06 2013 +0530
    48.3 @@ -289,7 +289,7 @@
    48.4          add(type, start, position);
    48.5      }
    48.6  
    48.7 -    static String getWhitespaceRegExp() {
    48.8 +    public static String getWhitespaceRegExp() {
    48.9          return JAVASCRIPT_WHITESPACE_IN_REGEXP;
   48.10      }
   48.11  
    49.1 --- a/src/jdk/nashorn/internal/parser/RegExp.java	Sat Feb 09 16:58:48 2013 +0100
    49.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.3 @@ -1,180 +0,0 @@
    49.4 -/*
    49.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    49.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    49.7 - *
    49.8 - * This code is free software; you can redistribute it and/or modify it
    49.9 - * under the terms of the GNU General Public License version 2 only, as
   49.10 - * published by the Free Software Foundation.  Oracle designates this
   49.11 - * particular file as subject to the "Classpath" exception as provided
   49.12 - * by Oracle in the LICENSE file that accompanied this code.
   49.13 - *
   49.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   49.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   49.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   49.17 - * version 2 for more details (a copy is included in the LICENSE file that
   49.18 - * accompanied this code).
   49.19 - *
   49.20 - * You should have received a copy of the GNU General Public License version
   49.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   49.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   49.23 - *
   49.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   49.25 - * or visit www.oracle.com if you need additional information or have any
   49.26 - * questions.
   49.27 - */
   49.28 -
   49.29 -package jdk.nashorn.internal.parser;
   49.30 -
   49.31 -import static java.util.regex.Pattern.CASE_INSENSITIVE;
   49.32 -import static java.util.regex.Pattern.MULTILINE;
   49.33 -import static java.util.regex.Pattern.UNICODE_CASE;
   49.34 -
   49.35 -import java.util.HashSet;
   49.36 -import java.util.regex.Pattern;
   49.37 -import java.util.regex.PatternSyntaxException;
   49.38 -import jdk.nashorn.internal.runtime.BitVector;
   49.39 -import jdk.nashorn.internal.runtime.ECMAErrors;
   49.40 -import jdk.nashorn.internal.runtime.ParserException;
   49.41 -
   49.42 -/**
   49.43 - * This class is used to represent a parsed regular expression. Accepts input
   49.44 - * pattern string and flagString. This is used by AbstractParser to validate
   49.45 - * RegExp literals as well as by NativeRegExp to parse RegExp constructor arguments.
   49.46 - */
   49.47 -public final class RegExp {
   49.48 -    /** Pattern string. */
   49.49 -    private final String input;
   49.50 -
   49.51 -    /** Global search flag for this regexp.*/
   49.52 -    private boolean global;
   49.53 -
   49.54 -    /** Case insensitive flag for this regexp */
   49.55 -    private boolean ignoreCase;
   49.56 -
   49.57 -    /** Multi-line flag for this regexp */
   49.58 -    private boolean multiline;
   49.59 -
   49.60 -    /** Java regexp pattern to use for match. We compile to one of these */
   49.61 -    private Pattern pattern;
   49.62 -
   49.63 -    /** BitVector that keeps track of groups in negative lookahead */
   49.64 -    private BitVector groupsInNegativeLookahead;
   49.65 -
   49.66 -    /**
   49.67 -     * Creates RegExpLiteral object from given input and flagString.
   49.68 -     *
   49.69 -     * @param input RegExp pattern string
   49.70 -     * @param flagString RegExp flags
   49.71 -     * @throws ParserException if flagString is invalid or input string has syntax error.
   49.72 -     */
   49.73 -    public RegExp(final String input, final String flagString) throws ParserException {
   49.74 -        this.input = input;
   49.75 -        final HashSet<Character> usedFlags = new HashSet<>();
   49.76 -        int flags = 0;
   49.77 -
   49.78 -        for (final char ch : flagString.toCharArray()) {
   49.79 -            if (usedFlags.contains(ch)) {
   49.80 -                throwParserException("repeated.flag", Character.toString(ch));
   49.81 -            }
   49.82 -
   49.83 -            switch (ch) {
   49.84 -            case 'g':
   49.85 -                this.global = true;
   49.86 -                usedFlags.add(ch);
   49.87 -                break;
   49.88 -            case 'i':
   49.89 -                this.ignoreCase = true;
   49.90 -                flags |= CASE_INSENSITIVE | UNICODE_CASE;
   49.91 -                usedFlags.add(ch);
   49.92 -                break;
   49.93 -            case 'm':
   49.94 -                this.multiline = true;
   49.95 -                flags |= MULTILINE;
   49.96 -                usedFlags.add(ch);
   49.97 -                break;
   49.98 -            default:
   49.99 -                throwParserException("unsupported.flag", Character.toString(ch));
  49.100 -            }
  49.101 -        }
  49.102 -
  49.103 -        try {
  49.104 -            RegExpScanner parsed;
  49.105 -
  49.106 -            try {
  49.107 -                parsed = RegExpScanner.scan(input);
  49.108 -            } catch (final PatternSyntaxException e) {
  49.109 -                // refine the exception with a better syntax error, if this
  49.110 -                // passes, just rethrow what we have
  49.111 -                Pattern.compile(input, flags);
  49.112 -                throw e;
  49.113 -            }
  49.114 -
  49.115 -            if (parsed != null) {
  49.116 -                this.pattern = Pattern.compile(parsed.getJavaPattern(), flags);
  49.117 -                this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
  49.118 -            }
  49.119 -        } catch (final PatternSyntaxException e2) {
  49.120 -            throwParserException("syntax", e2.getMessage());
  49.121 -        }
  49.122 -
  49.123 -    }
  49.124 -
  49.125 -    /**
  49.126 -     * @return the input
  49.127 -     */
  49.128 -    public String getInput() {
  49.129 -        return input;
  49.130 -    }
  49.131 -
  49.132 -    /**
  49.133 -     * @return the global
  49.134 -     */
  49.135 -    public boolean isGlobal() {
  49.136 -        return global;
  49.137 -    }
  49.138 -
  49.139 -    /**
  49.140 -     * @return the ignoreCase
  49.141 -     */
  49.142 -    public boolean isIgnoreCase() {
  49.143 -        return ignoreCase;
  49.144 -    }
  49.145 -
  49.146 -    /**
  49.147 -     * @return the multiline
  49.148 -     */
  49.149 -    public boolean isMultiline() {
  49.150 -        return multiline;
  49.151 -    }
  49.152 -
  49.153 -    /**
  49.154 -     * @return the pattern
  49.155 -     */
  49.156 -    public Pattern getPattern() {
  49.157 -        return pattern;
  49.158 -    }
  49.159 -
  49.160 -    /**
  49.161 -     * @return the groupsInNegativeLookahead
  49.162 -     */
  49.163 -    public BitVector getGroupsInNegativeLookahead() {
  49.164 -        return groupsInNegativeLookahead;
  49.165 -    }
  49.166 -
  49.167 -    /**
  49.168 -     * Validation method for RegExp input and flagString - we don't care about the RegExp object
  49.169 -     *
  49.170 -     * @param input        regexp input
  49.171 -     * @param flagString   flag string
  49.172 -     *
  49.173 -     * @throws ParserException if invalid regexp and flags
  49.174 -     */
  49.175 -    @SuppressWarnings({"unused", "ResultOfObjectAllocationIgnored"})
  49.176 -    public static void validate(final String input, final String flagString) throws ParserException {
  49.177 -        new RegExp(input, flagString);
  49.178 -    }
  49.179 -
  49.180 -    private static void throwParserException(final String key, final String str) throws ParserException {
  49.181 -        throw new ParserException(ECMAErrors.getMessage("parser.error.regex." + key, str));
  49.182 -    }
  49.183 -}
    50.1 --- a/src/jdk/nashorn/internal/parser/RegExpScanner.java	Sat Feb 09 16:58:48 2013 +0100
    50.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.3 @@ -1,1414 +0,0 @@
    50.4 -/*
    50.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    50.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    50.7 - *
    50.8 - * This code is free software; you can redistribute it and/or modify it
    50.9 - * under the terms of the GNU General Public License version 2 only, as
   50.10 - * published by the Free Software Foundation.  Oracle designates this
   50.11 - * particular file as subject to the "Classpath" exception as provided
   50.12 - * by Oracle in the LICENSE file that accompanied this code.
   50.13 - *
   50.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   50.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   50.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   50.17 - * version 2 for more details (a copy is included in the LICENSE file that
   50.18 - * accompanied this code).
   50.19 - *
   50.20 - * You should have received a copy of the GNU General Public License version
   50.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   50.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   50.23 - *
   50.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   50.25 - * or visit www.oracle.com if you need additional information or have any
   50.26 - * questions.
   50.27 - */
   50.28 -
   50.29 -package jdk.nashorn.internal.parser;
   50.30 -
   50.31 -import java.util.ArrayList;
   50.32 -import java.util.HashMap;
   50.33 -import java.util.Iterator;
   50.34 -import java.util.LinkedHashMap;
   50.35 -import java.util.LinkedList;
   50.36 -import java.util.List;
   50.37 -import java.util.Map;
   50.38 -import java.util.regex.PatternSyntaxException;
   50.39 -import jdk.nashorn.internal.runtime.BitVector;
   50.40 -
   50.41 -/**
   50.42 - * Scan a JavaScript regexp, converting to Java regex if necessary.
   50.43 - *
   50.44 - */
   50.45 -public class RegExpScanner extends Scanner {
   50.46 -
   50.47 -    /**
   50.48 -     * String builder to accumulate the result - this contains verbatim parsed JavaScript.
   50.49 -     * to get the java equivalent we need to create a Pattern token and return its toString()
   50.50 -     */
   50.51 -    private final StringBuilder sb;
   50.52 -
   50.53 -    /** An optional error message if one occurred during parse. */
   50.54 -    private String errorMessage;
   50.55 -
   50.56 -    /** Is this the special case of a regexp that never matches anything */
   50.57 -    private boolean neverMatches;
   50.58 -
   50.59 -    /** The resulting java.util.regex pattern string. */
   50.60 -    private String javaPattern;
   50.61 -
   50.62 -    /** Expected token table */
   50.63 -    private final Map<Character, Integer> expected = new HashMap<>();
   50.64 -
   50.65 -    /** Capturing parenthesis that have been found so far. */
   50.66 -    private final List<Capture> caps = new LinkedList<>();
   50.67 -
   50.68 -    /** Forward references to capturing parenthesis to be resolved later.*/
   50.69 -    private final Map<Integer, Token> forwardReferences = new LinkedHashMap<>();
   50.70 -
   50.71 -    /** Current level of zero-width negative lookahead assertions. */
   50.72 -    private int negativeLookaheadLevel;
   50.73 -
   50.74 -    private static final String NON_IDENT_ESCAPES = "$^*+(){}[]|\\.?";
   50.75 -
   50.76 -    private static class Capture {
   50.77 -        /**
   50.78 -         * Zero-width negative lookaheads enclosing the capture.
   50.79 -         */
   50.80 -        private final int negativeLookaheadLevel;
   50.81 -        /**
   50.82 -         * Captures that live inside a negative lookahead are dead after the
   50.83 -         * lookahead and will be undefined if referenced from outside.
   50.84 -         */
   50.85 -        private boolean isDead;
   50.86 -
   50.87 -        Capture(final int negativeLookaheadLevel) {
   50.88 -            this.negativeLookaheadLevel = negativeLookaheadLevel;
   50.89 -        }
   50.90 -
   50.91 -        public int getNegativeLookaheadLevel() {
   50.92 -            return negativeLookaheadLevel;
   50.93 -        }
   50.94 -
   50.95 -        public boolean isDead() {
   50.96 -            return isDead;
   50.97 -        }
   50.98 -
   50.99 -        public void setDead() {
  50.100 -            this.isDead = true;
  50.101 -        }
  50.102 -    }
  50.103 -
  50.104 -    /**
  50.105 -     * This is a token - the JavaScript regexp is scanned into a token tree
  50.106 -     * A token has other tokens as children as well as "atoms", i.e. Strings.
  50.107 -     *
  50.108 -     */
  50.109 -    private static class Token {
  50.110 -
  50.111 -        private enum Type {
  50.112 -            PATTERN,
  50.113 -            DISJUNCTION,
  50.114 -            ALTERNATIVE,
  50.115 -            TERM,
  50.116 -            ASSERTION,
  50.117 -            QUANTIFIER,
  50.118 -            QUANTIFIER_PREFIX,
  50.119 -            ATOM,
  50.120 -            PATTERN_CHARACTER,
  50.121 -            ATOM_ESCAPE,
  50.122 -            CHARACTER_ESCAPE,
  50.123 -            CONTROL_ESCAPE,
  50.124 -            CONTROL_LETTER,
  50.125 -            IDENTITY_ESCAPE,
  50.126 -            DECIMAL_ESCAPE,
  50.127 -            CHARACTERCLASS_ESCAPE,
  50.128 -            CHARACTERCLASS,
  50.129 -            CLASSRANGES,
  50.130 -            NON_EMPTY_CLASSRANGES,
  50.131 -            NON_EMPTY_CLASSRANGES_NODASH,
  50.132 -            CLASSATOM,
  50.133 -            CLASSATOM_NODASH,
  50.134 -            CLASS_ESCAPE,
  50.135 -            DECIMALDIGITS,
  50.136 -            HEX_ESCAPESEQUENCE,
  50.137 -            UNICODE_ESCAPESEQUENCE,
  50.138 -        }
  50.139 -
  50.140 -        /**
  50.141 -         * Token tyoe
  50.142 -         */
  50.143 -        private final Token.Type type;
  50.144 -
  50.145 -        /**
  50.146 -         * Child nodes
  50.147 -         */
  50.148 -        private final List<Object> children;
  50.149 -
  50.150 -        /**
  50.151 -         * Parent node
  50.152 -         */
  50.153 -        private Token parent;
  50.154 -
  50.155 -        /**
  50.156 -         * Dead code flag
  50.157 -         */
  50.158 -        private boolean isDead;
  50.159 -
  50.160 -        private static final Map<Type, ToString> toStringMap = new HashMap<>();
  50.161 -        private static final ToString DEFAULT_TOSTRING = new ToString();
  50.162 -
  50.163 -        private static String unicode(final int value) {
  50.164 -            final StringBuilder sb = new StringBuilder();
  50.165 -            final String hex = Integer.toHexString(value);
  50.166 -            sb.append('u');
  50.167 -            for (int i = 0; i < 4 - hex.length(); i++) {
  50.168 -                sb.append('0');
  50.169 -            }
  50.170 -            sb.append(hex);
  50.171 -
  50.172 -            return sb.toString();
  50.173 -        }
  50.174 -
  50.175 -        static {
  50.176 -            toStringMap.put(Type.CHARACTERCLASS, new ToString() {
  50.177 -                @Override
  50.178 -                public String toString(final Token token) {
  50.179 -                    return super.toString(token).replace("\\b", "\b");
  50.180 -                }
  50.181 -            });
  50.182 -
  50.183 -            // for some reason java regexps don't like control characters on the
  50.184 -            // form "\\ca".match([string with ascii 1 at char0]). Translating
  50.185 -            // them to unicode does it though.
  50.186 -            toStringMap.put(Type.CHARACTER_ESCAPE, new ToString() {
  50.187 -                @Override
  50.188 -                public String toString(final Token token) {
  50.189 -                    final String str = super.toString(token);
  50.190 -                    if (str.length() == 2) {
  50.191 -                        return Token.unicode(Character.toLowerCase(str.charAt(1)) - 'a' + 1);
  50.192 -                    }
  50.193 -                    return str;
  50.194 -                }
  50.195 -            });
  50.196 -
  50.197 -            toStringMap.put(Type.DECIMAL_ESCAPE, new ToString() {
  50.198 -                @Override
  50.199 -                public String toString(final Token token) {
  50.200 -                    final String str = super.toString(token);
  50.201 -
  50.202 -                    if ("\0".equals(str)) {
  50.203 -                        return str;
  50.204 -                    }
  50.205 -
  50.206 -                    int value;
  50.207 -
  50.208 -                    if (!token.hasParentOfType(Type.CLASSRANGES)) {
  50.209 -                        return str;
  50.210 -                    }
  50.211 -
  50.212 -                    value = Integer.parseInt(str, 8); //throws exception that leads to SyntaxError if not octal
  50.213 -                    if (value > 0xff) {
  50.214 -                        throw new NumberFormatException(str);
  50.215 -                    }
  50.216 -
  50.217 -                    return Token.unicode(value);
  50.218 -                }
  50.219 -            });
  50.220 -
  50.221 -        }
  50.222 -
  50.223 -        /**
  50.224 -         * JavaScript Token to Java regex substring framework.
  50.225 -         *
  50.226 -         */
  50.227 -        private static class ToString {
  50.228 -            String toString(final Token token) {
  50.229 -                final StringBuilder sb = new StringBuilder();
  50.230 -                for (final Object child : token.getChildren()) {
  50.231 -                    sb.append(child);
  50.232 -                }
  50.233 -
  50.234 -                //perform global substitutions that hold true for any evaluated form
  50.235 -                String str = sb.toString();
  50.236 -                switch (str) {
  50.237 -                case "\\s":
  50.238 -                    str = "[" + Lexer.getWhitespaceRegExp() + "]";
  50.239 -                    break;
  50.240 -                case "\\S":
  50.241 -                    str = "[^" + Lexer.getWhitespaceRegExp() + "]";
  50.242 -                    break;
  50.243 -                case "[^]":
  50.244 -                    str = "[\\s\\S]";
  50.245 -                    break;
  50.246 -                default:
  50.247 -                    break;
  50.248 -                }
  50.249 -                return str;
  50.250 -            }
  50.251 -        }
  50.252 -
  50.253 -        /**
  50.254 -         * Token iterator. Doesn't return "atom" children. i.e. string representations,
  50.255 -         * just tokens
  50.256 -         *
  50.257 -         */
  50.258 -        private static class TokenIterator implements Iterator<Token> {
  50.259 -            private final List<Token> preorder;
  50.260 -
  50.261 -            private void init(final Token root) {
  50.262 -                preorder.add(root);
  50.263 -                for (final Object child : root.getChildren()) {
  50.264 -                    if (child instanceof Token) {
  50.265 -                        init((Token)child);
  50.266 -                    }
  50.267 -                }
  50.268 -            }
  50.269 -
  50.270 -            TokenIterator(final Token root) {
  50.271 -                preorder = new ArrayList<>();
  50.272 -                init(root);
  50.273 -            }
  50.274 -
  50.275 -            @Override
  50.276 -            public boolean hasNext() {
  50.277 -                return !preorder.isEmpty();
  50.278 -            }
  50.279 -
  50.280 -            @Override
  50.281 -            public Token next() {
  50.282 -                return preorder.remove(0);
  50.283 -            }
  50.284 -
  50.285 -            @Override
  50.286 -            public void remove() {
  50.287 -                next();
  50.288 -            }
  50.289 -        }
  50.290 -
  50.291 -        /**
  50.292 -         * Constructor
  50.293 -         * @param type the token type
  50.294 -         */
  50.295 -        Token(final Token.Type type) {
  50.296 -            this.type = type;
  50.297 -            children = new ArrayList<>();
  50.298 -        }
  50.299 -
  50.300 -        /**
  50.301 -         * Add a an "atom" child to a token
  50.302 -         * @param child the child to add
  50.303 -         * @return the token (for chaining)
  50.304 -         */
  50.305 -        public Token add(final String child) {
  50.306 -            children.add(child);
  50.307 -            return this;
  50.308 -        }
  50.309 -
  50.310 -        /**
  50.311 -         * Add a child to a token
  50.312 -         * @param child the child
  50.313 -         * @return the token (for chaining)
  50.314 -         */
  50.315 -        public Token add(final Token child) {
  50.316 -            if (child != null) {
  50.317 -                children.add(child);
  50.318 -                child.setParent(this);
  50.319 -            }
  50.320 -            return this;
  50.321 -        }
  50.322 -
  50.323 -        /**
  50.324 -         * Remove a child from a token
  50.325 -         * @param child the child to remove
  50.326 -         * @return true if successful
  50.327 -         */
  50.328 -        public boolean remove(final Token child) {
  50.329 -            return children.remove(child);
  50.330 -        }
  50.331 -
  50.332 -        /**
  50.333 -         * Remove the last child from a token
  50.334 -         * @return the removed child
  50.335 -         */
  50.336 -        public Object removeLast() {
  50.337 -            return children.remove(children.size() - 1);
  50.338 -        }
  50.339 -
  50.340 -        /**
  50.341 -         * Flag this token as dead code
  50.342 -         * @param isDead is it dead or not
  50.343 -         */
  50.344 -        private void setIsDead(final boolean isDead) {
  50.345 -            this.isDead = isDead;
  50.346 -        }
  50.347 -
  50.348 -        /**
  50.349 -         * Is this token dead code
  50.350 -         * @return boolean
  50.351 -         */
  50.352 -        private boolean getIsDead() {
  50.353 -            return isDead;
  50.354 -        }
  50.355 -
  50.356 -        /**
  50.357 -         * Get the parent of this token
  50.358 -         * @return parent token
  50.359 -         */
  50.360 -        public Token getParent() {
  50.361 -            return parent;
  50.362 -        }
  50.363 -
  50.364 -        public boolean hasParentOfType(final Token.Type parentType) {
  50.365 -            for (Token p = getParent(); p != null; p = p.getParent()) {
  50.366 -                if (p.getType() == parentType) {
  50.367 -                    return true;
  50.368 -                }
  50.369 -            }
  50.370 -            return false;
  50.371 -        }
  50.372 -
  50.373 -        public boolean hasChildOfType(final Token.Type childType) {
  50.374 -            for (final Iterator<Token> iter = iterator() ; iter.hasNext() ; ) {
  50.375 -                if (iter.next().getType() == childType) {
  50.376 -                    return true;
  50.377 -                }
  50.378 -            }
  50.379 -            return false;
  50.380 -        }
  50.381 -
  50.382 -        /**
  50.383 -         * Set the parent of this token
  50.384 -         * @param parent
  50.385 -         */
  50.386 -        private void setParent(final Token parent) {
  50.387 -            this.parent = parent;
  50.388 -        }
  50.389 -
  50.390 -        /**
  50.391 -         * Get the children of this token
  50.392 -         * @return an array of children, never null
  50.393 -         */
  50.394 -        public Object[] getChildren() {
  50.395 -            return children.toArray();
  50.396 -        }
  50.397 -
  50.398 -        /**
  50.399 -         * Reset this token, remove all children
  50.400 -         */
  50.401 -        public void reset() {
  50.402 -            children.clear();
  50.403 -        }
  50.404 -
  50.405 -        /**
  50.406 -         * Get a preorder token iterator with this token as root
  50.407 -         * @return an iterator
  50.408 -         */
  50.409 -        public Iterator<Token> iterator() {
  50.410 -            return new TokenIterator(this);
  50.411 -        }
  50.412 -
  50.413 -        /**
  50.414 -         * Get the type of this token
  50.415 -         * @return type
  50.416 -         */
  50.417 -        public Type getType() {
  50.418 -            return type;
  50.419 -        }
  50.420 -
  50.421 -        /**
  50.422 -         * Turn this token into Java regexp compatible text
  50.423 -         * @return part of a java regexp
  50.424 -         */
  50.425 -        @Override
  50.426 -        public String toString() {
  50.427 -            ToString t = toStringMap.get(getType());
  50.428 -            if (t == null) {
  50.429 -                t = DEFAULT_TOSTRING;
  50.430 -            }
  50.431 -            return t.toString(this);
  50.432 -        }
  50.433 -    }
  50.434 -
  50.435 -    /**
  50.436 -     * Constructor
  50.437 -     * @param string the JavaScript regexp to parse
  50.438 -     */
  50.439 -    private RegExpScanner(final String string) {
  50.440 -        super(string);
  50.441 -        sb = new StringBuilder(limit);
  50.442 -        reset(0);
  50.443 -        expected.put(']', 0);
  50.444 -        expected.put('}', 0);
  50.445 -    }
  50.446 -
  50.447 -    private void processForwardReferences() {
  50.448 -        if (neverMatches()) {
  50.449 -            return;
  50.450 -        }
  50.451 -
  50.452 -        for (final Map.Entry<Integer, Token> fwdRef : forwardReferences.entrySet()) {
  50.453 -            if (fwdRef.getKey().intValue() > caps.size()) {
  50.454 -                neverMatches = true;
  50.455 -                break;
  50.456 -            }
  50.457 -
  50.458 -            fwdRef.getValue().setIsDead(true);
  50.459 -        }
  50.460 -
  50.461 -        forwardReferences.clear();
  50.462 -    }
  50.463 -
  50.464 -    /**
  50.465 -     * Scan a JavaScript regexp string returning a Java safe regex string.
  50.466 -     *
  50.467 -     * @param string
  50.468 -     *            JavaScript regexp string.
  50.469 -     * @return Java safe regex string.
  50.470 -     */
  50.471 -    public static RegExpScanner scan(final String string) {
  50.472 -        final RegExpScanner scanner = new RegExpScanner(string);
  50.473 -
  50.474 -        Token pattern;
  50.475 -
  50.476 -        try {
  50.477 -            pattern = scanner.pattern();
  50.478 -        } catch (final Exception e) {
  50.479 -            throw new PatternSyntaxException(e.getMessage(), string, scanner.sb.length());
  50.480 -        }
  50.481 -
  50.482 -        scanner.processForwardReferences();
  50.483 -        if (scanner.neverMatches()) {
  50.484 -            return null; // never matches
  50.485 -        }
  50.486 -
  50.487 -        // go over the code and remove dead code
  50.488 -        final Iterator<Token> iter = pattern.iterator();
  50.489 -        while (iter.hasNext()) {
  50.490 -            final Token next = iter.next();
  50.491 -            if (next.getIsDead()) {
  50.492 -                next.getParent().remove(next);
  50.493 -            }
  50.494 -        }
  50.495 -
  50.496 -        // turn the pattern into a string, p, the java equivalent string for our js regexp
  50.497 -        final String p = pattern.toString();
  50.498 -        // if builder contains all tokens that were sent in, we know
  50.499 -        // we correctly parsed the entire JavaScript regexp without syntax errors
  50.500 -        if (!string.equals(scanner.getStringBuilder().toString())) {
  50.501 -            throw new PatternSyntaxException(string, p, p.length() + 1);
  50.502 -        }
  50.503 -
  50.504 -        scanner.javaPattern = p;
  50.505 -        return scanner;
  50.506 -     }
  50.507 -
  50.508 -    /**
  50.509 -     * Does this regexp ever match anything? Use of e.g. [], which is legal in JavaScript,
  50.510 -     * is an example where we never match
  50.511 -     *
  50.512 -     * @return boolean
  50.513 -     */
  50.514 -    private boolean neverMatches() {
  50.515 -        return neverMatches;
  50.516 -    }
  50.517 -
  50.518 -    /**
  50.519 -     * This is used to set better error messages that can be reused
  50.520 -     * in NativeRegExp for augmenting e.g. SyntaxErrors.
  50.521 -     *
  50.522 -     * @return an error message or null if no extra info
  50.523 -     */
  50.524 -    public String getErrorMessage() {
  50.525 -        return errorMessage;
  50.526 -    }
  50.527 -
  50.528 -    final StringBuilder getStringBuilder() {
  50.529 -        return sb;
  50.530 -    }
  50.531 -
  50.532 -    String getJavaPattern() {
  50.533 -        return javaPattern;
  50.534 -    }
  50.535 -
  50.536 -    BitVector getGroupsInNegativeLookahead() {
  50.537 -        BitVector vec = null;
  50.538 -        for (int i = 0; i < caps.size(); i++) {
  50.539 -            final Capture cap = caps.get(i);
  50.540 -            if (cap.getNegativeLookaheadLevel() > 0) {
  50.541 -                if (vec == null) {
  50.542 -                    vec = new BitVector(caps.size() + 1);
  50.543 -                }
  50.544 -                vec.set(i + 1);
  50.545 -            }
  50.546 -        }
  50.547 -        return vec;
  50.548 -    }
  50.549 -
  50.550 -    /**
  50.551 -     * Commit n characters to the builder and to a given token
  50.552 -     * @param token Uncommitted token.
  50.553 -     * @param n     Number of characters.
  50.554 -     * @return Committed token
  50.555 -     */
  50.556 -    private Token commit(final Token token, final int n) {
  50.557 -        final int startIn = position;
  50.558 -
  50.559 -        switch (n) {
  50.560 -        case 1:
  50.561 -            sb.append(ch0);
  50.562 -            skip(1);
  50.563 -            break;
  50.564 -        case 2:
  50.565 -            sb.append(ch0);
  50.566 -            sb.append(ch1);
  50.567 -            skip(2);
  50.568 -            break;
  50.569 -        case 3:
  50.570 -            sb.append(ch0);
  50.571 -            sb.append(ch1);
  50.572 -            sb.append(ch2);
  50.573 -            skip(3);
  50.574 -            break;
  50.575 -        default:
  50.576 -            assert false : "Should not reach here";
  50.577 -        }
  50.578 -
  50.579 -        if (token == null) {
  50.580 -            return null;
  50.581 -        }
  50.582 -
  50.583 -        return token.add(sb.substring(startIn, sb.length()));
  50.584 -    }
  50.585 -
  50.586 -    /**
  50.587 -     * Restart the buffers back at an earlier position.
  50.588 -     *
  50.589 -     * @param startIn
  50.590 -     *            Position in the input stream.
  50.591 -     * @param startOut
  50.592 -     *            Position in the output stream.
  50.593 -     */
  50.594 -    private void restart(final int startIn, final int startOut) {
  50.595 -        reset(startIn);
  50.596 -        sb.setLength(startOut);
  50.597 -    }
  50.598 -
  50.599 -    private void push(final char ch) {
  50.600 -        expected.put(ch, expected.get(ch) + 1);
  50.601 -    }
  50.602 -
  50.603 -    private void pop(final char ch) {
  50.604 -        expected.put(ch, Math.min(0, expected.get(ch) - 1));
  50.605 -    }
  50.606 -
  50.607 -    /*
  50.608 -     * Recursive descent tokenizer starts below.
  50.609 -     */
  50.610 -
  50.611 -    /*
  50.612 -     * Pattern ::
  50.613 -     *      Disjunction
  50.614 -     */
  50.615 -    private Token pattern() {
  50.616 -        final Token token = new Token(Token.Type.PATTERN);
  50.617 -
  50.618 -        final Token child = disjunction();
  50.619 -        if (child != null) {
  50.620 -            return token.add(child);
  50.621 -        }
  50.622 -
  50.623 -        return null;
  50.624 -    }
  50.625 -
  50.626 -    /*
  50.627 -     * Disjunction ::
  50.628 -     *      Alternative
  50.629 -     *      Alternative | Disjunction
  50.630 -     */
  50.631 -    private Token disjunction() {
  50.632 -        final Token token = new Token(Token.Type.DISJUNCTION);
  50.633 -
  50.634 -        while (true) {
  50.635 -            token.add(alternative());
  50.636 -
  50.637 -            if (ch0 == '|') {
  50.638 -                commit(token, 1);
  50.639 -            } else {
  50.640 -                break;
  50.641 -            }
  50.642 -        }
  50.643 -
  50.644 -        return token;
  50.645 -    }
  50.646 -
  50.647 -    /*
  50.648 -     * Alternative ::
  50.649 -     *      [empty]
  50.650 -     *      Alternative Term
  50.651 -     */
  50.652 -    private Token alternative() {
  50.653 -        final Token token = new Token(Token.Type.ALTERNATIVE);
  50.654 -
  50.655 -        Token child;
  50.656 -        while ((child = term()) != null) {
  50.657 -            token.add(child);
  50.658 -        }
  50.659 -
  50.660 -        return token;
  50.661 -    }
  50.662 -
  50.663 -    /*
  50.664 -     * Term ::
  50.665 -     *      Assertion
  50.666 -     *      Atom
  50.667 -     *      Atom Quantifier
  50.668 -     */
  50.669 -    private Token term() {
  50.670 -        final int startIn  = position;
  50.671 -        final int startOut = sb.length();
  50.672 -        final Token token  = new Token(Token.Type.TERM);
  50.673 -        Token child;
  50.674 -
  50.675 -        child = assertion();
  50.676 -        if (child != null) {
  50.677 -            return token.add(child);
  50.678 -        }
  50.679 -
  50.680 -        child = atom();
  50.681 -        if (child != null) {
  50.682 -            boolean emptyCharacterClass = false;
  50.683 -            if ("[]".equals(child.toString())) {
  50.684 -                emptyCharacterClass = true;
  50.685 -            }
  50.686 -
  50.687 -            token.add(child);
  50.688 -
  50.689 -            final Token quantifier = quantifier();
  50.690 -            if (quantifier != null) {
  50.691 -                token.add(quantifier);
  50.692 -            }
  50.693 -
  50.694 -            if (emptyCharacterClass) {
  50.695 -                if (quantifier == null) {
  50.696 -                    neverMatches = true; //never matches ever.
  50.697 -                } else {
  50.698 -                    //if we can get away with max zero, remove this entire token
  50.699 -                    final String qs = quantifier.toString();
  50.700 -                    if ("+".equals(qs) || "*".equals(qs) || qs.startsWith("{0,")) {
  50.701 -                        token.setIsDead(true);
  50.702 -                    }
  50.703 -                }
  50.704 -            }
  50.705 -
  50.706 -            return token;
  50.707 -        }
  50.708 -
  50.709 -        restart(startIn, startOut);
  50.710 -        return null;
  50.711 -    }
  50.712 -
  50.713 -    /*
  50.714 -     * Assertion ::
  50.715 -     *      ^
  50.716 -     *      $
  50.717 -     *      \b
  50.718 -     *      \B
  50.719 -     *      ( ? = Disjunction )
  50.720 -     *      ( ? ! Disjunction )
  50.721 -     */
  50.722 -    private Token assertion() {
  50.723 -        final int startIn  = position;
  50.724 -        final int startOut = sb.length();
  50.725 -        final Token token  = new Token(Token.Type.ASSERTION);
  50.726 -
  50.727 -        switch (ch0) {
  50.728 -        case '^':
  50.729 -        case '$':
  50.730 -            return commit(token, 1);
  50.731 -
  50.732 -        case '\\':
  50.733 -            if (ch1 == 'b' || ch1 == 'B') {
  50.734 -                return commit(token, 2);
  50.735 -            }
  50.736 -            break;
  50.737 -
  50.738 -        case '(':
  50.739 -            if (ch1 != '?') {
  50.740 -                break;
  50.741 -            }
  50.742 -            if (ch2 != '=' && ch2 != '!') {
  50.743 -                break;
  50.744 -            }
  50.745 -            final boolean isNegativeLookahead = (ch2 == '!');
  50.746 -            commit(token, 3);
  50.747 -
  50.748 -            if (isNegativeLookahead) {
  50.749 -                negativeLookaheadLevel++;
  50.750 -            }
  50.751 -            final Token disjunction = disjunction();
  50.752 -            if (isNegativeLookahead) {
  50.753 -                for (final Capture cap : caps) {
  50.754 -                    if (cap.getNegativeLookaheadLevel() >= negativeLookaheadLevel) {
  50.755 -                        cap.setDead();
  50.756 -                    }
  50.757 -                }
  50.758 -                negativeLookaheadLevel--;
  50.759 -            }
  50.760 -
  50.761 -            if (disjunction != null && ch0 == ')') {
  50.762 -                token.add(disjunction);
  50.763 -                return commit(token, 1);
  50.764 -            }
  50.765 -            break;
  50.766 -
  50.767 -        default:
  50.768 -            break;
  50.769 -        }
  50.770 -
  50.771 -        restart(startIn, startOut);
  50.772 -
  50.773 -        return null;
  50.774 -    }
  50.775 -
  50.776 -    /*
  50.777 -     * Quantifier ::
  50.778 -     *      QuantifierPrefix
  50.779 -     *      QuantifierPrefix ?
  50.780 -     */
  50.781 -    private Token quantifier() {
  50.782 -        final Token token = new Token(Token.Type.QUANTIFIER);
  50.783 -        final Token child = quantifierPrefix();
  50.784 -        if (child != null) {
  50.785 -            token.add(child);
  50.786 -            if (ch0 == '?') {
  50.787 -                commit(token, 1);
  50.788 -            }
  50.789 -            return token;
  50.790 -        }
  50.791 -        return null;
  50.792 -    }
  50.793 -
  50.794 -    /*
  50.795 -     * QuantifierPrefix ::
  50.796 -     *      *
  50.797 -     *      +
  50.798 -     *      ?
  50.799 -     *      { DecimalDigits }
  50.800 -     *      { DecimalDigits , }
  50.801 -     *      { DecimalDigits , DecimalDigits }
  50.802 -     */
  50.803 -    private Token quantifierPrefix() {
  50.804 -        final int startIn  = position;
  50.805 -        final int startOut = sb.length();
  50.806 -        final Token token  = new Token(Token.Type.QUANTIFIER_PREFIX);
  50.807 -
  50.808 -        switch (ch0) {
  50.809 -        case '*':
  50.810 -        case '+':
  50.811 -        case '?':
  50.812 -            return commit(token, 1);
  50.813 -
  50.814 -        case '{':
  50.815 -            commit(token, 1);
  50.816 -
  50.817 -            final Token child = decimalDigits();
  50.818 -            if (child == null) {
  50.819 -                break; // not a quantifier - back out
  50.820 -            }
  50.821 -            push('}');
  50.822 -            token.add(child);
  50.823 -
  50.824 -            if (ch0 == ',') {
  50.825 -                commit(token, 1);
  50.826 -                token.add(decimalDigits());
  50.827 -            }
  50.828 -
  50.829 -            if (ch0 == '}') {
  50.830 -                pop('}');
  50.831 -                commit(token, 1);
  50.832 -            }
  50.833 -
  50.834 -            return token;
  50.835 -
  50.836 -        default:
  50.837 -            break;
  50.838 -        }
  50.839 -
  50.840 -        restart(startIn, startOut);
  50.841 -        return null;
  50.842 -    }
  50.843 -
  50.844 -    /*
  50.845 -     * Atom ::
  50.846 -     *      PatternCharacter
  50.847 -     *      .
  50.848 -     *      \ AtomEscape
  50.849 -     *      CharacterClass
  50.850 -     *      ( Disjunction )
  50.851 -     *      ( ? : Disjunction )
  50.852 -     *
  50.853 -     */
  50.854 -    private Token atom() {
  50.855 -        final int startIn  = position;
  50.856 -        final int startOut = sb.length();
  50.857 -        final Token token  = new Token(Token.Type.ATOM);
  50.858 -        Token child;
  50.859 -
  50.860 -        child = patternCharacter();
  50.861 -        if (child != null) {
  50.862 -            return token.add(child);
  50.863 -        }
  50.864 -
  50.865 -        if (ch0 == '.') {
  50.866 -            return commit(token, 1);
  50.867 -        }
  50.868 -
  50.869 -        if (ch0 == '\\') {
  50.870 -            commit(token, 1);
  50.871 -            child = atomEscape();
  50.872 -
  50.873 -            if (child != null) {
  50.874 -                if (child.hasChildOfType(Token.Type.IDENTITY_ESCAPE)) {
  50.875 -                    final char idEscape = child.toString().charAt(0);
  50.876 -                    if (NON_IDENT_ESCAPES.indexOf(idEscape) == -1) {
  50.877 -                        token.reset();
  50.878 -                    }
  50.879 -                }
  50.880 -
  50.881 -                token.add(child);
  50.882 -
  50.883 -                // forward backreferences always match empty. JavaScript != Java
  50.884 -                if (child.hasChildOfType(Token.Type.DECIMAL_ESCAPE) && !"\u0000".equals(child.toString())) {
  50.885 -                    final int refNum = Integer.parseInt(child.toString());
  50.886 -
  50.887 -                    if (refNum - 1 < caps.size() && caps.get(refNum - 1).isDead()) {
  50.888 -                        // reference to dead in-negative-lookahead capture
  50.889 -                        token.setIsDead(true);
  50.890 -                    } else if (caps.size() < refNum) {
  50.891 -                        // forward reference: always matches against empty string (dead token).
  50.892 -                        // invalid reference (non-existant capture): pattern never matches.
  50.893 -                        forwardReferences.put(refNum, token);
  50.894 -                    }
  50.895 -                }
  50.896 -
  50.897 -                return token;
  50.898 -            }
  50.899 -        }
  50.900 -
  50.901 -        child = characterClass();
  50.902 -        if (child != null) {
  50.903 -            return token.add(child);
  50.904 -        }
  50.905 -
  50.906 -        if (ch0 == '(') {
  50.907 -            boolean capturingParens = true;
  50.908 -            commit(token, 1);
  50.909 -            if (ch0 == '?' && ch1 == ':') {
  50.910 -                capturingParens = false;
  50.911 -                commit(token, 2);
  50.912 -            }
  50.913 -
  50.914 -            child = disjunction();
  50.915 -            if (child != null) {
  50.916 -                token.add(child);
  50.917 -                if (ch0 == ')') {
  50.918 -                    final Token atom = commit(token, 1);
  50.919 -                    if (capturingParens) {
  50.920 -                        caps.add(new Capture(negativeLookaheadLevel));
  50.921 -                    }
  50.922 -                    return atom;
  50.923 -                }
  50.924 -            }
  50.925 -        }
  50.926 -
  50.927 -        restart(startIn, startOut);
  50.928 -        return null;
  50.929 -    }
  50.930 -
  50.931 -    /*
  50.932 -     * PatternCharacter ::
  50.933 -     *      SourceCharacter but not any of: ^$\.*+?()[]{}|
  50.934 -     */
  50.935 -    @SuppressWarnings("fallthrough")
  50.936 -    private Token patternCharacter() {
  50.937 -        if (atEOF()) {
  50.938 -            return null;
  50.939 -        }
  50.940 -
  50.941 -        switch (ch0) {
  50.942 -        case '^':
  50.943 -        case '$':
  50.944 -        case '\\':
  50.945 -        case '.':
  50.946 -        case '*':
  50.947 -        case '+':
  50.948 -        case '?':
  50.949 -        case '(':
  50.950 -        case ')':
  50.951 -        case '[':
  50.952 -        case '|':
  50.953 -            return null;
  50.954 -
  50.955 -        case '}':
  50.956 -        case ']':
  50.957 -            final int n = expected.get(ch0);
  50.958 -            if (n != 0) {
  50.959 -                return null;
  50.960 -            }
  50.961 -
  50.962 -       case '{':
  50.963 -           // if not a valid quantifier escape curly brace to match itself
  50.964 -           // this ensures compatibility with other JS implementations
  50.965 -           final Token quant = quantifierPrefix();
  50.966 -           return (quant == null) ? commit(new Token(Token.Type.PATTERN_CHARACTER).add("\\"), 1) : null;
  50.967 -
  50.968 -        default:
  50.969 -            return commit(new Token(Token.Type.PATTERN_CHARACTER), 1); // SOURCECHARACTER
  50.970 -        }
  50.971 -    }
  50.972 -
  50.973 -    /*
  50.974 -     * AtomEscape ::
  50.975 -     *      DecimalEscape
  50.976 -     *      CharacterEscape
  50.977 -     *      CharacterClassEscape
  50.978 -     */
  50.979 -    private Token atomEscape() {
  50.980 -        final Token token = new Token(Token.Type.ATOM_ESCAPE);
  50.981 -        Token child;
  50.982 -
  50.983 -        child = decimalEscape();
  50.984 -        if (child != null) {
  50.985 -            return token.add(child);
  50.986 -        }
  50.987 -
  50.988 -        child = characterClassEscape();
  50.989 -        if (child != null) {
  50.990 -            return token.add(child);
  50.991 -        }
  50.992 -
  50.993 -        child = characterEscape();
  50.994 -        if (child != null) {
  50.995 -            return token.add(child);
  50.996 -        }
  50.997 -
  50.998 -
  50.999 -        return null;
 50.1000 -    }
 50.1001 -
 50.1002 -    /*
 50.1003 -     * CharacterEscape ::
 50.1004 -     *      ControlEscape
 50.1005 -     *      c ControlLetter
 50.1006 -     *      HexEscapeSequence
 50.1007 -     *      UnicodeEscapeSequence
 50.1008 -     *      IdentityEscape
 50.1009 -     */
 50.1010 -    private Token characterEscape() {
 50.1011 -        final int startIn  = position;
 50.1012 -        final int startOut = sb.length();
 50.1013 -
 50.1014 -        final Token token = new Token(Token.Type.CHARACTER_ESCAPE);
 50.1015 -        Token child;
 50.1016 -
 50.1017 -        child = controlEscape();
 50.1018 -        if (child != null) {
 50.1019 -            return token.add(child);
 50.1020 -        }
 50.1021 -
 50.1022 -        if (ch0 == 'c') {
 50.1023 -            commit(token, 1);
 50.1024 -            child = controlLetter();
 50.1025 -            if (child != null) {
 50.1026 -                return token.add(child);
 50.1027 -            }
 50.1028 -            restart(startIn, startOut);
 50.1029 -        }
 50.1030 -
 50.1031 -        child = hexEscapeSequence();
 50.1032 -        if (child != null) {
 50.1033 -            return token.add(child);
 50.1034 -        }
 50.1035 -
 50.1036 -        child = unicodeEscapeSequence();
 50.1037 -        if (child != null) {
 50.1038 -            return token.add(child);
 50.1039 -        }
 50.1040 -
 50.1041 -        child = identityEscape();
 50.1042 -        if (child != null) {
 50.1043 -            return token.add(child);
 50.1044 -        }
 50.1045 -
 50.1046 -        restart(startIn, startOut);
 50.1047 -
 50.1048 -        return null;
 50.1049 -    }
 50.1050 -
 50.1051 -    private boolean scanEscapeSequence(final char leader, final int length, final Token token) {
 50.1052 -        final int startIn  = position;
 50.1053 -        final int startOut = sb.length();
 50.1054 -
 50.1055 -        if (ch0 != leader) {
 50.1056 -            return false;
 50.1057 -        }
 50.1058 -
 50.1059 -        commit(token, 1);
 50.1060 -        for (int i = 0; i < length; i++) {
 50.1061 -            final char ch0l = Character.toLowerCase(ch0);
 50.1062 -            if ((ch0l >= 'a' && ch0l <= 'f') || isDecimalDigit(ch0)) {
 50.1063 -                commit(token, 1);
 50.1064 -            } else {
 50.1065 -                restart(startIn, startOut);
 50.1066 -                return false;
 50.1067 -            }
 50.1068 -        }
 50.1069 -
 50.1070 -        return true;
 50.1071 -    }
 50.1072 -
 50.1073 -    private Token hexEscapeSequence() {
 50.1074 -        final Token token = new Token(Token.Type.HEX_ESCAPESEQUENCE);
 50.1075 -        if (scanEscapeSequence('x', 2, token)) {
 50.1076 -            return token;
 50.1077 -        }
 50.1078 -        return null;
 50.1079 -    }
 50.1080 -
 50.1081 -    private Token unicodeEscapeSequence() {
 50.1082 -        final Token token = new Token(Token.Type.UNICODE_ESCAPESEQUENCE);
 50.1083 -        if (scanEscapeSequence('u', 4, token)) {
 50.1084 -            return token;
 50.1085 -        }
 50.1086 -        return null;
 50.1087 -    }
 50.1088 -
 50.1089 -    /*
 50.1090 -     * ControlEscape ::
 50.1091 -     *      one of fnrtv
 50.1092 -     */
 50.1093 -    private Token controlEscape() {
 50.1094 -        switch (ch0) {
 50.1095 -        case 'f':
 50.1096 -        case 'n':
 50.1097 -        case 'r':
 50.1098 -        case 't':
 50.1099 -        case 'v':
 50.1100 -            return commit(new Token(Token.Type.CONTROL_ESCAPE), 1);
 50.1101 -
 50.1102 -        default:
 50.1103 -            return null;
 50.1104 -        }
 50.1105 -    }
 50.1106 -
 50.1107 -    /*
 50.1108 -     * ControlLetter ::
 50.1109 -     *      one of abcdefghijklmnopqrstuvwxyz
 50.1110 -     *      ABCDEFGHIJKLMNOPQRSTUVWXYZ
 50.1111 -     */
 50.1112 -    private Token controlLetter() {
 50.1113 -        final char c = Character.toUpperCase(ch0);
 50.1114 -        if (c >= 'A' && c <= 'Z') {
 50.1115 -            final Token token = new Token(Token.Type.CONTROL_LETTER);
 50.1116 -            commit(token, 1);
 50.1117 -            return token;
 50.1118 -        }
 50.1119 -        return null;
 50.1120 -        /*
 50.1121 -        Token token = new Token(Token.Type.CONTROL_LETTER);
 50.1122 -        commit(null, 1);//add original char to builder not to token
 50.1123 -        this.neverMatches = c < 'A' || c > 'Z';
 50.1124 -        return token.add(""+c);*/
 50.1125 -    }
 50.1126 -
 50.1127 -    /*
 50.1128 -     * IdentityEscape ::
 50.1129 -     *      SourceCharacter but not IdentifierPart
 50.1130 -     *      <ZWJ>  (200c)
 50.1131 -     *      <ZWNJ> (200d)
 50.1132 -     */
 50.1133 -    private Token identityEscape() {
 50.1134 -        final Token token = new Token(Token.Type.IDENTITY_ESCAPE);
 50.1135 -        commit(token, 1);
 50.1136 -        return token;
 50.1137 -    }
 50.1138 -
 50.1139 -    /*
 50.1140 -     * DecimalEscape ::
 50.1141 -     *      DecimalIntegerLiteral [lookahead DecimalDigit]
 50.1142 -     */
 50.1143 -    private Token decimalEscape() {
 50.1144 -        final Token token = new Token(Token.Type.DECIMAL_ESCAPE);
 50.1145 -        final int startIn  = position;
 50.1146 -        final int startOut = sb.length();
 50.1147 -
 50.1148 -        if (ch0 == '0' && !isDecimalDigit(ch1)) {
 50.1149 -            commit(token, 1);
 50.1150 -            token.removeLast();
 50.1151 -            //  DecimalEscape :: 0. If i is zero, return the EscapeValue consisting of a <NUL> character (Unicodevalue0000);
 50.1152 -            return token.add("\u0000");
 50.1153 -        }
 50.1154 -
 50.1155 -        if (isDecimalDigit(ch0)) {
 50.1156 -            while (isDecimalDigit(ch0)) {
 50.1157 -                commit(token, 1);
 50.1158 -            }
 50.1159 -            return token;
 50.1160 -        }
 50.1161 -
 50.1162 -        restart(startIn, startOut);
 50.1163 -
 50.1164 -        return null;
 50.1165 -    }
 50.1166 -
 50.1167 -    /*
 50.1168 -     * CharacterClassEscape ::
 50.1169 -     *  one of dDsSwW
 50.1170 -     */
 50.1171 -    private Token characterClassEscape() {
 50.1172 -        switch (ch0) {
 50.1173 -        case 's':
 50.1174 -        case 'S':
 50.1175 -        case 'd':
 50.1176 -        case 'D':
 50.1177 -        case 'w':
 50.1178 -        case 'W':
 50.1179 -            return commit(new Token(Token.Type.CHARACTERCLASS_ESCAPE), 1);
 50.1180 -
 50.1181 -        default:
 50.1182 -            return null;
 50.1183 -        }
 50.1184 -    }
 50.1185 -
 50.1186 -    /*
 50.1187 -     * CharacterClass ::
 50.1188 -     *      [ [lookahead {^}] ClassRanges ]
 50.1189 -     *      [ ^ ClassRanges ]
 50.1190 -     */
 50.1191 -    private Token characterClass() {
 50.1192 -        final int startIn  = position;
 50.1193 -        final int startOut = sb.length();
 50.1194 -        final Token token  = new Token(Token.Type.CHARACTERCLASS);
 50.1195 -
 50.1196 -        if (ch0 == '[') {
 50.1197 -            push(']');
 50.1198 -            commit(token, 1);
 50.1199 -
 50.1200 -            if (ch0 == '^') {
 50.1201 -                commit(token, 1);
 50.1202 -            }
 50.1203 -
 50.1204 -            final Token child = classRanges();
 50.1205 -            if (child != null && ch0 == ']') {
 50.1206 -                pop(']');
 50.1207 -                token.add(child);
 50.1208 -                return commit(token, 1);
 50.1209 -            }
 50.1210 -        }
 50.1211 -
 50.1212 -        restart(startIn, startOut);
 50.1213 -        return null;
 50.1214 -    }
 50.1215 -
 50.1216 -    /*
 50.1217 -     * ClassRanges ::
 50.1218 -     *      [empty]
 50.1219 -     *      NonemptyClassRanges
 50.1220 -     */
 50.1221 -    private Token classRanges() {
 50.1222 -        return new Token(Token.Type.CLASSRANGES).add(nonemptyClassRanges());
 50.1223 -    }
 50.1224 -
 50.1225 -    /*
 50.1226 -     * NonemptyClassRanges ::
 50.1227 -     *      ClassAtom
 50.1228 -     *      ClassAtom NonemptyClassRangesNoDash
 50.1229 -     *      ClassAtom - ClassAtom ClassRanges
 50.1230 -     */
 50.1231 -    private Token nonemptyClassRanges() {
 50.1232 -        final int startIn  = position;
 50.1233 -        final int startOut = sb.length();
 50.1234 -        final Token token  = new Token(Token.Type.NON_EMPTY_CLASSRANGES);
 50.1235 -        Token child;
 50.1236 -
 50.1237 -        child = classAtom();
 50.1238 -        if (child != null) {
 50.1239 -            token.add(child);
 50.1240 -
 50.1241 -            if (ch0 == '-') {
 50.1242 -                commit(token, 1);
 50.1243 -
 50.1244 -                final Token child1 = classAtom();
 50.1245 -                final Token child2 = classRanges();
 50.1246 -                if (child1 != null && child2 != null) {
 50.1247 -                    token.add(child1);
 50.1248 -                    token.add(child2);
 50.1249 -
 50.1250 -                    return token;
 50.1251 -                }
 50.1252 -            }
 50.1253 -
 50.1254 -            child = nonemptyClassRangesNoDash();
 50.1255 -            if (child != null) {
 50.1256 -                token.add(child);
 50.1257 -                return token;
 50.1258 -            }
 50.1259 -
 50.1260 -            return token;
 50.1261 -        }
 50.1262 -
 50.1263 -        restart(startIn, startOut);
 50.1264 -        return null;
 50.1265 -    }
 50.1266 -
 50.1267 -    /*
 50.1268 -     * NonemptyClassRangesNoDash ::
 50.1269 -     *      ClassAtom
 50.1270 -     *      ClassAtomNoDash NonemptyClassRangesNoDash
 50.1271 -     *      ClassAtomNoDash - ClassAtom ClassRanges
 50.1272 -     */
 50.1273 -    private Token nonemptyClassRangesNoDash() {
 50.1274 -        final int startIn  = position;
 50.1275 -        final int startOut = sb.length();
 50.1276 -        final Token token  = new Token(Token.Type.NON_EMPTY_CLASSRANGES_NODASH);
 50.1277 -        Token child;
 50.1278 -
 50.1279 -        child = classAtomNoDash();
 50.1280 -        if (child != null) {
 50.1281 -            token.add(child);
 50.1282 -
 50.1283 -            // need to check dash first, as for e.g. [a-b|c-d] will otherwise parse - as an atom
 50.1284 -            if (ch0 == '-') {
 50.1285 -               commit(token, 1);
 50.1286 -
 50.1287 -               final Token child1 = classAtom();
 50.1288 -               final Token child2 = classRanges();
 50.1289 -               if (child1 != null && child2 != null) {
 50.1290 -                   token.add(child1);
 50.1291 -                   return token.add(child2);
 50.1292 -               }
 50.1293 -               //fallthru
 50.1294 -           }
 50.1295 -
 50.1296 -            child = nonemptyClassRangesNoDash();
 50.1297 -            if (child != null) {
 50.1298 -                token.add(child);
 50.1299 -            }
 50.1300 -            return token; // still a class atom
 50.1301 -        }
 50.1302 -
 50.1303 -        child = classAtom();
 50.1304 -        if (child != null) {
 50.1305 -            return token.add(child);
 50.1306 -        }
 50.1307 -
 50.1308 -        restart(startIn, startOut);
 50.1309 -        return null;
 50.1310 -    }
 50.1311 -
 50.1312 -    /*
 50.1313 -     * ClassAtom : - ClassAtomNoDash
 50.1314 -     */
 50.1315 -    private Token classAtom() {
 50.1316 -        final Token token = new Token(Token.Type.CLASSATOM);
 50.1317 -
 50.1318 -        if (ch0 == '-') {
 50.1319 -            return commit(token, 1);
 50.1320 -        }
 50.1321 -
 50.1322 -        final Token child = classAtomNoDash();
 50.1323 -        if (child != null) {
 50.1324 -            return token.add(child);
 50.1325 -        }
 50.1326 -
 50.1327 -        return null;
 50.1328 -    }
 50.1329 -
 50.1330 -    /*
 50.1331 -     * ClassAtomNoDash ::
 50.1332 -     *      SourceCharacter but not one of \ or ] or -
 50.1333 -     *      \ ClassEscape
 50.1334 -     */
 50.1335 -    private Token classAtomNoDash() {
 50.1336 -        final int startIn  = position;
 50.1337 -        final int startOut = sb.length();
 50.1338 -        final Token token  = new Token(Token.Type.CLASSATOM_NODASH);
 50.1339 -
 50.1340 -        switch (ch0) {
 50.1341 -        case ']':
 50.1342 -        case '-':
 50.1343 -        case '\0':
 50.1344 -            return null;
 50.1345 -
 50.1346 -        case '[':
 50.1347 -            // unescaped left square bracket - add escape
 50.1348 -            return commit(token.add("\\"), 1);
 50.1349 -
 50.1350 -        case '\\':
 50.1351 -            commit(token, 1);
 50.1352 -            final Token child = classEscape();
 50.1353 -            if (child != null) {
 50.1354 -                return token.add(child);
 50.1355 -            }
 50.1356 -
 50.1357 -            restart(startIn, startOut);
 50.1358 -            return null;
 50.1359 -
 50.1360 -        default:
 50.1361 -            return commit(token, 1);
 50.1362 -        }
 50.1363 -    }
 50.1364 -
 50.1365 -    /*
 50.1366 -     * ClassEscape ::
 50.1367 -     *      DecimalEscape
 50.1368 -     *      b
 50.1369 -     *      CharacterEscape
 50.1370 -     *      CharacterClassEscape
 50.1371 -     */
 50.1372 -    private Token classEscape() {
 50.1373 -        final Token token = new Token(Token.Type.CLASS_ESCAPE);
 50.1374 -        Token child;
 50.1375 -
 50.1376 -        child = decimalEscape();
 50.1377 -        if (child != null) {
 50.1378 -            return token.add(child);
 50.1379 -        }
 50.1380 -
 50.1381 -        if (ch0 == 'b') {
 50.1382 -            return commit(token, 1);
 50.1383 -        }
 50.1384 -
 50.1385 -        child = characterEscape();
 50.1386 -        if (child != null) {
 50.1387 -            return token.add(child);
 50.1388 -        }
 50.1389 -
 50.1390 -        child = characterClassEscape();
 50.1391 -        if (child != null) {
 50.1392 -            return token.add(child);
 50.1393 -        }
 50.1394 -
 50.1395 -        return null;
 50.1396 -    }
 50.1397 -
 50.1398 -    /*
 50.1399 -     * DecimalDigits
 50.1400 -     */
 50.1401 -    private Token decimalDigits() {
 50.1402 -        if (!isDecimalDigit(ch0)) {
 50.1403 -            return null;
 50.1404 -        }
 50.1405 -
 50.1406 -        final Token token = new Token(Token.Type.DECIMALDIGITS);
 50.1407 -        while (isDecimalDigit(ch0)) {
 50.1408 -            commit(token, 1);
 50.1409 -        }
 50.1410 -
 50.1411 -        return token;
 50.1412 -    }
 50.1413 -
 50.1414 -    private static boolean isDecimalDigit(final char ch) {
 50.1415 -        return ch >= '0' && ch <= '9';
 50.1416 -    }
 50.1417 -}
    51.1 --- a/src/jdk/nashorn/internal/runtime/ArgumentSetter.java	Sat Feb 09 16:58:48 2013 +0100
    51.2 +++ b/src/jdk/nashorn/internal/runtime/ArgumentSetter.java	Mon Feb 11 21:26:06 2013 +0530
    51.3 @@ -32,7 +32,8 @@
    51.4   * A class with static helper methods invoked from generated bytecode for setting values of parameters of variable-arity
    51.5   * functions.
    51.6   */
    51.7 -public class ArgumentSetter {
    51.8 +public final class ArgumentSetter {
    51.9 +    private ArgumentSetter() {}
   51.10  
   51.11      /** Method handle for setting a function argument at a given index in an arguments object. Used from generated bytecode */
   51.12      public static final Call SET_ARGUMENT      = staticCall(ArgumentSetter.class, "setArgument", void.class, Object.class, ScriptObject.class, int.class);
    52.1 --- a/src/jdk/nashorn/internal/runtime/BitVector.java	Sat Feb 09 16:58:48 2013 +0100
    52.2 +++ b/src/jdk/nashorn/internal/runtime/BitVector.java	Mon Feb 11 21:26:06 2013 +0530
    52.3 @@ -30,7 +30,7 @@
    52.4  /**
    52.5   * Faster implementation of BitSet
    52.6   */
    52.7 -public class BitVector implements Cloneable {
    52.8 +public final class BitVector implements Cloneable {
    52.9      /** Number of bits per slot. */
   52.10      private static final int BITSPERSLOT = 64;
   52.11  
    53.1 --- a/src/jdk/nashorn/internal/runtime/ConsString.java	Sat Feb 09 16:58:48 2013 +0100
    53.2 +++ b/src/jdk/nashorn/internal/runtime/ConsString.java	Mon Feb 11 21:26:06 2013 +0530
    53.3 @@ -33,7 +33,7 @@
    53.4   * instances of <tt>ConsString</tt> or {@link String}. Copying of characters to
    53.5   * a proper string is delayed until it becomes necessary.
    53.6   */
    53.7 -public class ConsString implements CharSequence {
    53.8 +public final class ConsString implements CharSequence {
    53.9  
   53.10      private CharSequence left, right;
   53.11      final private int length;
    54.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Sat Feb 09 16:58:48 2013 +0100
    54.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Mon Feb 11 21:26:06 2013 +0530
    54.3 @@ -36,6 +36,7 @@
    54.4  import java.io.PrintWriter;
    54.5  import java.lang.invoke.MethodHandle;
    54.6  import java.lang.invoke.MethodHandles;
    54.7 +import java.lang.reflect.Constructor;
    54.8  import java.net.MalformedURLException;
    54.9  import java.net.URL;
   54.10  import java.security.AccessController;
   54.11 @@ -84,11 +85,11 @@
   54.12              Class<?> caller = Reflection.getCallerClass(2);
   54.13              ClassLoader callerLoader = caller.getClassLoader();
   54.14  
   54.15 -            // Allow this method only for nashorn's own classes, script
   54.16 -            // generated classes and Java adapter classes. Rest should
   54.17 +            // Allow this method only for nashorn's own classes, objects
   54.18 +            // package classes and Java adapter classes. Rest should
   54.19              // have the necessary security permission.
   54.20              if (callerLoader != myLoader &&
   54.21 -                !(callerLoader instanceof NashornLoader) &&
   54.22 +                !(callerLoader instanceof StructureLoader) &&
   54.23                  !(JavaAdapterFactory.isAdapterClass(caller))) {
   54.24                  sm.checkPermission(new RuntimePermission("getNashornGlobal"));
   54.25              }
   54.26 @@ -332,7 +333,7 @@
   54.27               new PrivilegedAction<ClassLoader>() {
   54.28                  @Override
   54.29                  public ClassLoader run() {
   54.30 -                    final ClassLoader structureLoader = new StructureLoader(sharedLoader, Context.this);
   54.31 +                    final StructureLoader structureLoader = new StructureLoader(sharedLoader, Context.this);
   54.32                      return new ScriptLoader(structureLoader, Context.this);
   54.33                  }
   54.34               });
   54.35 @@ -959,7 +960,7 @@
   54.36                      // Generated code won't refer to any class generated by context
   54.37                      // script loader and so parent loader can be the structure
   54.38                      // loader -- which is parent of the context script loader.
   54.39 -                    return new ScriptLoader(scriptLoader.getParent(), Context.this);
   54.40 +                    return new ScriptLoader((StructureLoader)scriptLoader.getParent(), Context.this);
   54.41                  }
   54.42               });
   54.43      }
   54.44 @@ -967,10 +968,15 @@
   54.45      private ScriptObject newGlobalTrusted() {
   54.46          try {
   54.47              final Class<?> clazz = Class.forName("jdk.nashorn.internal.objects.Global", true, scriptLoader);
   54.48 -            return (ScriptObject) clazz.newInstance();
   54.49 -        } catch (final ClassNotFoundException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException e) {
   54.50 +            final Constructor cstr = clazz.getConstructor(Context.class);
   54.51 +            return (ScriptObject) cstr.newInstance(this);
   54.52 +        } catch (final Exception e) {
   54.53              printStackTrace(e);
   54.54 -            throw new RuntimeException(e);
   54.55 +            if (e instanceof RuntimeException) {
   54.56 +                throw (RuntimeException)e;
   54.57 +            } else {
   54.58 +                throw new RuntimeException(e);
   54.59 +            }
   54.60          }
   54.61      }
   54.62  }
    55.1 --- a/src/jdk/nashorn/internal/runtime/Debug.java	Sat Feb 09 16:58:48 2013 +0100
    55.2 +++ b/src/jdk/nashorn/internal/runtime/Debug.java	Mon Feb 11 21:26:06 2013 +0530
    55.3 @@ -36,7 +36,7 @@
    55.4   * Utilities for debugging Nashorn.
    55.5   *
    55.6   */
    55.7 -public class Debug {
    55.8 +public final class Debug {
    55.9      private Debug() {
   55.10      }
   55.11  
    56.1 --- a/src/jdk/nashorn/internal/runtime/DebugLogger.java	Sat Feb 09 16:58:48 2013 +0100
    56.2 +++ b/src/jdk/nashorn/internal/runtime/DebugLogger.java	Mon Feb 11 21:26:06 2013 +0530
    56.3 @@ -34,7 +34,7 @@
    56.4   * Wrapper class for Logging system. This is how you are supposed to register a logger and use it
    56.5   */
    56.6  
    56.7 -public class DebugLogger {
    56.8 +public final class DebugLogger {
    56.9      @SuppressWarnings("NonConstantLogger")
   56.10      private final Logger  logger;
   56.11      private final boolean isEnabled;
    57.1 --- a/src/jdk/nashorn/internal/runtime/GlobalFunctions.java	Sat Feb 09 16:58:48 2013 +0100
    57.2 +++ b/src/jdk/nashorn/internal/runtime/GlobalFunctions.java	Mon Feb 11 21:26:06 2013 +0530
    57.3 @@ -37,7 +37,7 @@
    57.4   * These are actual implementation methods for functions exposed by global
    57.5   * scope. The code lives here to share the code across the contexts.
    57.6   */
    57.7 -public class GlobalFunctions {
    57.8 +public final class GlobalFunctions {
    57.9  
   57.10      /** Methodhandle to implementation of ECMA 15.1.2.2, parseInt */
   57.11      public static final MethodHandle PARSEINT = findOwnMH("parseInt",   double.class, Object.class, Object.class, Object.class);
    58.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.2 +++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Mon Feb 11 21:26:06 2013 +0530
    58.3 @@ -0,0 +1,224 @@
    58.4 +/*
    58.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    58.7 + *
    58.8 + * This code is free software; you can redistribute it and/or modify it
    58.9 + * under the terms of the GNU General Public License version 2 only, as
   58.10 + * published by the Free Software Foundation.  Oracle designates this
   58.11 + * particular file as subject to the "Classpath" exception as provided
   58.12 + * by Oracle in the LICENSE file that accompanied this code.
   58.13 + *
   58.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   58.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   58.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   58.17 + * version 2 for more details (a copy is included in the LICENSE file that
   58.18 + * accompanied this code).
   58.19 + *
   58.20 + * You should have received a copy of the GNU General Public License version
   58.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   58.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   58.23 + *
   58.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   58.25 + * or visit www.oracle.com if you need additional information or have any
   58.26 + * questions.
   58.27 + */
   58.28 +
   58.29 +package jdk.nashorn.internal.runtime;
   58.30 +
   58.31 +import static jdk.nashorn.internal.runtime.ScriptObject.isArray;
   58.32 +
   58.33 +import java.lang.invoke.MethodHandle;
   58.34 +import java.util.Iterator;
   58.35 +import java.util.List;
   58.36 +import jdk.nashorn.internal.ir.LiteralNode;
   58.37 +import jdk.nashorn.internal.ir.Node;
   58.38 +import jdk.nashorn.internal.ir.ObjectNode;
   58.39 +import jdk.nashorn.internal.ir.PropertyNode;
   58.40 +import jdk.nashorn.internal.ir.UnaryNode;
   58.41 +import jdk.nashorn.internal.parser.JSONParser;
   58.42 +import jdk.nashorn.internal.parser.TokenType;
   58.43 +import jdk.nashorn.internal.runtime.linker.Bootstrap;
   58.44 +
   58.45 +/**
   58.46 + * Utilities used by "JSON" object implementation.
   58.47 + */
   58.48 +public final class JSONFunctions {
   58.49 +    private JSONFunctions() {}
   58.50 +    private static final MethodHandle REVIVER_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class,
   58.51 +            ScriptFunction.class, ScriptObject.class, String.class, Object.class);
   58.52 +
   58.53 +    /**
   58.54 +     * Returns JSON-compatible quoted version of the given string.
   58.55 +     *
   58.56 +     * @param str String to be quoted
   58.57 +     * @return JSON-compatible quoted string
   58.58 +     */
   58.59 +    public static String quote(final String str) {
   58.60 +        return JSONParser.quote(str);
   58.61 +    }
   58.62 +
   58.63 +    /**
   58.64 +     * Parses the given JSON text string and returns object representation.
   58.65 +     *
   58.66 +     * @param text JSON text to be parsed
   58.67 +     * @param reviver  optional value: function that takes two parameters (key, value)
   58.68 +     * @return Object representation of JSON text given
   58.69 +     */
   58.70 +    public static Object parse(final Object text, final Object reviver) {
   58.71 +        final String     str     = JSType.toString(text);
   58.72 +        final Context    context = Context.getContextTrusted();
   58.73 +        final JSONParser parser  = new JSONParser(
   58.74 +                new Source("<json>", str),
   58.75 +                new Context.ThrowErrorManager(),
   58.76 +                (context != null) ?
   58.77 +                    context._strict :
   58.78 +                    false);
   58.79 +
   58.80 +        Node node;
   58.81 +
   58.82 +        try {
   58.83 +            node = parser.parse();
   58.84 +        } catch (final ParserException e) {
   58.85 +            ECMAErrors.syntaxError(e, "invalid.json", e.getMessage());
   58.86 +            return ScriptRuntime.UNDEFINED;
   58.87 +        }
   58.88 +
   58.89 +        final ScriptObject global = Context.getGlobalTrusted();
   58.90 +        Object unfiltered = convertNode(global, node);
   58.91 +        return applyReviver(global, unfiltered, reviver);
   58.92 +    }
   58.93 +
   58.94 +    // -- Internals only below this point
   58.95 +
   58.96 +    // parse helpers
   58.97 +
   58.98 +    // apply 'reviver' function if available
   58.99 +    private static Object applyReviver(final ScriptObject global, final Object unfiltered, final Object reviver) {
  58.100 +        if (reviver instanceof ScriptFunction) {
  58.101 +            assert global instanceof GlobalObject;
  58.102 +            final ScriptObject root = ((GlobalObject)global).newObject();
  58.103 +            root.set("", unfiltered, root.isStrictContext());
  58.104 +            return walk(root, "", (ScriptFunction)reviver);
  58.105 +        }
  58.106 +        return unfiltered;
  58.107 +    }
  58.108 +
  58.109 +    // This is the abstract "Walk" operation from the spec.
  58.110 +    private static Object walk(final ScriptObject holder, final Object name, final ScriptFunction reviver) {
  58.111 +        final Object val = holder.get(name);
  58.112 +        if (val == ScriptRuntime.UNDEFINED) {
  58.113 +            return val;
  58.114 +        } else if (val instanceof ScriptObject) {
  58.115 +            final ScriptObject     valueObj = (ScriptObject)val;
  58.116 +            final boolean          strict   = valueObj.isStrictContext();
  58.117 +            final Iterator<String> iter     = valueObj.propertyIterator();
  58.118 +
  58.119 +            while (iter.hasNext()) {
  58.120 +                final String key        = iter.next();
  58.121 +                final Object newElement = walk(valueObj, key, reviver);
  58.122 +
  58.123 +                if (newElement == ScriptRuntime.UNDEFINED) {
  58.124 +                    valueObj.delete(key, strict);
  58.125 +                } else {
  58.126 +                    valueObj.set(key, newElement, strict);
  58.127 +                }
  58.128 +            }
  58.129 +
  58.130 +            return valueObj;
  58.131 +        } else if (isArray(val)) {
  58.132 +            final ScriptObject      valueArray = (ScriptObject)val;
  58.133 +            final boolean          strict     = valueArray.isStrictContext();
  58.134 +            final Iterator<String> iter       = valueArray.propertyIterator();
  58.135 +
  58.136 +            while (iter.hasNext()) {
  58.137 +                final String key        = iter.next();
  58.138 +                final Object newElement = walk(valueArray, valueArray.get(key), reviver);
  58.139 +
  58.140 +                if (newElement == ScriptRuntime.UNDEFINED) {
  58.141 +                    valueArray.delete(key, strict);
  58.142 +                } else {
  58.143 +                    valueArray.set(key, newElement, strict);
  58.144 +                }
  58.145 +            }
  58.146 +            return valueArray;
  58.147 +        } else {
  58.148 +            try {
  58.149 +                // Object.class, ScriptFunction.class, ScriptObject.class, String.class, Object.class);
  58.150 +                return REVIVER_INVOKER.invokeExact(reviver, holder, JSType.toString(name), val);
  58.151 +            } catch(Error|RuntimeException t) {
  58.152 +                throw t;
  58.153 +            } catch(final Throwable t) {
  58.154 +                throw new RuntimeException(t);
  58.155 +            }
  58.156 +        }
  58.157 +    }
  58.158 +
  58.159 +    // Converts IR node to runtime value
  58.160 +    private static Object convertNode(final ScriptObject global, final Node node) {
  58.161 +        assert global instanceof GlobalObject;
  58.162 +
  58.163 +        if (node instanceof LiteralNode) {
  58.164 +            // check for array literal
  58.165 +            if (node.tokenType() == TokenType.ARRAY) {
  58.166 +                assert node instanceof LiteralNode.ArrayLiteralNode;
  58.167 +                final Node[] elements = ((LiteralNode.ArrayLiteralNode)node).getValue();
  58.168 +
  58.169 +                // NOTE: We cannot use LiteralNode.isNumericArray() here as that
  58.170 +                // method uses symbols of element nodes. Since we don't do lower
  58.171 +                // pass, there won't be any symbols!
  58.172 +                if (isNumericArray(elements)) {
  58.173 +                    final double[] values = new double[elements.length];
  58.174 +                    int   index = 0;
  58.175 +
  58.176 +                    for (final Node elem : elements) {
  58.177 +                        values[index++] = JSType.toNumber(convertNode(global, elem));
  58.178 +                    }
  58.179 +                    return ((GlobalObject)global).wrapAsObject(values);
  58.180 +                }
  58.181 +
  58.182 +                final Object[] values = new Object[elements.length];
  58.183 +                int   index = 0;
  58.184 +
  58.185 +                for (final Node elem : elements) {
  58.186 +                    values[index++] = convertNode(global, elem);
  58.187 +                }
  58.188 +
  58.189 +                return ((GlobalObject)global).wrapAsObject(values);
  58.190 +            }
  58.191 +
  58.192 +            return ((LiteralNode<?>)node).getValue();
  58.193 +
  58.194 +        } else if (node instanceof ObjectNode) {
  58.195 +            final ObjectNode   objNode  = (ObjectNode) node;
  58.196 +            final ScriptObject object   = ((GlobalObject)global).newObject();
  58.197 +            final boolean      strict   = global.isStrictContext();
  58.198 +            final List<Node>   elements = objNode.getElements();
  58.199 +
  58.200 +            for (final Node elem : elements) {
  58.201 +                final PropertyNode pNode     = (PropertyNode) elem;
  58.202 +                final Node         valueNode = pNode.getValue();
  58.203 +
  58.204 +                object.set(pNode.getKeyName(), convertNode(global, valueNode), strict);
  58.205 +            }
  58.206 +
  58.207 +            return object;
  58.208 +        } else if (node instanceof UnaryNode) {
  58.209 +            // UnaryNode used only to represent negative number JSON value
  58.210 +            final UnaryNode unaryNode = (UnaryNode)node;
  58.211 +            return -((LiteralNode<?>)unaryNode.rhs()).getNumber();
  58.212 +        } else {
  58.213 +            return null;
  58.214 +        }
  58.215 +    }
  58.216 +
  58.217 +    // does the given IR node represent a numeric array?
  58.218 +    private static boolean isNumericArray(final Node[] values) {
  58.219 +        for (final Node node : values) {
  58.220 +            if (node instanceof LiteralNode && ((LiteralNode<?>)node).getValue() instanceof Number) {
  58.221 +                continue;
  58.222 +            }
  58.223 +            return false;
  58.224 +        }
  58.225 +        return true;
  58.226 +    }
  58.227 +}
    59.1 --- a/src/jdk/nashorn/internal/runtime/Logging.java	Sat Feb 09 16:58:48 2013 +0100
    59.2 +++ b/src/jdk/nashorn/internal/runtime/Logging.java	Mon Feb 11 21:26:06 2013 +0530
    59.3 @@ -40,7 +40,7 @@
    59.4   * specified on the command line. Supports all standard log levels
    59.5   *
    59.6   */
    59.7 -public class Logging {
    59.8 +public final class Logging {
    59.9  
   59.10      private Logging() {
   59.11      }
    60.1 --- a/src/jdk/nashorn/internal/runtime/NashornLoader.java	Sat Feb 09 16:58:48 2013 +0100
    60.2 +++ b/src/jdk/nashorn/internal/runtime/NashornLoader.java	Mon Feb 11 21:26:06 2013 +0530
    60.3 @@ -51,13 +51,16 @@
    60.4          this.context = context;
    60.5      }
    60.6  
    60.7 +
    60.8      /**
    60.9 -     * Override loadClass so that we can checkPackageAccess.
   60.10 +     * Called by subclass after package access check is done
   60.11 +     * @param name name of the class to be loaded
   60.12 +     * @param resolve whether the class should be resolved or not
   60.13 +     * @return Class object
   60.14 +     * @throws ClassNotFoundException
   60.15       */
   60.16 -    @Override
   60.17 -    public Class<?> loadClass(final String name) throws ClassNotFoundException {
   60.18 -        checkPackageAccess(name);
   60.19 -        return super.loadClass(name);
   60.20 +    protected final Class<?> loadClassTrusted(final String name, final boolean resolve) throws ClassNotFoundException {
   60.21 +        return super.loadClass(name, resolve);
   60.22      }
   60.23  
   60.24      protected static void checkPackageAccess(final String name) {
    61.1 --- a/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java	Sat Feb 09 16:58:48 2013 +0100
    61.2 +++ b/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java	Mon Feb 11 21:26:06 2013 +0530
    61.3 @@ -64,7 +64,7 @@
    61.4   * var ftype4 = Java.asType("java.awt.geom.Arc2D").Float
    61.5   * </pre>
    61.6   */
    61.7 -public class NativeJavaPackage extends ScriptObject {
    61.8 +public final class NativeJavaPackage extends ScriptObject {
    61.9      /** Full name of package (includes path.) */
   61.10      private final String name;
   61.11  
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/src/jdk/nashorn/internal/runtime/RegExp.java	Mon Feb 11 21:26:06 2013 +0530
    62.3 @@ -0,0 +1,177 @@
    62.4 +/*
    62.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    62.7 + *
    62.8 + * This code is free software; you can redistribute it and/or modify it
    62.9 + * under the terms of the GNU General Public License version 2 only, as
   62.10 + * published by the Free Software Foundation.  Oracle designates this
   62.11 + * particular file as subject to the "Classpath" exception as provided
   62.12 + * by Oracle in the LICENSE file that accompanied this code.
   62.13 + *
   62.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   62.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   62.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   62.17 + * version 2 for more details (a copy is included in the LICENSE file that
   62.18 + * accompanied this code).
   62.19 + *
   62.20 + * You should have received a copy of the GNU General Public License version
   62.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   62.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   62.23 + *
   62.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   62.25 + * or visit www.oracle.com if you need additional information or have any
   62.26 + * questions.
   62.27 + */
   62.28 +
   62.29 +package jdk.nashorn.internal.runtime;
   62.30 +
   62.31 +import static java.util.regex.Pattern.CASE_INSENSITIVE;
   62.32 +import static java.util.regex.Pattern.MULTILINE;
   62.33 +import static java.util.regex.Pattern.UNICODE_CASE;
   62.34 +
   62.35 +import java.util.HashSet;
   62.36 +import java.util.regex.Pattern;
   62.37 +import java.util.regex.PatternSyntaxException;
   62.38 +
   62.39 +/**
   62.40 + * This class is used to represent a parsed regular expression. Accepts input
   62.41 + * pattern string and flagString. This is used by AbstractParser to validate
   62.42 + * RegExp literals as well as by NativeRegExp to parse RegExp constructor arguments.
   62.43 + */
   62.44 +public final class RegExp {
   62.45 +    /** Pattern string. */
   62.46 +    private final String input;
   62.47 +
   62.48 +    /** Global search flag for this regexp.*/
   62.49 +    private boolean global;
   62.50 +
   62.51 +    /** Case insensitive flag for this regexp */
   62.52 +    private boolean ignoreCase;
   62.53 +
   62.54 +    /** Multi-line flag for this regexp */
   62.55 +    private boolean multiline;
   62.56 +
   62.57 +    /** Java regexp pattern to use for match. We compile to one of these */
   62.58 +    private Pattern pattern;
   62.59 +
   62.60 +    /** BitVector that keeps track of groups in negative lookahead */
   62.61 +    private BitVector groupsInNegativeLookahead;
   62.62 +
   62.63 +    /**
   62.64 +     * Creates RegExpLiteral object from given input and flagString.
   62.65 +     *
   62.66 +     * @param input RegExp pattern string
   62.67 +     * @param flagString RegExp flags
   62.68 +     * @throws ParserException if flagString is invalid or input string has syntax error.
   62.69 +     */
   62.70 +    public RegExp(final String input, final String flagString) throws ParserException {
   62.71 +        this.input = input;
   62.72 +        final HashSet<Character> usedFlags = new HashSet<>();
   62.73 +        int flags = 0;
   62.74 +
   62.75 +        for (final char ch : flagString.toCharArray()) {
   62.76 +            if (usedFlags.contains(ch)) {
   62.77 +                throwParserException("repeated.flag", Character.toString(ch));
   62.78 +            }
   62.79 +
   62.80 +            switch (ch) {
   62.81 +            case 'g':
   62.82 +                this.global = true;
   62.83 +                usedFlags.add(ch);
   62.84 +                break;
   62.85 +            case 'i':
   62.86 +                this.ignoreCase = true;
   62.87 +                flags |= CASE_INSENSITIVE | UNICODE_CASE;
   62.88 +                usedFlags.add(ch);
   62.89 +                break;
   62.90 +            case 'm':
   62.91 +                this.multiline = true;
   62.92 +                flags |= MULTILINE;
   62.93 +                usedFlags.add(ch);
   62.94 +                break;
   62.95 +            default:
   62.96 +                throwParserException("unsupported.flag", Character.toString(ch));
   62.97 +            }
   62.98 +        }
   62.99 +
  62.100 +        try {
  62.101 +            RegExpScanner parsed;
  62.102 +
  62.103 +            try {
  62.104 +                parsed = RegExpScanner.scan(input);
  62.105 +            } catch (final PatternSyntaxException e) {
  62.106 +                // refine the exception with a better syntax error, if this
  62.107 +                // passes, just rethrow what we have
  62.108 +                Pattern.compile(input, flags);
  62.109 +                throw e;
  62.110 +            }
  62.111 +
  62.112 +            if (parsed != null) {
  62.113 +                this.pattern = Pattern.compile(parsed.getJavaPattern(), flags);
  62.114 +                this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
  62.115 +            }
  62.116 +        } catch (final PatternSyntaxException e2) {
  62.117 +            throwParserException("syntax", e2.getMessage());
  62.118 +        }
  62.119 +
  62.120 +    }
  62.121 +
  62.122 +    /**
  62.123 +     * @return the input
  62.124 +     */
  62.125 +    public String getInput() {
  62.126 +        return input;
  62.127 +    }
  62.128 +
  62.129 +    /**
  62.130 +     * @return the global
  62.131 +     */
  62.132 +    public boolean isGlobal() {
  62.133 +        return global;
  62.134 +    }
  62.135 +
  62.136 +    /**
  62.137 +     * @return the ignoreCase
  62.138 +     */
  62.139 +    public boolean isIgnoreCase() {
  62.140 +        return ignoreCase;
  62.141 +    }
  62.142 +
  62.143 +    /**
  62.144 +     * @return the multiline
  62.145 +     */
  62.146 +    public boolean isMultiline() {
  62.147 +        return multiline;
  62.148 +    }
  62.149 +
  62.150 +    /**
  62.151 +     * @return the pattern
  62.152 +     */
  62.153 +    public Pattern getPattern() {
  62.154 +        return pattern;
  62.155 +    }
  62.156 +
  62.157 +    /**
  62.158 +     * @return the groupsInNegativeLookahead
  62.159 +     */
  62.160 +    public BitVector getGroupsInNegativeLookahead() {
  62.161 +        return groupsInNegativeLookahead;
  62.162 +    }
  62.163 +
  62.164 +    /**
  62.165 +     * Validation method for RegExp input and flagString - we don't care about the RegExp object
  62.166 +     *
  62.167 +     * @param input        regexp input
  62.168 +     * @param flagString   flag string
  62.169 +     *
  62.170 +     * @throws ParserException if invalid regexp and flags
  62.171 +     */
  62.172 +    @SuppressWarnings({"unused", "ResultOfObjectAllocationIgnored"})
  62.173 +    public static void validate(final String input, final String flagString) throws ParserException {
  62.174 +        new RegExp(input, flagString);
  62.175 +    }
  62.176 +
  62.177 +    private static void throwParserException(final String key, final String str) throws ParserException {
  62.178 +        throw new ParserException(ECMAErrors.getMessage("parser.error.regex." + key, str));
  62.179 +    }
  62.180 +}
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/src/jdk/nashorn/internal/runtime/RegExpScanner.java	Mon Feb 11 21:26:06 2013 +0530
    63.3 @@ -0,0 +1,1415 @@
    63.4 +/*
    63.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    63.7 + *
    63.8 + * This code is free software; you can redistribute it and/or modify it
    63.9 + * under the terms of the GNU General Public License version 2 only, as
   63.10 + * published by the Free Software Foundation.  Oracle designates this
   63.11 + * particular file as subject to the "Classpath" exception as provided
   63.12 + * by Oracle in the LICENSE file that accompanied this code.
   63.13 + *
   63.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   63.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   63.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   63.17 + * version 2 for more details (a copy is included in the LICENSE file that
   63.18 + * accompanied this code).
   63.19 + *
   63.20 + * You should have received a copy of the GNU General Public License version
   63.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   63.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   63.23 + *
   63.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   63.25 + * or visit www.oracle.com if you need additional information or have any
   63.26 + * questions.
   63.27 + */
   63.28 +
   63.29 +package jdk.nashorn.internal.runtime;
   63.30 +
   63.31 +import java.util.ArrayList;
   63.32 +import java.util.HashMap;
   63.33 +import java.util.Iterator;
   63.34 +import java.util.LinkedHashMap;
   63.35 +import java.util.LinkedList;
   63.36 +import java.util.List;
   63.37 +import java.util.Map;
   63.38 +import java.util.regex.PatternSyntaxException;
   63.39 +import jdk.nashorn.internal.parser.Lexer;
   63.40 +import jdk.nashorn.internal.parser.Scanner;
   63.41 +
   63.42 +/**
   63.43 + * Scan a JavaScript regexp, converting to Java regex if necessary.
   63.44 + *
   63.45 + */
   63.46 +final class RegExpScanner extends Scanner {
   63.47 +
   63.48 +    /**
   63.49 +     * String builder to accumulate the result - this contains verbatim parsed JavaScript.
   63.50 +     * to get the java equivalent we need to create a Pattern token and return its toString()
   63.51 +     */
   63.52 +    private final StringBuilder sb;
   63.53 +
   63.54 +    /** An optional error message if one occurred during parse. */
   63.55 +    private String errorMessage;
   63.56 +
   63.57 +    /** Is this the special case of a regexp that never matches anything */
   63.58 +    private boolean neverMatches;
   63.59 +
   63.60 +    /** The resulting java.util.regex pattern string. */
   63.61 +    private String javaPattern;
   63.62 +
   63.63 +    /** Expected token table */
   63.64 +    private final Map<Character, Integer> expected = new HashMap<>();
   63.65 +
   63.66 +    /** Capturing parenthesis that have been found so far. */
   63.67 +    private final List<Capture> caps = new LinkedList<>();
   63.68 +
   63.69 +    /** Forward references to capturing parenthesis to be resolved later.*/
   63.70 +    private final Map<Integer, Token> forwardReferences = new LinkedHashMap<>();
   63.71 +
   63.72 +    /** Current level of zero-width negative lookahead assertions. */
   63.73 +    private int negativeLookaheadLevel;
   63.74 +
   63.75 +    private static final String NON_IDENT_ESCAPES = "$^*+(){}[]|\\.?";
   63.76 +
   63.77 +    private static class Capture {
   63.78 +        /**
   63.79 +         * Zero-width negative lookaheads enclosing the capture.
   63.80 +         */
   63.81 +        private final int negativeLookaheadLevel;
   63.82 +        /**
   63.83 +         * Captures that live inside a negative lookahead are dead after the
   63.84 +         * lookahead and will be undefined if referenced from outside.
   63.85 +         */
   63.86 +        private boolean isDead;
   63.87 +
   63.88 +        Capture(final int negativeLookaheadLevel) {
   63.89 +            this.negativeLookaheadLevel = negativeLookaheadLevel;
   63.90 +        }
   63.91 +
   63.92 +        public int getNegativeLookaheadLevel() {
   63.93 +            return negativeLookaheadLevel;
   63.94 +        }
   63.95 +
   63.96 +        public boolean isDead() {
   63.97 +            return isDead;
   63.98 +        }
   63.99 +
  63.100 +        public void setDead() {
  63.101 +            this.isDead = true;
  63.102 +        }
  63.103 +    }
  63.104 +
  63.105 +    /**
  63.106 +     * This is a token - the JavaScript regexp is scanned into a token tree
  63.107 +     * A token has other tokens as children as well as "atoms", i.e. Strings.
  63.108 +     *
  63.109 +     */
  63.110 +    private static class Token {
  63.111 +
  63.112 +        private enum Type {
  63.113 +            PATTERN,
  63.114 +            DISJUNCTION,
  63.115 +            ALTERNATIVE,
  63.116 +            TERM,
  63.117 +            ASSERTION,
  63.118 +            QUANTIFIER,
  63.119 +            QUANTIFIER_PREFIX,
  63.120 +            ATOM,
  63.121 +            PATTERN_CHARACTER,
  63.122 +            ATOM_ESCAPE,
  63.123 +            CHARACTER_ESCAPE,
  63.124 +            CONTROL_ESCAPE,
  63.125 +            CONTROL_LETTER,
  63.126 +            IDENTITY_ESCAPE,
  63.127 +            DECIMAL_ESCAPE,
  63.128 +            CHARACTERCLASS_ESCAPE,
  63.129 +            CHARACTERCLASS,
  63.130 +            CLASSRANGES,
  63.131 +            NON_EMPTY_CLASSRANGES,
  63.132 +            NON_EMPTY_CLASSRANGES_NODASH,
  63.133 +            CLASSATOM,
  63.134 +            CLASSATOM_NODASH,
  63.135 +            CLASS_ESCAPE,
  63.136 +            DECIMALDIGITS,
  63.137 +            HEX_ESCAPESEQUENCE,
  63.138 +            UNICODE_ESCAPESEQUENCE,
  63.139 +        }
  63.140 +
  63.141 +        /**
  63.142 +         * Token tyoe
  63.143 +         */
  63.144 +        private final Token.Type type;
  63.145 +
  63.146 +        /**
  63.147 +         * Child nodes
  63.148 +         */
  63.149 +        private final List<Object> children;
  63.150 +
  63.151 +        /**
  63.152 +         * Parent node
  63.153 +         */
  63.154 +        private Token parent;
  63.155 +
  63.156 +        /**
  63.157 +         * Dead code flag
  63.158 +         */
  63.159 +        private boolean isDead;
  63.160 +
  63.161 +        private static final Map<Type, ToString> toStringMap = new HashMap<>();
  63.162 +        private static final ToString DEFAULT_TOSTRING = new ToString();
  63.163 +
  63.164 +        private static String unicode(final int value) {
  63.165 +            final StringBuilder sb = new StringBuilder();
  63.166 +            final String hex = Integer.toHexString(value);
  63.167 +            sb.append('u');
  63.168 +            for (int i = 0; i < 4 - hex.length(); i++) {
  63.169 +                sb.append('0');
  63.170 +            }
  63.171 +            sb.append(hex);
  63.172 +
  63.173 +            return sb.toString();
  63.174 +        }
  63.175 +
  63.176 +        static {
  63.177 +            toStringMap.put(Type.CHARACTERCLASS, new ToString() {
  63.178 +                @Override
  63.179 +                public String toString(final Token token) {
  63.180 +                    return super.toString(token).replace("\\b", "\b");
  63.181 +                }
  63.182 +            });
  63.183 +
  63.184 +            // for some reason java regexps don't like control characters on the
  63.185 +            // form "\\ca".match([string with ascii 1 at char0]). Translating
  63.186 +            // them to unicode does it though.
  63.187 +            toStringMap.put(Type.CHARACTER_ESCAPE, new ToString() {
  63.188 +                @Override
  63.189 +                public String toString(final Token token) {
  63.190 +                    final String str = super.toString(token);
  63.191 +                    if (str.length() == 2) {
  63.192 +                        return Token.unicode(Character.toLowerCase(str.charAt(1)) - 'a' + 1);
  63.193 +                    }
  63.194 +                    return str;
  63.195 +                }
  63.196 +            });
  63.197 +
  63.198 +            toStringMap.put(Type.DECIMAL_ESCAPE, new ToString() {
  63.199 +                @Override
  63.200 +                public String toString(final Token token) {
  63.201 +                    final String str = super.toString(token);
  63.202 +
  63.203 +                    if ("\0".equals(str)) {
  63.204 +                        return str;
  63.205 +                    }
  63.206 +
  63.207 +                    int value;
  63.208 +
  63.209 +                    if (!token.hasParentOfType(Type.CLASSRANGES)) {
  63.210 +                        return str;
  63.211 +                    }
  63.212 +
  63.213 +                    value = Integer.parseInt(str, 8); //throws exception that leads to SyntaxError if not octal
  63.214 +                    if (value > 0xff) {
  63.215 +                        throw new NumberFormatException(str);
  63.216 +                    }
  63.217 +
  63.218 +                    return Token.unicode(value);
  63.219 +                }
  63.220 +            });
  63.221 +
  63.222 +        }
  63.223 +
  63.224 +        /**
  63.225 +         * JavaScript Token to Java regex substring framework.
  63.226 +         *
  63.227 +         */
  63.228 +        private static class ToString {
  63.229 +            String toString(final Token token) {
  63.230 +                final StringBuilder sb = new StringBuilder();
  63.231 +                for (final Object child : token.getChildren()) {
  63.232 +                    sb.append(child);
  63.233 +                }
  63.234 +
  63.235 +                //perform global substitutions that hold true for any evaluated form
  63.236 +                String str = sb.toString();
  63.237 +                switch (str) {
  63.238 +                case "\\s":
  63.239 +                    str = "[" + Lexer.getWhitespaceRegExp() + "]";
  63.240 +                    break;
  63.241 +                case "\\S":
  63.242 +                    str = "[^" + Lexer.getWhitespaceRegExp() + "]";
  63.243 +                    break;
  63.244 +                case "[^]":
  63.245 +                    str = "[\\s\\S]";
  63.246 +                    break;
  63.247 +                default:
  63.248 +                    break;
  63.249 +                }
  63.250 +                return str;
  63.251 +            }
  63.252 +        }
  63.253 +
  63.254 +        /**
  63.255 +         * Token iterator. Doesn't return "atom" children. i.e. string representations,
  63.256 +         * just tokens
  63.257 +         *
  63.258 +         */
  63.259 +        private static class TokenIterator implements Iterator<Token> {
  63.260 +            private final List<Token> preorder;
  63.261 +
  63.262 +            private void init(final Token root) {
  63.263 +                preorder.add(root);
  63.264 +                for (final Object child : root.getChildren()) {
  63.265 +                    if (child instanceof Token) {
  63.266 +                        init((Token)child);
  63.267 +                    }
  63.268 +                }
  63.269 +            }
  63.270 +
  63.271 +            TokenIterator(final Token root) {
  63.272 +                preorder = new ArrayList<>();
  63.273 +                init(root);
  63.274 +            }
  63.275 +
  63.276 +            @Override
  63.277 +            public boolean hasNext() {
  63.278 +                return !preorder.isEmpty();
  63.279 +            }
  63.280 +
  63.281 +            @Override
  63.282 +            public Token next() {
  63.283 +                return preorder.remove(0);
  63.284 +            }
  63.285 +
  63.286 +            @Override
  63.287 +            public void remove() {
  63.288 +                next();
  63.289 +            }
  63.290 +        }
  63.291 +
  63.292 +        /**
  63.293 +         * Constructor
  63.294 +         * @param type the token type
  63.295 +         */
  63.296 +        Token(final Token.Type type) {
  63.297 +            this.type = type;
  63.298 +            children = new ArrayList<>();
  63.299 +        }
  63.300 +
  63.301 +        /**
  63.302 +         * Add a an "atom" child to a token
  63.303 +         * @param child the child to add
  63.304 +         * @return the token (for chaining)
  63.305 +         */
  63.306 +        public Token add(final String child) {
  63.307 +            children.add(child);
  63.308 +            return this;
  63.309 +        }
  63.310 +
  63.311 +        /**
  63.312 +         * Add a child to a token
  63.313 +         * @param child the child
  63.314 +         * @return the token (for chaining)
  63.315 +         */
  63.316 +        public Token add(final Token child) {
  63.317 +            if (child != null) {
  63.318 +                children.add(child);
  63.319 +                child.setParent(this);
  63.320 +            }
  63.321 +            return this;
  63.322 +        }
  63.323 +
  63.324 +        /**
  63.325 +         * Remove a child from a token
  63.326 +         * @param child the child to remove
  63.327 +         * @return true if successful
  63.328 +         */
  63.329 +        public boolean remove(final Token child) {
  63.330 +            return children.remove(child);
  63.331 +        }
  63.332 +
  63.333 +        /**
  63.334 +         * Remove the last child from a token
  63.335 +         * @return the removed child
  63.336 +         */
  63.337 +        public Object removeLast() {
  63.338 +            return children.remove(children.size() - 1);
  63.339 +        }
  63.340 +
  63.341 +        /**
  63.342 +         * Flag this token as dead code
  63.343 +         * @param isDead is it dead or not
  63.344 +         */
  63.345 +        private void setIsDead(final boolean isDead) {
  63.346 +            this.isDead = isDead;
  63.347 +        }
  63.348 +
  63.349 +        /**
  63.350 +         * Is this token dead code
  63.351 +         * @return boolean
  63.352 +         */
  63.353 +        private boolean getIsDead() {
  63.354 +            return isDead;
  63.355 +        }
  63.356 +
  63.357 +        /**
  63.358 +         * Get the parent of this token
  63.359 +         * @return parent token
  63.360 +         */
  63.361 +        public Token getParent() {
  63.362 +            return parent;
  63.363 +        }
  63.364 +
  63.365 +        public boolean hasParentOfType(final Token.Type parentType) {
  63.366 +            for (Token p = getParent(); p != null; p = p.getParent()) {
  63.367 +                if (p.getType() == parentType) {
  63.368 +                    return true;
  63.369 +                }
  63.370 +            }
  63.371 +            return false;
  63.372 +        }
  63.373 +
  63.374 +        public boolean hasChildOfType(final Token.Type childType) {
  63.375 +            for (final Iterator<Token> iter = iterator() ; iter.hasNext() ; ) {
  63.376 +                if (iter.next().getType() == childType) {
  63.377 +                    return true;
  63.378 +                }
  63.379 +            }
  63.380 +            return false;
  63.381 +        }
  63.382 +
  63.383 +        /**
  63.384 +         * Set the parent of this token
  63.385 +         * @param parent
  63.386 +         */
  63.387 +        private void setParent(final Token parent) {
  63.388 +            this.parent = parent;
  63.389 +        }
  63.390 +
  63.391 +        /**
  63.392 +         * Get the children of this token
  63.393 +         * @return an array of children, never null
  63.394 +         */
  63.395 +        public Object[] getChildren() {
  63.396 +            return children.toArray();
  63.397 +        }
  63.398 +
  63.399 +        /**
  63.400 +         * Reset this token, remove all children
  63.401 +         */
  63.402 +        public void reset() {
  63.403 +            children.clear();
  63.404 +        }
  63.405 +
  63.406 +        /**
  63.407 +         * Get a preorder token iterator with this token as root
  63.408 +         * @return an iterator
  63.409 +         */
  63.410 +        public Iterator<Token> iterator() {
  63.411 +            return new TokenIterator(this);
  63.412 +        }
  63.413 +
  63.414 +        /**
  63.415 +         * Get the type of this token
  63.416 +         * @return type
  63.417 +         */
  63.418 +        public Type getType() {
  63.419 +            return type;
  63.420 +        }
  63.421 +
  63.422 +        /**
  63.423 +         * Turn this token into Java regexp compatible text
  63.424 +         * @return part of a java regexp
  63.425 +         */
  63.426 +        @Override
  63.427 +        public String toString() {
  63.428 +            ToString t = toStringMap.get(getType());
  63.429 +            if (t == null) {
  63.430 +                t = DEFAULT_TOSTRING;
  63.431 +            }
  63.432 +            return t.toString(this);
  63.433 +        }
  63.434 +    }
  63.435 +
  63.436 +    /**
  63.437 +     * Constructor
  63.438 +     * @param string the JavaScript regexp to parse
  63.439 +     */
  63.440 +    private RegExpScanner(final String string) {
  63.441 +        super(string);
  63.442 +        sb = new StringBuilder(limit);
  63.443 +        reset(0);
  63.444 +        expected.put(']', 0);
  63.445 +        expected.put('}', 0);
  63.446 +    }
  63.447 +
  63.448 +    private void processForwardReferences() {
  63.449 +        if (neverMatches()) {
  63.450 +            return;
  63.451 +        }
  63.452 +
  63.453 +        for (final Map.Entry<Integer, Token> fwdRef : forwardReferences.entrySet()) {
  63.454 +            if (fwdRef.getKey().intValue() > caps.size()) {
  63.455 +                neverMatches = true;
  63.456 +                break;
  63.457 +            }
  63.458 +
  63.459 +            fwdRef.getValue().setIsDead(true);
  63.460 +        }
  63.461 +
  63.462 +        forwardReferences.clear();
  63.463 +    }
  63.464 +
  63.465 +    /**
  63.466 +     * Scan a JavaScript regexp string returning a Java safe regex string.
  63.467 +     *
  63.468 +     * @param string
  63.469 +     *            JavaScript regexp string.
  63.470 +     * @return Java safe regex string.
  63.471 +     */
  63.472 +    public static RegExpScanner scan(final String string) {
  63.473 +        final RegExpScanner scanner = new RegExpScanner(string);
  63.474 +
  63.475 +        Token pattern;
  63.476 +
  63.477 +        try {
  63.478 +            pattern = scanner.pattern();
  63.479 +        } catch (final Exception e) {
  63.480 +            throw new PatternSyntaxException(e.getMessage(), string, scanner.sb.length());
  63.481 +        }
  63.482 +
  63.483 +        scanner.processForwardReferences();
  63.484 +        if (scanner.neverMatches()) {
  63.485 +            return null; // never matches
  63.486 +        }
  63.487 +
  63.488 +        // go over the code and remove dead code
  63.489 +        final Iterator<Token> iter = pattern.iterator();
  63.490 +        while (iter.hasNext()) {
  63.491 +            final Token next = iter.next();
  63.492 +            if (next.getIsDead()) {
  63.493 +                next.getParent().remove(next);
  63.494 +            }
  63.495 +        }
  63.496 +
  63.497 +        // turn the pattern into a string, p, the java equivalent string for our js regexp
  63.498 +        final String p = pattern.toString();
  63.499 +        // if builder contains all tokens that were sent in, we know
  63.500 +        // we correctly parsed the entire JavaScript regexp without syntax errors
  63.501 +        if (!string.equals(scanner.getStringBuilder().toString())) {
  63.502 +            throw new PatternSyntaxException(string, p, p.length() + 1);
  63.503 +        }
  63.504 +
  63.505 +        scanner.javaPattern = p;
  63.506 +        return scanner;
  63.507 +     }
  63.508 +
  63.509 +    /**
  63.510 +     * Does this regexp ever match anything? Use of e.g. [], which is legal in JavaScript,
  63.511 +     * is an example where we never match
  63.512 +     *
  63.513 +     * @return boolean
  63.514 +     */
  63.515 +    private boolean neverMatches() {
  63.516 +        return neverMatches;
  63.517 +    }
  63.518 +
  63.519 +    /**
  63.520 +     * This is used to set better error messages that can be reused
  63.521 +     * in NativeRegExp for augmenting e.g. SyntaxErrors.
  63.522 +     *
  63.523 +     * @return an error message or null if no extra info
  63.524 +     */
  63.525 +    public String getErrorMessage() {
  63.526 +        return errorMessage;
  63.527 +    }
  63.528 +
  63.529 +    final StringBuilder getStringBuilder() {
  63.530 +        return sb;
  63.531 +    }
  63.532 +
  63.533 +    String getJavaPattern() {
  63.534 +        return javaPattern;
  63.535 +    }
  63.536 +
  63.537 +    BitVector getGroupsInNegativeLookahead() {
  63.538 +        BitVector vec = null;
  63.539 +        for (int i = 0; i < caps.size(); i++) {
  63.540 +            final Capture cap = caps.get(i);
  63.541 +            if (cap.getNegativeLookaheadLevel() > 0) {
  63.542 +                if (vec == null) {
  63.543 +                    vec = new BitVector(caps.size() + 1);
  63.544 +                }
  63.545 +                vec.set(i + 1);
  63.546 +            }
  63.547 +        }
  63.548 +        return vec;
  63.549 +    }
  63.550 +
  63.551 +    /**
  63.552 +     * Commit n characters to the builder and to a given token
  63.553 +     * @param token Uncommitted token.
  63.554 +     * @param n     Number of characters.
  63.555 +     * @return Committed token
  63.556 +     */
  63.557 +    private Token commit(final Token token, final int n) {
  63.558 +        final int startIn = position;
  63.559 +
  63.560 +        switch (n) {
  63.561 +        case 1:
  63.562 +            sb.append(ch0);
  63.563 +            skip(1);
  63.564 +            break;
  63.565 +        case 2:
  63.566 +            sb.append(ch0);
  63.567 +            sb.append(ch1);
  63.568 +            skip(2);
  63.569 +            break;
  63.570 +        case 3:
  63.571 +            sb.append(ch0);
  63.572 +            sb.append(ch1);
  63.573 +            sb.append(ch2);
  63.574 +            skip(3);
  63.575 +            break;
  63.576 +        default:
  63.577 +            assert false : "Should not reach here";
  63.578 +        }
  63.579 +
  63.580 +        if (token == null) {
  63.581 +            return null;
  63.582 +        }
  63.583 +
  63.584 +        return token.add(sb.substring(startIn, sb.length()));
  63.585 +    }
  63.586 +
  63.587 +    /**
  63.588 +     * Restart the buffers back at an earlier position.
  63.589 +     *
  63.590 +     * @param startIn
  63.591 +     *            Position in the input stream.
  63.592 +     * @param startOut
  63.593 +     *            Position in the output stream.
  63.594 +     */
  63.595 +    private void restart(final int startIn, final int startOut) {
  63.596 +        reset(startIn);
  63.597 +        sb.setLength(startOut);
  63.598 +    }
  63.599 +
  63.600 +    private void push(final char ch) {
  63.601 +        expected.put(ch, expected.get(ch) + 1);
  63.602 +    }
  63.603 +
  63.604 +    private void pop(final char ch) {
  63.605 +        expected.put(ch, Math.min(0, expected.get(ch) - 1));
  63.606 +    }
  63.607 +
  63.608 +    /*
  63.609 +     * Recursive descent tokenizer starts below.
  63.610 +     */
  63.611 +
  63.612 +    /*
  63.613 +     * Pattern ::
  63.614 +     *      Disjunction
  63.615 +     */
  63.616 +    private Token pattern() {
  63.617 +        final Token token = new Token(Token.Type.PATTERN);
  63.618 +
  63.619 +        final Token child = disjunction();
  63.620 +        if (child != null) {
  63.621 +            return token.add(child);
  63.622 +        }
  63.623 +
  63.624 +        return null;
  63.625 +    }
  63.626 +
  63.627 +    /*
  63.628 +     * Disjunction ::
  63.629 +     *      Alternative
  63.630 +     *      Alternative | Disjunction
  63.631 +     */
  63.632 +    private Token disjunction() {
  63.633 +        final Token token = new Token(Token.Type.DISJUNCTION);
  63.634 +
  63.635 +        while (true) {
  63.636 +            token.add(alternative());
  63.637 +
  63.638 +            if (ch0 == '|') {
  63.639 +                commit(token, 1);
  63.640 +            } else {
  63.641 +                break;
  63.642 +            }
  63.643 +        }
  63.644 +
  63.645 +        return token;
  63.646 +    }
  63.647 +
  63.648 +    /*
  63.649 +     * Alternative ::
  63.650 +     *      [empty]
  63.651 +     *      Alternative Term
  63.652 +     */
  63.653 +    private Token alternative() {
  63.654 +        final Token token = new Token(Token.Type.ALTERNATIVE);
  63.655 +
  63.656 +        Token child;
  63.657 +        while ((child = term()) != null) {
  63.658 +            token.add(child);
  63.659 +        }
  63.660 +
  63.661 +        return token;
  63.662 +    }
  63.663 +
  63.664 +    /*
  63.665 +     * Term ::
  63.666 +     *      Assertion
  63.667 +     *      Atom
  63.668 +     *      Atom Quantifier
  63.669 +     */
  63.670 +    private Token term() {
  63.671 +        final int startIn  = position;
  63.672 +        final int startOut = sb.length();
  63.673 +        final Token token  = new Token(Token.Type.TERM);
  63.674 +        Token child;
  63.675 +
  63.676 +        child = assertion();
  63.677 +        if (child != null) {
  63.678 +            return token.add(child);
  63.679 +        }
  63.680 +
  63.681 +        child = atom();
  63.682 +        if (child != null) {
  63.683 +            boolean emptyCharacterClass = false;
  63.684 +            if ("[]".equals(child.toString())) {
  63.685 +                emptyCharacterClass = true;
  63.686 +            }
  63.687 +
  63.688 +            token.add(child);
  63.689 +
  63.690 +            final Token quantifier = quantifier();
  63.691 +            if (quantifier != null) {
  63.692 +                token.add(quantifier);
  63.693 +            }
  63.694 +
  63.695 +            if (emptyCharacterClass) {
  63.696 +                if (quantifier == null) {
  63.697 +                    neverMatches = true; //never matches ever.
  63.698 +                } else {
  63.699 +                    //if we can get away with max zero, remove this entire token
  63.700 +                    final String qs = quantifier.toString();
  63.701 +                    if ("+".equals(qs) || "*".equals(qs) || qs.startsWith("{0,")) {
  63.702 +                        token.setIsDead(true);
  63.703 +                    }
  63.704 +                }
  63.705 +            }
  63.706 +
  63.707 +            return token;
  63.708 +        }
  63.709 +
  63.710 +        restart(startIn, startOut);
  63.711 +        return null;
  63.712 +    }
  63.713 +
  63.714 +    /*
  63.715 +     * Assertion ::
  63.716 +     *      ^
  63.717 +     *      $
  63.718 +     *      \b
  63.719 +     *      \B
  63.720 +     *      ( ? = Disjunction )
  63.721 +     *      ( ? ! Disjunction )
  63.722 +     */
  63.723 +    private Token assertion() {
  63.724 +        final int startIn  = position;
  63.725 +        final int startOut = sb.length();
  63.726 +        final Token token  = new Token(Token.Type.ASSERTION);
  63.727 +
  63.728 +        switch (ch0) {
  63.729 +        case '^':
  63.730 +        case '$':
  63.731 +            return commit(token, 1);
  63.732 +
  63.733 +        case '\\':
  63.734 +            if (ch1 == 'b' || ch1 == 'B') {
  63.735 +                return commit(token, 2);
  63.736 +            }
  63.737 +            break;
  63.738 +
  63.739 +        case '(':
  63.740 +            if (ch1 != '?') {
  63.741 +                break;
  63.742 +            }
  63.743 +            if (ch2 != '=' && ch2 != '!') {
  63.744 +                break;
  63.745 +            }
  63.746 +            final boolean isNegativeLookahead = (ch2 == '!');
  63.747 +            commit(token, 3);
  63.748 +
  63.749 +            if (isNegativeLookahead) {
  63.750 +                negativeLookaheadLevel++;
  63.751 +            }
  63.752 +            final Token disjunction = disjunction();
  63.753 +            if (isNegativeLookahead) {
  63.754 +                for (final Capture cap : caps) {
  63.755 +                    if (cap.getNegativeLookaheadLevel() >= negativeLookaheadLevel) {
  63.756 +                        cap.setDead();
  63.757 +                    }
  63.758 +                }
  63.759 +                negativeLookaheadLevel--;
  63.760 +            }
  63.761 +
  63.762 +            if (disjunction != null && ch0 == ')') {
  63.763 +                token.add(disjunction);
  63.764 +                return commit(token, 1);
  63.765 +            }
  63.766 +            break;
  63.767 +
  63.768 +        default:
  63.769 +            break;
  63.770 +        }
  63.771 +
  63.772 +        restart(startIn, startOut);
  63.773 +
  63.774 +        return null;
  63.775 +    }
  63.776 +
  63.777 +    /*
  63.778 +     * Quantifier ::
  63.779 +     *      QuantifierPrefix
  63.780 +     *      QuantifierPrefix ?
  63.781 +     */
  63.782 +    private Token quantifier() {
  63.783 +        final Token token = new Token(Token.Type.QUANTIFIER);
  63.784 +        final Token child = quantifierPrefix();
  63.785 +        if (child != null) {
  63.786 +            token.add(child);
  63.787 +            if (ch0 == '?') {
  63.788 +                commit(token, 1);
  63.789 +            }
  63.790 +            return token;
  63.791 +        }
  63.792 +        return null;
  63.793 +    }
  63.794 +
  63.795 +    /*
  63.796 +     * QuantifierPrefix ::
  63.797 +     *      *
  63.798 +     *      +
  63.799 +     *      ?
  63.800 +     *      { DecimalDigits }
  63.801 +     *      { DecimalDigits , }
  63.802 +     *      { DecimalDigits , DecimalDigits }
  63.803 +     */
  63.804 +    private Token quantifierPrefix() {
  63.805 +        final int startIn  = position;
  63.806 +        final int startOut = sb.length();
  63.807 +        final Token token  = new Token(Token.Type.QUANTIFIER_PREFIX);
  63.808 +
  63.809 +        switch (ch0) {
  63.810 +        case '*':
  63.811 +        case '+':
  63.812 +        case '?':
  63.813 +            return commit(token, 1);
  63.814 +
  63.815 +        case '{':
  63.816 +            commit(token, 1);
  63.817 +
  63.818 +            final Token child = decimalDigits();
  63.819 +            if (child == null) {
  63.820 +                break; // not a quantifier - back out
  63.821 +            }
  63.822 +            push('}');
  63.823 +            token.add(child);
  63.824 +
  63.825 +            if (ch0 == ',') {
  63.826 +                commit(token, 1);
  63.827 +                token.add(decimalDigits());
  63.828 +            }
  63.829 +
  63.830 +            if (ch0 == '}') {
  63.831 +                pop('}');
  63.832 +                commit(token, 1);
  63.833 +            }
  63.834 +
  63.835 +            return token;
  63.836 +
  63.837 +        default:
  63.838 +            break;
  63.839 +        }
  63.840 +
  63.841 +        restart(startIn, startOut);
  63.842 +        return null;
  63.843 +    }
  63.844 +
  63.845 +    /*
  63.846 +     * Atom ::
  63.847 +     *      PatternCharacter
  63.848 +     *      .
  63.849 +     *      \ AtomEscape
  63.850 +     *      CharacterClass
  63.851 +     *      ( Disjunction )
  63.852 +     *      ( ? : Disjunction )
  63.853 +     *
  63.854 +     */
  63.855 +    private Token atom() {
  63.856 +        final int startIn  = position;
  63.857 +        final int startOut = sb.length();
  63.858 +        final Token token  = new Token(Token.Type.ATOM);
  63.859 +        Token child;
  63.860 +
  63.861 +        child = patternCharacter();
  63.862 +        if (child != null) {
  63.863 +            return token.add(child);
  63.864 +        }
  63.865 +
  63.866 +        if (ch0 == '.') {
  63.867 +            return commit(token, 1);
  63.868 +        }
  63.869 +
  63.870 +        if (ch0 == '\\') {
  63.871 +            commit(token, 1);
  63.872 +            child = atomEscape();
  63.873 +
  63.874 +            if (child != null) {
  63.875 +                if (child.hasChildOfType(Token.Type.IDENTITY_ESCAPE)) {
  63.876 +                    final char idEscape = child.toString().charAt(0);
  63.877 +                    if (NON_IDENT_ESCAPES.indexOf(idEscape) == -1) {
  63.878 +                        token.reset();
  63.879 +                    }
  63.880 +                }
  63.881 +
  63.882 +                token.add(child);
  63.883 +
  63.884 +                // forward backreferences always match empty. JavaScript != Java
  63.885 +                if (child.hasChildOfType(Token.Type.DECIMAL_ESCAPE) && !"\u0000".equals(child.toString())) {
  63.886 +                    final int refNum = Integer.parseInt(child.toString());
  63.887 +
  63.888 +                    if (refNum - 1 < caps.size() && caps.get(refNum - 1).isDead()) {
  63.889 +                        // reference to dead in-negative-lookahead capture
  63.890 +                        token.setIsDead(true);
  63.891 +                    } else if (caps.size() < refNum) {
  63.892 +                        // forward reference: always matches against empty string (dead token).
  63.893 +                        // invalid reference (non-existant capture): pattern never matches.
  63.894 +                        forwardReferences.put(refNum, token);
  63.895 +                    }
  63.896 +                }
  63.897 +
  63.898 +                return token;
  63.899 +            }
  63.900 +        }
  63.901 +
  63.902 +        child = characterClass();
  63.903 +        if (child != null) {
  63.904 +            return token.add(child);
  63.905 +        }
  63.906 +
  63.907 +        if (ch0 == '(') {
  63.908 +            boolean capturingParens = true;
  63.909 +            commit(token, 1);
  63.910 +            if (ch0 == '?' && ch1 == ':') {
  63.911 +                capturingParens = false;
  63.912 +                commit(token, 2);
  63.913 +            }
  63.914 +
  63.915 +            child = disjunction();
  63.916 +            if (child != null) {
  63.917 +                token.add(child);
  63.918 +                if (ch0 == ')') {
  63.919 +                    final Token atom = commit(token, 1);
  63.920 +                    if (capturingParens) {
  63.921 +                        caps.add(new Capture(negativeLookaheadLevel));
  63.922 +                    }
  63.923 +                    return atom;
  63.924 +                }
  63.925 +            }
  63.926 +        }
  63.927 +
  63.928 +        restart(startIn, startOut);
  63.929 +        return null;
  63.930 +    }
  63.931 +
  63.932 +    /*
  63.933 +     * PatternCharacter ::
  63.934 +     *      SourceCharacter but not any of: ^$\.*+?()[]{}|
  63.935 +     */
  63.936 +    @SuppressWarnings("fallthrough")
  63.937 +    private Token patternCharacter() {
  63.938 +        if (atEOF()) {
  63.939 +            return null;
  63.940 +        }
  63.941 +
  63.942 +        switch (ch0) {
  63.943 +        case '^':
  63.944 +        case '$':
  63.945 +        case '\\':
  63.946 +        case '.':
  63.947 +        case '*':
  63.948 +        case '+':
  63.949 +        case '?':
  63.950 +        case '(':
  63.951 +        case ')':
  63.952 +        case '[':
  63.953 +        case '|':
  63.954 +            return null;
  63.955 +
  63.956 +        case '}':
  63.957 +        case ']':
  63.958 +            final int n = expected.get(ch0);
  63.959 +            if (n != 0) {
  63.960 +                return null;
  63.961 +            }
  63.962 +
  63.963 +       case '{':
  63.964 +           // if not a valid quantifier escape curly brace to match itself
  63.965 +           // this ensures compatibility with other JS implementations
  63.966 +           final Token quant = quantifierPrefix();
  63.967 +           return (quant == null) ? commit(new Token(Token.Type.PATTERN_CHARACTER).add("\\"), 1) : null;
  63.968 +
  63.969 +        default:
  63.970 +            return commit(new Token(Token.Type.PATTERN_CHARACTER), 1); // SOURCECHARACTER
  63.971 +        }
  63.972 +    }
  63.973 +
  63.974 +    /*
  63.975 +     * AtomEscape ::
  63.976 +     *      DecimalEscape
  63.977 +     *      CharacterEscape
  63.978 +     *      CharacterClassEscape
  63.979 +     */
  63.980 +    private Token atomEscape() {
  63.981 +        final Token token = new Token(Token.Type.ATOM_ESCAPE);
  63.982 +        Token child;
  63.983 +
  63.984 +        child = decimalEscape();
  63.985 +        if (child != null) {
  63.986 +            return token.add(child);
  63.987 +        }
  63.988 +
  63.989 +        child = characterClassEscape();
  63.990 +        if (child != null) {
  63.991 +            return token.add(child);
  63.992 +        }
  63.993 +
  63.994 +        child = characterEscape();
  63.995 +        if (child != null) {
  63.996 +            return token.add(child);
  63.997 +        }
  63.998 +
  63.999 +
 63.1000 +        return null;
 63.1001 +    }
 63.1002 +
 63.1003 +    /*
 63.1004 +     * CharacterEscape ::
 63.1005 +     *      ControlEscape
 63.1006 +     *      c ControlLetter
 63.1007 +     *      HexEscapeSequence
 63.1008 +     *      UnicodeEscapeSequence
 63.1009 +     *      IdentityEscape
 63.1010 +     */
 63.1011 +    private Token characterEscape() {
 63.1012 +        final int startIn  = position;
 63.1013 +        final int startOut = sb.length();
 63.1014 +
 63.1015 +        final Token token = new Token(Token.Type.CHARACTER_ESCAPE);
 63.1016 +        Token child;
 63.1017 +
 63.1018 +        child = controlEscape();
 63.1019 +        if (child != null) {
 63.1020 +            return token.add(child);
 63.1021 +        }
 63.1022 +
 63.1023 +        if (ch0 == 'c') {
 63.1024 +            commit(token, 1);
 63.1025 +            child = controlLetter();
 63.1026 +            if (child != null) {
 63.1027 +                return token.add(child);
 63.1028 +            }
 63.1029 +            restart(startIn, startOut);
 63.1030 +        }
 63.1031 +
 63.1032 +        child = hexEscapeSequence();
 63.1033 +        if (child != null) {
 63.1034 +            return token.add(child);
 63.1035 +        }
 63.1036 +
 63.1037 +        child = unicodeEscapeSequence();
 63.1038 +        if (child != null) {
 63.1039 +            return token.add(child);
 63.1040 +        }
 63.1041 +
 63.1042 +        child = identityEscape();
 63.1043 +        if (child != null) {
 63.1044 +            return token.add(child);
 63.1045 +        }
 63.1046 +
 63.1047 +        restart(startIn, startOut);
 63.1048 +
 63.1049 +        return null;
 63.1050 +    }
 63.1051 +
 63.1052 +    private boolean scanEscapeSequence(final char leader, final int length, final Token token) {
 63.1053 +        final int startIn  = position;
 63.1054 +        final int startOut = sb.length();
 63.1055 +
 63.1056 +        if (ch0 != leader) {
 63.1057 +            return false;
 63.1058 +        }
 63.1059 +
 63.1060 +        commit(token, 1);
 63.1061 +        for (int i = 0; i < length; i++) {
 63.1062 +            final char ch0l = Character.toLowerCase(ch0);
 63.1063 +            if ((ch0l >= 'a' && ch0l <= 'f') || isDecimalDigit(ch0)) {
 63.1064 +                commit(token, 1);
 63.1065 +            } else {
 63.1066 +                restart(startIn, startOut);
 63.1067 +                return false;
 63.1068 +            }
 63.1069 +        }
 63.1070 +
 63.1071 +        return true;
 63.1072 +    }
 63.1073 +
 63.1074 +    private Token hexEscapeSequence() {
 63.1075 +        final Token token = new Token(Token.Type.HEX_ESCAPESEQUENCE);
 63.1076 +        if (scanEscapeSequence('x', 2, token)) {
 63.1077 +            return token;
 63.1078 +        }
 63.1079 +        return null;
 63.1080 +    }
 63.1081 +
 63.1082 +    private Token unicodeEscapeSequence() {
 63.1083 +        final Token token = new Token(Token.Type.UNICODE_ESCAPESEQUENCE);
 63.1084 +        if (scanEscapeSequence('u', 4, token)) {
 63.1085 +            return token;
 63.1086 +        }
 63.1087 +        return null;
 63.1088 +    }
 63.1089 +
 63.1090 +    /*
 63.1091 +     * ControlEscape ::
 63.1092 +     *      one of fnrtv
 63.1093 +     */
 63.1094 +    private Token controlEscape() {
 63.1095 +        switch (ch0) {
 63.1096 +        case 'f':
 63.1097 +        case 'n':
 63.1098 +        case 'r':
 63.1099 +        case 't':
 63.1100 +        case 'v':
 63.1101 +            return commit(new Token(Token.Type.CONTROL_ESCAPE), 1);
 63.1102 +
 63.1103 +        default:
 63.1104 +            return null;
 63.1105 +        }
 63.1106 +    }
 63.1107 +
 63.1108 +    /*
 63.1109 +     * ControlLetter ::
 63.1110 +     *      one of abcdefghijklmnopqrstuvwxyz
 63.1111 +     *      ABCDEFGHIJKLMNOPQRSTUVWXYZ
 63.1112 +     */
 63.1113 +    private Token controlLetter() {
 63.1114 +        final char c = Character.toUpperCase(ch0);
 63.1115 +        if (c >= 'A' && c <= 'Z') {
 63.1116 +            final Token token = new Token(Token.Type.CONTROL_LETTER);
 63.1117 +            commit(token, 1);
 63.1118 +            return token;
 63.1119 +        }
 63.1120 +        return null;
 63.1121 +        /*
 63.1122 +        Token token = new Token(Token.Type.CONTROL_LETTER);
 63.1123 +        commit(null, 1);//add original char to builder not to token
 63.1124 +        this.neverMatches = c < 'A' || c > 'Z';
 63.1125 +        return token.add(""+c);*/
 63.1126 +    }
 63.1127 +
 63.1128 +    /*
 63.1129 +     * IdentityEscape ::
 63.1130 +     *      SourceCharacter but not IdentifierPart
 63.1131 +     *      <ZWJ>  (200c)
 63.1132 +     *      <ZWNJ> (200d)
 63.1133 +     */
 63.1134 +    private Token identityEscape() {
 63.1135 +        final Token token = new Token(Token.Type.IDENTITY_ESCAPE);
 63.1136 +        commit(token, 1);
 63.1137 +        return token;
 63.1138 +    }
 63.1139 +
 63.1140 +    /*
 63.1141 +     * DecimalEscape ::
 63.1142 +     *      DecimalIntegerLiteral [lookahead DecimalDigit]
 63.1143 +     */
 63.1144 +    private Token decimalEscape() {
 63.1145 +        final Token token = new Token(Token.Type.DECIMAL_ESCAPE);
 63.1146 +        final int startIn  = position;
 63.1147 +        final int startOut = sb.length();
 63.1148 +
 63.1149 +        if (ch0 == '0' && !isDecimalDigit(ch1)) {
 63.1150 +            commit(token, 1);
 63.1151 +            token.removeLast();
 63.1152 +            //  DecimalEscape :: 0. If i is zero, return the EscapeValue consisting of a <NUL> character (Unicodevalue0000);
 63.1153 +            return token.add("\u0000");
 63.1154 +        }
 63.1155 +
 63.1156 +        if (isDecimalDigit(ch0)) {
 63.1157 +            while (isDecimalDigit(ch0)) {
 63.1158 +                commit(token, 1);
 63.1159 +            }
 63.1160 +            return token;
 63.1161 +        }
 63.1162 +
 63.1163 +        restart(startIn, startOut);
 63.1164 +
 63.1165 +        return null;
 63.1166 +    }
 63.1167 +
 63.1168 +    /*
 63.1169 +     * CharacterClassEscape ::
 63.1170 +     *  one of dDsSwW
 63.1171 +     */
 63.1172 +    private Token characterClassEscape() {
 63.1173 +        switch (ch0) {
 63.1174 +        case 's':
 63.1175 +        case 'S':
 63.1176 +        case 'd':
 63.1177 +        case 'D':
 63.1178 +        case 'w':
 63.1179 +        case 'W':
 63.1180 +            return commit(new Token(Token.Type.CHARACTERCLASS_ESCAPE), 1);
 63.1181 +
 63.1182 +        default:
 63.1183 +            return null;
 63.1184 +        }
 63.1185 +    }
 63.1186 +
 63.1187 +    /*
 63.1188 +     * CharacterClass ::
 63.1189 +     *      [ [lookahead {^}] ClassRanges ]
 63.1190 +     *      [ ^ ClassRanges ]
 63.1191 +     */
 63.1192 +    private Token characterClass() {
 63.1193 +        final int startIn  = position;
 63.1194 +        final int startOut = sb.length();
 63.1195 +        final Token token  = new Token(Token.Type.CHARACTERCLASS);
 63.1196 +
 63.1197 +        if (ch0 == '[') {
 63.1198 +            push(']');
 63.1199 +            commit(token, 1);
 63.1200 +
 63.1201 +            if (ch0 == '^') {
 63.1202 +                commit(token, 1);
 63.1203 +            }
 63.1204 +
 63.1205 +            final Token child = classRanges();
 63.1206 +            if (child != null && ch0 == ']') {
 63.1207 +                pop(']');
 63.1208 +                token.add(child);
 63.1209 +                return commit(token, 1);
 63.1210 +            }
 63.1211 +        }
 63.1212 +
 63.1213 +        restart(startIn, startOut);
 63.1214 +        return null;
 63.1215 +    }
 63.1216 +
 63.1217 +    /*
 63.1218 +     * ClassRanges ::
 63.1219 +     *      [empty]
 63.1220 +     *      NonemptyClassRanges
 63.1221 +     */
 63.1222 +    private Token classRanges() {
 63.1223 +        return new Token(Token.Type.CLASSRANGES).add(nonemptyClassRanges());
 63.1224 +    }
 63.1225 +
 63.1226 +    /*
 63.1227 +     * NonemptyClassRanges ::
 63.1228 +     *      ClassAtom
 63.1229 +     *      ClassAtom NonemptyClassRangesNoDash
 63.1230 +     *      ClassAtom - ClassAtom ClassRanges
 63.1231 +     */
 63.1232 +    private Token nonemptyClassRanges() {
 63.1233 +        final int startIn  = position;
 63.1234 +        final int startOut = sb.length();
 63.1235 +        final Token token  = new Token(Token.Type.NON_EMPTY_CLASSRANGES);
 63.1236 +        Token child;
 63.1237 +
 63.1238 +        child = classAtom();
 63.1239 +        if (child != null) {
 63.1240 +            token.add(child);
 63.1241 +
 63.1242 +            if (ch0 == '-') {
 63.1243 +                commit(token, 1);
 63.1244 +
 63.1245 +                final Token child1 = classAtom();
 63.1246 +                final Token child2 = classRanges();
 63.1247 +                if (child1 != null && child2 != null) {
 63.1248 +                    token.add(child1);
 63.1249 +                    token.add(child2);
 63.1250 +
 63.1251 +                    return token;
 63.1252 +                }
 63.1253 +            }
 63.1254 +
 63.1255 +            child = nonemptyClassRangesNoDash();
 63.1256 +            if (child != null) {
 63.1257 +                token.add(child);
 63.1258 +                return token;
 63.1259 +            }
 63.1260 +
 63.1261 +            return token;
 63.1262 +        }
 63.1263 +
 63.1264 +        restart(startIn, startOut);
 63.1265 +        return null;
 63.1266 +    }
 63.1267 +
 63.1268 +    /*
 63.1269 +     * NonemptyClassRangesNoDash ::
 63.1270 +     *      ClassAtom
 63.1271 +     *      ClassAtomNoDash NonemptyClassRangesNoDash
 63.1272 +     *      ClassAtomNoDash - ClassAtom ClassRanges
 63.1273 +     */
 63.1274 +    private Token nonemptyClassRangesNoDash() {
 63.1275 +        final int startIn  = position;
 63.1276 +        final int startOut = sb.length();
 63.1277 +        final Token token  = new Token(Token.Type.NON_EMPTY_CLASSRANGES_NODASH);
 63.1278 +        Token child;
 63.1279 +
 63.1280 +        child = classAtomNoDash();
 63.1281 +        if (child != null) {
 63.1282 +            token.add(child);
 63.1283 +
 63.1284 +            // need to check dash first, as for e.g. [a-b|c-d] will otherwise parse - as an atom
 63.1285 +            if (ch0 == '-') {
 63.1286 +               commit(token, 1);
 63.1287 +
 63.1288 +               final Token child1 = classAtom();
 63.1289 +               final Token child2 = classRanges();
 63.1290 +               if (child1 != null && child2 != null) {
 63.1291 +                   token.add(child1);
 63.1292 +                   return token.add(child2);
 63.1293 +               }
 63.1294 +               //fallthru
 63.1295 +           }
 63.1296 +
 63.1297 +            child = nonemptyClassRangesNoDash();
 63.1298 +            if (child != null) {
 63.1299 +                token.add(child);
 63.1300 +            }
 63.1301 +            return token; // still a class atom
 63.1302 +        }
 63.1303 +
 63.1304 +        child = classAtom();
 63.1305 +        if (child != null) {
 63.1306 +            return token.add(child);
 63.1307 +        }
 63.1308 +
 63.1309 +        restart(startIn, startOut);
 63.1310 +        return null;
 63.1311 +    }
 63.1312 +
 63.1313 +    /*
 63.1314 +     * ClassAtom : - ClassAtomNoDash
 63.1315 +     */
 63.1316 +    private Token classAtom() {
 63.1317 +        final Token token = new Token(Token.Type.CLASSATOM);
 63.1318 +
 63.1319 +        if (ch0 == '-') {
 63.1320 +            return commit(token, 1);
 63.1321 +        }
 63.1322 +
 63.1323 +        final Token child = classAtomNoDash();
 63.1324 +        if (child != null) {
 63.1325 +            return token.add(child);
 63.1326 +        }
 63.1327 +
 63.1328 +        return null;
 63.1329 +    }
 63.1330 +
 63.1331 +    /*
 63.1332 +     * ClassAtomNoDash ::
 63.1333 +     *      SourceCharacter but not one of \ or ] or -
 63.1334 +     *      \ ClassEscape
 63.1335 +     */
 63.1336 +    private Token classAtomNoDash() {
 63.1337 +        final int startIn  = position;
 63.1338 +        final int startOut = sb.length();
 63.1339 +        final Token token  = new Token(Token.Type.CLASSATOM_NODASH);
 63.1340 +
 63.1341 +        switch (ch0) {
 63.1342 +        case ']':
 63.1343 +        case '-':
 63.1344 +        case '\0':
 63.1345 +            return null;
 63.1346 +
 63.1347 +        case '[':
 63.1348 +            // unescaped left square bracket - add escape
 63.1349 +            return commit(token.add("\\"), 1);
 63.1350 +
 63.1351 +        case '\\':
 63.1352 +            commit(token, 1);
 63.1353 +            final Token child = classEscape();
 63.1354 +            if (child != null) {
 63.1355 +                return token.add(child);
 63.1356 +            }
 63.1357 +
 63.1358 +            restart(startIn, startOut);
 63.1359 +            return null;
 63.1360 +
 63.1361 +        default:
 63.1362 +            return commit(token, 1);
 63.1363 +        }
 63.1364 +    }
 63.1365 +
 63.1366 +    /*
 63.1367 +     * ClassEscape ::
 63.1368 +     *      DecimalEscape
 63.1369 +     *      b
 63.1370 +     *      CharacterEscape
 63.1371 +     *      CharacterClassEscape
 63.1372 +     */
 63.1373 +    private Token classEscape() {
 63.1374 +        final Token token = new Token(Token.Type.CLASS_ESCAPE);
 63.1375 +        Token child;
 63.1376 +
 63.1377 +        child = decimalEscape();
 63.1378 +        if (child != null) {
 63.1379 +            return token.add(child);
 63.1380 +        }
 63.1381 +
 63.1382 +        if (ch0 == 'b') {
 63.1383 +            return commit(token, 1);
 63.1384 +        }
 63.1385 +
 63.1386 +        child = characterEscape();
 63.1387 +        if (child != null) {
 63.1388 +            return token.add(child);
 63.1389 +        }
 63.1390 +
 63.1391 +        child = characterClassEscape();
 63.1392 +        if (child != null) {
 63.1393 +            return token.add(child);
 63.1394 +        }
 63.1395 +
 63.1396 +        return null;
 63.1397 +    }
 63.1398 +
 63.1399 +    /*
 63.1400 +     * DecimalDigits
 63.1401 +     */
 63.1402 +    private Token decimalDigits() {
 63.1403 +        if (!isDecimalDigit(ch0)) {
 63.1404 +            return null;
 63.1405 +        }
 63.1406 +
 63.1407 +        final Token token = new Token(Token.Type.DECIMALDIGITS);
 63.1408 +        while (isDecimalDigit(ch0)) {
 63.1409 +            commit(token, 1);
 63.1410 +        }
 63.1411 +
 63.1412 +        return token;
 63.1413 +    }
 63.1414 +
 63.1415 +    private static boolean isDecimalDigit(final char ch) {
 63.1416 +        return ch >= '0' && ch <= '9';
 63.1417 +    }
 63.1418 +}
    64.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java	Sat Feb 09 16:58:48 2013 +0100
    64.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java	Mon Feb 11 21:26:06 2013 +0530
    64.3 @@ -377,7 +377,7 @@
    64.4       * @param args other arguments (beside self) to bind the function to
    64.5       * @return the bound function
    64.6       */
    64.7 -    public abstract ScriptFunction makeBoundFunction(Object self, Object[] args);
    64.8 +    protected abstract ScriptFunction makeBoundFunction(Object self, Object[] args);
    64.9  
   64.10  
   64.11      @Override
    65.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java	Sat Feb 09 16:58:48 2013 +0100
    65.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java	Mon Feb 11 21:26:06 2013 +0530
    65.3 @@ -38,7 +38,7 @@
    65.4   * Instances of this class are created during codegen and stored in script classes'
    65.5   * constants array to reduce function instantiation overhead during runtime.
    65.6   */
    65.7 -public class ScriptFunctionData {
    65.8 +public final class ScriptFunctionData {
    65.9  
   65.10      // per-function object flags
   65.11      private static final int IS_STRICT  = 0b0000_0001;
    66.1 --- a/src/jdk/nashorn/internal/runtime/ScriptLoader.java	Sat Feb 09 16:58:48 2013 +0100
    66.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptLoader.java	Mon Feb 11 21:26:06 2013 +0530
    66.3 @@ -28,34 +28,17 @@
    66.4  import java.security.CodeSource;
    66.5  
    66.6  /**
    66.7 - * Responsible for loading generated and disk based classes.
    66.8 + * Responsible for loading script generated classes.
    66.9   *
   66.10   */
   66.11  final class ScriptLoader extends NashornLoader {
   66.12      /**
   66.13       * Constructor.
   66.14       */
   66.15 -    ScriptLoader(final ClassLoader parent, final Context context) {
   66.16 +    ScriptLoader(final StructureLoader parent, final Context context) {
   66.17          super(parent, context);
   66.18      }
   66.19  
   66.20 -    @Override
   66.21 -    protected synchronized Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
   66.22 -        checkPackageAccess(name);
   66.23 -
   66.24 -        // check the cache first
   66.25 -        Class<?> cl = findLoadedClass(name);
   66.26 -        if (cl == null) {
   66.27 -            cl = getParent().loadClass(name);
   66.28 -        }
   66.29 -
   66.30 -        if (resolve) {
   66.31 -            resolveClass(cl);
   66.32 -        }
   66.33 -
   66.34 -        return cl;
   66.35 -    }
   66.36 -
   66.37      // package-private and private stuff below this point
   66.38  
   66.39      /**
    67.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Sat Feb 09 16:58:48 2013 +0100
    67.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Mon Feb 11 21:26:06 2013 +0530
    67.3 @@ -1053,7 +1053,7 @@
    67.4       * Return the current context from the object's map.
    67.5       * @return Current context.
    67.6       */
    67.7 -    protected final Context getContext() {
    67.8 +    final Context getContext() {
    67.9          return getMap().getContext();
   67.10      }
   67.11  
    68.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Sat Feb 09 16:58:48 2013 +0100
    68.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Mon Feb 11 21:26:06 2013 +0530
    68.3 @@ -36,8 +36,11 @@
    68.4  import java.lang.reflect.Array;
    68.5  import java.util.Collections;
    68.6  import java.util.Iterator;
    68.7 +import java.util.NoSuchElementException;
    68.8  import java.util.Objects;
    68.9  import jdk.nashorn.internal.codegen.CompilerConstants.Call;
   68.10 +import jdk.nashorn.internal.ir.debug.JSONWriter;
   68.11 +import jdk.nashorn.internal.parser.Lexer;
   68.12  import jdk.nashorn.internal.runtime.linker.Bootstrap;
   68.13  import org.dynalang.dynalink.beans.StaticClass;
   68.14  
   68.15 @@ -265,6 +268,9 @@
   68.16  
   68.17                  @Override
   68.18                  public Object next() {
   68.19 +                    if (index >= length) {
   68.20 +                        throw new NoSuchElementException();
   68.21 +                    }
   68.22                      return Array.get(array, index++);
   68.23                  }
   68.24  
   68.25 @@ -377,6 +383,28 @@
   68.26      }
   68.27  
   68.28      /**
   68.29 +     * Returns AST as JSON compatible string. This is used to
   68.30 +     * implement "parse" function in resources/parse.js script.
   68.31 +     *
   68.32 +     * @param code code to be parsed
   68.33 +     * @param name name of the code source (used for location)
   68.34 +     * @param includeLoc tells whether to include location information for nodes or not
   68.35 +     * @return JSON string representation of AST of the supplied code
   68.36 +     */
   68.37 +    public static String parse(final String code, final String name, final boolean includeLoc) {
   68.38 +        return JSONWriter.parse(Context.getContextTrusted(), code, name, includeLoc);
   68.39 +    }
   68.40 +
   68.41 +    /**
   68.42 +     * Test whether a char is valid JavaScript whitespace
   68.43 +     * @param ch a char
   68.44 +     * @return true if valid JavaScript whitespace
   68.45 +     */
   68.46 +    public static boolean isJSWhitespace(final char ch) {
   68.47 +        return Lexer.isJSWhitespace(ch);
   68.48 +    }
   68.49 +
   68.50 +    /**
   68.51       * Entering a {@code with} node requires new scope. This is the implementation
   68.52       *
   68.53       * @param scope      existing scope
    69.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Sat Feb 09 16:58:48 2013 +0100
    69.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Mon Feb 11 21:26:06 2013 +0530
    69.3 @@ -37,15 +37,13 @@
    69.4  import java.io.OutputStream;
    69.5  import java.lang.invoke.MethodHandle;
    69.6  import java.lang.invoke.MethodHandles;
    69.7 -import java.util.HashMap;
    69.8  import java.util.Map;
    69.9 -import java.util.Set;
   69.10  import java.util.StringTokenizer;
   69.11  
   69.12  /**
   69.13   * Global functions supported only in scripting mode.
   69.14   */
   69.15 -public class ScriptingFunctions {
   69.16 +public final class ScriptingFunctions {
   69.17  
   69.18      /** Handle to implementation of {@link ScriptingFunctions#readLine} - Nashorn extension */
   69.19      public static final MethodHandle READLINE = findOwnMH("readLine", Object.class, Object.class);
    70.1 --- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java	Sat Feb 09 16:58:48 2013 +0100
    70.2 +++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java	Mon Feb 11 21:26:06 2013 +0530
    70.3 @@ -43,7 +43,7 @@
    70.4   * {@link ScriptObject#findSetMethod(CallSiteDescriptor, org.dynalang.dynalink.linker.LinkRequest)} and
    70.5   * serve as the actual encapsulation of the algorithm for creating an appropriate property setter method.
    70.6   */
    70.7 -class SetMethodCreator {
    70.8 +final class SetMethodCreator {
    70.9      // See constructor parameters for description of fields
   70.10      private final ScriptObject sobj;
   70.11      private final PropertyMap map;
    71.1 --- a/src/jdk/nashorn/internal/runtime/StructureLoader.java	Sat Feb 09 16:58:48 2013 +0100
    71.2 +++ b/src/jdk/nashorn/internal/runtime/StructureLoader.java	Mon Feb 11 21:26:06 2013 +0530
    71.3 @@ -104,7 +104,7 @@
    71.4              }
    71.5          }
    71.6  
    71.7 -        return super.loadClass(name, resolve);
    71.8 +        return super.loadClassTrusted(name, resolve);
    71.9      }
   71.10  
   71.11  
   71.12 @@ -117,8 +117,6 @@
   71.13          return super.findClass(name);
   71.14      }
   71.15  
   71.16 -    private static final boolean IS_JAVA_7 = System.getProperty("java.version").indexOf("1.7") != -1;
   71.17 -
   71.18      /**
   71.19       * Generate a layout class.
   71.20       * @param name       Name of class.
   71.21 @@ -133,13 +131,6 @@
   71.22          }
   71.23  
   71.24          final byte[] code = new ObjectClassGenerator(context).generate(descriptor);
   71.25 -
   71.26 -        try {
   71.27 -            return IS_JAVA_7 ? sun.misc.Unsafe.getUnsafe().defineClass(name, code, 0, code.length) : defineClass(name, code, 0, code.length);
   71.28 -        } catch (final SecurityException e) {
   71.29 -            throw new AssertionError("Nashorn needs to run in the bootclasspath when using Java7, or the NoClassDefFoundError bug in Java7 will trigger." +
   71.30 -                                     "(This may not be enough - it has been known to happen anyway. Please use Java8)");
   71.31 -        }
   71.32 -
   71.33 +        return defineClass(name, code, 0, code.length);
   71.34      }
   71.35  }
    72.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java	Sat Feb 09 16:58:48 2013 +0100
    72.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java	Mon Feb 11 21:26:06 2013 +0530
    72.3 @@ -40,7 +40,7 @@
    72.4   * This class supports the handling of scope in a with body.
    72.5   *
    72.6   */
    72.7 -public class WithObject extends ScriptObject implements Scope {
    72.8 +public final class WithObject extends ScriptObject implements Scope {
    72.9  
   72.10      private static final MethodHandle WITHEXPRESSIONFILTER = findOwnMH("withFilterExpression", Object.class, Object.class);
   72.11      private static final MethodHandle WITHSCOPEFILTER      = findOwnMH("withFilterScope",      Object.class, Object.class);
    73.1 --- a/src/jdk/nashorn/internal/runtime/arrays/EmptyArrayLikeIterator.java	Sat Feb 09 16:58:48 2013 +0100
    73.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/EmptyArrayLikeIterator.java	Mon Feb 11 21:26:06 2013 +0530
    73.3 @@ -25,6 +25,8 @@
    73.4  
    73.5  package jdk.nashorn.internal.runtime.arrays;
    73.6  
    73.7 +import java.util.NoSuchElementException;
    73.8 +
    73.9  /**
   73.10   * Dummy array iterator that has no elements
   73.11   */
   73.12 @@ -41,7 +43,7 @@
   73.13  
   73.14      @Override
   73.15      public Object next() {
   73.16 -        return null;
   73.17 +        throw new NoSuchElementException();
   73.18      }
   73.19  
   73.20      @Override
    74.1 --- a/src/jdk/nashorn/internal/runtime/arrays/MapIterator.java	Sat Feb 09 16:58:48 2013 +0100
    74.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/MapIterator.java	Mon Feb 11 21:26:06 2013 +0530
    74.3 @@ -25,6 +25,7 @@
    74.4  
    74.5  package jdk.nashorn.internal.runtime.arrays;
    74.6  
    74.7 +import java.util.NoSuchElementException;
    74.8  import jdk.nashorn.internal.runtime.JSType;
    74.9  import jdk.nashorn.internal.runtime.ScriptObject;
   74.10  
   74.11 @@ -71,6 +72,10 @@
   74.12  
   74.13      @Override
   74.14      public Object next() {
   74.15 -        return indexInArray() ? obj.get(bumpIndex()) : null;
   74.16 +        if (indexInArray()) {
   74.17 +            return obj.get(bumpIndex());
   74.18 +        }
   74.19 +
   74.20 +        throw new NoSuchElementException();
   74.21      }
   74.22  }
    75.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Sat Feb 09 16:58:48 2013 +0100
    75.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Mon Feb 11 21:26:06 2013 +0530
    75.3 @@ -29,9 +29,11 @@
    75.4  
    75.5  import java.lang.invoke.CallSite;
    75.6  import java.lang.invoke.MethodHandle;
    75.7 +import java.lang.invoke.MethodHandles;
    75.8  import java.lang.invoke.MethodHandles.Lookup;
    75.9  import java.lang.invoke.MethodType;
   75.10  import jdk.nashorn.internal.codegen.CompilerConstants.Call;
   75.11 +import jdk.nashorn.internal.codegen.RuntimeCallSite;
   75.12  import jdk.nashorn.internal.runtime.options.Options;
   75.13  import org.dynalang.dynalink.CallSiteDescriptor;
   75.14  import org.dynalang.dynalink.DynamicLinker;
   75.15 @@ -80,6 +82,20 @@
   75.16      }
   75.17  
   75.18      /**
   75.19 +     * Bootstrapper for a specialized Runtime call
   75.20 +     *
   75.21 +     * @param lookup       lookup
   75.22 +     * @param initialName  initial name for callsite
   75.23 +     * @param type         method type for call site
   75.24 +     *
   75.25 +     * @return callsite for a runtime node
   75.26 +     */
   75.27 +    public static CallSite runtimeBootstrap(final MethodHandles.Lookup lookup, final String initialName, final MethodType type) {
   75.28 +        return new RuntimeCallSite(type, initialName);
   75.29 +    }
   75.30 +
   75.31 +
   75.32 +    /**
   75.33       * Returns a dynamic invoker for a specified dynamic operation. You can use this method to create a method handle
   75.34       * that when invoked acts completely as if it were a Nashorn-linked call site. An overview of available dynamic
   75.35       * operations can be found in the <a href="https://github.com/szegedi/dynalink/wiki/User-Guide-0.4">Dynalink User Guide</a>,
    76.1 --- a/src/jdk/nashorn/internal/runtime/resources/parser.js	Sat Feb 09 16:58:48 2013 +0100
    76.2 +++ b/src/jdk/nashorn/internal/runtime/resources/parser.js	Mon Feb 11 21:26:06 2013 +0530
    76.3 @@ -47,7 +47,7 @@
    76.4              code = arguments[0];
    76.5      }
    76.6  
    76.7 -    var jsonStr = Packages.jdk.nashorn.internal.ir.debug.JSONWriter.parse(code, name, location);
    76.8 +    var jsonStr = Packages.jdk.nashorn.internal.runtime.ScriptRuntime.parse(code, name, location);
    76.9      return JSON.parse(jsonStr,
   76.10          function (prop, value) {
   76.11              if (typeof(value) == 'string' && prop == "value") {
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/test/script/sandbox/nashorninternals.js	Mon Feb 11 21:26:06 2013 +0530
    77.3 @@ -0,0 +1,57 @@
    77.4 +/*
    77.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    77.7 + * 
    77.8 + * This code is free software; you can redistribute it and/or modify it
    77.9 + * under the terms of the GNU General Public License version 2 only, as
   77.10 + * published by the Free Software Foundation.
   77.11 + * 
   77.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   77.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   77.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   77.15 + * version 2 for more details (a copy is included in the LICENSE file that
   77.16 + * accompanied this code).
   77.17 + * 
   77.18 + * You should have received a copy of the GNU General Public License version
   77.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   77.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   77.21 + * 
   77.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   77.23 + * or visit www.oracle.com if you need additional information or have any
   77.24 + * questions.
   77.25 + */
   77.26 +
   77.27 +
   77.28 +/**
   77.29 + * Test to check that nashorn "internal" classes in codegen, parser, ir 
   77.30 + * packages cannot * be accessed from sandbox scripts.
   77.31 + *
   77.32 + * @test
   77.33 + * @run
   77.34 + * @security
   77.35 + */
   77.36 +
   77.37 +function checkClass(name) {
   77.38 +    try {
   77.39 +        Java.type(name);
   77.40 +        fail("should have thrown exception for: " + name);
   77.41 +    } catch (e) {
   77.42 +        if (! (e instanceof java.lang.SecurityException)) {
   77.43 +            fail("Expected SecurityException, but got " + e);
   77.44 +        }
   77.45 +    }
   77.46 +}
   77.47 +
   77.48 +// Not exhaustive - but a representative list of classes
   77.49 +checkClass("jdk.nashorn.internal.codegen.Compiler");
   77.50 +checkClass("jdk.nashorn.internal.codegen.objects.MapCreator");
   77.51 +checkClass("jdk.nashorn.internal.codegen.types.Type");
   77.52 +checkClass("jdk.nashorn.internal.ir.Node");
   77.53 +checkClass("jdk.nashorn.internal.ir.FunctionNode");
   77.54 +checkClass("jdk.nashorn.internal.ir.debug.JSONWriter");
   77.55 +checkClass("jdk.nashorn.internal.ir.visitor.NodeVisitor");
   77.56 +checkClass("jdk.nashorn.internal.parser.AbstractParser");
   77.57 +checkClass("jdk.nashorn.internal.parser.Parser");
   77.58 +checkClass("jdk.nashorn.internal.parser.JSONParser");
   77.59 +checkClass("jdk.nashorn.internal.parser.Lexer");
   77.60 +checkClass("jdk.nashorn.internal.parser.Scanner");
    78.1 --- a/test/script/trusted/JDK-8006529.js	Sat Feb 09 16:58:48 2013 +0100
    78.2 +++ b/test/script/trusted/JDK-8006529.js	Mon Feb 11 21:26:06 2013 +0530
    78.3 @@ -29,23 +29,74 @@
    78.4   * @run
    78.5   */
    78.6  
    78.7 +/*
    78.8 + * This test script depends on nashorn Compiler internals. It uses reflection
    78.9 + * to get access to private field and many public methods of Compiler and
   78.10 + * FunctionNode classes. Note that this is trusted code and access to such
   78.11 + * internal package classes and methods is okay. But, if you modify any 
   78.12 + * Compiler or FunctionNode class, you may have to revisit this script.
   78.13 + * We cannot use direct Java class (via dynalink bean linker) to Compiler
   78.14 + * and FunctionNode because of package-access check and so reflective calls.
   78.15 + */
   78.16 +
   78.17 +var Compiler       = Java.type("jdk.nashorn.internal.codegen.Compiler")
   78.18 +var Context        = Java.type("jdk.nashorn.internal.runtime.Context")
   78.19 +var Source         = Java.type("jdk.nashorn.internal.runtime.Source")
   78.20 +var FunctionNode   = Java.type("jdk.nashorn.internal.ir.FunctionNode")
   78.21 +
   78.22 +// Compiler class methods and fields
   78.23 +
   78.24 +// Compiler.compile(Source, Context)
   78.25 +var compilerMethod = Compiler.class.getMethod("compiler", Source.class, Context.class);
   78.26 +// Compiler.compile()
   78.27 +var compileMethod  = Compiler.class.getMethod("compile");
   78.28 +
   78.29 +// NOTE: private field. But this is a trusted test!
   78.30 +// Compiler.functionNode
   78.31 +var functionNodeField = Compiler.class.getDeclaredField("functionNode");
   78.32 +functionNodeField.setAccessible(true);
   78.33 +
   78.34 +// FunctionNode methods
   78.35 +
   78.36 +// FunctionNode.getFunctions method
   78.37 +var getFunctionsMethod = FunctionNode.class.getMethod("getFunctions");
   78.38 +
   78.39 +// These are method names of methods in FunctionNode class
   78.40 +var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'varsInScope', 'isStrictMode']
   78.41 +
   78.42 +// corresponding Method objects of FunctionNode class
   78.43 +var functionNodeMethods = {};
   78.44 +// initialize FunctionNode methods
   78.45 +(function() {
   78.46 +    for (var f in allAssertionList) {
   78.47 +        var method = allAssertionList[f];
   78.48 +        functionNodeMethods[method] = FunctionNode.class.getMethod(method);
   78.49 +    }
   78.50 +})();
   78.51 +
   78.52 +// returns "script" functionNode from Compiler instance
   78.53 +function getScriptNode(compiler) {
   78.54 +    // compiler.functionNode
   78.55 +    return functionNodeField.get(compiler);
   78.56 +}
   78.57 +
   78.58 +// returns functionNode.getFunctions().get(0)
   78.59 +function getFirstFunction(functionNode) {
   78.60 +    // functionNode.getFunctions().get(0)
   78.61 +    return getFunctionsMethod.invoke(functionNode).get(0);
   78.62 +}
   78.63 +
   78.64  // compile(script) -- compiles a script specified as a string with its 
   78.65  // source code, returns a jdk.nashorn.internal.ir.FunctionNode object 
   78.66  // representing it.
   78.67 -var compile = (function() {
   78.68 -    var Compiler       = Java.type("jdk.nashorn.internal.codegen.Compiler")
   78.69 -    var Context        = Java.type("jdk.nashorn.internal.runtime.Context")
   78.70 -    var Source         = Java.type("jdk.nashorn.internal.runtime.Source")
   78.71 -    var CompilerAccess = Java.type("jdk.nashorn.internal.codegen.CompilerAccess")
   78.72 -    return function(source) {
   78.73 -	    var compiler = Compiler.compiler(new Source("<no name>", source), Context.getContext())
   78.74 -        compiler.compile()
   78.75 -        return CompilerAccess.getScriptNode(compiler)
   78.76 -    }
   78.77 -})();
   78.78 +function compile(source) {
   78.79 +   var compiler = compilerMethod.invoke(null,
   78.80 +       new Source("<no name>", source), Context.getContext())
   78.81 +   compileMethod.invoke(compiler);
   78.82 +   return getScriptNode(compiler)
   78.83 +};
   78.84  
   78.85  var allAssertions = (function() {
   78.86 -    var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'varsInScope', 'isStrictMode']
   78.87      var allAssertions = {}
   78.88      for(var assertion in allAssertionList) {
   78.89          allAssertions[allAssertionList[assertion]] = true
   78.90 @@ -53,6 +104,7 @@
   78.91      return allAssertions;
   78.92  })();
   78.93  
   78.94 +
   78.95  // test(f[, assertions...]) tests whether all the specified assertions on the
   78.96  // passed function node are true.
   78.97  function test(f) {
   78.98 @@ -66,10 +118,7 @@
   78.99      }
  78.100      for(var assertion in allAssertions) {
  78.101          var expectedValue = !!assertions[assertion]
  78.102 -        if(f[assertion] == null) {
  78.103 -            throw "Can't find " + assertion + " on " + f;
  78.104 -        }
  78.105 -        if(f[assertion]() !== expectedValue) {
  78.106 +        if(functionNodeMethods[assertion].invoke(f) !== expectedValue) {
  78.107              throw "Expected " + assertion + " === " + expectedValue + " for " + f;
  78.108          }
  78.109      }
  78.110 @@ -79,7 +128,7 @@
  78.111  // assertions are true in the first function in the given script; "script"
  78.112  // is a string with the source text of the script.
  78.113  function testFirstFn(script) {
  78.114 -    arguments[0] = compile(script).functions[0]
  78.115 +    arguments[0] = getFirstFunction(compile(script))
  78.116      test.apply(null, arguments)
  78.117  }
  78.118  
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java	Mon Feb 11 21:26:06 2013 +0530
    79.3 @@ -0,0 +1,206 @@
    79.4 +/*
    79.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    79.7 + *
    79.8 + * This code is free software; you can redistribute it and/or modify it
    79.9 + * under the terms of the GNU General Public License version 2 only, as
   79.10 + * published by the Free Software Foundation.  Oracle designates this
   79.11 + * particular file as subject to the "Classpath" exception as provided
   79.12 + * by Oracle in the LICENSE file that accompanied this code.
   79.13 + *
   79.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   79.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   79.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   79.17 + * version 2 for more details (a copy is included in the LICENSE file that
   79.18 + * accompanied this code).
   79.19 + *
   79.20 + * You should have received a copy of the GNU General Public License version
   79.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   79.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   79.23 + *
   79.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   79.25 + * or visit www.oracle.com if you need additional information or have any
   79.26 + * questions.
   79.27 + */
   79.28 +
   79.29 +package jdk.nashorn.api.javaaccess;
   79.30 +
   79.31 +import static org.testng.AssertJUnit.assertEquals;
   79.32 +import static org.testng.AssertJUnit.assertTrue;
   79.33 +
   79.34 +import java.util.Arrays;
   79.35 +import javax.script.ScriptEngine;
   79.36 +import javax.script.ScriptEngineManager;
   79.37 +import javax.script.ScriptException;
   79.38 +import org.testng.TestNG;
   79.39 +import org.testng.annotations.BeforeClass;
   79.40 +import org.testng.annotations.Test;
   79.41 +
   79.42 +public class BooleanAccessTest {
   79.43 +
   79.44 +    private static ScriptEngine e = null;
   79.45 +    private static SharedObject o = new SharedObject();
   79.46 +
   79.47 +    public static void main(final String[] args) {
   79.48 +        TestNG.main(args);
   79.49 +    }
   79.50 +
   79.51 +    @BeforeClass
   79.52 +    public static void setUpClass() throws ScriptException {
   79.53 +        final ScriptEngineManager m = new ScriptEngineManager();
   79.54 +        e = m.getEngineByName("nashorn");
   79.55 +        e.put("o", o);
   79.56 +        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   79.57 +    }
   79.58 +
   79.59 +    @Test
   79.60 +    public void accessFieldBoolean() throws ScriptException {
   79.61 +        e.eval("var p_boolean = o.publicBoolean;");
   79.62 +        assertEquals(o.publicBoolean, e.get("p_boolean"));
   79.63 +        assertEquals("boolean", e.eval("typeof p_boolean;"));
   79.64 +        e.eval("o.publicBoolean = false;");
   79.65 +        assertEquals(false, o.publicBoolean);
   79.66 +    }
   79.67 +
   79.68 +    @Test
   79.69 +    public void accessFieldBooleanArray() throws ScriptException {
   79.70 +        e.eval("var p_boolean_array = o.publicBooleanArray;");
   79.71 +        assertEquals(o.publicBooleanArray[0], e.eval("o.publicBooleanArray[0]"));
   79.72 +        assertTrue(Arrays.equals(o.publicBooleanArray, (boolean[])e.get("p_boolean_array")));
   79.73 +        e.eval("var t_boolean_arr = java.lang.reflect.Array.newInstance(java.lang.Boolean.TYPE, 3);" +
   79.74 +                "t_boolean_arr[0] = true;" +
   79.75 +                "t_boolean_arr[1] = false;" +
   79.76 +                "t_boolean_arr[2] = false;" +
   79.77 +                "o.publicBooleanArray = t_boolean_arr;");
   79.78 +        assertTrue(Arrays.equals(new boolean[] { true, false, false }, o.publicBooleanArray));
   79.79 +        e.eval("o.publicBooleanArray[0] = false;");
   79.80 +        assertEquals(false, o.publicBooleanArray[0]);
   79.81 +    }
   79.82 +
   79.83 +    @Test
   79.84 +    public void accessStaticFieldBoolean() throws ScriptException {
   79.85 +        e.eval("var ps_boolean = SharedObject.publicStaticBoolean;");
   79.86 +        assertEquals(SharedObject.publicStaticBoolean, e.get("ps_boolean"));
   79.87 +        assertEquals("boolean", e.eval("typeof ps_boolean;"));
   79.88 +        e.eval("SharedObject.publicStaticBoolean = false;");
   79.89 +        assertEquals(false, SharedObject.publicStaticBoolean);
   79.90 +    }
   79.91 +
   79.92 +    @Test
   79.93 +    public void accessStaticFieldBooleanArray() throws ScriptException {
   79.94 +        e.eval("var ps_boolean_array = SharedObject.publicStaticBooleanArray;");
   79.95 +        assertEquals(SharedObject.publicStaticBooleanArray[0], e.eval("SharedObject.publicStaticBooleanArray[0]"));
   79.96 +        assertTrue(Arrays.equals(SharedObject.publicStaticBooleanArray, (boolean[])e.get("ps_boolean_array")));
   79.97 +        e.eval("var ts_boolean_arr = java.lang.reflect.Array.newInstance(java.lang.Boolean.TYPE, 3);" +
   79.98 +                "ts_boolean_arr[0] = true;" +
   79.99 +                "ts_boolean_arr[1] = false;" +
  79.100 +                "ts_boolean_arr[2] = true;" +
  79.101 +                "SharedObject.publicStaticBooleanArray = ts_boolean_arr;");
  79.102 +        assertTrue(Arrays.equals(new boolean[] { true, false, true }, SharedObject.publicStaticBooleanArray));
  79.103 +        e.eval("SharedObject.publicStaticBooleanArray[0] = false;");
  79.104 +        assertEquals(false, SharedObject.publicStaticBooleanArray[0]);
  79.105 +    }
  79.106 +
  79.107 +    @Test
  79.108 +    public void accessFinalFieldBoolean() throws ScriptException {
  79.109 +        e.eval("var pf_boolean = o.publicFinalBoolean;");
  79.110 +        assertEquals(o.publicFinalBoolean, e.get("pf_boolean"));
  79.111 +        assertEquals("boolean", e.eval("typeof pf_boolean;"));
  79.112 +        e.eval("o.publicFinalBoolean = false;");
  79.113 +        assertEquals(true, o.publicFinalBoolean);
  79.114 +    }
  79.115 +
  79.116 +    @Test
  79.117 +    public void accessFinalFieldBooleanArray() throws ScriptException {
  79.118 +        e.eval("var pf_boolean_array = o.publicFinalBooleanArray;");
  79.119 +        assertEquals(o.publicFinalBooleanArray[0], e.eval("o.publicFinalBooleanArray[0]"));
  79.120 +        assertTrue(Arrays.equals(o.publicFinalBooleanArray, (boolean[])e.get("pf_boolean_array")));
  79.121 +        e.eval("var tf_boolean_arr = java.lang.reflect.Array.newInstance(java.lang.Boolean.TYPE, 3);" +
  79.122 +                "tf_boolean_arr[0] = false;" +
  79.123 +                "tf_boolean_arr[1] = false;" +
  79.124 +                "tf_boolean_arr[2] = true;" +
  79.125 +                "o.publicOFinalbjectArray = tf_boolean_arr;");
  79.126 +        assertTrue(Arrays.equals(new boolean[] { false, false, true, false }, o.publicFinalBooleanArray));
  79.127 +        e.eval("o.publicFinalBooleanArray[0] = true;");
  79.128 +        assertEquals(true, o.publicFinalBooleanArray[0]);
  79.129 +    }
  79.130 +
  79.131 +    @Test
  79.132 +    public void accessStaticFinalFieldBoolean() throws ScriptException {
  79.133 +        e.eval("var psf_boolean = SharedObject.publicStaticFinalBoolean;");
  79.134 +        assertEquals(SharedObject.publicStaticFinalBoolean, e.get("psf_boolean"));
  79.135 +        assertEquals("boolean", e.eval("typeof psf_boolean;"));
  79.136 +        e.eval("SharedObject.publicStaticFinalBoolean = false;");
  79.137 +        assertEquals(true, SharedObject.publicStaticFinalBoolean);
  79.138 +    }
  79.139 +
  79.140 +    @Test
  79.141 +    public void accessStaticFinalFieldBooleanArray() throws ScriptException {
  79.142 +        e.eval("var psf_boolean_array = SharedObject.publicStaticFinalBooleanArray;");
  79.143 +        assertEquals(SharedObject.publicStaticFinalBooleanArray[0], e.eval("SharedObject.publicStaticFinalBooleanArray[0]"));
  79.144 +        assertTrue(Arrays.equals(SharedObject.publicStaticFinalBooleanArray, (boolean[])e.get("psf_boolean_array")));
  79.145 +        e.eval("var tsf_boolean_arr = java.lang.reflect.Array.newInstance(java.lang.Boolean.TYPE, 3);" +
  79.146 +                "tsf_boolean_arr[0] = false;" +
  79.147 +                "tsf_boolean_arr[1] = true;" +
  79.148 +                "tsf_boolean_arr[2] = false;" +
  79.149 +                "SharedObject.publicStaticFinalBooleanArray = tsf_boolean_arr;");
  79.150 +        assertTrue(Arrays.equals(new boolean[] { false, true, false, false }, SharedObject.publicStaticFinalBooleanArray));
  79.151 +        e.eval("SharedObject.publicStaticFinalBooleanArray[0] = true;");
  79.152 +        assertEquals(true, SharedObject.publicStaticFinalBooleanArray[0]);
  79.153 +    }
  79.154 +
  79.155 +    @Test
  79.156 +    public void accessFieldBooleanBoxing() throws ScriptException {
  79.157 +        e.eval("var p_boolean_box = o.publicBooleanBox;");
  79.158 +        assertEquals(o.publicBooleanBox, e.get("p_boolean_box"));
  79.159 +        assertEquals("boolean", e.eval("typeof p_boolean_box;"));
  79.160 +        e.eval("o.publicBooleanBox = false;");
  79.161 +        assertEquals(false, (boolean)o.publicBooleanBox);
  79.162 +    }
  79.163 +
  79.164 +    @Test
  79.165 +    public void accessStaticFieldBooleanBoxing() throws ScriptException {
  79.166 +        e.eval("var ps_boolean_box = SharedObject.publicStaticBooleanBox;");
  79.167 +        assertEquals(SharedObject.publicStaticBooleanBox, e.get("ps_boolean_box"));
  79.168 +        assertEquals("boolean", e.eval("typeof ps_boolean_box;"));
  79.169 +        e.eval("SharedObject.publicStaticBooleanBox = false;");
  79.170 +        assertEquals(false, (boolean)SharedObject.publicStaticBooleanBox);
  79.171 +    }
  79.172 +
  79.173 +    @Test
  79.174 +    public void accessFinalFieldBooleanBoxing() throws ScriptException {
  79.175 +        e.eval("var pf_boolean_box = o.publicFinalBooleanBox;");
  79.176 +        assertEquals(o.publicFinalBooleanBox, e.get("pf_boolean_box"));
  79.177 +        assertEquals("boolean", e.eval("typeof pf_boolean_box;"));
  79.178 +        e.eval("o.publicFinalBooleanBox = false;");
  79.179 +        assertEquals(true, (boolean)o.publicFinalBooleanBox);
  79.180 +    }
  79.181 +
  79.182 +    @Test
  79.183 +    public void accessStaticFinalFieldBooleanBoxing() throws ScriptException {
  79.184 +        e.eval("var psf_boolean_box = SharedObject.publicStaticFinalBooleanBox;");
  79.185 +        assertEquals(SharedObject.publicStaticFinalBooleanBox, e.get("psf_boolean_box"));
  79.186 +        assertEquals("boolean", e.eval("typeof psf_boolean_box;"));
  79.187 +        e.eval("SharedObject.publicStaticFinalBooleanBox = false;");
  79.188 +        assertEquals(true, (boolean)SharedObject.publicStaticFinalBooleanBox);
  79.189 +    }
  79.190 +
  79.191 +    @Test
  79.192 +    public void accessVolatileField() throws ScriptException {
  79.193 +        e.eval("var pv_boolean = o.volatileBoolean;");
  79.194 +        assertEquals(o.volatileBoolean, e.get("pv_boolean"));
  79.195 +        assertEquals("boolean", e.eval("typeof pv_boolean;"));
  79.196 +        e.eval("o.volatileBoolean = false;");
  79.197 +        assertEquals(false, o.volatileBoolean);
  79.198 +    }
  79.199 +
  79.200 +    @Test
  79.201 +    public void accessTransientField() throws ScriptException {
  79.202 +        e.eval("var pt_boolean = o.transientBoolean;");
  79.203 +        assertEquals(o.transientBoolean, e.get("pt_boolean"));
  79.204 +        assertEquals("boolean", e.eval("typeof pt_boolean;"));
  79.205 +        e.eval("o.transientBoolean = false;");
  79.206 +        assertEquals(false, o.transientBoolean);
  79.207 +    }
  79.208 +
  79.209 +}
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java	Mon Feb 11 21:26:06 2013 +0530
    80.3 @@ -0,0 +1,453 @@
    80.4 +/*
    80.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    80.7 + *
    80.8 + * This code is free software; you can redistribute it and/or modify it
    80.9 + * under the terms of the GNU General Public License version 2 only, as
   80.10 + * published by the Free Software Foundation.  Oracle designates this
   80.11 + * particular file as subject to the "Classpath" exception as provided
   80.12 + * by Oracle in the LICENSE file that accompanied this code.
   80.13 + *
   80.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   80.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   80.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   80.17 + * version 2 for more details (a copy is included in the LICENSE file that
   80.18 + * accompanied this code).
   80.19 + *
   80.20 + * You should have received a copy of the GNU General Public License version
   80.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   80.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   80.23 + *
   80.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   80.25 + * or visit www.oracle.com if you need additional information or have any
   80.26 + * questions.
   80.27 + */
   80.28 +
   80.29 +package jdk.nashorn.api.javaaccess;
   80.30 +
   80.31 +import static org.testng.AssertJUnit.assertEquals;
   80.32 +import static org.testng.AssertJUnit.assertTrue;
   80.33 +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
   80.34 +
   80.35 +import java.util.Arrays;
   80.36 +import java.util.Calendar;
   80.37 +import java.util.Locale;
   80.38 +import javax.script.ScriptEngine;
   80.39 +import javax.script.ScriptEngineManager;
   80.40 +import javax.script.ScriptException;
   80.41 +import org.testng.TestNG;
   80.42 +import org.testng.annotations.BeforeClass;
   80.43 +import org.testng.annotations.Test;
   80.44 +
   80.45 +public class MethodAccessTest {
   80.46 +
   80.47 +    private static ScriptEngine e = null;
   80.48 +    private static SharedObject o = new SharedObject();
   80.49 +
   80.50 +    public static void main(final String[] args) {
   80.51 +        TestNG.main(args);
   80.52 +    }
   80.53 +
   80.54 +    @BeforeClass
   80.55 +    public static void setUpClass() throws ScriptException {
   80.56 +        final ScriptEngineManager m = new ScriptEngineManager();
   80.57 +        e = m.getEngineByName("nashorn");
   80.58 +        o.setEngine(e);
   80.59 +        e.put("o", o);
   80.60 +        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   80.61 +        e.eval("var Person = Packages.jdk.nashorn.internal.access.Person;");
   80.62 +    }
   80.63 +
   80.64 +    @Test
   80.65 +    public void accessMethodthrowsCheckedException() throws ScriptException {
   80.66 +        e.eval("try {" +
   80.67 +                "    var a = java.lang.Long.parseLong('foo');" +
   80.68 +                "} catch(e) {" +
   80.69 +                "    var isThrown = true;" +
   80.70 +                "    var isNumberException = e instanceof java.lang.NumberFormatException;" +
   80.71 +                "} finally {" +
   80.72 +                "    var isFinalized = true;" +
   80.73 +                "}");
   80.74 +        assertEquals("Exception thrown", true, e.get("isThrown"));
   80.75 +        assertEquals("Finally called", true, e.get("isFinalized"));
   80.76 +        assertEquals("Type is NumberFormatException", true, e.get("isNumberException"));
   80.77 +    }
   80.78 +
   80.79 +    @Test
   80.80 +    public void accessMethodthrowsUnCheckedException() throws ScriptException {
   80.81 +        e.eval("try {" +
   80.82 +                "    var a = java.lang.String.valueOf(null);" +
   80.83 +                "} catch(e) {" +
   80.84 +                "    var isThrown = true;" +
   80.85 +                "    var isNumberException = e instanceof java.lang.NullPointerException;" +
   80.86 +                "} finally {" +
   80.87 +                "    var isFinalized = true;" +
   80.88 +                "}");
   80.89 +        assertEquals(true, e.get("isThrown"));
   80.90 +        assertEquals(true, e.get("isFinalized"));
   80.91 +        assertEquals(true, e.get("isNumberException"));
   80.92 +    }
   80.93 +
   80.94 +    @Test
   80.95 +    public void accessMethodStartsThread() throws ScriptException {
   80.96 +        e.eval("o.methodStartsThread();");
   80.97 +        assertEquals(false, o.isFinished);
   80.98 +    }
   80.99 +
  80.100 +    @Test
  80.101 +    public void accessStaticMethod() throws ScriptException {
  80.102 +        assertEquals(10, e.eval("java.lang.Math.abs(-10);"));
  80.103 +    }
  80.104 +
  80.105 +    @Test
  80.106 +    public void accessSynchronousMethod() throws ScriptException {
  80.107 +        e.eval("var v = new java.util.Vector();" + "v.add(10);" + "v.add(20);" + "v.add(30);");
  80.108 +        assertEquals(10, e.eval("v[0]"));
  80.109 +        assertEquals(20, e.eval("v[1]"));
  80.110 +        assertEquals(30, e.eval("v[2]"));
  80.111 +        assertEquals(3, e.eval("v.size()"));
  80.112 +    }
  80.113 +
  80.114 +    @Test
  80.115 +    public void accessStaticSynchronousMethod() throws ScriptException {
  80.116 +        e.eval("var locales = java.util.Calendar.getAvailableLocales();");
  80.117 +        final Locale[] locales = (Locale[])e.get("locales");
  80.118 +        assertEquals(locales.length, Calendar.getAvailableLocales().length);
  80.119 +    }
  80.120 +
  80.121 +    @Test
  80.122 +    public void accessNativeMethod() throws ScriptException {
  80.123 +        assertEquals(4.0, e.eval("java.lang.StrictMath.log10(10000);"));
  80.124 +    }
  80.125 +
  80.126 +    @Test
  80.127 +    public void accessConstructorOfAbstractClass() throws ScriptException {
  80.128 +        e.eval("try {" +
  80.129 +                "    var a = new java.util.AbstractList();" +
  80.130 +                "    print('fail');" +
  80.131 +                "} catch(e) {" +
  80.132 +                "    var isThrown = true;" +
  80.133 +                "}");
  80.134 +        assertEquals(true, e.get("isThrown"));
  80.135 +    }
  80.136 +
  80.137 +    @Test
  80.138 +    public void accessMethodVoid() throws ScriptException {
  80.139 +        o.isAccessed = false;
  80.140 +        e.eval("o.voidMethod();");
  80.141 +        assertTrue(o.isAccessed);
  80.142 +    }
  80.143 +
  80.144 +    @Test
  80.145 +    public void accessMethodBoolean() throws ScriptException {
  80.146 +        assertEquals(true, e.eval("o.booleanMethod(false);"));
  80.147 +        assertEquals(false, e.eval("o.booleanMethod(true);"));
  80.148 +        assertEquals(false, e.eval("o.booleanMethod('false');"));
  80.149 +        assertEquals(true, e.eval("o.booleanMethod('');"));
  80.150 +        assertEquals(true, e.eval("o.booleanMethod(0);"));
  80.151 +    }
  80.152 +
  80.153 +    @Test
  80.154 +    public void accessMethodInt() throws ScriptException {
  80.155 +        assertEquals(0, e.eval("o.intMethod(0);"));
  80.156 +        assertEquals(-200, e.eval("o.intMethod(-100);"));
  80.157 +        assertEquals(0, e.eval("o.intMethod('0');"));
  80.158 +        assertEquals(-200, e.eval("o.intMethod('-100');"));
  80.159 +    }
  80.160 +
  80.161 +    @Test
  80.162 +    public void accessMethodLong() throws ScriptException {
  80.163 +        assertEquals((long)0, e.eval("o.longMethod(0);"));
  80.164 +        assertEquals((long)400, e.eval("o.longMethod(200);"));
  80.165 +        assertEquals((long) 0, e.eval("o.longMethod('0');"));
  80.166 +        assertEquals((long) 400, e.eval("o.longMethod('200');"));
  80.167 +    }
  80.168 +
  80.169 +    @Test
  80.170 +    public void accessMethodByte() throws ScriptException {
  80.171 +        assertEquals((byte) 0, e.eval("o.byteMethod(0);"));
  80.172 +        assertEquals((byte) 10, e.eval("o.byteMethod(5);"));
  80.173 +        assertEquals((byte) 0, e.eval("o.byteMethod('0');"));
  80.174 +        assertEquals((byte) 10, e.eval("o.byteMethod('5');"));
  80.175 +    }
  80.176 +
  80.177 +    @Test
  80.178 +    public void accessMethodShort() throws ScriptException {
  80.179 +        assertEquals((short)0, e.eval("o.shortMethod(0);"));
  80.180 +        assertEquals((short)8000, e.eval("o.shortMethod(4000);"));
  80.181 +        assertEquals((short) 0, e.eval("o.shortMethod('0');"));
  80.182 +        assertEquals((short) 8000, e.eval("o.shortMethod('4000');"));
  80.183 +    }
  80.184 +
  80.185 +    @Test
  80.186 +    public void accessMethodChar() throws ScriptException {
  80.187 +        assertEquals('A', e.eval("o.charMethod('a');"));
  80.188 +        assertEquals('Z', e.eval("o.charMethod('z');"));
  80.189 +        assertEquals(o.charMethod((char)0), e.eval("o.charMethod(0);"));
  80.190 +        assertEquals(o.charMethod((char)3150), e.eval("o.charMethod(3150);"));
  80.191 +    }
  80.192 +
  80.193 +    @Test
  80.194 +    public void accessMethodFloat() throws ScriptException {
  80.195 +        assertEquals(0.0f, e.eval("o.floatMethod(0.0);"));
  80.196 +        assertEquals(4.2f, e.eval("o.floatMethod(2.1);"));
  80.197 +        assertEquals(0.0f, e.eval("o.floatMethod('0.0');"));
  80.198 +        assertEquals(4.2f, e.eval("o.floatMethod('2.1');"));
  80.199 +    }
  80.200 +
  80.201 +    @Test
  80.202 +    public void accessMethodDouble() throws ScriptException {
  80.203 +        assertEquals(0.0, e.eval("o.doubleMethod(0.0);"));
  80.204 +        assertEquals(14.0, e.eval("o.doubleMethod(7.0);"));
  80.205 +        assertEquals(0.0, e.eval("o.doubleMethod('0.0');"));
  80.206 +        assertEquals(14.0, e.eval("o.doubleMethod('7.0');"));
  80.207 +    }
  80.208 +
  80.209 +    @Test
  80.210 +    public void accessMethodBooleanBoxing() throws ScriptException {
  80.211 +        assertEquals(Boolean.TRUE, e.eval("o.booleanBoxingMethod(java.lang.Boolean.FALSE);"));
  80.212 +        assertEquals(Boolean.FALSE, e.eval("o.booleanBoxingMethod(java.lang.Boolean.TRUE);"));
  80.213 +        assertEquals(Boolean.TRUE, e.eval("o.booleanBoxingMethod('');"));
  80.214 +        assertEquals(Boolean.FALSE, e.eval("o.booleanBoxingMethod('false');"));
  80.215 +    }
  80.216 +
  80.217 +    @Test
  80.218 +    public void accessMethodIntBoxing() throws ScriptException {
  80.219 +        assertEquals(0, e.eval("o.intBoxingMethod(0);"));
  80.220 +        assertEquals(-200, e.eval("o.intBoxingMethod(-100);"));
  80.221 +        assertTrue((int)e.eval("(new java.lang.Integer(2)).compareTo(10.0)") < 0);
  80.222 +    }
  80.223 +
  80.224 +    @Test
  80.225 +    public void accessMethodLongBoxing() throws ScriptException {
  80.226 +        assertEquals((long) 0, e.eval("o.longBoxingMethod(0);"));
  80.227 +        assertEquals((long) 400, e.eval("o.longBoxingMethod(200);"));
  80.228 +        assertTrue((int)e.eval("(new java.lang.Long(2)).compareTo(10.0)") < 0);
  80.229 +    }
  80.230 +
  80.231 +    @Test
  80.232 +    public void accessMethodByteBoxing() throws ScriptException {
  80.233 +        assertEquals((byte) 0, e.eval("o.byteBoxingMethod(0);"));
  80.234 +        assertEquals((byte) 10, e.eval("o.byteBoxingMethod(5);"));
  80.235 +        assertTrue((int)e.eval("(new java.lang.Byte(2)).compareTo(10.0)") < 0);
  80.236 +    }
  80.237 +
  80.238 +    @Test
  80.239 +    public void accessMethodShortBoxing() throws ScriptException {
  80.240 +        assertEquals((short) 0, e.eval("o.shortBoxingMethod(0);"));
  80.241 +        assertEquals((short) 8000, e.eval("o.shortBoxingMethod(4000);"));
  80.242 +        assertTrue((int)e.eval("(new java.lang.Short(2)).compareTo(10.0)") < 0);
  80.243 +    }
  80.244 +
  80.245 +    @Test
  80.246 +    public void accessMethodCharBoxing() throws ScriptException {
  80.247 +        assertEquals('A', e.eval("o.charBoxingMethod('a');"));
  80.248 +        assertEquals('Z', e.eval("o.charBoxingMethod('z');"));
  80.249 +        assertTrue((int)e.eval("(new java.lang.Character(2)).compareTo(10)") < 0);
  80.250 +    }
  80.251 +
  80.252 +    @Test
  80.253 +    public void accessMethodFloatBoxing() throws ScriptException {
  80.254 +        assertEquals(0.0f, e.eval("o.floatBoxingMethod(0.0);"));
  80.255 +        assertEquals(4.2f, e.eval("o.floatBoxingMethod(2.1);"));
  80.256 +        assertTrue((int)e.eval("(new java.lang.Float(2.0)).compareTo(10.0)") < 0);
  80.257 +    }
  80.258 +
  80.259 +    @Test
  80.260 +    public void accessMethodDoubleBoxing() throws ScriptException {
  80.261 +        assertEquals(0.0, e.eval("o.doubleBoxingMethod(0.0);"));
  80.262 +        assertEquals(14.0, e.eval("o.doubleBoxingMethod(7.0);"));
  80.263 +        assertTrue((int)e.eval("(new java.lang.Double(2)).compareTo(10.0)") < 0);
  80.264 +    }
  80.265 +
  80.266 +    @Test
  80.267 +    public void accessMethodString() throws ScriptException {
  80.268 +        assertEquals("", e.eval("o.stringMethod('');"));
  80.269 +        assertEquals("abcabc", e.eval("o.stringMethod('abc');"));
  80.270 +    }
  80.271 +
  80.272 +    @Test
  80.273 +    public void accessMethodObject() throws ScriptException {
  80.274 +        e.put("so", new Person(5));
  80.275 +        e.eval("var rso = o.objectMethod(so);");
  80.276 +        assertEquals(new Person(10), e.get("rso"));
  80.277 +    }
  80.278 +
  80.279 +    @Test
  80.280 +    public void accessMethodBooleanArray() throws ScriptException {
  80.281 +        assertTrue(Arrays.equals(o.booleanArrayMethod(o.publicBooleanArray), (boolean[])e.eval("o.booleanArrayMethod(o.publicBooleanArray);")));
  80.282 +    }
  80.283 +
  80.284 +    @Test
  80.285 +    public void accessMethodIntArray() throws ScriptException {
  80.286 +        assertArrayEquals(o.intArrayMethod(o.publicIntArray), (int[])e.eval("o.intArrayMethod(o.publicIntArray);"));
  80.287 +    }
  80.288 +
  80.289 +    @Test
  80.290 +    public void accessMethodLongArray() throws ScriptException {
  80.291 +        assertArrayEquals(o.longArrayMethod(o.publicLongArray), (long[])e.eval("o.longArrayMethod(o.publicLongArray);"));
  80.292 +    }
  80.293 +
  80.294 +    @Test
  80.295 +    public void accessMethodByteArray() throws ScriptException {
  80.296 +        assertArrayEquals(o.byteArrayMethod(o.publicByteArray), (byte[])e.eval("o.byteArrayMethod(o.publicByteArray);"));
  80.297 +    }
  80.298 +
  80.299 +    @Test
  80.300 +    public void accessMethodShortArray() throws ScriptException {
  80.301 +        assertArrayEquals(o.shortArrayMethod(o.publicShortArray), (short[])e.eval("o.shortArrayMethod(o.publicShortArray);"));
  80.302 +    }
  80.303 +
  80.304 +    @Test
  80.305 +    public void accessMethodCharArray() throws ScriptException {
  80.306 +        assertArrayEquals(o.charArrayMethod(o.publicCharArray), (char[])e.eval("o.charArrayMethod(o.publicCharArray);"));
  80.307 +    }
  80.308 +
  80.309 +    @Test
  80.310 +    public void accessMethodFloatArray() throws ScriptException {
  80.311 +        assertArrayEquals(o.floatArrayMethod(o.publicFloatArray), (float[])e.eval("o.floatArrayMethod(o.publicFloatArray);"), 1e-10f);
  80.312 +    }
  80.313 +
  80.314 +    @Test
  80.315 +    public void accessMethodDoubleArray() throws ScriptException {
  80.316 +        assertArrayEquals(o.doubleArrayMethod(o.publicDoubleArray), (double[])e.eval("o.doubleArrayMethod(o.publicDoubleArray);"), 1e-10);
  80.317 +    }
  80.318 +
  80.319 +    @Test
  80.320 +    public void accessMethodStringArray() throws ScriptException {
  80.321 +        assertArrayEquals(o.stringArrayMethod(o.publicStringArray), (String[])e.eval("o.stringArrayMethod(o.publicStringArray);"));
  80.322 +    }
  80.323 +
  80.324 +    @Test
  80.325 +    public void accessMethodObjectArray() throws ScriptException {
  80.326 +        assertArrayEquals(o.objectArrayMethod(o.publicObjectArray), (Person[])e.eval("o.objectArrayMethod(o.publicObjectArray);"));
  80.327 +    }
  80.328 +
  80.329 +    @Test
  80.330 +    public void accessDefaultConstructor() throws ScriptException {
  80.331 +        e.eval("var dc = new Packages.jdk.nashorn.internal.access.Person()");
  80.332 +        assertEquals(new Person(), e.get("dc"));
  80.333 +    }
  80.334 +
  80.335 +    @Test
  80.336 +    public void accessCustomConstructor() throws ScriptException {
  80.337 +        e.eval("var cc = new Packages.jdk.nashorn.internal.access.Person(17)");
  80.338 +        assertEquals(new Person(17), e.get("cc"));
  80.339 +    }
  80.340 +
  80.341 +    @Test
  80.342 +    public void accessMethod2PrimitiveParams() throws ScriptException {
  80.343 +        assertEquals(o.twoParamMethod(50, 40.0), e.eval("o.twoParamMethod(50,40);"));
  80.344 +    }
  80.345 +
  80.346 +    @Test
  80.347 +    public void accessMethod3PrimitiveParams() throws ScriptException {
  80.348 +        assertEquals(o.threeParamMethod((short)10, 20L, 'b'), e.eval("o.threeParamMethod(10,20,'b');"));
  80.349 +    }
  80.350 +
  80.351 +    @Test
  80.352 +    public void accessMethod2ObjectParams() throws ScriptException {
  80.353 +        assertArrayEquals(new Person[] { new Person(200), new Person(300) }, (Person[])e.eval("o.twoObjectParamMethod(new Person(300),new Person(200));"));
  80.354 +    }
  80.355 +
  80.356 +    @Test
  80.357 +    public void accessMethod3ObjectParams() throws ScriptException {
  80.358 +        assertArrayEquals(new Person[] { new Person(3), new Person(2), new Person(1) }, (Person[])e.eval("o.threeObjectParamMethod(new Person(1),new Person(2),new Person(3));"));
  80.359 +    }
  80.360 +
  80.361 +    @Test
  80.362 +    public void accessMethod8ObjectParams() throws ScriptException {
  80.363 +        assertArrayEquals(new Person[] { new Person(8), new Person(7), new Person(6), new Person(5), new Person(4), new Person(3), new Person(2), new Person(1) }, (Person[])e.eval("o.eightObjectParamMethod(new Person(1),new Person(2),new Person(3)," + "new Person(4),new Person(5),new Person(6),new Person(7),new Person(8));"));
  80.364 +    }
  80.365 +
  80.366 +    @Test
  80.367 +    public void accessMethod9ObjectParams() throws ScriptException {
  80.368 +        assertArrayEquals(new Person[] { new Person(9), new Person(8), new Person(7), new Person(6), new Person(5), new Person(4), new Person(3), new Person(2), new Person(1) }, (Person[])e.eval("o.nineObjectParamMethod(new Person(1),new Person(2),new Person(3)," + "new Person(4),new Person(5),new Person(6)," + "new Person(7),new Person(8),new Person(9));"));
  80.369 +    }
  80.370 +
  80.371 +    @Test
  80.372 +    public void accessMethodObjectEllipsis() throws ScriptException {
  80.373 +        assertArrayEquals(new Person[] { new Person(9), new Person(8), new Person(7), new Person(6), new Person(5), new Person(4), new Person(3), new Person(2), new Person(1) }, (Person[])e.eval("o.methodObjectEllipsis(new Person(1),new Person(2),new Person(3)," + "new Person(4),new Person(5),new Person(6)," + "new Person(7),new Person(8),new Person(9));"));
  80.374 +        assertArrayEquals(new Person[] {}, (Person[])e.eval("o.methodObjectEllipsis()"));
  80.375 +        assertArrayEquals(new Person[] { new Person(9) }, (Person[])e.eval("o.methodObjectEllipsis(new Person(9))"));
  80.376 +    }
  80.377 +
  80.378 +    @Test
  80.379 +    public void accessMethodPrimitiveEllipsis() throws ScriptException {
  80.380 +        assertArrayEquals(new Person[] { new Person(1), new Person(3), new Person(2) }, (Person[])e.eval("o.methodPrimitiveEllipsis(1,3,2);"));
  80.381 +        assertArrayEquals(new Person[] {}, (Person[])e.eval("o.methodPrimitiveEllipsis();"));
  80.382 +        assertArrayEquals(o.methodPrimitiveEllipsis(9, 8, 7, 6, 5, 4, 3, 2, 1), (Person[])e.eval("o.methodPrimitiveEllipsis(9,8,7,6,5,4,3,2,1);"));
  80.383 +    }
  80.384 +
  80.385 +    @Test
  80.386 +    public void accessMethodMixedEllipsis() throws ScriptException {
  80.387 +        assertArrayEquals(new Object[] { new Person(1), 12, "hello", true }, (Object[])e.eval("o.methodMixedEllipsis(new Person(1),12,'hello',true);"));
  80.388 +        assertArrayEquals(new Object[] {}, (Object[])e.eval("o.methodMixedEllipsis();"));
  80.389 +    }
  80.390 +
  80.391 +    @Test
  80.392 +    public void accessMethodObjectWithEllipsis() throws ScriptException {
  80.393 +        assertArrayEquals(new Object[] { "hello", 12, 15, 16 }, (Object[])e.eval("o.methodObjectWithEllipsis('hello',12,15,16);"));
  80.394 +        assertArrayEquals(new Object[] { "hello" }, (Object[])e.eval("o.methodObjectWithEllipsis('hello');"));
  80.395 +    }
  80.396 +
  80.397 +    @Test
  80.398 +    public void accessMethodPrimitiveWithEllipsis() throws ScriptException {
  80.399 +        assertArrayEquals(new Object[] { 14, 12L, 15L, 16L }, (Object[])e.eval("o.methodPrimitiveWithEllipsis(14,12,15,16);"));
  80.400 +        assertArrayEquals(new Object[] { 12 }, (Object[])e.eval("o.methodPrimitiveWithEllipsis(12);"));
  80.401 +    }
  80.402 +
  80.403 +    @Test
  80.404 +    public void accessMethodMixedWithEllipsis() throws ScriptException {
  80.405 +        assertArrayEquals(new Object[] { "Hello", 10, true, -100500, 80 }, (Object[])e.eval("o.methodMixedWithEllipsis('Hello', 10, true, -100500,80.0);"));
  80.406 +        assertArrayEquals(new Object[] { "Nashorn", 15 }, (Object[])e.eval("o.methodMixedWithEllipsis('Nashorn',15);"));
  80.407 +    }
  80.408 +
  80.409 +    @Test
  80.410 +    public void accessMethodOverloaded() throws ScriptException {
  80.411 +        assertEquals(0, e.eval("o.overloadedMethod(0);"));
  80.412 +        assertEquals(2000, e.eval("o.overloadedMethod(1000);"));
  80.413 +        assertEquals(2, e.eval("o.overloadedMethod('10');"));
  80.414 +        assertEquals(7, e.eval("o.overloadedMethod('Nashorn');"));
  80.415 +        assertEquals(4, e.eval("o.overloadedMethod('true');"));
  80.416 +        assertEquals(1, e.eval("o.overloadedMethod(true);"));
  80.417 +        assertEquals(0, e.eval("o.overloadedMethod(false);"));
  80.418 +        assertEquals(44, e.eval("o.overloadedMethod(new Person(22));"));
  80.419 +        assertEquals(0, e.eval("o.overloadedMethod(new Person());"));
  80.420 +    }
  80.421 +
  80.422 +    @Test
  80.423 +    public void accessMethodDoubleVSintOverloaded() throws ScriptException {
  80.424 +        assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(0.0);"));
  80.425 +        assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(1000.0);"));
  80.426 +        assertEquals("double", e.eval("o.overloadedMethodDoubleVSint(0.01);"));
  80.427 +        assertEquals("double", e.eval("o.overloadedMethodDoubleVSint(100.02);"));
  80.428 +        assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(0);"));
  80.429 +        assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(1000);"));
  80.430 +    }
  80.431 +
  80.432 +    @Test
  80.433 +    public void accessJavaMethodIntFromJSFromJavaFromJS() throws ScriptException {
  80.434 +        e.eval("function secondLevelMethodInt(a) {"
  80.435 +                + "return o.thirdLevelMethodInt(a);"
  80.436 +                + "}");
  80.437 +        assertEquals(50, e.eval("o.firstLevelMethodInt(10);"));
  80.438 +    }
  80.439 +
  80.440 +    @Test
  80.441 +    public void accessJavaMethodIntegerFromJSFromJavaFromJS() throws ScriptException {
  80.442 +        e.eval("function secondLevelMethodInteger(a) {"
  80.443 +                + "return o.thirdLevelMethodInteger(a);"
  80.444 +                + "}");
  80.445 +        assertEquals(100, e.eval("o.firstLevelMethodInteger(10);"));
  80.446 +    }
  80.447 +
  80.448 +    @Test
  80.449 +    public void accessJavaMethodObjectFromJSFromJavaFromJS() throws ScriptException {
  80.450 +        e.eval("function secondLevelMethodObject(p) {"
  80.451 +                + "return o.thirdLevelMethodObject(p);"
  80.452 +                + "}");
  80.453 +        assertEquals(new Person(100), e.eval("o.firstLevelMethodObject(new Person(10));"));
  80.454 +    }
  80.455 +
  80.456 +}
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java	Mon Feb 11 21:26:06 2013 +0530
    81.3 @@ -0,0 +1,776 @@
    81.4 +/*
    81.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    81.7 + *
    81.8 + * This code is free software; you can redistribute it and/or modify it
    81.9 + * under the terms of the GNU General Public License version 2 only, as
   81.10 + * published by the Free Software Foundation.  Oracle designates this
   81.11 + * particular file as subject to the "Classpath" exception as provided
   81.12 + * by Oracle in the LICENSE file that accompanied this code.
   81.13 + *
   81.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   81.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   81.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   81.17 + * version 2 for more details (a copy is included in the LICENSE file that
   81.18 + * accompanied this code).
   81.19 + *
   81.20 + * You should have received a copy of the GNU General Public License version
   81.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   81.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   81.23 + *
   81.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   81.25 + * or visit www.oracle.com if you need additional information or have any
   81.26 + * questions.
   81.27 + */
   81.28 +
   81.29 +package jdk.nashorn.api.javaaccess;
   81.30 +
   81.31 +import static org.testng.AssertJUnit.assertEquals;
   81.32 +import static org.testng.AssertJUnit.assertTrue;
   81.33 +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
   81.34 +
   81.35 +import javax.script.ScriptEngine;
   81.36 +import javax.script.ScriptEngineManager;
   81.37 +import javax.script.ScriptException;
   81.38 +import org.testng.TestNG;
   81.39 +import org.testng.annotations.BeforeClass;
   81.40 +import org.testng.annotations.Test;
   81.41 +
   81.42 +public class NumberAccessTest {
   81.43 +
   81.44 +    private static ScriptEngine e = null;
   81.45 +    private static SharedObject o = new SharedObject();
   81.46 +
   81.47 +    public static void main(final String[] args) {
   81.48 +        TestNG.main(args);
   81.49 +    }
   81.50 +
   81.51 +    @BeforeClass
   81.52 +    public static void setUpClass() throws ScriptException {
   81.53 +        final ScriptEngineManager m = new ScriptEngineManager();
   81.54 +        e = m.getEngineByName("nashorn");
   81.55 +        e.put("o", o);
   81.56 +        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   81.57 +    }
   81.58 +
   81.59 +    // --------------------------------long
   81.60 +    // tests------------------------------------
   81.61 +    @Test
   81.62 +    public void accessFieldLong() throws ScriptException {
   81.63 +        e.eval("var p_long = o.publicLong;");
   81.64 +        assertEquals(o.publicLong, e.get("p_long"));
   81.65 +        e.eval("o.publicLong = 12;");
   81.66 +        assertEquals(12, o.publicLong);
   81.67 +    }
   81.68 +
   81.69 +    @Test
   81.70 +    public void accessFieldLongArray() throws ScriptException {
   81.71 +        e.eval("var p_long_array = o.publicLongArray;");
   81.72 +        assertEquals(o.publicLongArray[0], e.eval("o.publicLongArray[0];"));
   81.73 +        assertArrayEquals(o.publicLongArray, (long[])e.get("p_long_array"));
   81.74 +        e.eval("var t_long_arr = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, 3);" +
   81.75 +                "t_long_arr[0] = -189009;" +
   81.76 +                "t_long_arr[1] = 456;" +
   81.77 +                "t_long_arr[2] = 600000001;" +
   81.78 +                "o.publicLongArray = t_long_arr;");
   81.79 +        // e.eval("o.publicIntArray = [-189009,456,600000001];");
   81.80 +        assertArrayEquals(new long[] { -189009, 456, 600000001 }, o.publicLongArray);
   81.81 +        e.eval("o.publicLongArray[0] = 10;");
   81.82 +        assertEquals(10, o.publicLongArray[0]);
   81.83 +    }
   81.84 +
   81.85 +    @Test
   81.86 +    public void accessStaticFieldLong() throws ScriptException {
   81.87 +        e.eval("var ps_long = SharedObject.publicStaticLong;");
   81.88 +        assertEquals(SharedObject.publicStaticLong, e.get("ps_long"));
   81.89 +        e.eval("SharedObject.publicStaticLong = 120;");
   81.90 +        assertEquals(120, SharedObject.publicStaticLong);
   81.91 +    }
   81.92 +
   81.93 +    @Test
   81.94 +    public void accessStaticFieldLongArray() throws ScriptException {
   81.95 +        e.eval("var ps_long_array = SharedObject.publicStaticLongArray;");
   81.96 +        assertEquals(SharedObject.publicStaticLongArray[0], e.eval("SharedObject.publicStaticLongArray[0];"));
   81.97 +        assertArrayEquals(SharedObject.publicStaticLongArray, (long[])e.get("ps_long_array"));
   81.98 +        e.eval("var ts_long_arr = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, 3);" +
   81.99 +                "ts_long_arr[0] = -189009;" +
  81.100 +                "ts_long_arr[1] = 456;" +
  81.101 +                "ts_long_arr[2] = 600000001;" +
  81.102 +                "SharedObject.publicStaticLongArray = ts_long_arr;");
  81.103 +        // e.eval("o.publicIntArray = [-189009,456,600000001];");
  81.104 +        assertArrayEquals(new long[] { -189009, 456, 600000001 }, SharedObject.publicStaticLongArray);
  81.105 +        e.eval("SharedObject.publicStaticLongArray[0] = 10;");
  81.106 +        assertEquals(10, SharedObject.publicStaticLongArray[0]);
  81.107 +    }
  81.108 +
  81.109 +    @Test
  81.110 +    public void accessFinalFieldLong() throws ScriptException {
  81.111 +        e.eval("var pf_long = o.publicFinalLong;");
  81.112 +        assertEquals(o.publicFinalLong, e.get("pf_long"));
  81.113 +        e.eval("o.publicFinalLong = 120;");
  81.114 +        assertEquals(13353333333333333L, o.publicFinalLong);
  81.115 +    }
  81.116 +
  81.117 +    @Test
  81.118 +    public void accessFinalFieldLongArray() throws ScriptException {
  81.119 +        e.eval("var pf_long_array = o.publicFinalLongArray;");
  81.120 +        assertEquals(o.publicFinalLongArray[0], e.eval("o.publicFinalLongArray[0];"));
  81.121 +        assertArrayEquals(o.publicFinalLongArray, (long[])e.get("pf_long_array"));
  81.122 +        e.eval("var tf_long_arr = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, 3);" +
  81.123 +                "tf_long_arr[0] = -189009;" +
  81.124 +                "tf_long_arr[1] = 456;" +
  81.125 +                "tf_long_arr[2] = 600000001;" +
  81.126 +                "o.publicFinalLongArray = tf_long_arr;");
  81.127 +        // e.eval("o.publicIntArray = [-189009,456,600000001];");
  81.128 +        assertArrayEquals(new long[] { 1901733333333L, -2247355555L, 3977377777L }, o.publicFinalLongArray);
  81.129 +        e.eval("o.publicFinalLongArray[0] = 10;");
  81.130 +        assertEquals(10, o.publicFinalLongArray[0]);
  81.131 +    }
  81.132 +
  81.133 +    @Test
  81.134 +    public void accessStaticFinalFieldLong() throws ScriptException {
  81.135 +        e.eval("var psf_long = SharedObject.publicStaticFinalLong;");
  81.136 +        assertEquals(SharedObject.publicStaticFinalLong, e.get("psf_long"));
  81.137 +        e.eval("SharedObject.publicStaticFinalLong = 120;");
  81.138 +        assertEquals(8333333333333L, SharedObject.publicStaticFinalLong);
  81.139 +    }
  81.140 +
  81.141 +    @Test
  81.142 +    public void accessStaticFinalFieldLongArray() throws ScriptException {
  81.143 +        e.eval("var psf_long_array = SharedObject.publicStaticFinalLongArray;");
  81.144 +        assertEquals(SharedObject.publicStaticFinalLongArray[0], e.eval("SharedObject.publicStaticFinalLongArray[0];"));
  81.145 +        assertArrayEquals(SharedObject.publicStaticFinalLongArray, (long[])e.get("psf_long_array"));
  81.146 +        e.eval("var tsf_long_arr = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, 3);" +
  81.147 +                "tsf_long_arr[0] = -189009;" +
  81.148 +                "tsf_long_arr[1] = 456;" +
  81.149 +                "tsf_long_arr[2] = 600000001;" +
  81.150 +                "SharedObject.publicStaticFinalLongArray = tsf_long_arr;");
  81.151 +        // e.eval("o.publicIntArray = [-189009,456,600000001];");
  81.152 +        assertArrayEquals(new long[] { 19017383333L, -2247358L, 39773787L }, SharedObject.publicStaticFinalLongArray);
  81.153 +        e.eval("SharedObject.publicStaticFinalLongArray[0] = 10;");
  81.154 +        assertEquals(10, SharedObject.publicStaticFinalLongArray[0]);
  81.155 +    }
  81.156 +
  81.157 +    // --------------------------------int
  81.158 +    // tests------------------------------------
  81.159 +    @Test
  81.160 +    public void accessFieldInt() throws ScriptException {
  81.161 +        e.eval("var p_int = o.publicInt;");
  81.162 +        assertEquals(o.publicInt, e.get("p_int"));
  81.163 +        e.eval("o.publicInt = 14;");
  81.164 +        assertEquals(14, o.publicInt);
  81.165 +    }
  81.166 +
  81.167 +    @Test
  81.168 +    public void accessFieldIntArray() throws ScriptException {
  81.169 +        e.eval("var p_int_array = o.publicIntArray;");
  81.170 +        assertEquals(o.publicIntArray[0], e.eval("o.publicIntArray[0];"));
  81.171 +        assertArrayEquals(o.publicIntArray, (int[])e.get("p_int_array"));
  81.172 +        e.eval("var t_int_arr = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 3);" +
  81.173 +                "t_int_arr[0] = 4;" +
  81.174 +                "t_int_arr[1] = 5;" +
  81.175 +                "t_int_arr[2] = 6;" +
  81.176 +                "o.publicIntArray = t_int_arr;");
  81.177 +        assertArrayEquals(new int[] { 4, 5, 6 }, o.publicIntArray);
  81.178 +        e.eval("o.publicIntArray[0] = 100;");
  81.179 +        assertEquals(100, o.publicIntArray[0]);
  81.180 +    }
  81.181 +
  81.182 +    @Test
  81.183 +    public void accessStaticFieldInt() throws ScriptException {
  81.184 +        e.eval("var ps_int = SharedObject.publicStaticInt;");
  81.185 +        assertEquals(SharedObject.publicStaticInt, e.get("ps_int"));
  81.186 +        e.eval("SharedObject.publicStaticInt = 140;");
  81.187 +        assertEquals(140, SharedObject.publicStaticInt);
  81.188 +    }
  81.189 +
  81.190 +    @Test
  81.191 +    public void accessStaticFieldIntArray() throws ScriptException {
  81.192 +        e.eval("var ps_int_array = SharedObject.publicStaticIntArray;");
  81.193 +        assertEquals(SharedObject.publicStaticIntArray[0], e.eval("SharedObject.publicStaticIntArray[0];"));
  81.194 +        assertArrayEquals(SharedObject.publicStaticIntArray, (int[])e.get("ps_int_array"));
  81.195 +        e.eval("var ts_int_arr = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 3);" +
  81.196 +                "ts_int_arr[0] = 4;" +
  81.197 +                "ts_int_arr[1] = 5;" +
  81.198 +                "ts_int_arr[2] = 6;" +
  81.199 +                "SharedObject.publicStaticIntArray = ts_int_arr;");
  81.200 +        assertArrayEquals(new int[] { 4, 5, 6 }, SharedObject.publicStaticIntArray);
  81.201 +        e.eval("SharedObject.publicStaticIntArray[0] = 100;");
  81.202 +        assertEquals(100, SharedObject.publicStaticIntArray[0]);
  81.203 +    }
  81.204 +
  81.205 +    @Test
  81.206 +    public void accessFinalFieldInt() throws ScriptException {
  81.207 +        e.eval("var pf_int = o.publicFinalInt;");
  81.208 +        assertEquals(o.publicFinalInt, e.get("pf_int"));
  81.209 +
  81.210 +        e.eval("o.publicFinalInt = 10;");
  81.211 +        assertEquals(20712023, o.publicFinalInt);
  81.212 +    }
  81.213 +
  81.214 +    @Test
  81.215 +    public void accessFinalFieldIntArray() throws ScriptException {
  81.216 +        e.eval("var pf_int_array = o.publicFinalIntArray;");
  81.217 +        assertEquals(o.publicFinalIntArray[0], e.eval("o.publicFinalIntArray[0];"));
  81.218 +        assertArrayEquals(o.publicFinalIntArray, (int[])e.get("pf_int_array"));
  81.219 +        e.eval("var tf_int_arr = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 3);" +
  81.220 +                "tf_int_arr[0] = 4;" +
  81.221 +                "tf_int_arr[1] = 5;" +
  81.222 +                "tf_int_arr[2] = 6;" +
  81.223 +                "o.publicFinalIntArray = tf_int_arr;");
  81.224 +        assertArrayEquals(new int[] { 50, 80, 130, 210, 340 }, o.publicFinalIntArray);
  81.225 +        e.eval("o.publicFinalIntArray[0] = 100;");
  81.226 +        assertEquals(100, o.publicFinalIntArray[0]);
  81.227 +    }
  81.228 +
  81.229 +    @Test
  81.230 +    public void accessStaticFinalFieldInt() throws ScriptException {
  81.231 +        e.eval("var psf_int = SharedObject.publicStaticFinalInt;");
  81.232 +        assertEquals(SharedObject.publicStaticFinalInt, e.get("psf_int"));
  81.233 +        e.eval("SharedObject.publicStaticFinalInt = 140;");
  81.234 +        assertEquals(207182023, SharedObject.publicStaticFinalInt);
  81.235 +    }
  81.236 +
  81.237 +    @Test
  81.238 +    public void accessStaticFinalFieldIntArray() throws ScriptException {
  81.239 +        e.eval("var psf_int_array = SharedObject.publicStaticFinalIntArray;");
  81.240 +        assertEquals(SharedObject.publicStaticFinalIntArray[0], e.eval("SharedObject.publicStaticFinalIntArray[0];"));
  81.241 +        assertArrayEquals(SharedObject.publicStaticFinalIntArray, (int[])e.get("psf_int_array"));
  81.242 +        e.eval("var tsf_int_arr = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 3);" +
  81.243 +                "tsf_int_arr[0] = 4;" +
  81.244 +                "tsf_int_arr[1] = 5;" +
  81.245 +                "tsf_int_arr[2] = 6;" +
  81.246 +                "SharedObject.publicStaticFinalIntArray = tsf_int_arr;");
  81.247 +        assertArrayEquals(new int[] { 1308, 210, 340 }, SharedObject.publicStaticFinalIntArray);
  81.248 +        e.eval("SharedObject.publicStaticFinalIntArray[0] = 100;");
  81.249 +        assertEquals(100, SharedObject.publicStaticFinalIntArray[0]);
  81.250 +    }
  81.251 +
  81.252 +    // --------------------------------byte
  81.253 +    // tests------------------------------------
  81.254 +    @Test
  81.255 +    public void accessFieldByte() throws ScriptException {
  81.256 +        e.eval("var p_byte = o.publicByte;");
  81.257 +        assertEquals(o.publicByte, e.get("p_byte"));
  81.258 +        e.eval("o.publicByte = 16;");
  81.259 +        assertEquals(16, o.publicByte);
  81.260 +    }
  81.261 +
  81.262 +    @Test
  81.263 +    public void accessFieldByteArray() throws ScriptException {
  81.264 +        e.eval("var p_byte_array = o.publicByteArray;");
  81.265 +        assertEquals(o.publicByteArray[0], e.eval("o.publicByteArray[0];"));
  81.266 +        assertArrayEquals(o.publicByteArray, (byte[])e.get("p_byte_array"));
  81.267 +        e.eval("var t_byte_arr = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 3);" +
  81.268 +                "t_byte_arr[0] = -18;" +
  81.269 +                "t_byte_arr[1] = 56;" +
  81.270 +                "t_byte_arr[2] = 60;" +
  81.271 +                "o.publicByteArray = t_byte_arr;");
  81.272 +        assertArrayEquals(new byte[] { -18, 56, 60 }, o.publicByteArray);
  81.273 +        e.eval("o.publicByteArray[0] = 100;");
  81.274 +        assertEquals(100, o.publicByteArray[0]);
  81.275 +    }
  81.276 +
  81.277 +    @Test
  81.278 +    public void accessStaticFieldByte() throws ScriptException {
  81.279 +        e.eval("var ps_byte = SharedObject.publicStaticByte;");
  81.280 +        assertEquals(SharedObject.publicStaticByte, e.get("ps_byte"));
  81.281 +        e.eval("SharedObject.publicStaticByte = 16;");
  81.282 +        assertEquals(16, SharedObject.publicStaticByte);
  81.283 +    }
  81.284 +
  81.285 +    @Test
  81.286 +    public void accessStaticFieldByteArray() throws ScriptException {
  81.287 +        e.eval("var ps_byte_array = SharedObject.publicStaticByteArray;");
  81.288 +        assertEquals(SharedObject.publicStaticByteArray[0], e.eval("SharedObject.publicStaticByteArray[0];"));
  81.289 +        assertArrayEquals(SharedObject.publicStaticByteArray, (byte[])e.get("ps_byte_array"));
  81.290 +        e.eval("var ts_byte_arr = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 3);" +
  81.291 +                "ts_byte_arr[0] = -18;" +
  81.292 +                "ts_byte_arr[1] = 56;" +
  81.293 +                "ts_byte_arr[2] = 60;" +
  81.294 +                "SharedObject.publicStaticByteArray = ts_byte_arr;");
  81.295 +        assertArrayEquals(new byte[] { -18, 56, 60 }, SharedObject.publicStaticByteArray);
  81.296 +        e.eval("SharedObject.publicStaticByteArray[0] = -90;");
  81.297 +        assertEquals(-90, SharedObject.publicStaticByteArray[0]);
  81.298 +    }
  81.299 +
  81.300 +    @Test
  81.301 +    public void accessFinalFieldByte() throws ScriptException {
  81.302 +        e.eval("var pf_byte = o.publicFinalByte;");
  81.303 +        assertEquals(o.publicFinalByte, e.get("pf_byte"));
  81.304 +        e.eval("o.publicFinalByte = 16;");
  81.305 +        assertEquals(-7, o.publicFinalByte);
  81.306 +    }
  81.307 +
  81.308 +    @Test
  81.309 +    public void accessFinalFieldByteArray() throws ScriptException {
  81.310 +        e.eval("var pf_byte_array = o.publicFinalByteArray;");
  81.311 +        assertEquals(o.publicFinalByteArray[0], e.eval("o.publicFinalByteArray[0];"));
  81.312 +        assertArrayEquals(o.publicFinalByteArray, (byte[])e.get("pf_byte_array"));
  81.313 +        e.eval("var tf_byte_arr = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 3);" +
  81.314 +                "tf_byte_arr[0] = -18;" +
  81.315 +                "tf_byte_arr[1] = 56;" +
  81.316 +                "tf_byte_arr[2] = 60;" +
  81.317 +                "o.publicFinalByteArray = tf_byte_arr;");
  81.318 +        assertArrayEquals(new byte[] { 1, 3, 6, 17, -128 }, o.publicFinalByteArray);
  81.319 +        e.eval("o.publicFinalByteArray[0] = -90;");
  81.320 +        assertEquals(-90, o.publicFinalByteArray[0]);
  81.321 +    }
  81.322 +
  81.323 +    @Test
  81.324 +    public void accessStaticFinalFieldByte() throws ScriptException {
  81.325 +        e.eval("var psf_byte = SharedObject.publicStaticFinalByte;");
  81.326 +        assertEquals(SharedObject.publicStaticFinalByte, e.get("psf_byte"));
  81.327 +        e.eval("SharedObject.publicStaticFinalByte = 16;");
  81.328 +        assertEquals(-70, SharedObject.publicStaticFinalByte);
  81.329 +    }
  81.330 +
  81.331 +    @Test
  81.332 +    public void accessStaticFinalFieldByteArray() throws ScriptException {
  81.333 +        e.eval("var psf_byte_array = SharedObject.publicStaticFinalByteArray;");
  81.334 +        assertEquals(SharedObject.publicStaticFinalByteArray[0], e.eval("SharedObject.publicStaticFinalByteArray[0];"));
  81.335 +        assertArrayEquals(SharedObject.publicStaticFinalByteArray, (byte[])e.get("psf_byte_array"));
  81.336 +        e.eval("var tsf_byte_arr = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 3);" +
  81.337 +                "tsf_byte_arr[0] = -18;" +
  81.338 +                "tsf_byte_arr[1] = 56;" +
  81.339 +                "tsf_byte_arr[2] = 60;" +
  81.340 +                "SharedObject.publicStaticFinalByteArray = tsf_byte_arr;");
  81.341 +        assertArrayEquals(new byte[] { 17, -128, 81 }, SharedObject.publicStaticFinalByteArray);
  81.342 +        e.eval("SharedObject.publicStaticFinalByteArray[0] = -90;");
  81.343 +        assertEquals(-90, SharedObject.publicStaticFinalByteArray[0]);
  81.344 +    }
  81.345 +
  81.346 +    // --------------------------------short
  81.347 +    // tests------------------------------------
  81.348 +    @Test
  81.349 +    public void accessFieldShort() throws ScriptException {
  81.350 +        e.eval("var p_short = o.publicShort;");
  81.351 +        assertEquals(o.publicShort, e.get("p_short"));
  81.352 +        e.eval("o.publicShort = 18;");
  81.353 +        assertEquals(18, o.publicShort);
  81.354 +    }
  81.355 +
  81.356 +    @Test
  81.357 +    public void accessFieldShortArray() throws ScriptException {
  81.358 +        e.eval("var p_short_array = o.publicShortArray;");
  81.359 +        assertEquals(o.publicShortArray[0], e.eval("o.publicShortArray[0];"));
  81.360 +        assertArrayEquals(o.publicShortArray, (short[])e.get("p_short_array"));
  81.361 +        e.eval("var t_short_arr = java.lang.reflect.Array.newInstance(java.lang.Short.TYPE, 3);" +
  81.362 +                "t_short_arr[0] = 90;" +
  81.363 +                "t_short_arr[1] = 5;" +
  81.364 +                "t_short_arr[2] = -6000;" +
  81.365 +                "o.publicShortArray = t_short_arr;");
  81.366 +        assertArrayEquals(new short[] { 90, 5, -6000 }, o.publicShortArray);
  81.367 +        e.eval("o.publicShortArray[0] = -1000;");
  81.368 +        assertEquals(-1000, o.publicShortArray[0]);
  81.369 +    }
  81.370 +
  81.371 +    @Test
  81.372 +    public void accessStaticFieldShort() throws ScriptException {
  81.373 +        e.eval("var ps_short = SharedObject.publicStaticShort;");
  81.374 +        assertEquals(SharedObject.publicStaticShort, e.get("ps_short"));
  81.375 +        e.eval("SharedObject.publicStaticShort = 180;");
  81.376 +        assertEquals(180, SharedObject.publicStaticShort);
  81.377 +    }
  81.378 +
  81.379 +    @Test
  81.380 +    public void accessStaticFieldShortArray() throws ScriptException {
  81.381 +        e.eval("var ps_short_array = SharedObject.publicStaticShortArray;");
  81.382 +        assertEquals(SharedObject.publicStaticShortArray[0], e.eval("SharedObject.publicStaticShortArray[0];"));
  81.383 +        assertArrayEquals(SharedObject.publicStaticShortArray, (short[])e.get("ps_short_array"));
  81.384 +        e.eval("var ts_short_arr = java.lang.reflect.Array.newInstance(java.lang.Short.TYPE, 3);" +
  81.385 +                "ts_short_arr[0] = 90;" +
  81.386 +                "ts_short_arr[1] = 5;" +
  81.387 +                "ts_short_arr[2] = -6000;" +
  81.388 +                "SharedObject.publicStaticShortArray = ts_short_arr;");
  81.389 +        assertArrayEquals(new short[] { 90, 5, -6000 }, SharedObject.publicStaticShortArray);
  81.390 +        e.eval("SharedObject.publicStaticShortArray[0] = -1000;");
  81.391 +        assertEquals(-1000, SharedObject.publicStaticShortArray[0]);
  81.392 +    }
  81.393 +
  81.394 +    @Test
  81.395 +    public void accessFinalFieldShort() throws ScriptException {
  81.396 +        e.eval("var pf_short = o.publicFinalShort;");
  81.397 +        assertEquals(o.publicFinalShort, e.get("pf_short"));
  81.398 +        e.eval("o.publicFinalShort = 180;");
  81.399 +        assertEquals(31220, o.publicFinalShort);
  81.400 +    }
  81.401 +
  81.402 +    @Test
  81.403 +    public void accessFinalFieldShortArray() throws ScriptException {
  81.404 +        e.eval("var pf_short_array = o.publicFinalShortArray;");
  81.405 +        assertEquals(o.publicFinalShortArray[0], e.eval("o.publicFinalShortArray[0];"));
  81.406 +        assertArrayEquals(o.publicFinalShortArray, (short[])e.get("pf_short_array"));
  81.407 +        e.eval("var tf_short_arr = java.lang.reflect.Array.newInstance(java.lang.Short.TYPE, 3);" +
  81.408 +                "tf_short_arr[0] = 90;" +
  81.409 +                "tf_short_arr[1] = 5;" +
  81.410 +                "tf_short_arr[2] = -6000;" +
  81.411 +                "o.publicFinalShortArray = tf_short_arr;");
  81.412 +        assertArrayEquals(new short[] { 12240, 9200, -17289, 1200, 12 }, o.publicFinalShortArray);
  81.413 +        e.eval("o.publicFinalShortArray[0] = -1000;");
  81.414 +        assertEquals(-1000, o.publicFinalShortArray[0]);
  81.415 +    }
  81.416 +
  81.417 +    @Test
  81.418 +    public void accessStaticFinalFieldShort() throws ScriptException {
  81.419 +        e.eval("var psf_short = SharedObject.publicStaticFinalShort;");
  81.420 +        assertEquals(SharedObject.publicStaticFinalShort, e.get("psf_short"));
  81.421 +        e.eval("SharedObject.publicStaticFinalShort = 180;");
  81.422 +        assertEquals(8888, SharedObject.publicStaticFinalShort);
  81.423 +    }
  81.424 +
  81.425 +    @Test
  81.426 +    public void accessStaticFinalFieldShortArray() throws ScriptException {
  81.427 +        e.eval("var psf_short_array = SharedObject.publicStaticFinalShortArray;");
  81.428 +        assertEquals(SharedObject.publicStaticFinalShortArray[0], e.eval("SharedObject.publicStaticFinalShortArray[0];"));
  81.429 +        assertArrayEquals(SharedObject.publicStaticFinalShortArray, (short[])e.get("psf_short_array"));
  81.430 +        e.eval("var tsf_short_arr = java.lang.reflect.Array.newInstance(java.lang.Short.TYPE, 3);" +
  81.431 +                "tsf_short_arr[0] = 90;" +
  81.432 +                "tsf_short_arr[1] = 5;" +
  81.433 +                "tsf_short_arr[2] = -6000;" +
  81.434 +                "SharedObject.publicStaticFinalShortArray = tsf_short_arr;");
  81.435 +        assertArrayEquals(new short[] { 8240, 9280, -1289, 120, 812 }, SharedObject.publicStaticFinalShortArray);
  81.436 +        e.eval("SharedObject.publicStaticFinalShortArray[0] = -1000;");
  81.437 +        assertEquals(-1000, SharedObject.publicStaticFinalShortArray[0]);
  81.438 +    }
  81.439 +
  81.440 +    // --------------------------------char
  81.441 +    // tests------------------------------------
  81.442 +    @Test
  81.443 +    public void accessFieldChar() throws ScriptException {
  81.444 +        e.eval("var p_char = o.publicChar;");
  81.445 +        assertEquals(o.publicChar, e.get("p_char"));
  81.446 +        e.eval("o.publicChar = 'S';");
  81.447 +        assertEquals('S', o.publicChar);
  81.448 +        e.eval("o.publicChar = 10;");
  81.449 +        assertEquals(10, o.publicChar);
  81.450 +        e.eval("try {"
  81.451 +                + "    o.publicChar = 'Big string';" +
  81.452 +                "} catch(e) {" +
  81.453 +                "    var isThrown = true;" +
  81.454 +                "}");
  81.455 +        assertEquals("Exception thrown", true, e.get("isThrown"));
  81.456 +        assertEquals(10, o.publicChar);
  81.457 +    }
  81.458 +
  81.459 +    @Test
  81.460 +    public void accessFieldCharArray() throws ScriptException {
  81.461 +        e.eval("var p_char_array = o.publicCharArray;");
  81.462 +        assertEquals(o.publicCharArray[0], e.eval("o.publicCharArray[0];"));
  81.463 +        assertArrayEquals(o.publicCharArray, (char[])e.get("p_char_array"));
  81.464 +        e.eval("var t_char_arr = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 3);" +
  81.465 +                "t_char_arr[0] = 'F';" +
  81.466 +                "t_char_arr[1] = 'o';" +
  81.467 +                "t_char_arr[2] = 'o';" +
  81.468 +                "o.publicCharArray = t_char_arr;");
  81.469 +        assertArrayEquals("Foo".toCharArray(), o.publicCharArray);
  81.470 +        e.eval("o.publicCharArray[0] = 'Z';");
  81.471 +        assertEquals('Z', o.publicCharArray[0]);
  81.472 +    }
  81.473 +
  81.474 +    @Test
  81.475 +    public void accessStaticFieldChar() throws ScriptException {
  81.476 +        e.eval("var ps_char = SharedObject.publicStaticChar;");
  81.477 +        assertEquals(SharedObject.publicStaticChar, e.get("ps_char"));
  81.478 +        e.eval("SharedObject.publicStaticChar = 'Z';");
  81.479 +        assertEquals('Z', SharedObject.publicStaticChar);
  81.480 +    }
  81.481 +
  81.482 +    @Test
  81.483 +    public void accessStaticFieldCharArray() throws ScriptException {
  81.484 +        e.eval("var ps_char_array = SharedObject.publicStaticCharArray;");
  81.485 +        assertEquals(SharedObject.publicStaticCharArray[0], e.eval("SharedObject.publicStaticCharArray[0];"));
  81.486 +        assertArrayEquals(SharedObject.publicStaticCharArray, (char[])e.get("ps_char_array"));
  81.487 +        e.eval("var ts_char_arr = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 3);" +
  81.488 +                "ts_char_arr[0] = 'G';" +
  81.489 +                "ts_char_arr[1] = 'o';" +
  81.490 +                "ts_char_arr[2] = 'o';" +
  81.491 +                "SharedObject.publicStaticCharArray = ts_char_arr;");
  81.492 +        assertArrayEquals("Goo".toCharArray(), SharedObject.publicStaticCharArray);
  81.493 +        e.eval("SharedObject.publicStaticCharArray[0] = 'Z';");
  81.494 +        assertEquals('Z', SharedObject.publicStaticCharArray[0]);
  81.495 +    }
  81.496 +
  81.497 +    @Test
  81.498 +    public void accessFinalFieldChar() throws ScriptException {
  81.499 +        e.eval("var pf_char = o.publicFinalChar;");
  81.500 +        assertEquals(o.publicFinalChar, e.get("pf_char"));
  81.501 +        e.eval("o.publicFinalChar = 'S';");
  81.502 +        assertEquals('E', o.publicFinalChar);
  81.503 +    }
  81.504 +
  81.505 +    @Test
  81.506 +    public void accessFinalCharArray() throws ScriptException {
  81.507 +        e.eval("var pf_char_array = o.publicFinalCharArray;");
  81.508 +        assertEquals(o.publicFinalCharArray[0], e.eval("o.publicFinalCharArray[0];"));
  81.509 +        assertArrayEquals(o.publicFinalCharArray, (char[])e.get("pf_char_array"));
  81.510 +        e.eval("var tf_char_arr = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 3);" +
  81.511 +                "tf_char_arr[0] = 'F';" +
  81.512 +                "tf_char_arr[1] = 'o';" +
  81.513 +                "tf_char_arr[2] = 'o';" +
  81.514 +                "o.publicFinalCharArray = tf_char_arr;");
  81.515 +        assertArrayEquals("Nashorn hello".toCharArray(), o.publicFinalCharArray);
  81.516 +        e.eval("o.publicFinalCharArray[0] = 'Z';");
  81.517 +        assertEquals('Z', o.publicFinalCharArray[0]);
  81.518 +    }
  81.519 +
  81.520 +    @Test
  81.521 +    public void accessStaticFinalFieldChar() throws ScriptException {
  81.522 +        e.eval("var psf_char = SharedObject.publicStaticFinalChar;");
  81.523 +        assertEquals(SharedObject.publicStaticFinalChar, e.get("psf_char"));
  81.524 +        e.eval("SharedObject.publicStaticFinalChar = 'Z';");
  81.525 +        assertEquals('K', SharedObject.publicStaticFinalChar);
  81.526 +    }
  81.527 +
  81.528 +    @Test
  81.529 +    public void accessStaticFinalFieldCharArray() throws ScriptException {
  81.530 +        e.eval("var psf_char_array = SharedObject.publicStaticFinalCharArray;");
  81.531 +        assertEquals(SharedObject.publicStaticFinalCharArray[0], e.eval("SharedObject.publicStaticFinalCharArray[0];"));
  81.532 +        assertArrayEquals(SharedObject.publicStaticFinalCharArray, (char[])e.get("psf_char_array"));
  81.533 +        e.eval("var tsf_char_arr = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 3);" +
  81.534 +                "tsf_char_arr[0] = 'Z';" +
  81.535 +                "tsf_char_arr[1] = 'o';" +
  81.536 +                "tsf_char_arr[2] = 'o';" +
  81.537 +                "SharedObject.publicStaticFinalCharArray = tsf_char_arr;");
  81.538 +        assertArrayEquals("StaticString".toCharArray(), SharedObject.publicStaticFinalCharArray);
  81.539 +        e.eval("SharedObject.publicStaticFinalCharArray[0] = 'Z';");
  81.540 +        assertEquals('Z', SharedObject.publicStaticFinalCharArray[0]);
  81.541 +    }
  81.542 +
  81.543 +    // --------------------------------float
  81.544 +    // tests------------------------------------
  81.545 +    @Test
  81.546 +    public void accessFieldFloat() throws ScriptException {
  81.547 +        e.eval("var p_float = o.publicFloat;");
  81.548 +        assertEquals(o.publicFloat, e.get("p_float"));
  81.549 +        o.publicFloat = 0.0f / 0.0f;
  81.550 +        assertEquals(true, e.eval("isNaN(o.publicFloat)"));
  81.551 +        o.publicFloat = 1.0f / 0.0f;
  81.552 +        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === o.publicFloat"));
  81.553 +        o.publicFloat = -1.0f / 0.0f;
  81.554 +        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === o.publicFloat"));
  81.555 +        e.eval("o.publicFloat = 20;");
  81.556 +        assertEquals(20, o.publicFloat, 1e-10);
  81.557 +        e.eval("o.publicFloat = 0.0/0.0;");
  81.558 +        assertTrue(Float.isNaN(o.publicFloat));
  81.559 +        e.eval("o.publicFloat = 1.0/0.0;");
  81.560 +        assertEquals(Float.floatToIntBits(Float.POSITIVE_INFINITY), Float.floatToIntBits(o.publicFloat));
  81.561 +        e.eval("o.publicFloat = -1.0/0.0;");
  81.562 +        assertEquals(Float.NEGATIVE_INFINITY, o.publicFloat, 1e-10);
  81.563 +    }
  81.564 +
  81.565 +    @Test
  81.566 +    public void accessFieldFloatArray() throws ScriptException {
  81.567 +        e.eval("var p_float_array = o.publicFloatArray;");
  81.568 +        assertEquals(o.publicFloatArray[0], e.eval("o.publicFloatArray[0];"));
  81.569 +        assertArrayEquals(o.publicFloatArray, (float[])e.get("p_float_array"), 1e-10f);
  81.570 +        e.eval("var t_float_arr = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, 3);" +
  81.571 +                "t_float_arr[0] = 9.0;" +
  81.572 +                "t_float_arr[1] = 5.12345;" +
  81.573 +                "t_float_arr[2] = -60.03;" +
  81.574 +                "o.publicFloatArray = t_float_arr;");
  81.575 +        assertArrayEquals(new float[] { 9.0f, 5.12345f, -60.03f }, o.publicFloatArray, 1e-10f);
  81.576 +        e.eval("o.publicFloatArray[0] = -513.2;");
  81.577 +        assertArrayEquals(new float[] { -513.2f, 5.12345f, -60.03f }, o.publicFloatArray, 1e-10f);
  81.578 +    }
  81.579 +
  81.580 +    @Test
  81.581 +    public void accessStaticFieldFloat() throws ScriptException {
  81.582 +        e.eval("var ps_float = SharedObject.publicStaticFloat;");
  81.583 +        assertEquals(SharedObject.publicStaticFloat, e.get("ps_float"));
  81.584 +        SharedObject.publicStaticFloat = 0.0f / 0.0f;
  81.585 +        assertEquals(true, e.eval("isNaN(SharedObject.publicStaticFloat)"));
  81.586 +        SharedObject.publicStaticFloat = 1.0f / 0.0f;
  81.587 +        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === SharedObject.publicStaticFloat"));
  81.588 +        SharedObject.publicStaticFloat = -1.0f / 0.0f;
  81.589 +        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === SharedObject.publicStaticFloat"));
  81.590 +        e.eval("SharedObject.publicStaticFloat = 20.0;");
  81.591 +        assertEquals(20.0f, SharedObject.publicStaticFloat, 1e-10);
  81.592 +        e.eval("SharedObject.publicStaticFloat = 0.0/0.0;");
  81.593 +        assertTrue(Float.isNaN(SharedObject.publicStaticFloat));
  81.594 +        e.eval("SharedObject.publicStaticFloat = 1.0/0.0;");
  81.595 +        assertEquals(Float.floatToIntBits(Float.POSITIVE_INFINITY), Float.floatToIntBits(SharedObject.publicStaticFloat));
  81.596 +        e.eval("SharedObject.publicStaticFloat = -1.0/0.0;");
  81.597 +        assertEquals(Float.floatToIntBits(Float.NEGATIVE_INFINITY), Float.floatToIntBits(SharedObject.publicStaticFloat));
  81.598 +    }
  81.599 +
  81.600 +    @Test
  81.601 +    public void accessStaticFieldFloatArray() throws ScriptException {
  81.602 +        e.eval("var ps_float_array = SharedObject.publicStaticFloatArray;");
  81.603 +        assertEquals(SharedObject.publicStaticFloatArray[0], e.eval("SharedObject.publicStaticFloatArray[0];"));
  81.604 +        assertArrayEquals(SharedObject.publicStaticFloatArray, (float[])e.get("ps_float_array"), 1e-10f);
  81.605 +        e.eval("var ts_float_arr = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, 3);" +
  81.606 +                "ts_float_arr[0] = 9.0;" +
  81.607 +                "ts_float_arr[1] = 5.12345;" +
  81.608 +                "ts_float_arr[2] = -60.03;" +
  81.609 +                "SharedObject.publicStaticFloatArray = ts_float_arr;");
  81.610 +        assertArrayEquals(new float[] { 9.0f, 5.12345f, -60.03f }, SharedObject.publicStaticFloatArray, 1e-10f);
  81.611 +        e.eval("SharedObject.publicStaticFloatArray[0] = -513.2;");
  81.612 +        assertArrayEquals(new float[] { -513.2f, 5.12345f, -60.03f }, SharedObject.publicStaticFloatArray, 1e-10f);
  81.613 +    }
  81.614 +
  81.615 +    @Test
  81.616 +    public void accessFinalFloat() throws ScriptException {
  81.617 +        e.eval("var pf_float = o.publicFinalFloat;");
  81.618 +        assertEquals(o.publicFinalFloat, e.get("pf_float"));
  81.619 +        e.eval("o.publicFinalFloat = 20.0;");
  81.620 +        assertEquals(7.72e8f, o.publicFinalFloat, 1e-10);
  81.621 +    }
  81.622 +
  81.623 +    @Test
  81.624 +    public void accessFinalFloatArray() throws ScriptException {
  81.625 +        e.eval("var pf_float_array = o.publicFinalFloatArray;");
  81.626 +        assertEquals(o.publicFinalFloatArray[0], e.eval("o.publicFinalFloatArray[0];"));
  81.627 +        assertArrayEquals(o.publicFinalFloatArray, (float[])e.get("pf_float_array"), 1e-10f);
  81.628 +        e.eval("var tf_float_arr = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, 3);" +
  81.629 +                "tf_float_arr[0] = 9.0;" +
  81.630 +                "tf_float_arr[1] = 5.12345;" +
  81.631 +                "tf_float_arr[2] = -60.03;" +
  81.632 +                "o.publicFinalFloatArray = tf_float_arr;");
  81.633 +        assertArrayEquals(new float[] { -131.012f, 189.32f, -31.32e8f, 3.72f }, o.publicFinalFloatArray, 1e-10f);
  81.634 +        e.eval("o.publicFinalFloatArray[0] = -513.2;");
  81.635 +        assertEquals(-513.2f, o.publicFinalFloatArray[0], 1e-10f);
  81.636 +    }
  81.637 +
  81.638 +    @Test
  81.639 +    public void accessStaticFinalFieldFloat() throws ScriptException {
  81.640 +        e.eval("var psf_float = SharedObject.publicStaticFinalFloat;");
  81.641 +        assertEquals(SharedObject.publicStaticFinalFloat, e.get("psf_float"));
  81.642 +        e.eval("SharedObject.publicStaticFinalFloat = 20.0;");
  81.643 +        assertEquals(0.72e8f, SharedObject.publicStaticFinalFloat, 1e-10);
  81.644 +    }
  81.645 +
  81.646 +    @Test
  81.647 +    public void accessStaticFinalFieldFloatArray() throws ScriptException {
  81.648 +        e.eval("var psf_float_array = SharedObject.publicStaticFinalFloatArray;");
  81.649 +        assertEquals(SharedObject.publicStaticFinalFloatArray[0], e.eval("SharedObject.publicStaticFinalFloatArray[0];"));
  81.650 +        assertArrayEquals(SharedObject.publicStaticFinalFloatArray, (float[])e.get("psf_float_array"), 1e-10f);
  81.651 +        e.eval("var tsf_float_arr = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, 3);" +
  81.652 +                "tsf_float_arr[0] = 9.0;" +
  81.653 +                "tsf_float_arr[1] = 5.12345;" +
  81.654 +                "tsf_float_arr[2] = -60.03;" +
  81.655 +                "SharedObject.publicStaticFinalFloatArray = tsf_float_arr;");
  81.656 +        assertArrayEquals(new float[] { -8131.012f, 9.32f, -138.32e8f, 0.72f }, SharedObject.publicStaticFinalFloatArray, 1e-10f);
  81.657 +        e.eval("SharedObject.publicStaticFinalFloatArray[0] = -513.2;");
  81.658 +        assertEquals(-513.2f, SharedObject.publicStaticFinalFloatArray[0], 1e-10f);
  81.659 +    }
  81.660 +
  81.661 +    // --------------------------------double
  81.662 +    // tests------------------------------------
  81.663 +    @Test
  81.664 +    public void accessFieldDouble() throws ScriptException {
  81.665 +        e.eval("var p_double = o.publicDouble;");
  81.666 +        assertEquals(o.publicDouble, e.get("p_double"));
  81.667 +        o.publicDouble = 0.0 / 0.0;
  81.668 +        assertEquals(true, e.eval("isNaN(o.publicDouble)"));
  81.669 +        o.publicDouble = 1.0 / 0.0;
  81.670 +        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === o.publicDouble"));
  81.671 +        o.publicDouble = -1.0 / 0.0;
  81.672 +        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === o.publicDouble"));
  81.673 +        e.eval("o.publicDouble = 30;");
  81.674 +        assertEquals(Double.doubleToLongBits(30.0), Double.doubleToLongBits(o.publicDouble));
  81.675 +        e.eval("o.publicDouble = 0.0/0.0;");
  81.676 +        assertTrue(Double.isNaN(o.publicDouble));
  81.677 +        e.eval("o.publicDouble = 1.0/0.0;");
  81.678 +        assertEquals(Double.doubleToLongBits(Double.POSITIVE_INFINITY), Double.doubleToLongBits(o.publicDouble));
  81.679 +        e.eval("o.publicDouble = -1.0/0.0;");
  81.680 +        assertEquals(Double.doubleToLongBits(Double.NEGATIVE_INFINITY), Double.doubleToLongBits(o.publicDouble));
  81.681 +    }
  81.682 +
  81.683 +    @Test
  81.684 +    public void accessFieldDoubleArrayRead() throws ScriptException {
  81.685 +        e.eval("var p_double_array = o.publicDoubleArray;");
  81.686 +        assertEquals(o.publicDoubleArray[0], e.eval("o.publicDoubleArray[0];"));
  81.687 +        assertArrayEquals(o.publicDoubleArray, (double[])e.get("p_double_array"), 1e-10);
  81.688 +        e.eval("var t_double_arr = java.lang.reflect.Array.newInstance(java.lang.Double.TYPE, 3);" +
  81.689 +                "t_double_arr[0] = 9e10;" +
  81.690 +                "t_double_arr[1] = 0.677777;" +
  81.691 +                "t_double_arr[2] = -0.0000001;" +
  81.692 +                "o.publicDoubleArray = t_double_arr;");
  81.693 +        assertArrayEquals(new double[] { 9e10, 0.677777, -0.0000001 }, o.publicDoubleArray, 1e-10f);
  81.694 +        e.eval("o.publicDoubleArray[0] = -5.2e10;");
  81.695 +        assertEquals(-5.2e10, o.publicDoubleArray[0], 1e-10f);
  81.696 +    }
  81.697 +
  81.698 +    @Test
  81.699 +    public void accessStaticFieldDouble() throws ScriptException {
  81.700 +        e.eval("var ps_double = SharedObject.publicStaticDouble;");
  81.701 +        assertEquals(SharedObject.publicStaticDouble, e.get("ps_double"));
  81.702 +        SharedObject.publicStaticDouble = 0.0 / 0.0;
  81.703 +        assertEquals(true, e.eval("isNaN(SharedObject.publicStaticDouble)"));
  81.704 +        SharedObject.publicStaticDouble = 1.0 / 0.0;
  81.705 +        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === SharedObject.publicStaticDouble"));
  81.706 +        SharedObject.publicStaticDouble = -1.0 / 0.0;
  81.707 +        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === SharedObject.publicStaticDouble"));
  81.708 +        e.eval("SharedObject.publicStaticDouble = 40.0;");
  81.709 +        assertEquals(Double.doubleToLongBits(40.0), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  81.710 +        e.eval("SharedObject.publicStaticDouble = 0.0/0.0;");
  81.711 +        assertTrue(Double.isNaN(SharedObject.publicStaticDouble));
  81.712 +        e.eval("SharedObject.publicStaticDouble = 1.0/0.0;");
  81.713 +        assertEquals(Double.doubleToLongBits(Double.POSITIVE_INFINITY), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  81.714 +        e.eval("SharedObject.publicStaticDouble = -1.0/0.0;");
  81.715 +        assertEquals(Double.doubleToLongBits(Double.NEGATIVE_INFINITY), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  81.716 +    }
  81.717 +
  81.718 +    @Test
  81.719 +    public void accessStaticFieldDoubleArrayRead() throws ScriptException {
  81.720 +        e.eval("var ps_double_array = SharedObject.publicStaticDoubleArray;");
  81.721 +        assertEquals(SharedObject.publicStaticDoubleArray[0], e.eval("SharedObject.publicStaticDoubleArray[0];"));
  81.722 +        assertArrayEquals(SharedObject.publicStaticDoubleArray, (double[])e.get("ps_double_array"), 1e-10);
  81.723 +        e.eval("var ts_double_arr = java.lang.reflect.Array.newInstance(java.lang.Double.TYPE, 3);" +
  81.724 +                "ts_double_arr[0] = 9e10;" +
  81.725 +                "ts_double_arr[1] = 0.677777;" +
  81.726 +                "ts_double_arr[2] = -0.0000001;" +
  81.727 +                "SharedObject.publicStaticDoubleArray = ts_double_arr;");
  81.728 +        assertArrayEquals(new double[] { 9e10, 0.677777, -0.0000001 }, SharedObject.publicStaticDoubleArray, 1e-10f);
  81.729 +        e.eval("SharedObject.publicStaticDoubleArray[0] = -5.2e10;");
  81.730 +        assertEquals(-5.2e10, SharedObject.publicStaticDoubleArray[0], 1e-10f);
  81.731 +    }
  81.732 +
  81.733 +    @Test
  81.734 +    public void accessFinalFieldDouble() throws ScriptException {
  81.735 +        e.eval("var pf_double = o.publicFinalDouble;");
  81.736 +        assertEquals(o.publicFinalDouble, e.get("pf_double"));
  81.737 +        e.eval("o.publicFinalDouble = 30.0;");
  81.738 +        assertEquals(Double.doubleToLongBits(1.3412e20), Double.doubleToLongBits(o.publicFinalDouble));
  81.739 +    }
  81.740 +
  81.741 +    @Test
  81.742 +    public void accessFinalFieldDoubleArrayRead() throws ScriptException {
  81.743 +        e.eval("var pf_double_array = o.publicFinalDoubleArray;");
  81.744 +        assertEquals(o.publicFinalDoubleArray[0], e.eval("o.publicFinalDoubleArray[0];"));
  81.745 +        assertArrayEquals(o.publicFinalDoubleArray, (double[])e.get("pf_double_array"), 1e-10);
  81.746 +        e.eval("var tf_double_arr = java.lang.reflect.Array.newInstance(java.lang.Double.TYPE, 3);" +
  81.747 +                "tf_double_arr[0] = 9e10;" +
  81.748 +                "tf_double_arr[1] = 0.677777;" +
  81.749 +                "tf_double_arr[2] = -0.0000001;" +
  81.750 +                "o.publicFinalDoubleArray = tf_double_arr;");
  81.751 +        assertArrayEquals(new double[] { 0.725e80, 0.12e10, 8e-3, 1.00077 }, o.publicFinalDoubleArray, 1e-10f);
  81.752 +        e.eval("o.publicFinalDoubleArray[0] = -5.2e10;");
  81.753 +        assertEquals(-5.2e10, o.publicFinalDoubleArray[0], 1e-10f);
  81.754 +    }
  81.755 +
  81.756 +    @Test
  81.757 +    public void accessStaticFinalFieldDouble() throws ScriptException {
  81.758 +        e.eval("var psf_double = SharedObject.publicStaticFinalDouble;");
  81.759 +        assertEquals(SharedObject.publicStaticFinalDouble, e.get("psf_double"));
  81.760 +        e.eval("SharedObject.publicStaticFinalDouble = 40.0;");
  81.761 +        assertEquals(Double.doubleToLongBits(1.8e12), Double.doubleToLongBits(SharedObject.publicStaticFinalDouble));
  81.762 +    }
  81.763 +
  81.764 +    @Test
  81.765 +    public void accessStaticFinalFieldDoubleArrayRead() throws ScriptException {
  81.766 +        e.eval("var psf_double_array = SharedObject.publicStaticFinalDoubleArray;");
  81.767 +        assertEquals(SharedObject.publicStaticFinalDoubleArray[0], e.eval("SharedObject.publicStaticFinalDoubleArray[0];"));
  81.768 +        assertArrayEquals(SharedObject.publicStaticFinalDoubleArray, (double[])e.get("psf_double_array"), 1e-10);
  81.769 +        e.eval("var tsf_double_arr = java.lang.reflect.Array.newInstance(java.lang.Double.TYPE, 3);" +
  81.770 +                "tsf_double_arr[0] = 9e10;" +
  81.771 +                "tsf_double_arr[1] = 0.677777;" +
  81.772 +                "tsf_double_arr[2] = -0.0000001;" +
  81.773 +                "SharedObject.publicStaticFinalDoubleArray = tsf_double_arr;");
  81.774 +        assertArrayEquals(new double[] { 8.725e80, 0.82e10, 18e-3, 1.08077 }, SharedObject.publicStaticFinalDoubleArray, 1e-10f);
  81.775 +        e.eval("SharedObject.publicStaticFinalDoubleArray[0] = -5.2e10;");
  81.776 +        assertEquals(-5.2e10, SharedObject.publicStaticFinalDoubleArray[0], 1e-10f);
  81.777 +    }
  81.778 +
  81.779 +}
    82.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.2 +++ b/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java	Mon Feb 11 21:26:06 2013 +0530
    82.3 @@ -0,0 +1,348 @@
    82.4 +/*
    82.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    82.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    82.7 + *
    82.8 + * This code is free software; you can redistribute it and/or modify it
    82.9 + * under the terms of the GNU General Public License version 2 only, as
   82.10 + * published by the Free Software Foundation.  Oracle designates this
   82.11 + * particular file as subject to the "Classpath" exception as provided
   82.12 + * by Oracle in the LICENSE file that accompanied this code.
   82.13 + *
   82.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   82.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   82.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   82.17 + * version 2 for more details (a copy is included in the LICENSE file that
   82.18 + * accompanied this code).
   82.19 + *
   82.20 + * You should have received a copy of the GNU General Public License version
   82.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   82.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   82.23 + *
   82.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   82.25 + * or visit www.oracle.com if you need additional information or have any
   82.26 + * questions.
   82.27 + */
   82.28 +
   82.29 +package jdk.nashorn.api.javaaccess;
   82.30 +
   82.31 +import static org.testng.AssertJUnit.assertEquals;
   82.32 +import static org.testng.AssertJUnit.assertTrue;
   82.33 +
   82.34 +import javax.script.ScriptEngine;
   82.35 +import javax.script.ScriptEngineManager;
   82.36 +import javax.script.ScriptException;
   82.37 +import org.testng.TestNG;
   82.38 +import org.testng.annotations.BeforeClass;
   82.39 +import org.testng.annotations.Test;
   82.40 +
   82.41 +public class NumberBoxingTest {
   82.42 +
   82.43 +    private static ScriptEngine e = null;
   82.44 +    private static SharedObject o = new SharedObject();
   82.45 +
   82.46 +    public static void main(final String[] args) {
   82.47 +        TestNG.main(args);
   82.48 +    }
   82.49 +
   82.50 +    @BeforeClass
   82.51 +    public static void setUpClass() throws ScriptException {
   82.52 +        final ScriptEngineManager m = new ScriptEngineManager();
   82.53 +        e = m.getEngineByName("nashorn");
   82.54 +        e.put("o", o);
   82.55 +        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   82.56 +    }
   82.57 +
   82.58 +    // --------------------------------long
   82.59 +    // tests------------------------------------
   82.60 +    @Test
   82.61 +    public void accessFieldLongBoxing() throws ScriptException {
   82.62 +        e.eval("var p_long = o.publicLongBox;");
   82.63 +        assertEquals(o.publicLongBox, e.get("p_long"));
   82.64 +        e.eval("o.publicLongBox = 12;");
   82.65 +        assertEquals(Long.valueOf(12), o.publicLongBox);
   82.66 +    }
   82.67 +
   82.68 +    @Test
   82.69 +    public void accessStaticFieldLongBoxing() throws ScriptException {
   82.70 +        e.eval("var ps_long = SharedObject.publicStaticLong;");
   82.71 +        assertEquals(SharedObject.publicStaticLong, e.get("ps_long"));
   82.72 +        e.eval("SharedObject.publicStaticLong = 120;");
   82.73 +        assertEquals(120, SharedObject.publicStaticLong);
   82.74 +    }
   82.75 +
   82.76 +    @Test
   82.77 +    public void accessFinalFieldLongBoxing() throws ScriptException {
   82.78 +        e.eval("var pf_long = o.publicFinalLongBox;");
   82.79 +        assertEquals(o.publicFinalLongBox, e.get("pf_long"));
   82.80 +        e.eval("o.publicFinalLongBox = 120;");
   82.81 +        assertEquals(Long.valueOf(9377333334L), o.publicFinalLongBox);
   82.82 +    }
   82.83 +
   82.84 +    @Test
   82.85 +    public void accessStaticFinalFieldLongBoxing() throws ScriptException {
   82.86 +        e.eval("var psf_long = SharedObject.publicStaticFinalLong;");
   82.87 +        assertEquals(SharedObject.publicStaticFinalLong, e.get("psf_long"));
   82.88 +        e.eval("SharedObject.publicStaticFinalLong = 120;");
   82.89 +        assertEquals(8333333333333L, SharedObject.publicStaticFinalLong);
   82.90 +    }
   82.91 +
   82.92 +    // --------------------------------int
   82.93 +    // tests------------------------------------
   82.94 +    @Test
   82.95 +    public void accessFieldIntBoxing() throws ScriptException {
   82.96 +        e.eval("var p_int = o.publicIntBox;");
   82.97 +        assertEquals(o.publicIntBox, e.get("p_int"));
   82.98 +        e.eval("o.publicIntBox = 14;");
   82.99 +        assertEquals(Integer.valueOf(14), o.publicIntBox);
  82.100 +    }
  82.101 +
  82.102 +    @Test
  82.103 +    public void accessStaticFieldIntBoxing() throws ScriptException {
  82.104 +        e.eval("var ps_int = SharedObject.publicStaticInt;");
  82.105 +        assertEquals(SharedObject.publicStaticInt, e.get("ps_int"));
  82.106 +        e.eval("SharedObject.publicStaticInt = 140;");
  82.107 +        assertEquals(140, SharedObject.publicStaticInt);
  82.108 +    }
  82.109 +
  82.110 +    @Test
  82.111 +    public void accessFinalFieldIntBoxing() throws ScriptException {
  82.112 +        e.eval("var pf_int = o.publicFinalIntBox;");
  82.113 +        assertEquals(o.publicFinalIntBox, e.get("pf_int"));
  82.114 +        e.eval("o.publicFinalIntBox = 10;");
  82.115 +        assertEquals(Integer.valueOf(207512301), o.publicFinalIntBox);
  82.116 +    }
  82.117 +
  82.118 +    @Test
  82.119 +    public void accessStaticFinalFieldIntBoxing() throws ScriptException {
  82.120 +        e.eval("var psf_int = SharedObject.publicStaticFinalInt;");
  82.121 +        assertEquals(SharedObject.publicStaticFinalInt, e.get("psf_int"));
  82.122 +        e.eval("SharedObject.publicStaticFinalInt = 140;");
  82.123 +        assertEquals(207182023, SharedObject.publicStaticFinalInt);
  82.124 +    }
  82.125 +
  82.126 +    // --------------------------------byte
  82.127 +    // tests------------------------------------
  82.128 +    @Test
  82.129 +    public void accessFieldByteBoxing() throws ScriptException {
  82.130 +        e.eval("var p_byte = o.publicByteBox;");
  82.131 +        assertEquals(o.publicByteBox, e.get("p_byte"));
  82.132 +        e.eval("o.publicByteBox = 16;");
  82.133 +        assertEquals(Byte.valueOf((byte)16), o.publicByteBox);
  82.134 +    }
  82.135 +
  82.136 +    @Test
  82.137 +    public void accessStaticFieldByteBoxing() throws ScriptException {
  82.138 +        e.eval("var ps_byte = SharedObject.publicStaticByte;");
  82.139 +        assertEquals(SharedObject.publicStaticByte, e.get("ps_byte"));
  82.140 +        e.eval("SharedObject.publicStaticByte = 16;");
  82.141 +        assertEquals(16, SharedObject.publicStaticByte);
  82.142 +    }
  82.143 +
  82.144 +    @Test
  82.145 +    public void accessFinalFieldByteBoxing() throws ScriptException {
  82.146 +        e.eval("var pf_byte = o.publicFinalByteBox;");
  82.147 +        assertEquals(o.publicFinalByteBox, e.get("pf_byte"));
  82.148 +        e.eval("o.publicFinalByteBox = 16;");
  82.149 +        assertEquals(Byte.valueOf((byte)19), o.publicFinalByteBox);
  82.150 +    }
  82.151 +
  82.152 +    @Test
  82.153 +    public void accessStaticFinalFieldByteBoxing() throws ScriptException {
  82.154 +        e.eval("var psf_byte = SharedObject.publicStaticFinalByte;");
  82.155 +        assertEquals(SharedObject.publicStaticFinalByte, e.get("psf_byte"));
  82.156 +        e.eval("SharedObject.publicStaticFinalByte = 16;");
  82.157 +        assertEquals(-70, SharedObject.publicStaticFinalByte);
  82.158 +    }
  82.159 +
  82.160 +    // --------------------------------short
  82.161 +    // tests------------------------------------
  82.162 +    @Test
  82.163 +    public void accessFieldShortBoxing() throws ScriptException {
  82.164 +        e.eval("var p_short = o.publicShortBox;");
  82.165 +        assertEquals(o.publicShortBox, e.get("p_short"));
  82.166 +        e.eval("o.publicShortBox = 18;");
  82.167 +        assertEquals(Short.valueOf((short)18), o.publicShortBox);
  82.168 +    }
  82.169 +
  82.170 +    @Test
  82.171 +    public void accessStaticFieldShortBoxing() throws ScriptException {
  82.172 +        e.eval("var ps_short = SharedObject.publicStaticShort;");
  82.173 +        assertEquals(SharedObject.publicStaticShort, e.get("ps_short"));
  82.174 +        e.eval("SharedObject.publicStaticShort = 180;");
  82.175 +        assertEquals(180, SharedObject.publicStaticShort);
  82.176 +    }
  82.177 +
  82.178 +    @Test
  82.179 +    public void accessFinalFieldShortBoxing() throws ScriptException {
  82.180 +        e.eval("var pf_short = o.publicFinalShortBox;");
  82.181 +        assertEquals(o.publicFinalShortBox, e.get("pf_short"));
  82.182 +        e.eval("o.publicFinalShortBox = 180;");
  82.183 +        assertEquals(Short.valueOf((short)-26777), o.publicFinalShortBox);
  82.184 +    }
  82.185 +
  82.186 +    @Test
  82.187 +    public void accessStaticFinalFieldShortBoxing() throws ScriptException {
  82.188 +        e.eval("var psf_short = SharedObject.publicStaticFinalShort;");
  82.189 +        assertEquals(SharedObject.publicStaticFinalShort, e.get("psf_short"));
  82.190 +        e.eval("SharedObject.publicStaticFinalShort = 180;");
  82.191 +        assertEquals(8888, SharedObject.publicStaticFinalShort);
  82.192 +    }
  82.193 +
  82.194 +    // --------------------------------char
  82.195 +    // tests------------------------------------
  82.196 +    @Test
  82.197 +    public void accessFieldCharBoxing() throws ScriptException {
  82.198 +        e.eval("var p_char = o.publicCharBox;");
  82.199 +        assertEquals(o.publicCharBox, e.get("p_char"));
  82.200 +        e.eval("o.publicCharBox = 'S';");
  82.201 +        assertEquals(Character.valueOf('S'), o.publicCharBox);
  82.202 +        e.eval("try {" +
  82.203 +                "    o.publicCharBox = 'Big string';" +
  82.204 +                "} catch(e) {" +
  82.205 +                "    var isThrown = true;" +
  82.206 +                "}");
  82.207 +        assertEquals("Exception thrown", true, e.get("isThrown"));
  82.208 +        assertEquals(Character.valueOf('S'), o.publicCharBox);
  82.209 +    }
  82.210 +
  82.211 +    @Test
  82.212 +    public void accessStaticFieldCharBoxing() throws ScriptException {
  82.213 +        e.eval("var ps_char = SharedObject.publicStaticChar;");
  82.214 +        assertEquals(SharedObject.publicStaticChar, e.get("ps_char"));
  82.215 +        e.eval("SharedObject.publicStaticChar = 'Z';");
  82.216 +        assertEquals('Z', SharedObject.publicStaticChar);
  82.217 +    }
  82.218 +
  82.219 +    @Test
  82.220 +    public void accessFinalFieldCharBoxing() throws ScriptException {
  82.221 +        e.eval("var pf_char = o.publicFinalCharBox;");
  82.222 +        assertEquals(o.publicFinalCharBox, e.get("pf_char"));
  82.223 +        e.eval("o.publicFinalCharBox = 'S';");
  82.224 +        assertEquals(Character.valueOf('F'), o.publicFinalCharBox);
  82.225 +    }
  82.226 +
  82.227 +    @Test
  82.228 +    public void accessStaticFinalFieldCharBoxing() throws ScriptException {
  82.229 +        e.eval("var psf_char = SharedObject.publicStaticFinalChar;");
  82.230 +        assertEquals(SharedObject.publicStaticFinalChar, e.get("psf_char"));
  82.231 +        e.eval("SharedObject.publicStaticFinalChar = 'Z';");
  82.232 +        assertEquals('K', SharedObject.publicStaticFinalChar);
  82.233 +    }
  82.234 +
  82.235 +    // --------------------------------float
  82.236 +    // tests------------------------------------
  82.237 +    @Test
  82.238 +    public void accessFieldFloatBoxing() throws ScriptException {
  82.239 +        e.eval("var p_float = o.publicFloatBox;");
  82.240 +        assertEquals(o.publicFloatBox, e.get("p_float"));
  82.241 +        o.publicFloatBox = 0.0f / 0.0f;
  82.242 +        assertEquals(true, e.eval("isNaN(o.publicFloatBox)"));
  82.243 +        o.publicFloatBox = 1.0f / 0.0f;
  82.244 +        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === o.publicFloatBox"));
  82.245 +        o.publicFloatBox = -1.0f / 0.0f;
  82.246 +        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === o.publicFloatBox"));
  82.247 +        e.eval("o.publicFloatBox = 20;");
  82.248 +        assertEquals(20, o.publicFloatBox, 1e-10);
  82.249 +        e.eval("o.publicFloatBox = 0.0/0.0;");
  82.250 +        assertTrue(Float.isNaN(o.publicFloatBox));
  82.251 +        e.eval("o.publicFloatBox = 1.0/0.0;");
  82.252 +        assertEquals(Float.floatToIntBits(Float.POSITIVE_INFINITY), Float.floatToIntBits(o.publicFloatBox));
  82.253 +        e.eval("o.publicFloatBox = -1.0/0.0;");
  82.254 +        assertEquals(Float.NEGATIVE_INFINITY, o.publicFloatBox, 1e-10);
  82.255 +    }
  82.256 +
  82.257 +    @Test
  82.258 +    public void accessStaticFieldFloatBoxing() throws ScriptException {
  82.259 +        e.eval("var ps_float = SharedObject.publicStaticFloat;");
  82.260 +        assertEquals(SharedObject.publicStaticFloat, e.get("ps_float"));
  82.261 +        SharedObject.publicStaticFloat = 0.0f / 0.0f;
  82.262 +        assertEquals(true, e.eval("isNaN(SharedObject.publicStaticFloat)"));
  82.263 +        SharedObject.publicStaticFloat = 1.0f / 0.0f;
  82.264 +        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === SharedObject.publicStaticFloat"));
  82.265 +        SharedObject.publicStaticFloat = -1.0f / 0.0f;
  82.266 +        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === SharedObject.publicStaticFloat"));
  82.267 +        e.eval("SharedObject.publicStaticFloat = 20.0;");
  82.268 +        assertEquals(20.0f, SharedObject.publicStaticFloat, 1e-10);
  82.269 +        e.eval("SharedObject.publicStaticFloat = 0.0/0.0;");
  82.270 +        assertTrue(Float.isNaN(SharedObject.publicStaticFloat));
  82.271 +        e.eval("SharedObject.publicStaticFloat = 1.0/0.0;");
  82.272 +        assertEquals(Float.floatToIntBits(Float.POSITIVE_INFINITY), Float.floatToIntBits(SharedObject.publicStaticFloat));
  82.273 +        e.eval("SharedObject.publicStaticFloat = -1.0/0.0;");
  82.274 +        assertEquals(Float.floatToIntBits(Float.NEGATIVE_INFINITY), Float.floatToIntBits(SharedObject.publicStaticFloat));
  82.275 +    }
  82.276 +
  82.277 +    @Test
  82.278 +    public void accessFinalFloatBoxing() throws ScriptException {
  82.279 +        e.eval("var pf_float = o.publicFinalFloatBox;");
  82.280 +        assertEquals(o.publicFinalFloatBox, e.get("pf_float"));
  82.281 +        e.eval("o.publicFinalFloatBox = 20.0;");
  82.282 +        assertEquals(1.372e4f, o.publicFinalFloatBox, 1e-10);
  82.283 +    }
  82.284 +
  82.285 +    @Test
  82.286 +    public void accessStaticFinalFieldFloatBoxing() throws ScriptException {
  82.287 +        e.eval("var psf_float = SharedObject.publicStaticFinalFloat;");
  82.288 +        assertEquals(SharedObject.publicStaticFinalFloat, e.get("psf_float"));
  82.289 +        e.eval("SharedObject.publicStaticFinalFloat = 20.0;");
  82.290 +        assertEquals(0.72e8f, SharedObject.publicStaticFinalFloat, 1e-10);
  82.291 +    }
  82.292 +
  82.293 +    // --------------------------------double
  82.294 +    // tests------------------------------------
  82.295 +    @Test
  82.296 +    public void accessFieldDoubleBoxing() throws ScriptException {
  82.297 +        e.eval("var p_double = o.publicDoubleBox;");
  82.298 +        assertEquals(o.publicDoubleBox, e.get("p_double"));
  82.299 +        o.publicDoubleBox = 0.0 / 0.0;
  82.300 +        assertEquals(true, e.eval("isNaN(o.publicDoubleBox)"));
  82.301 +        o.publicDoubleBox = 1.0 / 0.0;
  82.302 +        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === o.publicDoubleBox"));
  82.303 +        o.publicDoubleBox = -1.0 / 0.0;
  82.304 +        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === o.publicDoubleBox"));
  82.305 +        e.eval("o.publicDoubleBox = 30;");
  82.306 +        assertEquals(Double.doubleToLongBits(30.0), Double.doubleToLongBits(o.publicDoubleBox));
  82.307 +        e.eval("o.publicDoubleBox = 0.0/0.0;");
  82.308 +        assertTrue(Double.isNaN(o.publicDoubleBox));
  82.309 +        e.eval("o.publicDoubleBox = 1.0/0.0;");
  82.310 +        assertEquals(Double.doubleToLongBits(Double.POSITIVE_INFINITY), Double.doubleToLongBits(o.publicDoubleBox));
  82.311 +        e.eval("o.publicDoubleBox = -1.0/0.0;");
  82.312 +        assertEquals(Double.doubleToLongBits(Double.NEGATIVE_INFINITY), Double.doubleToLongBits(o.publicDoubleBox));
  82.313 +    }
  82.314 +
  82.315 +    @Test
  82.316 +    public void accessStaticFieldDoubleBoxing() throws ScriptException {
  82.317 +        e.eval("var ps_double = SharedObject.publicStaticDouble;");
  82.318 +        assertEquals(SharedObject.publicStaticDouble, e.get("ps_double"));
  82.319 +        SharedObject.publicStaticDouble = 0.0 / 0.0;
  82.320 +        assertEquals(true, e.eval("isNaN(SharedObject.publicStaticDouble)"));
  82.321 +        SharedObject.publicStaticDouble = 1.0 / 0.0;
  82.322 +        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === SharedObject.publicStaticDouble"));
  82.323 +        SharedObject.publicStaticDouble = -1.0 / 0.0;
  82.324 +        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === SharedObject.publicStaticDouble"));
  82.325 +        e.eval("SharedObject.publicStaticDouble = 40.0;");
  82.326 +        assertEquals(Double.doubleToLongBits(40.0), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  82.327 +        e.eval("SharedObject.publicStaticDouble = 0.0/0.0;");
  82.328 +        assertTrue(Double.isNaN(SharedObject.publicStaticDouble));
  82.329 +        e.eval("SharedObject.publicStaticDouble = 1.0/0.0;");
  82.330 +        assertEquals(Double.doubleToLongBits(Double.POSITIVE_INFINITY), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  82.331 +        e.eval("SharedObject.publicStaticDouble = -1.0/0.0;");
  82.332 +        assertEquals(Double.doubleToLongBits(Double.NEGATIVE_INFINITY), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  82.333 +    }
  82.334 +
  82.335 +    @Test
  82.336 +    public void accessFinalFieldDoubleBoxing() throws ScriptException {
  82.337 +        e.eval("var pf_double = o.publicFinalDoubleBox;");
  82.338 +        assertEquals(o.publicFinalDoubleBox, e.get("pf_double"));
  82.339 +        e.eval("o.publicFinalDoubleBox = 30.0;");
  82.340 +        assertEquals(Double.doubleToLongBits(1.412e-12), Double.doubleToLongBits(o.publicFinalDoubleBox));
  82.341 +    }
  82.342 +
  82.343 +    @Test
  82.344 +    public void accessStaticFinalFieldDoubleBoxing() throws ScriptException {
  82.345 +        e.eval("var psf_double = SharedObject.publicStaticFinalDouble;");
  82.346 +        assertEquals(SharedObject.publicStaticFinalDouble, e.get("psf_double"));
  82.347 +        e.eval("SharedObject.publicStaticFinalDouble = 40.0;");
  82.348 +        assertEquals(Double.doubleToLongBits(1.8e12), Double.doubleToLongBits(SharedObject.publicStaticFinalDouble));
  82.349 +    }
  82.350 +
  82.351 +}
    83.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.2 +++ b/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java	Mon Feb 11 21:26:06 2013 +0530
    83.3 @@ -0,0 +1,152 @@
    83.4 +/*
    83.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    83.7 + *
    83.8 + * This code is free software; you can redistribute it and/or modify it
    83.9 + * under the terms of the GNU General Public License version 2 only, as
   83.10 + * published by the Free Software Foundation.  Oracle designates this
   83.11 + * particular file as subject to the "Classpath" exception as provided
   83.12 + * by Oracle in the LICENSE file that accompanied this code.
   83.13 + *
   83.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   83.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   83.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   83.17 + * version 2 for more details (a copy is included in the LICENSE file that
   83.18 + * accompanied this code).
   83.19 + *
   83.20 + * You should have received a copy of the GNU General Public License version
   83.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   83.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   83.23 + *
   83.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   83.25 + * or visit www.oracle.com if you need additional information or have any
   83.26 + * questions.
   83.27 + */
   83.28 +
   83.29 +package jdk.nashorn.api.javaaccess;
   83.30 +
   83.31 +import static org.testng.AssertJUnit.assertEquals;
   83.32 +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
   83.33 +
   83.34 +import javax.script.ScriptEngine;
   83.35 +import javax.script.ScriptEngineManager;
   83.36 +import javax.script.ScriptException;
   83.37 +import org.testng.TestNG;
   83.38 +import org.testng.annotations.BeforeClass;
   83.39 +import org.testng.annotations.Test;
   83.40 +
   83.41 +public class ObjectAccessTest {
   83.42 +
   83.43 +    private static ScriptEngine e = null;
   83.44 +    private static SharedObject o = new SharedObject();
   83.45 +
   83.46 +    public static void main(final String[] args) {
   83.47 +        TestNG.main(args);
   83.48 +    }
   83.49 +
   83.50 +    @BeforeClass
   83.51 +    public static void setUpClass() throws ScriptException {
   83.52 +        final ScriptEngineManager m = new ScriptEngineManager();
   83.53 +        e = m.getEngineByName("nashorn");
   83.54 +        e.put("o", o);
   83.55 +        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   83.56 +        e.eval("var Person = Packages.jdk.nashorn.internal.access.Person;");
   83.57 +    }
   83.58 +
   83.59 +    @Test
   83.60 +    public void accessFieldObject() throws ScriptException {
   83.61 +        e.eval("var p_object = o.publicObject;");
   83.62 +        assertEquals(o.publicObject, e.get("p_object"));
   83.63 +        assertEquals("object", e.eval("typeof p_object;"));
   83.64 +        e.eval("o.publicObject = new Person(14);");
   83.65 +        assertEquals(new Person(14), o.publicObject);
   83.66 +    }
   83.67 +
   83.68 +    @Test
   83.69 +    public void accessFieldObjectArray() throws ScriptException {
   83.70 +        e.eval("var p_object_array = o.publicObjectArray;");
   83.71 +        assertEquals(o.publicObjectArray[0], e.eval("o.publicObjectArray[0]"));
   83.72 +        assertArrayEquals(o.publicObjectArray, (Object[])e.get("p_object_array"));
   83.73 +        e.eval("var t_object_arr = java.lang.reflect.Array.newInstance(Person.class, 3);" +
   83.74 +                "t_object_arr[0] = new Person(100);" +
   83.75 +                "t_object_arr[1] = new Person(120);" +
   83.76 +                "t_object_arr[2] = new Person(140);" +
   83.77 +                "o.publicObjectArray = t_object_arr;");
   83.78 +        assertArrayEquals(new Person[] { new Person(100), new Person(120), new Person(140) }, o.publicObjectArray);
   83.79 +        e.eval("o.publicObjectArray[0] = new Person(10);");
   83.80 +        assertEquals(new Person(10), o.publicObjectArray[0]);
   83.81 +    }
   83.82 +
   83.83 +    @Test
   83.84 +    public void accessStaticFieldObject() throws ScriptException {
   83.85 +        e.eval("var ps_object = SharedObject.publicStaticObject;");
   83.86 +        assertEquals(SharedObject.publicStaticObject, e.get("ps_object"));
   83.87 +        assertEquals("object", e.eval("typeof ps_object;"));
   83.88 +        e.eval("SharedObject.publicStaticObject = new Person(16);");
   83.89 +        assertEquals(new Person(16), SharedObject.publicStaticObject);
   83.90 +    }
   83.91 +
   83.92 +    @Test
   83.93 +    public void accessStaticFieldObjectArray() throws ScriptException {
   83.94 +        e.eval("var ps_object_array = SharedObject.publicStaticObjectArray;");
   83.95 +        assertEquals(SharedObject.publicStaticObjectArray[0], e.eval("SharedObject.publicStaticObjectArray[0]"));
   83.96 +        assertArrayEquals(SharedObject.publicStaticObjectArray, (Object[])e.get("ps_object_array"));
   83.97 +        e.eval("var ts_object_arr = java.lang.reflect.Array.newInstance(Person.class, 3);" +
   83.98 +                "ts_object_arr[0] = new Person(100);" +
   83.99 +                "ts_object_arr[1] = new Person(120);" +
  83.100 +                "ts_object_arr[2] = new Person(140);" +
  83.101 +                "SharedObject.publicStaticObjectArray = ts_object_arr;");
  83.102 +        assertArrayEquals(new Person[] { new Person(100), new Person(120), new Person(140) }, SharedObject.publicStaticObjectArray);
  83.103 +        e.eval("SharedObject.publicStaticObjectArray[0] = new Person(10);");
  83.104 +        assertEquals(new Person(10), SharedObject.publicStaticObjectArray[0]);
  83.105 +    }
  83.106 +
  83.107 +    @Test
  83.108 +    public void accessFinalFieldObject() throws ScriptException {
  83.109 +        e.eval("var pf_object = o.publicFinalObject;");
  83.110 +        assertEquals(o.publicFinalObject, e.get("pf_object"));
  83.111 +        assertEquals("object", e.eval("typeof pf_object;"));
  83.112 +        e.eval("o.publicFinalObject = new Person(-999);");
  83.113 +        assertEquals(new Person(1024), o.publicFinalObject);
  83.114 +    }
  83.115 +
  83.116 +    @Test
  83.117 +    public void accessFinalFieldObjectArray() throws ScriptException {
  83.118 +        e.eval("var pf_object_array = o.publicFinalObjectArray;");
  83.119 +        assertEquals(o.publicFinalObjectArray[0], e.eval("o.publicFinalObjectArray[0]"));
  83.120 +        assertArrayEquals(o.publicFinalObjectArray, (Object[])e.get("pf_object_array"));
  83.121 +        e.eval("var tf_object_arr = java.lang.reflect.Array.newInstance(Person.class, 3);" +
  83.122 +                "tf_object_arr[0] = new Person(100);" +
  83.123 +                "tf_object_arr[1] = new Person(120);" +
  83.124 +                "tf_object_arr[2] = new Person(140);" +
  83.125 +                "o.publicOFinalbjectArray = tf_object_arr;");
  83.126 +        assertArrayEquals(new Person[] { new Person(-900), new Person(1000), new Person(180) }, o.publicFinalObjectArray);
  83.127 +        e.eval("o.publicFinalObjectArray[0] = new Person(10);");
  83.128 +        assertEquals(new Person(10), o.publicFinalObjectArray[0]);
  83.129 +    }
  83.130 +
  83.131 +    @Test
  83.132 +    public void accessStaticFinalFieldObject() throws ScriptException {
  83.133 +        e.eval("var psf_object = SharedObject.publicStaticFinalObject;");
  83.134 +        assertEquals(SharedObject.publicStaticFinalObject, e.get("psf_object"));
  83.135 +        assertEquals("object", e.eval("typeof psf_object;"));
  83.136 +        e.eval("SharedObject.publicStaticFinalObject = new Person(6);");
  83.137 +        assertEquals(new Person(2048), SharedObject.publicStaticFinalObject);
  83.138 +    }
  83.139 +
  83.140 +    @Test
  83.141 +    public void accessStaticFinalFieldObjectArray() throws ScriptException {
  83.142 +        e.eval("var psf_object_array = SharedObject.publicStaticFinalObjectArray;");
  83.143 +        assertEquals(SharedObject.publicStaticFinalObjectArray[0], e.eval("SharedObject.publicStaticFinalObjectArray[0]"));
  83.144 +        assertArrayEquals(SharedObject.publicStaticFinalObjectArray, (Object[])e.get("psf_object_array"));
  83.145 +        e.eval("var tsf_object_arr = java.lang.reflect.Array.newInstance(Person.class, 3);" +
  83.146 +                "tsf_object_arr[0] = new Person(100);" +
  83.147 +                "tsf_object_arr[1] = new Person(120);" +
  83.148 +                "tsf_object_arr[2] = new Person(140);" +
  83.149 +                "SharedObject.publicStaticFinalObjectArray = tsf_object_arr;");
  83.150 +        assertArrayEquals(new Person[] { new Person(-9), new Person(110), new Person(Integer.MAX_VALUE) }, SharedObject.publicStaticFinalObjectArray);
  83.151 +        e.eval("SharedObject.publicStaticFinalObjectArray[0] = new Person(90);");
  83.152 +        assertEquals(new Person(90), SharedObject.publicStaticFinalObjectArray[0]);
  83.153 +    }
  83.154 +
  83.155 +}
    84.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.2 +++ b/test/src/jdk/nashorn/api/javaaccess/Person.java	Mon Feb 11 21:26:06 2013 +0530
    84.3 @@ -0,0 +1,58 @@
    84.4 +/*
    84.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    84.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    84.7 + *
    84.8 + * This code is free software; you can redistribute it and/or modify it
    84.9 + * under the terms of the GNU General Public License version 2 only, as
   84.10 + * published by the Free Software Foundation.  Oracle designates this
   84.11 + * particular file as subject to the "Classpath" exception as provided
   84.12 + * by Oracle in the LICENSE file that accompanied this code.
   84.13 + *
   84.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   84.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   84.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   84.17 + * version 2 for more details (a copy is included in the LICENSE file that
   84.18 + * accompanied this code).
   84.19 + *
   84.20 + * You should have received a copy of the GNU General Public License version
   84.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   84.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   84.23 + *
   84.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   84.25 + * or visit www.oracle.com if you need additional information or have any
   84.26 + * questions.
   84.27 + */
   84.28 +
   84.29 +package jdk.nashorn.api.javaaccess;
   84.30 +
   84.31 +public class Person {
   84.32 +
   84.33 +    public int id = 0;
   84.34 +
   84.35 +    public Person() {
   84.36 +    }
   84.37 +
   84.38 +    public Person(final int code) {
   84.39 +        this.id = code;
   84.40 +    }
   84.41 +
   84.42 +    @Override
   84.43 +    public boolean equals(final Object obj) {
   84.44 +        if (obj != null && obj instanceof Person) {
   84.45 +            final Person o = (Person)obj;
   84.46 +            return this.id == o.id;
   84.47 +        }
   84.48 +        return false;
   84.49 +    }
   84.50 +
   84.51 +    @Override
   84.52 +    public int hashCode() {
   84.53 +        return id;
   84.54 +    }
   84.55 +
   84.56 +    @Override
   84.57 +    public String toString() {
   84.58 +        return "Person(" + id + ")";
   84.59 +    }
   84.60 +
   84.61 +}
    85.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.2 +++ b/test/src/jdk/nashorn/api/javaaccess/SharedObject.java	Mon Feb 11 21:26:06 2013 +0530
    85.3 @@ -0,0 +1,466 @@
    85.4 +/*
    85.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    85.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    85.7 + *
    85.8 + * This code is free software; you can redistribute it and/or modify it
    85.9 + * under the terms of the GNU General Public License version 2 only, as
   85.10 + * published by the Free Software Foundation.  Oracle designates this
   85.11 + * particular file as subject to the "Classpath" exception as provided
   85.12 + * by Oracle in the LICENSE file that accompanied this code.
   85.13 + *
   85.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   85.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   85.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   85.17 + * version 2 for more details (a copy is included in the LICENSE file that
   85.18 + * accompanied this code).
   85.19 + *
   85.20 + * You should have received a copy of the GNU General Public License version
   85.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   85.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   85.23 + *
   85.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   85.25 + * or visit www.oracle.com if you need additional information or have any
   85.26 + * questions.
   85.27 + */
   85.28 +
   85.29 +package jdk.nashorn.api.javaaccess;
   85.30 +
   85.31 +import javax.script.Invocable;
   85.32 +import javax.script.ScriptEngine;
   85.33 +import javax.script.ScriptException;
   85.34 +
   85.35 +public class SharedObject {
   85.36 +
   85.37 +    // Public fields
   85.38 +    public String                 publicString                  = "PublicString";
   85.39 +    public String[]               publicStringArray             = { "ArrayString[0]", "ArrayString[1]", "ArrayString[2]", "ArrayString[3]" };
   85.40 +    public Person                 publicObject                  = new Person(256);
   85.41 +    public Person[]               publicObjectArray             = { new Person(4), new Person(-422), new Person(14) };
   85.42 +    public boolean                publicBoolean                 = true;
   85.43 +    public boolean[]              publicBooleanArray            = { true, false, false, true };
   85.44 +    public Boolean                publicBooleanBox              = true;
   85.45 +    public long                   publicLong                    = 933333333333333333L;
   85.46 +    public long[]                 publicLongArray               = { 99012333333333L, -124355555L, 89777777777L };
   85.47 +    public Long                   publicLongBox                 = 9333333333L;
   85.48 +    public int                    publicInt                     = 2076543123;
   85.49 +    public int[]                  publicIntArray                = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 };
   85.50 +    public Integer                publicIntBox                  = 20765123;
   85.51 +    public byte                   publicByte                    = -128;
   85.52 +    public byte[]                 publicByteArray               = { 1, 2, 4, 8, 16, 32, 64, 127, -128 };
   85.53 +    public Byte                   publicByteBox                 = 127;
   85.54 +    public short                  publicShort                   = 32000;
   85.55 +    public short[]                publicShortArray              = { 3240, 8900, -16789, 1, 12 };
   85.56 +    public Short                  publicShortBox                = Short.MIN_VALUE;
   85.57 +    public float                  publicFloat                   = 0.7e6f;
   85.58 +    public float[]                publicFloatArray              = { -32.01f, 89.3f, -1.3e8f, 3.1f };
   85.59 +    public Float                  publicFloatBox                = 1.377e4f;
   85.60 +    public double                 publicDouble                  = 1.34e20;
   85.61 +    public double[]               publicDoubleArray             = { 0.75e80, 8e-43, 1.000077, 0.123e10 };
   85.62 +    public Double                 publicDoubleBox               = 1.4e-19;
   85.63 +    public char                   publicChar                    = 'A';
   85.64 +    public char[]                 publicCharArray               = "Hello Nashorn".toCharArray();
   85.65 +    public Character              publicCharBox                 = 'B';
   85.66 +    // Public static fields
   85.67 +    public static String          publicStaticString            = "PublicStaticString";
   85.68 +    public static String[]        publicStaticStringArray       = { "StaticArrayString[0]", "StaticArrayString[1]", "StaticArrayString[2]", "StaticArrayString[3]" };
   85.69 +    public static Person          publicStaticObject            = new Person(512);
   85.70 +    public static Person[]        publicStaticObjectArray       = { new Person(40), new Person(-22), new Person(18) };
   85.71 +    public static boolean         publicStaticBoolean           = true;
   85.72 +    public static boolean[]       publicStaticBooleanArray      = { false, false, false, true };
   85.73 +    public static Boolean         publicStaticBooleanBox        = true;
   85.74 +    public static long            publicStaticLong              = 13333333333333333L;
   85.75 +    public static long[]          publicStaticLongArray         = { 19012333333333L, -224355555L, 39777777777L };
   85.76 +    public static Long            publicStaticLongBox           = 9333333334L;
   85.77 +    public static int             publicStaticInt               = 207654323;
   85.78 +    public static int[]           publicStaticIntArray          = { 5, 8, 13, 21, 34 };
   85.79 +    public static Integer         publicStaticIntBox            = 2075123;
   85.80 +    public static byte            publicStaticByte              = -12;
   85.81 +    public static byte[]          publicStaticByteArray         = { 16, 32, 64, 127, -128 };
   85.82 +    public static Byte            publicStaticByteBox           = 17;
   85.83 +    public static short           publicStaticShort             = 320;
   85.84 +    public static short[]         publicStaticShortArray        = { 1240, 900, -1789, 100, 12 };
   85.85 +    public static Short           publicStaticShortBox          = -16777;
   85.86 +    public static float           publicStaticFloat             = 7.7e8f;
   85.87 +    public static float[]         publicStaticFloatArray        = { -131.01f, 189.3f, -31.3e8f, 3.7f };
   85.88 +    public static Float           publicStaticFloatBox          = 1.37e4f;
   85.89 +    public static double          publicStaticDouble            = 1.341e20;
   85.90 +    public static double[]        publicStaticDoubleArray       = { 0.75e80, 0.123e10, 8e-43, 1.000077 };
   85.91 +    public static Double          publicStaticDoubleBox         = 1.41e-12;
   85.92 +    public static char            publicStaticChar              = 'C';
   85.93 +    public static char[]          publicStaticCharArray         = "Nashorn".toCharArray();
   85.94 +    public static Character       publicStaticCharBox           = 'D';
   85.95 +    // Public final fields
   85.96 +    public final String           publicFinalString             = "PublicFinalString";
   85.97 +    public final String[]         publicFinalStringArray        = { "FinalArrayString[0]", "FinalArrayString[1]", "FinalArrayString[2]", "FinalArrayString[3]" };
   85.98 +    public final Person           publicFinalObject             = new Person(1024);
   85.99 +    public final Person[]         publicFinalObjectArray        = { new Person(-900), new Person(1000), new Person(180) };
  85.100 +    public final boolean          publicFinalBoolean            = true;
  85.101 +    public final boolean[]        publicFinalBooleanArray       = { false, false, true, false };
  85.102 +    public final Boolean          publicFinalBooleanBox         = true;
  85.103 +    public final long             publicFinalLong               = 13353333333333333L;
  85.104 +    public final long[]           publicFinalLongArray          = { 1901733333333L, -2247355555L, 3977377777L };
  85.105 +    public final Long             publicFinalLongBox            = 9377333334L;
  85.106 +    public final int              publicFinalInt                = 20712023;
  85.107 +    public final int[]            publicFinalIntArray           = { 50, 80, 130, 210, 340 };
  85.108 +    public final Integer          publicFinalIntBox             = 207512301;
  85.109 +    public final byte             publicFinalByte               = -7;
  85.110 +    public final byte[]           publicFinalByteArray          = { 1, 3, 6, 17, -128 };
  85.111 +    public final Byte             publicFinalByteBox            = 19;
  85.112 +    public final short            publicFinalShort              = 31220;
  85.113 +    public final short[]          publicFinalShortArray         = { 12240, 9200, -17289, 1200, 12 };
  85.114 +    public final Short            publicFinalShortBox           = -26777;
  85.115 +    public final float            publicFinalFloat              = 7.72e8f;
  85.116 +    public final float[]          publicFinalFloatArray         = { -131.012f, 189.32f, -31.32e8f, 3.72f };
  85.117 +    public final Float            publicFinalFloatBox           = 1.372e4f;
  85.118 +    public final double           publicFinalDouble             = 1.3412e20;
  85.119 +    public final double[]         publicFinalDoubleArray        = { 0.725e80, 0.12e10, 8e-3, 1.00077 };
  85.120 +    public final Double           publicFinalDoubleBox          = 1.412e-12;
  85.121 +    public final char             publicFinalChar               = 'E';
  85.122 +    public final char[]           publicFinalCharArray          = "Nashorn hello".toCharArray();
  85.123 +    public final Character        publicFinalCharBox            = 'F';
  85.124 +    // Public static final fields
  85.125 +    public static final String    publicStaticFinalString       = "PublicStaticFinalString";
  85.126 +    public static final String[]  publicStaticFinalStringArray  = { "StaticFinalArrayString[0]", "StaticFinalArrayString[1]", "StaticFinalArrayString[2]", "StaticFinalArrayString[3]" };
  85.127 +    public static final Person    publicStaticFinalObject       = new Person(2048);
  85.128 +    public static final Person[]  publicStaticFinalObjectArray  = { new Person(-9), new Person(110), new Person(Integer.MAX_VALUE) };
  85.129 +    public static final boolean   publicStaticFinalBoolean      = true;
  85.130 +    public static final boolean[] publicStaticFinalBooleanArray = { false, true, false, false };
  85.131 +    public static final Boolean   publicStaticFinalBooleanBox   = true;
  85.132 +    public static final long      publicStaticFinalLong         = 8333333333333L;
  85.133 +    public static final long[]    publicStaticFinalLongArray    = { 19017383333L, -2247358L, 39773787L };
  85.134 +    public static final Long      publicStaticFinalLongBox      = 9377388334L;
  85.135 +    public static final int       publicStaticFinalInt          = 207182023;
  85.136 +    public static final int[]     publicStaticFinalIntArray     = { 1308, 210, 340 };
  85.137 +    public static final Integer   publicStaticFinalIntBox       = 2078301;
  85.138 +    public static final byte      publicStaticFinalByte         = -70;
  85.139 +    public static final byte[]    publicStaticFinalByteArray    = { 17, -128, 81 };
  85.140 +    public static final Byte      publicStaticFinalByteBox      = 91;
  85.141 +    public static final short     publicStaticFinalShort        = 8888;
  85.142 +    public static final short[]   publicStaticFinalShortArray   = { 8240, 9280, -1289, 120, 812 };
  85.143 +    public static final Short     publicStaticFinalShortBox     = -26;
  85.144 +    public static final float     publicStaticFinalFloat        = 0.72e8f;
  85.145 +    public static final float[]   publicStaticFinalFloatArray   = { -8131.012f, 9.32f, -138.32e8f, 0.72f };
  85.146 +    public static final Float     publicStaticFinalFloatBox     = 1.2e4f;
  85.147 +    public static final double    publicStaticFinalDouble       = 1.8e12;
  85.148 +    public static final double[]  publicStaticFinalDoubleArray  = { 8.725e80, 0.82e10, 18e-3, 1.08077 };
  85.149 +    public static final Double    publicStaticFinalDoubleBox    = 1.5612e-13;
  85.150 +    public static final char      publicStaticFinalChar         = 'K';
  85.151 +    public static final char[]    publicStaticFinalCharArray    = "StaticString".toCharArray();
  85.152 +    public static final Character publicStaticFinalCharBox      = 'L';
  85.153 +
  85.154 +    // Special vars
  85.155 +    public volatile boolean       volatileBoolean               = true;
  85.156 +    public transient boolean      transientBoolean              = true;
  85.157 +
  85.158 +    // For methods testing
  85.159 +    public boolean                isAccessed                    = false;
  85.160 +    public volatile boolean       isFinished                    = false;
  85.161 +
  85.162 +    private ScriptEngine engine;
  85.163 +
  85.164 +    public ScriptEngine getEngine() {
  85.165 +        return engine;
  85.166 +    }
  85.167 +
  85.168 +    public void setEngine(ScriptEngine engine) {
  85.169 +        this.engine = engine;
  85.170 +    }
  85.171 +
  85.172 +    public void voidMethod() {
  85.173 +        isAccessed = true;
  85.174 +    }
  85.175 +
  85.176 +    public boolean booleanMethod(final boolean arg) {
  85.177 +        return !arg;
  85.178 +    }
  85.179 +
  85.180 +    public Boolean booleanBoxingMethod(final Boolean arg) {
  85.181 +        return !arg.booleanValue();
  85.182 +    }
  85.183 +
  85.184 +    public boolean[] booleanArrayMethod(final boolean arg[]) {
  85.185 +        final boolean[] res = new boolean[arg.length];
  85.186 +        for (int i = 0; i < arg.length; i++) {
  85.187 +            res[i] = !arg[i];
  85.188 +        }
  85.189 +        return res;
  85.190 +    }
  85.191 +
  85.192 +    public int intMethod(final int arg) {
  85.193 +        return arg + arg;
  85.194 +    }
  85.195 +
  85.196 +    public Integer intBoxingMethod(final Integer arg) {
  85.197 +        return arg + arg;
  85.198 +    }
  85.199 +
  85.200 +    public int[] intArrayMethod(final int arg[]) {
  85.201 +        final int[] res = new int[arg.length];
  85.202 +        for (int i = 0; i < arg.length; i++) {
  85.203 +            res[i] = arg[i] * 2;
  85.204 +        }
  85.205 +        return res;
  85.206 +    }
  85.207 +
  85.208 +    public long longMethod(final long arg) {
  85.209 +        return arg + arg;
  85.210 +    }
  85.211 +
  85.212 +    public Long longBoxingMethod(final Long arg) {
  85.213 +        return arg + arg;
  85.214 +    }
  85.215 +
  85.216 +    public long[] longArrayMethod(final long[] arg) {
  85.217 +        final long[] res = new long[arg.length];
  85.218 +        for (int i = 0; i < arg.length; i++) {
  85.219 +            res[i] = arg[i] * 2;
  85.220 +        }
  85.221 +        return res;
  85.222 +    }
  85.223 +
  85.224 +    public byte byteMethod(final byte arg) {
  85.225 +        return (byte)(arg + arg);
  85.226 +    }
  85.227 +
  85.228 +    public Byte byteBoxingMethod(final Byte arg) {
  85.229 +        return (byte)(arg + arg);
  85.230 +    }
  85.231 +
  85.232 +    public byte[] byteArrayMethod(final byte[] arg) {
  85.233 +        final byte[] res = new byte[arg.length];
  85.234 +        for (int i = 0; i < arg.length; i++) {
  85.235 +            res[i] = (byte)(arg[i] * 2);
  85.236 +        }
  85.237 +        return res;
  85.238 +    }
  85.239 +
  85.240 +    public char charMethod(final char arg) {
  85.241 +        return Character.toUpperCase(arg);
  85.242 +    }
  85.243 +
  85.244 +    public Character charBoxingMethod(final Character arg) {
  85.245 +        return Character.toUpperCase(arg);
  85.246 +    }
  85.247 +
  85.248 +    public char[] charArrayMethod(final char[] arg) {
  85.249 +        final char[] res = new char[arg.length];
  85.250 +        for (int i = 0; i < arg.length; i++) {
  85.251 +            res[i] = Character.toUpperCase(arg[i]);
  85.252 +        }
  85.253 +        return res;
  85.254 +    }
  85.255 +
  85.256 +    public short shortMethod(final short arg) {
  85.257 +        return (short)(arg + arg);
  85.258 +    }
  85.259 +
  85.260 +    public Short shortBoxingMethod(final Short arg) {
  85.261 +        return (short)(arg + arg);
  85.262 +    }
  85.263 +
  85.264 +    public short[] shortArrayMethod(final short[] arg) {
  85.265 +        final short[] res = new short[arg.length];
  85.266 +        for (int i = 0; i < arg.length; i++) {
  85.267 +            res[i] = (short)(arg[i] * 2);
  85.268 +        }
  85.269 +        return res;
  85.270 +    }
  85.271 +
  85.272 +    public float floatMethod(final float arg) {
  85.273 +        return arg + arg;
  85.274 +    }
  85.275 +
  85.276 +    public Float floatBoxingMethod(final Float arg) {
  85.277 +        return arg + arg;
  85.278 +    }
  85.279 +
  85.280 +    public float[] floatArrayMethod(final float[] arg) {
  85.281 +        final float[] res = new float[arg.length];
  85.282 +        for (int i = 0; i < arg.length; i++) {
  85.283 +            res[i] = arg[i] * 2;
  85.284 +        }
  85.285 +        return res;
  85.286 +    }
  85.287 +
  85.288 +    public double doubleMethod(final double arg) {
  85.289 +        return arg + arg;
  85.290 +    }
  85.291 +
  85.292 +    public Double doubleBoxingMethod(final Double arg) {
  85.293 +        return arg + arg;
  85.294 +    }
  85.295 +
  85.296 +    public double[] doubleArrayMethod(final double[] arg) {
  85.297 +        final double[] res = new double[arg.length];
  85.298 +        for (int i = 0; i < arg.length; i++) {
  85.299 +            res[i] = arg[i] * 2;
  85.300 +        }
  85.301 +        return res;
  85.302 +    }
  85.303 +
  85.304 +    public String stringMethod(final String str) {
  85.305 +        return str + str;
  85.306 +    }
  85.307 +
  85.308 +    public String[] stringArrayMethod(final String[] arr) {
  85.309 +        final int l = arr.length;
  85.310 +        final String[] res = new String[l];
  85.311 +        for (int i = 0; i < l; i++) {
  85.312 +            res[i] = arr[l - i - 1];
  85.313 +        }
  85.314 +        return res;
  85.315 +    }
  85.316 +
  85.317 +    public Person[] objectArrayMethod(final Person[] arr) {
  85.318 +        final Person[] res = new Person[arr.length];
  85.319 +        for (int i = 0; i < arr.length; i++) {
  85.320 +            res[i] = new Person(i + 100);
  85.321 +        }
  85.322 +        return res;
  85.323 +    }
  85.324 +
  85.325 +    public Person objectMethod(final Person t) {
  85.326 +        t.id *= 2;
  85.327 +        return t;
  85.328 +    }
  85.329 +
  85.330 +    public int twoParamMethod(final long l, final double d) {
  85.331 +        return (int)(l + d);
  85.332 +    }
  85.333 +
  85.334 +    public int threeParamMethod(final short s, final long l, final char c) {
  85.335 +        return (int)(s + l + c);
  85.336 +    }
  85.337 +
  85.338 +    public Person[] twoObjectParamMethod(final Person arg1, final Person arg2) {
  85.339 +        return new Person[] { arg2, arg1 };
  85.340 +    }
  85.341 +
  85.342 +    public Person[] threeObjectParamMethod(final Person arg1, final Person arg2, final Person arg3) {
  85.343 +        return new Person[] { arg3, arg2, arg1 };
  85.344 +    }
  85.345 +
  85.346 +    public Person[] eightObjectParamMethod(final Person arg1, final Person arg2, final Person arg3, final Person arg4, final Person arg5, final Person arg6, final Person arg7, final Person arg8) {
  85.347 +        return new Person[] { arg8, arg7, arg6, arg5, arg4, arg3, arg2, arg1 };
  85.348 +    }
  85.349 +
  85.350 +    public Person[] nineObjectParamMethod(final Person arg1, final Person arg2, final Person arg3, final Person arg4, final Person arg5, final Person arg6, final Person arg7, final Person arg8, final Person arg9) {
  85.351 +        return new Person[] { arg9, arg8, arg7, arg6, arg5, arg4, arg3, arg2, arg1 };
  85.352 +    }
  85.353 +
  85.354 +    public Person[] methodObjectEllipsis(final Person... args) {
  85.355 +        final int l = args.length;
  85.356 +        final Person[] res = new Person[l];
  85.357 +        for (int i = 0; i < l; i++) {
  85.358 +            res[i] = args[l - i - 1];
  85.359 +        }
  85.360 +        return res;
  85.361 +    }
  85.362 +
  85.363 +    public Person[] methodPrimitiveEllipsis(final int... args) {
  85.364 +        final int l = args.length;
  85.365 +        final Person[] res = new Person[l];
  85.366 +        for (int i = 0; i < l; i++) {
  85.367 +            res[i] = new Person(args[i]);
  85.368 +        }
  85.369 +        return res;
  85.370 +    }
  85.371 +
  85.372 +    public Object[] methodMixedEllipsis(final Object... args) {
  85.373 +        return args;
  85.374 +    }
  85.375 +
  85.376 +    public Object[] methodObjectWithEllipsis(final String arg, final int... args) {
  85.377 +        final Object[] res = new Object[args.length + 1];
  85.378 +        res[0] = arg;
  85.379 +        for (int i = 0; i < args.length; i++) {
  85.380 +            res[i + 1] = args[i];
  85.381 +        }
  85.382 +        return res;
  85.383 +    }
  85.384 +
  85.385 +    public Object[] methodPrimitiveWithEllipsis(final int arg, final long... args) {
  85.386 +        final Object[] res = new Object[args.length + 1];
  85.387 +        res[0] = arg;
  85.388 +        for (int i = 0; i < args.length; i++) {
  85.389 +            res[i + 1] = args[i];
  85.390 +        }
  85.391 +        return res;
  85.392 +    }
  85.393 +
  85.394 +    public Object[] methodMixedWithEllipsis(final String arg1, final int arg2, final Object... args) {
  85.395 +        final Object[] res = new Object[args.length + 2];
  85.396 +        res[0] = arg1;
  85.397 +        res[1] = arg2;
  85.398 +        System.arraycopy(args, 0, res, 2, args.length);
  85.399 +        return res;
  85.400 +    }
  85.401 +
  85.402 +    public void methodStartsThread() {
  85.403 +        isFinished = false;
  85.404 +
  85.405 +        final Thread t = new Thread(new Runnable() {
  85.406 +            @Override
  85.407 +            public void run() {
  85.408 +                try {
  85.409 +                    Thread.sleep(1000);
  85.410 +                    isFinished = true;
  85.411 +                } catch (final InterruptedException e) {
  85.412 +                    e.printStackTrace();
  85.413 +                }
  85.414 +            }
  85.415 +        });
  85.416 +
  85.417 +        t.start();
  85.418 +    }
  85.419 +
  85.420 +    public String overloadedMethodDoubleVSint(int arg) {
  85.421 +        return "int";
  85.422 +    }
  85.423 +
  85.424 +    public String overloadedMethodDoubleVSint(double arg) {
  85.425 +        return "double";
  85.426 +    }
  85.427 +
  85.428 +    public int overloadedMethod(int arg) {
  85.429 +        return arg*2;
  85.430 +    }
  85.431 +
  85.432 +    public int overloadedMethod(String arg) {
  85.433 +        return arg.length();
  85.434 +    }
  85.435 +
  85.436 +    public int overloadedMethod(boolean arg) {
  85.437 +        return (arg) ? 1 : 0;
  85.438 +    }
  85.439 +
  85.440 +    public int overloadedMethod(Person arg) {
  85.441 +        return arg.id*2;
  85.442 +    }
  85.443 +
  85.444 +    public int firstLevelMethodInt(int arg) throws ScriptException, NoSuchMethodException {
  85.445 +        return (int) ((Invocable)engine).invokeFunction("secondLevelMethodInt", arg);
  85.446 +    }
  85.447 +
  85.448 +    public int thirdLevelMethodInt(int arg) {
  85.449 +        return arg*5;
  85.450 +    }
  85.451 +
  85.452 +    public int firstLevelMethodInteger(Integer arg) throws ScriptException, NoSuchMethodException {
  85.453 +        return (int) ((Invocable)engine).invokeFunction("secondLevelMethodInteger", arg);
  85.454 +    }
  85.455 +
  85.456 +    public int thirdLevelMethodInteger(Integer arg) {
  85.457 +        return arg*10;
  85.458 +    }
  85.459 +
  85.460 +    public Person firstLevelMethodObject(Person p) throws ScriptException, NoSuchMethodException {
  85.461 +        return (Person) ((Invocable)engine).invokeFunction("secondLevelMethodObject", p);
  85.462 +    }
  85.463 +
  85.464 +    public Person thirdLevelMethodObject(Person p) {
  85.465 +        p.id *= 10;
  85.466 +        return p;
  85.467 +    }
  85.468 +
  85.469 +}
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java	Mon Feb 11 21:26:06 2013 +0530
    86.3 @@ -0,0 +1,155 @@
    86.4 +/*
    86.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    86.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    86.7 + *
    86.8 + * This code is free software; you can redistribute it and/or modify it
    86.9 + * under the terms of the GNU General Public License version 2 only, as
   86.10 + * published by the Free Software Foundation.  Oracle designates this
   86.11 + * particular file as subject to the "Classpath" exception as provided
   86.12 + * by Oracle in the LICENSE file that accompanied this code.
   86.13 + *
   86.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   86.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   86.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   86.17 + * version 2 for more details (a copy is included in the LICENSE file that
   86.18 + * accompanied this code).
   86.19 + *
   86.20 + * You should have received a copy of the GNU General Public License version
   86.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   86.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   86.23 + *
   86.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   86.25 + * or visit www.oracle.com if you need additional information or have any
   86.26 + * questions.
   86.27 + */
   86.28 +
   86.29 +package jdk.nashorn.api.javaaccess;
   86.30 +
   86.31 +import static org.testng.AssertJUnit.assertEquals;
   86.32 +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
   86.33 +
   86.34 +import javax.script.ScriptEngine;
   86.35 +import javax.script.ScriptEngineManager;
   86.36 +import javax.script.ScriptException;
   86.37 +import org.testng.TestNG;
   86.38 +import org.testng.annotations.BeforeClass;
   86.39 +import org.testng.annotations.Test;
   86.40 +
   86.41 +public class StringAccessTest {
   86.42 +
   86.43 +    private static ScriptEngine e = null;
   86.44 +    private static SharedObject o = new SharedObject();
   86.45 +
   86.46 +    public static void main(final String[] args) {
   86.47 +        TestNG.main(args);
   86.48 +    }
   86.49 +
   86.50 +    @BeforeClass
   86.51 +    public static void setUpClass() throws ScriptException {
   86.52 +        final ScriptEngineManager m = new ScriptEngineManager();
   86.53 +        e = m.getEngineByName("nashorn");
   86.54 +        e.put("o", o);
   86.55 +        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   86.56 +    }
   86.57 +
   86.58 +    @Test
   86.59 +    public void accessFieldString() throws ScriptException {
   86.60 +        e.eval("var p_string = o.publicString;");
   86.61 +        assertEquals(o.publicString, e.get("p_string"));
   86.62 +        assertEquals("string", e.eval("typeof p_string;"));
   86.63 +        e.eval("o.publicString = 'changedString';");
   86.64 +        assertEquals("changedString", o.publicString);
   86.65 +    }
   86.66 +
   86.67 +    @Test
   86.68 +    public void accessFieldStringArray() throws ScriptException {
   86.69 +        e.eval("var p_string_array = o.publicStringArray;");
   86.70 +        assertEquals(o.publicStringArray[0], e.eval("o.publicStringArray[0]"));
   86.71 +        assertArrayEquals(o.publicStringArray, (String[])e.get("p_string_array"));
   86.72 +        e.eval("var t_string_arr = java.lang.reflect.Array.newInstance(java.lang.String.class, 3);" +
   86.73 +                "t_string_arr[0] = 'abc';" +
   86.74 +                "t_string_arr[1] = '123';" +
   86.75 +                "t_string_arr[2] = 'xyzzzz';" +
   86.76 +                "o.publicStringArray = t_string_arr;");
   86.77 +        assertArrayEquals(new String[] { "abc", "123", "xyzzzz" }, o.publicStringArray);
   86.78 +        e.eval("o.publicStringArray[0] = 'nashorn';");
   86.79 +        assertEquals("nashorn", o.publicStringArray[0]);
   86.80 +    }
   86.81 +
   86.82 +    @Test
   86.83 +    public void accessStaticFieldString() throws ScriptException {
   86.84 +        e.eval("var ps_string = SharedObject.publicStaticString;");
   86.85 +        assertEquals(SharedObject.publicStaticString, e.get("ps_string"));
   86.86 +        assertEquals("string", e.eval("typeof ps_string;"));
   86.87 +        e.eval("SharedObject.publicStaticString = 'changedString';");
   86.88 +        assertEquals("changedString", SharedObject.publicStaticString);
   86.89 +    }
   86.90 +
   86.91 +    @Test
   86.92 +    public void accessStaticFieldStringArray() throws ScriptException {
   86.93 +        e.eval("var ps_string_array = SharedObject.publicStaticStringArray;");
   86.94 +        assertEquals(SharedObject.publicStaticStringArray[0], e.eval("SharedObject.publicStaticStringArray[0]"));
   86.95 +        assertArrayEquals(SharedObject.publicStaticStringArray, (String[])e.get("ps_string_array"));
   86.96 +        e.eval("var ts_string_arr = java.lang.reflect.Array.newInstance(java.lang.String.class, 3);" +
   86.97 +                "ts_string_arr[0] = 'abc';" +
   86.98 +                "ts_string_arr[1] = '123';" +
   86.99 +                "ts_string_arr[2] = 'xyzzzz';" +
  86.100 +                "SharedObject.publicStaticStringArray = ts_string_arr;");
  86.101 +        assertArrayEquals(new String[] { "abc", "123", "xyzzzz" }, SharedObject.publicStaticStringArray);
  86.102 +        e.eval("SharedObject.publicStaticStringArray[0] = 'nashorn';");
  86.103 +        assertEquals("nashorn", SharedObject.publicStaticStringArray[0]);
  86.104 +    }
  86.105 +
  86.106 +    @Test
  86.107 +    public void accessFinalFieldString() throws ScriptException {
  86.108 +        e.eval("var pf_string = o.publicFinalString;");
  86.109 +        assertEquals(o.publicFinalString, e.get("pf_string"));
  86.110 +        assertEquals("string", e.eval("typeof pf_string;"));
  86.111 +        e.eval("o.publicFinalString = 'changedString';");
  86.112 +        assertEquals("PublicFinalString", o.publicFinalString);
  86.113 +    }
  86.114 +
  86.115 +    @Test
  86.116 +    public void accessFinalFieldStringArray() throws ScriptException {
  86.117 +        e.eval("var pf_string_array = o.publicFinalStringArray;");
  86.118 +        assertEquals(o.publicFinalStringArray[0], e.eval("o.publicFinalStringArray[0]"));
  86.119 +        assertArrayEquals(o.publicFinalStringArray, (String[])e.get("pf_string_array"));
  86.120 +        e.eval("var tf_string_arr = java.lang.reflect.Array.newInstance(java.lang.String.class, 3);" +
  86.121 +                "tf_string_arr[0] = 'abc';" +
  86.122 +                "tf_string_arr[1] = '123';" +
  86.123 +                "tf_string_arr[2] = 'xyzzzz';" +
  86.124 +                "o.publicFinalStringArray = tf_string_arr;");
  86.125 +        assertArrayEquals(new String[] { "FinalArrayString[0]", "FinalArrayString[1]", "FinalArrayString[2]", "FinalArrayString[3]" }, o.publicFinalStringArray);
  86.126 +        e.eval("o.publicFinalStringArray[0] = 'nashorn';");
  86.127 +        assertEquals("nashorn", o.publicFinalStringArray[0]);
  86.128 +    }
  86.129 +
  86.130 +    @Test
  86.131 +    public void accessStaticFinalFieldString() throws ScriptException {
  86.132 +        e.eval("var psf_string = SharedObject.publicStaticFinalString;");
  86.133 +        assertEquals(SharedObject.publicStaticFinalString, e.get("psf_string"));
  86.134 +        assertEquals("string", e.eval("typeof psf_string;"));
  86.135 +        e.eval("SharedObject.publicStaticFinalString = 'changedString';");
  86.136 +        assertEquals("PublicStaticFinalString", SharedObject.publicStaticFinalString);
  86.137 +    }
  86.138 +
  86.139 +    @Test
  86.140 +    public void accessStaticFinalFieldStringArray() throws ScriptException {
  86.141 +        e.eval("var psf_string_array = SharedObject.publicStaticFinalStringArray;");
  86.142 +        assertEquals(SharedObject.publicStaticFinalStringArray[0], e.eval("SharedObject.publicStaticFinalStringArray[0]"));
  86.143 +        assertArrayEquals(SharedObject.publicStaticFinalStringArray, (String[])e.get("psf_string_array"));
  86.144 +        e.eval("var tsf_string_arr = java.lang.reflect.Array.newInstance(java.lang.String.class, 3);" +
  86.145 +                "tsf_string_arr[0] = 'abc';" +
  86.146 +                "tsf_string_arr[1] = '123';" +
  86.147 +                "tsf_string_arr[2] = 'xyzzzz';" +
  86.148 +                "SharedObject.publicStaticFinalStringArray = tsf_string_arr;");
  86.149 +        assertArrayEquals(new String[] { "StaticFinalArrayString[0]",
  86.150 +                    "StaticFinalArrayString[1]",
  86.151 +                    "StaticFinalArrayString[2]",
  86.152 +                    "StaticFinalArrayString[3]" },
  86.153 +                SharedObject.publicStaticFinalStringArray);
  86.154 +        e.eval("SharedObject.publicStaticFinalStringArray[0] = 'nashorn';");
  86.155 +        assertEquals("nashorn", SharedObject.publicStaticFinalStringArray[0]);
  86.156 +    }
  86.157 +
  86.158 +}
    87.1 --- a/test/src/jdk/nashorn/internal/access/BooleanAccessTest.java	Sat Feb 09 16:58:48 2013 +0100
    87.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.3 @@ -1,206 +0,0 @@
    87.4 -/*
    87.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    87.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    87.7 - *
    87.8 - * This code is free software; you can redistribute it and/or modify it
    87.9 - * under the terms of the GNU General Public License version 2 only, as
   87.10 - * published by the Free Software Foundation.  Oracle designates this
   87.11 - * particular file as subject to the "Classpath" exception as provided
   87.12 - * by Oracle in the LICENSE file that accompanied this code.
   87.13 - *
   87.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   87.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   87.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   87.17 - * version 2 for more details (a copy is included in the LICENSE file that
   87.18 - * accompanied this code).
   87.19 - *
   87.20 - * You should have received a copy of the GNU General Public License version
   87.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   87.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   87.23 - *
   87.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   87.25 - * or visit www.oracle.com if you need additional information or have any
   87.26 - * questions.
   87.27 - */
   87.28 -
   87.29 -package jdk.nashorn.internal.access;
   87.30 -
   87.31 -import static org.testng.AssertJUnit.assertEquals;
   87.32 -import static org.testng.AssertJUnit.assertTrue;
   87.33 -
   87.34 -import java.util.Arrays;
   87.35 -import javax.script.ScriptEngine;
   87.36 -import javax.script.ScriptEngineManager;
   87.37 -import javax.script.ScriptException;
   87.38 -import org.testng.TestNG;
   87.39 -import org.testng.annotations.BeforeClass;
   87.40 -import org.testng.annotations.Test;
   87.41 -
   87.42 -public class BooleanAccessTest {
   87.43 -
   87.44 -    private static ScriptEngine e = null;
   87.45 -    private static SharedObject o = new SharedObject();
   87.46 -
   87.47 -    public static void main(final String[] args) {
   87.48 -        TestNG.main(args);
   87.49 -    }
   87.50 -
   87.51 -    @BeforeClass
   87.52 -    public static void setUpClass() throws ScriptException {
   87.53 -        final ScriptEngineManager m = new ScriptEngineManager();
   87.54 -        e = m.getEngineByName("nashorn");
   87.55 -        e.put("o", o);
   87.56 -        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   87.57 -    }
   87.58 -
   87.59 -    @Test
   87.60 -    public void accessFieldBoolean() throws ScriptException {
   87.61 -        e.eval("var p_boolean = o.publicBoolean;");
   87.62 -        assertEquals(o.publicBoolean, e.get("p_boolean"));
   87.63 -        assertEquals("boolean", e.eval("typeof p_boolean;"));
   87.64 -        e.eval("o.publicBoolean = false;");
   87.65 -        assertEquals(false, o.publicBoolean);
   87.66 -    }
   87.67 -
   87.68 -    @Test
   87.69 -    public void accessFieldBooleanArray() throws ScriptException {
   87.70 -        e.eval("var p_boolean_array = o.publicBooleanArray;");
   87.71 -        assertEquals(o.publicBooleanArray[0], e.eval("o.publicBooleanArray[0]"));
   87.72 -        assertTrue(Arrays.equals(o.publicBooleanArray, (boolean[])e.get("p_boolean_array")));
   87.73 -        e.eval("var t_boolean_arr = java.lang.reflect.Array.newInstance(java.lang.Boolean.TYPE, 3);" +
   87.74 -                "t_boolean_arr[0] = true;" +
   87.75 -                "t_boolean_arr[1] = false;" +
   87.76 -                "t_boolean_arr[2] = false;" +
   87.77 -                "o.publicBooleanArray = t_boolean_arr;");
   87.78 -        assertTrue(Arrays.equals(new boolean[] { true, false, false }, o.publicBooleanArray));
   87.79 -        e.eval("o.publicBooleanArray[0] = false;");
   87.80 -        assertEquals(false, o.publicBooleanArray[0]);
   87.81 -    }
   87.82 -
   87.83 -    @Test
   87.84 -    public void accessStaticFieldBoolean() throws ScriptException {
   87.85 -        e.eval("var ps_boolean = SharedObject.publicStaticBoolean;");
   87.86 -        assertEquals(SharedObject.publicStaticBoolean, e.get("ps_boolean"));
   87.87 -        assertEquals("boolean", e.eval("typeof ps_boolean;"));
   87.88 -        e.eval("SharedObject.publicStaticBoolean = false;");
   87.89 -        assertEquals(false, SharedObject.publicStaticBoolean);
   87.90 -    }
   87.91 -
   87.92 -    @Test
   87.93 -    public void accessStaticFieldBooleanArray() throws ScriptException {
   87.94 -        e.eval("var ps_boolean_array = SharedObject.publicStaticBooleanArray;");
   87.95 -        assertEquals(SharedObject.publicStaticBooleanArray[0], e.eval("SharedObject.publicStaticBooleanArray[0]"));
   87.96 -        assertTrue(Arrays.equals(SharedObject.publicStaticBooleanArray, (boolean[])e.get("ps_boolean_array")));
   87.97 -        e.eval("var ts_boolean_arr = java.lang.reflect.Array.newInstance(java.lang.Boolean.TYPE, 3);" +
   87.98 -                "ts_boolean_arr[0] = true;" +
   87.99 -                "ts_boolean_arr[1] = false;" +
  87.100 -                "ts_boolean_arr[2] = true;" +
  87.101 -                "SharedObject.publicStaticBooleanArray = ts_boolean_arr;");
  87.102 -        assertTrue(Arrays.equals(new boolean[] { true, false, true }, SharedObject.publicStaticBooleanArray));
  87.103 -        e.eval("SharedObject.publicStaticBooleanArray[0] = false;");
  87.104 -        assertEquals(false, SharedObject.publicStaticBooleanArray[0]);
  87.105 -    }
  87.106 -
  87.107 -    @Test
  87.108 -    public void accessFinalFieldBoolean() throws ScriptException {
  87.109 -        e.eval("var pf_boolean = o.publicFinalBoolean;");
  87.110 -        assertEquals(o.publicFinalBoolean, e.get("pf_boolean"));
  87.111 -        assertEquals("boolean", e.eval("typeof pf_boolean;"));
  87.112 -        e.eval("o.publicFinalBoolean = false;");
  87.113 -        assertEquals(true, o.publicFinalBoolean);
  87.114 -    }
  87.115 -
  87.116 -    @Test
  87.117 -    public void accessFinalFieldBooleanArray() throws ScriptException {
  87.118 -        e.eval("var pf_boolean_array = o.publicFinalBooleanArray;");
  87.119 -        assertEquals(o.publicFinalBooleanArray[0], e.eval("o.publicFinalBooleanArray[0]"));
  87.120 -        assertTrue(Arrays.equals(o.publicFinalBooleanArray, (boolean[])e.get("pf_boolean_array")));
  87.121 -        e.eval("var tf_boolean_arr = java.lang.reflect.Array.newInstance(java.lang.Boolean.TYPE, 3);" +
  87.122 -                "tf_boolean_arr[0] = false;" +
  87.123 -                "tf_boolean_arr[1] = false;" +
  87.124 -                "tf_boolean_arr[2] = true;" +
  87.125 -                "o.publicOFinalbjectArray = tf_boolean_arr;");
  87.126 -        assertTrue(Arrays.equals(new boolean[] { false, false, true, false }, o.publicFinalBooleanArray));
  87.127 -        e.eval("o.publicFinalBooleanArray[0] = true;");
  87.128 -        assertEquals(true, o.publicFinalBooleanArray[0]);
  87.129 -    }
  87.130 -
  87.131 -    @Test
  87.132 -    public void accessStaticFinalFieldBoolean() throws ScriptException {
  87.133 -        e.eval("var psf_boolean = SharedObject.publicStaticFinalBoolean;");
  87.134 -        assertEquals(SharedObject.publicStaticFinalBoolean, e.get("psf_boolean"));
  87.135 -        assertEquals("boolean", e.eval("typeof psf_boolean;"));
  87.136 -        e.eval("SharedObject.publicStaticFinalBoolean = false;");
  87.137 -        assertEquals(true, SharedObject.publicStaticFinalBoolean);
  87.138 -    }
  87.139 -
  87.140 -    @Test
  87.141 -    public void accessStaticFinalFieldBooleanArray() throws ScriptException {
  87.142 -        e.eval("var psf_boolean_array = SharedObject.publicStaticFinalBooleanArray;");
  87.143 -        assertEquals(SharedObject.publicStaticFinalBooleanArray[0], e.eval("SharedObject.publicStaticFinalBooleanArray[0]"));
  87.144 -        assertTrue(Arrays.equals(SharedObject.publicStaticFinalBooleanArray, (boolean[])e.get("psf_boolean_array")));
  87.145 -        e.eval("var tsf_boolean_arr = java.lang.reflect.Array.newInstance(java.lang.Boolean.TYPE, 3);" +
  87.146 -                "tsf_boolean_arr[0] = false;" +
  87.147 -                "tsf_boolean_arr[1] = true;" +
  87.148 -                "tsf_boolean_arr[2] = false;" +
  87.149 -                "SharedObject.publicStaticFinalBooleanArray = tsf_boolean_arr;");
  87.150 -        assertTrue(Arrays.equals(new boolean[] { false, true, false, false }, SharedObject.publicStaticFinalBooleanArray));
  87.151 -        e.eval("SharedObject.publicStaticFinalBooleanArray[0] = true;");
  87.152 -        assertEquals(true, SharedObject.publicStaticFinalBooleanArray[0]);
  87.153 -    }
  87.154 -
  87.155 -    @Test
  87.156 -    public void accessFieldBooleanBoxing() throws ScriptException {
  87.157 -        e.eval("var p_boolean_box = o.publicBooleanBox;");
  87.158 -        assertEquals(o.publicBooleanBox, e.get("p_boolean_box"));
  87.159 -        assertEquals("boolean", e.eval("typeof p_boolean_box;"));
  87.160 -        e.eval("o.publicBooleanBox = false;");
  87.161 -        assertEquals(false, (boolean)o.publicBooleanBox);
  87.162 -    }
  87.163 -
  87.164 -    @Test
  87.165 -    public void accessStaticFieldBooleanBoxing() throws ScriptException {
  87.166 -        e.eval("var ps_boolean_box = SharedObject.publicStaticBooleanBox;");
  87.167 -        assertEquals(SharedObject.publicStaticBooleanBox, e.get("ps_boolean_box"));
  87.168 -        assertEquals("boolean", e.eval("typeof ps_boolean_box;"));
  87.169 -        e.eval("SharedObject.publicStaticBooleanBox = false;");
  87.170 -        assertEquals(false, (boolean)SharedObject.publicStaticBooleanBox);
  87.171 -    }
  87.172 -
  87.173 -    @Test
  87.174 -    public void accessFinalFieldBooleanBoxing() throws ScriptException {
  87.175 -        e.eval("var pf_boolean_box = o.publicFinalBooleanBox;");
  87.176 -        assertEquals(o.publicFinalBooleanBox, e.get("pf_boolean_box"));
  87.177 -        assertEquals("boolean", e.eval("typeof pf_boolean_box;"));
  87.178 -        e.eval("o.publicFinalBooleanBox = false;");
  87.179 -        assertEquals(true, (boolean)o.publicFinalBooleanBox);
  87.180 -    }
  87.181 -
  87.182 -    @Test
  87.183 -    public void accessStaticFinalFieldBooleanBoxing() throws ScriptException {
  87.184 -        e.eval("var psf_boolean_box = SharedObject.publicStaticFinalBooleanBox;");
  87.185 -        assertEquals(SharedObject.publicStaticFinalBooleanBox, e.get("psf_boolean_box"));
  87.186 -        assertEquals("boolean", e.eval("typeof psf_boolean_box;"));
  87.187 -        e.eval("SharedObject.publicStaticFinalBooleanBox = false;");
  87.188 -        assertEquals(true, (boolean)SharedObject.publicStaticFinalBooleanBox);
  87.189 -    }
  87.190 -
  87.191 -    @Test
  87.192 -    public void accessVolatileField() throws ScriptException {
  87.193 -        e.eval("var pv_boolean = o.volatileBoolean;");
  87.194 -        assertEquals(o.volatileBoolean, e.get("pv_boolean"));
  87.195 -        assertEquals("boolean", e.eval("typeof pv_boolean;"));
  87.196 -        e.eval("o.volatileBoolean = false;");
  87.197 -        assertEquals(false, o.volatileBoolean);
  87.198 -    }
  87.199 -
  87.200 -    @Test
  87.201 -    public void accessTransientField() throws ScriptException {
  87.202 -        e.eval("var pt_boolean = o.transientBoolean;");
  87.203 -        assertEquals(o.transientBoolean, e.get("pt_boolean"));
  87.204 -        assertEquals("boolean", e.eval("typeof pt_boolean;"));
  87.205 -        e.eval("o.transientBoolean = false;");
  87.206 -        assertEquals(false, o.transientBoolean);
  87.207 -    }
  87.208 -
  87.209 -}
    88.1 --- a/test/src/jdk/nashorn/internal/access/MethodAccessTest.java	Sat Feb 09 16:58:48 2013 +0100
    88.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.3 @@ -1,453 +0,0 @@
    88.4 -/*
    88.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    88.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    88.7 - *
    88.8 - * This code is free software; you can redistribute it and/or modify it
    88.9 - * under the terms of the GNU General Public License version 2 only, as
   88.10 - * published by the Free Software Foundation.  Oracle designates this
   88.11 - * particular file as subject to the "Classpath" exception as provided
   88.12 - * by Oracle in the LICENSE file that accompanied this code.
   88.13 - *
   88.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   88.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   88.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   88.17 - * version 2 for more details (a copy is included in the LICENSE file that
   88.18 - * accompanied this code).
   88.19 - *
   88.20 - * You should have received a copy of the GNU General Public License version
   88.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   88.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   88.23 - *
   88.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   88.25 - * or visit www.oracle.com if you need additional information or have any
   88.26 - * questions.
   88.27 - */
   88.28 -
   88.29 -package jdk.nashorn.internal.access;
   88.30 -
   88.31 -import static org.testng.AssertJUnit.assertEquals;
   88.32 -import static org.testng.AssertJUnit.assertTrue;
   88.33 -import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
   88.34 -
   88.35 -import java.util.Arrays;
   88.36 -import java.util.Calendar;
   88.37 -import java.util.Locale;
   88.38 -import javax.script.ScriptEngine;
   88.39 -import javax.script.ScriptEngineManager;
   88.40 -import javax.script.ScriptException;
   88.41 -import org.testng.TestNG;
   88.42 -import org.testng.annotations.BeforeClass;
   88.43 -import org.testng.annotations.Test;
   88.44 -
   88.45 -public class MethodAccessTest {
   88.46 -
   88.47 -    private static ScriptEngine e = null;
   88.48 -    private static SharedObject o = new SharedObject();
   88.49 -
   88.50 -    public static void main(final String[] args) {
   88.51 -        TestNG.main(args);
   88.52 -    }
   88.53 -
   88.54 -    @BeforeClass
   88.55 -    public static void setUpClass() throws ScriptException {
   88.56 -        final ScriptEngineManager m = new ScriptEngineManager();
   88.57 -        e = m.getEngineByName("nashorn");
   88.58 -        o.setEngine(e);
   88.59 -        e.put("o", o);
   88.60 -        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   88.61 -        e.eval("var Person = Packages.jdk.nashorn.internal.access.Person;");
   88.62 -    }
   88.63 -
   88.64 -    @Test
   88.65 -    public void accessMethodthrowsCheckedException() throws ScriptException {
   88.66 -        e.eval("try {" +
   88.67 -                "    var a = java.lang.Long.parseLong('foo');" +
   88.68 -                "} catch(e) {" +
   88.69 -                "    var isThrown = true;" +
   88.70 -                "    var isNumberException = e instanceof java.lang.NumberFormatException;" +
   88.71 -                "} finally {" +
   88.72 -                "    var isFinalized = true;" +
   88.73 -                "}");
   88.74 -        assertEquals("Exception thrown", true, e.get("isThrown"));
   88.75 -        assertEquals("Finally called", true, e.get("isFinalized"));
   88.76 -        assertEquals("Type is NumberFormatException", true, e.get("isNumberException"));
   88.77 -    }
   88.78 -
   88.79 -    @Test
   88.80 -    public void accessMethodthrowsUnCheckedException() throws ScriptException {
   88.81 -        e.eval("try {" +
   88.82 -                "    var a = java.lang.String.valueOf(null);" +
   88.83 -                "} catch(e) {" +
   88.84 -                "    var isThrown = true;" +
   88.85 -                "    var isNumberException = e instanceof java.lang.NullPointerException;" +
   88.86 -                "} finally {" +
   88.87 -                "    var isFinalized = true;" +
   88.88 -                "}");
   88.89 -        assertEquals(true, e.get("isThrown"));
   88.90 -        assertEquals(true, e.get("isFinalized"));
   88.91 -        assertEquals(true, e.get("isNumberException"));
   88.92 -    }
   88.93 -
   88.94 -    @Test
   88.95 -    public void accessMethodStartsThread() throws ScriptException {
   88.96 -        e.eval("o.methodStartsThread();");
   88.97 -        assertEquals(false, o.isFinished);
   88.98 -    }
   88.99 -
  88.100 -    @Test
  88.101 -    public void accessStaticMethod() throws ScriptException {
  88.102 -        assertEquals(10, e.eval("java.lang.Math.abs(-10);"));
  88.103 -    }
  88.104 -
  88.105 -    @Test
  88.106 -    public void accessSynchronousMethod() throws ScriptException {
  88.107 -        e.eval("var v = new java.util.Vector();" + "v.add(10);" + "v.add(20);" + "v.add(30);");
  88.108 -        assertEquals(10, e.eval("v[0]"));
  88.109 -        assertEquals(20, e.eval("v[1]"));
  88.110 -        assertEquals(30, e.eval("v[2]"));
  88.111 -        assertEquals(3, e.eval("v.size()"));
  88.112 -    }
  88.113 -
  88.114 -    @Test
  88.115 -    public void accessStaticSynchronousMethod() throws ScriptException {
  88.116 -        e.eval("var locales = java.util.Calendar.getAvailableLocales();");
  88.117 -        final Locale[] locales = (Locale[])e.get("locales");
  88.118 -        assertEquals(locales.length, Calendar.getAvailableLocales().length);
  88.119 -    }
  88.120 -
  88.121 -    @Test
  88.122 -    public void accessNativeMethod() throws ScriptException {
  88.123 -        assertEquals(4.0, e.eval("java.lang.StrictMath.log10(10000);"));
  88.124 -    }
  88.125 -
  88.126 -    @Test
  88.127 -    public void accessConstructorOfAbstractClass() throws ScriptException {
  88.128 -        e.eval("try {" +
  88.129 -                "    var a = new java.util.AbstractList();" +
  88.130 -                "    print('fail');" +
  88.131 -                "} catch(e) {" +
  88.132 -                "    var isThrown = true;" +
  88.133 -                "}");
  88.134 -        assertEquals(true, e.get("isThrown"));
  88.135 -    }
  88.136 -
  88.137 -    @Test
  88.138 -    public void accessMethodVoid() throws ScriptException {
  88.139 -        o.isAccessed = false;
  88.140 -        e.eval("o.voidMethod();");
  88.141 -        assertTrue(o.isAccessed);
  88.142 -    }
  88.143 -
  88.144 -    @Test
  88.145 -    public void accessMethodBoolean() throws ScriptException {
  88.146 -        assertEquals(true, e.eval("o.booleanMethod(false);"));
  88.147 -        assertEquals(false, e.eval("o.booleanMethod(true);"));
  88.148 -        assertEquals(false, e.eval("o.booleanMethod('false');"));
  88.149 -        assertEquals(true, e.eval("o.booleanMethod('');"));
  88.150 -        assertEquals(true, e.eval("o.booleanMethod(0);"));
  88.151 -    }
  88.152 -
  88.153 -    @Test
  88.154 -    public void accessMethodInt() throws ScriptException {
  88.155 -        assertEquals(0, e.eval("o.intMethod(0);"));
  88.156 -        assertEquals(-200, e.eval("o.intMethod(-100);"));
  88.157 -        assertEquals(0, e.eval("o.intMethod('0');"));
  88.158 -        assertEquals(-200, e.eval("o.intMethod('-100');"));
  88.159 -    }
  88.160 -
  88.161 -    @Test
  88.162 -    public void accessMethodLong() throws ScriptException {
  88.163 -        assertEquals((long)0, e.eval("o.longMethod(0);"));
  88.164 -        assertEquals((long)400, e.eval("o.longMethod(200);"));
  88.165 -        assertEquals((long) 0, e.eval("o.longMethod('0');"));
  88.166 -        assertEquals((long) 400, e.eval("o.longMethod('200');"));
  88.167 -    }
  88.168 -
  88.169 -    @Test
  88.170 -    public void accessMethodByte() throws ScriptException {
  88.171 -        assertEquals((byte) 0, e.eval("o.byteMethod(0);"));
  88.172 -        assertEquals((byte) 10, e.eval("o.byteMethod(5);"));
  88.173 -        assertEquals((byte) 0, e.eval("o.byteMethod('0');"));
  88.174 -        assertEquals((byte) 10, e.eval("o.byteMethod('5');"));
  88.175 -    }
  88.176 -
  88.177 -    @Test
  88.178 -    public void accessMethodShort() throws ScriptException {
  88.179 -        assertEquals((short)0, e.eval("o.shortMethod(0);"));
  88.180 -        assertEquals((short)8000, e.eval("o.shortMethod(4000);"));
  88.181 -        assertEquals((short) 0, e.eval("o.shortMethod('0');"));
  88.182 -        assertEquals((short) 8000, e.eval("o.shortMethod('4000');"));
  88.183 -    }
  88.184 -
  88.185 -    @Test
  88.186 -    public void accessMethodChar() throws ScriptException {
  88.187 -        assertEquals('A', e.eval("o.charMethod('a');"));
  88.188 -        assertEquals('Z', e.eval("o.charMethod('z');"));
  88.189 -        assertEquals(o.charMethod((char)0), e.eval("o.charMethod(0);"));
  88.190 -        assertEquals(o.charMethod((char)3150), e.eval("o.charMethod(3150);"));
  88.191 -    }
  88.192 -
  88.193 -    @Test
  88.194 -    public void accessMethodFloat() throws ScriptException {
  88.195 -        assertEquals(0.0f, e.eval("o.floatMethod(0.0);"));
  88.196 -        assertEquals(4.2f, e.eval("o.floatMethod(2.1);"));
  88.197 -        assertEquals(0.0f, e.eval("o.floatMethod('0.0');"));
  88.198 -        assertEquals(4.2f, e.eval("o.floatMethod('2.1');"));
  88.199 -    }
  88.200 -
  88.201 -    @Test
  88.202 -    public void accessMethodDouble() throws ScriptException {
  88.203 -        assertEquals(0.0, e.eval("o.doubleMethod(0.0);"));
  88.204 -        assertEquals(14.0, e.eval("o.doubleMethod(7.0);"));
  88.205 -        assertEquals(0.0, e.eval("o.doubleMethod('0.0');"));
  88.206 -        assertEquals(14.0, e.eval("o.doubleMethod('7.0');"));
  88.207 -    }
  88.208 -
  88.209 -    @Test
  88.210 -    public void accessMethodBooleanBoxing() throws ScriptException {
  88.211 -        assertEquals(Boolean.TRUE, e.eval("o.booleanBoxingMethod(java.lang.Boolean.FALSE);"));
  88.212 -        assertEquals(Boolean.FALSE, e.eval("o.booleanBoxingMethod(java.lang.Boolean.TRUE);"));
  88.213 -        assertEquals(Boolean.TRUE, e.eval("o.booleanBoxingMethod('');"));
  88.214 -        assertEquals(Boolean.FALSE, e.eval("o.booleanBoxingMethod('false');"));
  88.215 -    }
  88.216 -
  88.217 -    @Test
  88.218 -    public void accessMethodIntBoxing() throws ScriptException {
  88.219 -        assertEquals(0, e.eval("o.intBoxingMethod(0);"));
  88.220 -        assertEquals(-200, e.eval("o.intBoxingMethod(-100);"));
  88.221 -        assertTrue((int)e.eval("(new java.lang.Integer(2)).compareTo(10.0)") < 0);
  88.222 -    }
  88.223 -
  88.224 -    @Test
  88.225 -    public void accessMethodLongBoxing() throws ScriptException {
  88.226 -        assertEquals((long) 0, e.eval("o.longBoxingMethod(0);"));
  88.227 -        assertEquals((long) 400, e.eval("o.longBoxingMethod(200);"));
  88.228 -        assertTrue((int)e.eval("(new java.lang.Long(2)).compareTo(10.0)") < 0);
  88.229 -    }
  88.230 -
  88.231 -    @Test
  88.232 -    public void accessMethodByteBoxing() throws ScriptException {
  88.233 -        assertEquals((byte) 0, e.eval("o.byteBoxingMethod(0);"));
  88.234 -        assertEquals((byte) 10, e.eval("o.byteBoxingMethod(5);"));
  88.235 -        assertTrue((int)e.eval("(new java.lang.Byte(2)).compareTo(10.0)") < 0);
  88.236 -    }
  88.237 -
  88.238 -    @Test
  88.239 -    public void accessMethodShortBoxing() throws ScriptException {
  88.240 -        assertEquals((short) 0, e.eval("o.shortBoxingMethod(0);"));
  88.241 -        assertEquals((short) 8000, e.eval("o.shortBoxingMethod(4000);"));
  88.242 -        assertTrue((int)e.eval("(new java.lang.Short(2)).compareTo(10.0)") < 0);
  88.243 -    }
  88.244 -
  88.245 -    @Test
  88.246 -    public void accessMethodCharBoxing() throws ScriptException {
  88.247 -        assertEquals('A', e.eval("o.charBoxingMethod('a');"));
  88.248 -        assertEquals('Z', e.eval("o.charBoxingMethod('z');"));
  88.249 -        assertTrue((int)e.eval("(new java.lang.Character(2)).compareTo(10)") < 0);
  88.250 -    }
  88.251 -
  88.252 -    @Test
  88.253 -    public void accessMethodFloatBoxing() throws ScriptException {
  88.254 -        assertEquals(0.0f, e.eval("o.floatBoxingMethod(0.0);"));
  88.255 -        assertEquals(4.2f, e.eval("o.floatBoxingMethod(2.1);"));
  88.256 -        assertTrue((int)e.eval("(new java.lang.Float(2.0)).compareTo(10.0)") < 0);
  88.257 -    }
  88.258 -
  88.259 -    @Test
  88.260 -    public void accessMethodDoubleBoxing() throws ScriptException {
  88.261 -        assertEquals(0.0, e.eval("o.doubleBoxingMethod(0.0);"));
  88.262 -        assertEquals(14.0, e.eval("o.doubleBoxingMethod(7.0);"));
  88.263 -        assertTrue((int)e.eval("(new java.lang.Double(2)).compareTo(10.0)") < 0);
  88.264 -    }
  88.265 -
  88.266 -    @Test
  88.267 -    public void accessMethodString() throws ScriptException {
  88.268 -        assertEquals("", e.eval("o.stringMethod('');"));
  88.269 -        assertEquals("abcabc", e.eval("o.stringMethod('abc');"));
  88.270 -    }
  88.271 -
  88.272 -    @Test
  88.273 -    public void accessMethodObject() throws ScriptException {
  88.274 -        e.put("so", new Person(5));
  88.275 -        e.eval("var rso = o.objectMethod(so);");
  88.276 -        assertEquals(new Person(10), e.get("rso"));
  88.277 -    }
  88.278 -
  88.279 -    @Test
  88.280 -    public void accessMethodBooleanArray() throws ScriptException {
  88.281 -        assertTrue(Arrays.equals(o.booleanArrayMethod(o.publicBooleanArray), (boolean[])e.eval("o.booleanArrayMethod(o.publicBooleanArray);")));
  88.282 -    }
  88.283 -
  88.284 -    @Test
  88.285 -    public void accessMethodIntArray() throws ScriptException {
  88.286 -        assertArrayEquals(o.intArrayMethod(o.publicIntArray), (int[])e.eval("o.intArrayMethod(o.publicIntArray);"));
  88.287 -    }
  88.288 -
  88.289 -    @Test
  88.290 -    public void accessMethodLongArray() throws ScriptException {
  88.291 -        assertArrayEquals(o.longArrayMethod(o.publicLongArray), (long[])e.eval("o.longArrayMethod(o.publicLongArray);"));
  88.292 -    }
  88.293 -
  88.294 -    @Test
  88.295 -    public void accessMethodByteArray() throws ScriptException {
  88.296 -        assertArrayEquals(o.byteArrayMethod(o.publicByteArray), (byte[])e.eval("o.byteArrayMethod(o.publicByteArray);"));
  88.297 -    }
  88.298 -
  88.299 -    @Test
  88.300 -    public void accessMethodShortArray() throws ScriptException {
  88.301 -        assertArrayEquals(o.shortArrayMethod(o.publicShortArray), (short[])e.eval("o.shortArrayMethod(o.publicShortArray);"));
  88.302 -    }
  88.303 -
  88.304 -    @Test
  88.305 -    public void accessMethodCharArray() throws ScriptException {
  88.306 -        assertArrayEquals(o.charArrayMethod(o.publicCharArray), (char[])e.eval("o.charArrayMethod(o.publicCharArray);"));
  88.307 -    }
  88.308 -
  88.309 -    @Test
  88.310 -    public void accessMethodFloatArray() throws ScriptException {
  88.311 -        assertArrayEquals(o.floatArrayMethod(o.publicFloatArray), (float[])e.eval("o.floatArrayMethod(o.publicFloatArray);"), 1e-10f);
  88.312 -    }
  88.313 -
  88.314 -    @Test
  88.315 -    public void accessMethodDoubleArray() throws ScriptException {
  88.316 -        assertArrayEquals(o.doubleArrayMethod(o.publicDoubleArray), (double[])e.eval("o.doubleArrayMethod(o.publicDoubleArray);"), 1e-10);
  88.317 -    }
  88.318 -
  88.319 -    @Test
  88.320 -    public void accessMethodStringArray() throws ScriptException {
  88.321 -        assertArrayEquals(o.stringArrayMethod(o.publicStringArray), (String[])e.eval("o.stringArrayMethod(o.publicStringArray);"));
  88.322 -    }
  88.323 -
  88.324 -    @Test
  88.325 -    public void accessMethodObjectArray() throws ScriptException {
  88.326 -        assertArrayEquals(o.objectArrayMethod(o.publicObjectArray), (Person[])e.eval("o.objectArrayMethod(o.publicObjectArray);"));
  88.327 -    }
  88.328 -
  88.329 -    @Test
  88.330 -    public void accessDefaultConstructor() throws ScriptException {
  88.331 -        e.eval("var dc = new Packages.jdk.nashorn.internal.access.Person()");
  88.332 -        assertEquals(new Person(), e.get("dc"));
  88.333 -    }
  88.334 -
  88.335 -    @Test
  88.336 -    public void accessCustomConstructor() throws ScriptException {
  88.337 -        e.eval("var cc = new Packages.jdk.nashorn.internal.access.Person(17)");
  88.338 -        assertEquals(new Person(17), e.get("cc"));
  88.339 -    }
  88.340 -
  88.341 -    @Test
  88.342 -    public void accessMethod2PrimitiveParams() throws ScriptException {
  88.343 -        assertEquals(o.twoParamMethod(50, 40.0), e.eval("o.twoParamMethod(50,40);"));
  88.344 -    }
  88.345 -
  88.346 -    @Test
  88.347 -    public void accessMethod3PrimitiveParams() throws ScriptException {
  88.348 -        assertEquals(o.threeParamMethod((short)10, 20L, 'b'), e.eval("o.threeParamMethod(10,20,'b');"));
  88.349 -    }
  88.350 -
  88.351 -    @Test
  88.352 -    public void accessMethod2ObjectParams() throws ScriptException {
  88.353 -        assertArrayEquals(new Person[] { new Person(200), new Person(300) }, (Person[])e.eval("o.twoObjectParamMethod(new Person(300),new Person(200));"));
  88.354 -    }
  88.355 -
  88.356 -    @Test
  88.357 -    public void accessMethod3ObjectParams() throws ScriptException {
  88.358 -        assertArrayEquals(new Person[] { new Person(3), new Person(2), new Person(1) }, (Person[])e.eval("o.threeObjectParamMethod(new Person(1),new Person(2),new Person(3));"));
  88.359 -    }
  88.360 -
  88.361 -    @Test
  88.362 -    public void accessMethod8ObjectParams() throws ScriptException {
  88.363 -        assertArrayEquals(new Person[] { new Person(8), new Person(7), new Person(6), new Person(5), new Person(4), new Person(3), new Person(2), new Person(1) }, (Person[])e.eval("o.eightObjectParamMethod(new Person(1),new Person(2),new Person(3)," + "new Person(4),new Person(5),new Person(6),new Person(7),new Person(8));"));
  88.364 -    }
  88.365 -
  88.366 -    @Test
  88.367 -    public void accessMethod9ObjectParams() throws ScriptException {
  88.368 -        assertArrayEquals(new Person[] { new Person(9), new Person(8), new Person(7), new Person(6), new Person(5), new Person(4), new Person(3), new Person(2), new Person(1) }, (Person[])e.eval("o.nineObjectParamMethod(new Person(1),new Person(2),new Person(3)," + "new Person(4),new Person(5),new Person(6)," + "new Person(7),new Person(8),new Person(9));"));
  88.369 -    }
  88.370 -
  88.371 -    @Test
  88.372 -    public void accessMethodObjectEllipsis() throws ScriptException {
  88.373 -        assertArrayEquals(new Person[] { new Person(9), new Person(8), new Person(7), new Person(6), new Person(5), new Person(4), new Person(3), new Person(2), new Person(1) }, (Person[])e.eval("o.methodObjectEllipsis(new Person(1),new Person(2),new Person(3)," + "new Person(4),new Person(5),new Person(6)," + "new Person(7),new Person(8),new Person(9));"));
  88.374 -        assertArrayEquals(new Person[] {}, (Person[])e.eval("o.methodObjectEllipsis()"));
  88.375 -        assertArrayEquals(new Person[] { new Person(9) }, (Person[])e.eval("o.methodObjectEllipsis(new Person(9))"));
  88.376 -    }
  88.377 -
  88.378 -    @Test
  88.379 -    public void accessMethodPrimitiveEllipsis() throws ScriptException {
  88.380 -        assertArrayEquals(new Person[] { new Person(1), new Person(3), new Person(2) }, (Person[])e.eval("o.methodPrimitiveEllipsis(1,3,2);"));
  88.381 -        assertArrayEquals(new Person[] {}, (Person[])e.eval("o.methodPrimitiveEllipsis();"));
  88.382 -        assertArrayEquals(o.methodPrimitiveEllipsis(9, 8, 7, 6, 5, 4, 3, 2, 1), (Person[])e.eval("o.methodPrimitiveEllipsis(9,8,7,6,5,4,3,2,1);"));
  88.383 -    }
  88.384 -
  88.385 -    @Test
  88.386 -    public void accessMethodMixedEllipsis() throws ScriptException {
  88.387 -        assertArrayEquals(new Object[] { new Person(1), 12, "hello", true }, (Object[])e.eval("o.methodMixedEllipsis(new Person(1),12,'hello',true);"));
  88.388 -        assertArrayEquals(new Object[] {}, (Object[])e.eval("o.methodMixedEllipsis();"));
  88.389 -    }
  88.390 -
  88.391 -    @Test
  88.392 -    public void accessMethodObjectWithEllipsis() throws ScriptException {
  88.393 -        assertArrayEquals(new Object[] { "hello", 12, 15, 16 }, (Object[])e.eval("o.methodObjectWithEllipsis('hello',12,15,16);"));
  88.394 -        assertArrayEquals(new Object[] { "hello" }, (Object[])e.eval("o.methodObjectWithEllipsis('hello');"));
  88.395 -    }
  88.396 -
  88.397 -    @Test
  88.398 -    public void accessMethodPrimitiveWithEllipsis() throws ScriptException {
  88.399 -        assertArrayEquals(new Object[] { 14, 12L, 15L, 16L }, (Object[])e.eval("o.methodPrimitiveWithEllipsis(14,12,15,16);"));
  88.400 -        assertArrayEquals(new Object[] { 12 }, (Object[])e.eval("o.methodPrimitiveWithEllipsis(12);"));
  88.401 -    }
  88.402 -
  88.403 -    @Test
  88.404 -    public void accessMethodMixedWithEllipsis() throws ScriptException {
  88.405 -        assertArrayEquals(new Object[] { "Hello", 10, true, -100500, 80 }, (Object[])e.eval("o.methodMixedWithEllipsis('Hello', 10, true, -100500,80.0);"));
  88.406 -        assertArrayEquals(new Object[] { "Nashorn", 15 }, (Object[])e.eval("o.methodMixedWithEllipsis('Nashorn',15);"));
  88.407 -    }
  88.408 -
  88.409 -    @Test
  88.410 -    public void accessMethodOverloaded() throws ScriptException {
  88.411 -        assertEquals(0, e.eval("o.overloadedMethod(0);"));
  88.412 -        assertEquals(2000, e.eval("o.overloadedMethod(1000);"));
  88.413 -        assertEquals(2, e.eval("o.overloadedMethod('10');"));
  88.414 -        assertEquals(7, e.eval("o.overloadedMethod('Nashorn');"));
  88.415 -        assertEquals(4, e.eval("o.overloadedMethod('true');"));
  88.416 -        assertEquals(1, e.eval("o.overloadedMethod(true);"));
  88.417 -        assertEquals(0, e.eval("o.overloadedMethod(false);"));
  88.418 -        assertEquals(44, e.eval("o.overloadedMethod(new Person(22));"));
  88.419 -        assertEquals(0, e.eval("o.overloadedMethod(new Person());"));
  88.420 -    }
  88.421 -
  88.422 -    @Test
  88.423 -    public void accessMethodDoubleVSintOverloaded() throws ScriptException {
  88.424 -        assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(0.0);"));
  88.425 -        assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(1000.0);"));
  88.426 -        assertEquals("double", e.eval("o.overloadedMethodDoubleVSint(0.01);"));
  88.427 -        assertEquals("double", e.eval("o.overloadedMethodDoubleVSint(100.02);"));
  88.428 -        assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(0);"));
  88.429 -        assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(1000);"));
  88.430 -    }
  88.431 -
  88.432 -    @Test
  88.433 -    public void accessJavaMethodIntFromJSFromJavaFromJS() throws ScriptException {
  88.434 -        e.eval("function secondLevelMethodInt(a) {"
  88.435 -                + "return o.thirdLevelMethodInt(a);"
  88.436 -                + "}");
  88.437 -        assertEquals(50, e.eval("o.firstLevelMethodInt(10);"));
  88.438 -    }
  88.439 -
  88.440 -    @Test
  88.441 -    public void accessJavaMethodIntegerFromJSFromJavaFromJS() throws ScriptException {
  88.442 -        e.eval("function secondLevelMethodInteger(a) {"
  88.443 -                + "return o.thirdLevelMethodInteger(a);"
  88.444 -                + "}");
  88.445 -        assertEquals(100, e.eval("o.firstLevelMethodInteger(10);"));
  88.446 -    }
  88.447 -
  88.448 -    @Test
  88.449 -    public void accessJavaMethodObjectFromJSFromJavaFromJS() throws ScriptException {
  88.450 -        e.eval("function secondLevelMethodObject(p) {"
  88.451 -                + "return o.thirdLevelMethodObject(p);"
  88.452 -                + "}");
  88.453 -        assertEquals(new Person(100), e.eval("o.firstLevelMethodObject(new Person(10));"));
  88.454 -    }
  88.455 -
  88.456 -}
    89.1 --- a/test/src/jdk/nashorn/internal/access/NumberAccessTest.java	Sat Feb 09 16:58:48 2013 +0100
    89.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.3 @@ -1,776 +0,0 @@
    89.4 -/*
    89.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    89.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    89.7 - *
    89.8 - * This code is free software; you can redistribute it and/or modify it
    89.9 - * under the terms of the GNU General Public License version 2 only, as
   89.10 - * published by the Free Software Foundation.  Oracle designates this
   89.11 - * particular file as subject to the "Classpath" exception as provided
   89.12 - * by Oracle in the LICENSE file that accompanied this code.
   89.13 - *
   89.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   89.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   89.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   89.17 - * version 2 for more details (a copy is included in the LICENSE file that
   89.18 - * accompanied this code).
   89.19 - *
   89.20 - * You should have received a copy of the GNU General Public License version
   89.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   89.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   89.23 - *
   89.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   89.25 - * or visit www.oracle.com if you need additional information or have any
   89.26 - * questions.
   89.27 - */
   89.28 -
   89.29 -package jdk.nashorn.internal.access;
   89.30 -
   89.31 -import static org.testng.AssertJUnit.assertEquals;
   89.32 -import static org.testng.AssertJUnit.assertTrue;
   89.33 -import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
   89.34 -
   89.35 -import javax.script.ScriptEngine;
   89.36 -import javax.script.ScriptEngineManager;
   89.37 -import javax.script.ScriptException;
   89.38 -import org.testng.TestNG;
   89.39 -import org.testng.annotations.BeforeClass;
   89.40 -import org.testng.annotations.Test;
   89.41 -
   89.42 -public class NumberAccessTest {
   89.43 -
   89.44 -    private static ScriptEngine e = null;
   89.45 -    private static SharedObject o = new SharedObject();
   89.46 -
   89.47 -    public static void main(final String[] args) {
   89.48 -        TestNG.main(args);
   89.49 -    }
   89.50 -
   89.51 -    @BeforeClass
   89.52 -    public static void setUpClass() throws ScriptException {
   89.53 -        final ScriptEngineManager m = new ScriptEngineManager();
   89.54 -        e = m.getEngineByName("nashorn");
   89.55 -        e.put("o", o);
   89.56 -        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   89.57 -    }
   89.58 -
   89.59 -    // --------------------------------long
   89.60 -    // tests------------------------------------
   89.61 -    @Test
   89.62 -    public void accessFieldLong() throws ScriptException {
   89.63 -        e.eval("var p_long = o.publicLong;");
   89.64 -        assertEquals(o.publicLong, e.get("p_long"));
   89.65 -        e.eval("o.publicLong = 12;");
   89.66 -        assertEquals(12, o.publicLong);
   89.67 -    }
   89.68 -
   89.69 -    @Test
   89.70 -    public void accessFieldLongArray() throws ScriptException {
   89.71 -        e.eval("var p_long_array = o.publicLongArray;");
   89.72 -        assertEquals(o.publicLongArray[0], e.eval("o.publicLongArray[0];"));
   89.73 -        assertArrayEquals(o.publicLongArray, (long[])e.get("p_long_array"));
   89.74 -        e.eval("var t_long_arr = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, 3);" +
   89.75 -                "t_long_arr[0] = -189009;" +
   89.76 -                "t_long_arr[1] = 456;" +
   89.77 -                "t_long_arr[2] = 600000001;" +
   89.78 -                "o.publicLongArray = t_long_arr;");
   89.79 -        // e.eval("o.publicIntArray = [-189009,456,600000001];");
   89.80 -        assertArrayEquals(new long[] { -189009, 456, 600000001 }, o.publicLongArray);
   89.81 -        e.eval("o.publicLongArray[0] = 10;");
   89.82 -        assertEquals(10, o.publicLongArray[0]);
   89.83 -    }
   89.84 -
   89.85 -    @Test
   89.86 -    public void accessStaticFieldLong() throws ScriptException {
   89.87 -        e.eval("var ps_long = SharedObject.publicStaticLong;");
   89.88 -        assertEquals(SharedObject.publicStaticLong, e.get("ps_long"));
   89.89 -        e.eval("SharedObject.publicStaticLong = 120;");
   89.90 -        assertEquals(120, SharedObject.publicStaticLong);
   89.91 -    }
   89.92 -
   89.93 -    @Test
   89.94 -    public void accessStaticFieldLongArray() throws ScriptException {
   89.95 -        e.eval("var ps_long_array = SharedObject.publicStaticLongArray;");
   89.96 -        assertEquals(SharedObject.publicStaticLongArray[0], e.eval("SharedObject.publicStaticLongArray[0];"));
   89.97 -        assertArrayEquals(SharedObject.publicStaticLongArray, (long[])e.get("ps_long_array"));
   89.98 -        e.eval("var ts_long_arr = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, 3);" +
   89.99 -                "ts_long_arr[0] = -189009;" +
  89.100 -                "ts_long_arr[1] = 456;" +
  89.101 -                "ts_long_arr[2] = 600000001;" +
  89.102 -                "SharedObject.publicStaticLongArray = ts_long_arr;");
  89.103 -        // e.eval("o.publicIntArray = [-189009,456,600000001];");
  89.104 -        assertArrayEquals(new long[] { -189009, 456, 600000001 }, SharedObject.publicStaticLongArray);
  89.105 -        e.eval("SharedObject.publicStaticLongArray[0] = 10;");
  89.106 -        assertEquals(10, SharedObject.publicStaticLongArray[0]);
  89.107 -    }
  89.108 -
  89.109 -    @Test
  89.110 -    public void accessFinalFieldLong() throws ScriptException {
  89.111 -        e.eval("var pf_long = o.publicFinalLong;");
  89.112 -        assertEquals(o.publicFinalLong, e.get("pf_long"));
  89.113 -        e.eval("o.publicFinalLong = 120;");
  89.114 -        assertEquals(13353333333333333L, o.publicFinalLong);
  89.115 -    }
  89.116 -
  89.117 -    @Test
  89.118 -    public void accessFinalFieldLongArray() throws ScriptException {
  89.119 -        e.eval("var pf_long_array = o.publicFinalLongArray;");
  89.120 -        assertEquals(o.publicFinalLongArray[0], e.eval("o.publicFinalLongArray[0];"));
  89.121 -        assertArrayEquals(o.publicFinalLongArray, (long[])e.get("pf_long_array"));
  89.122 -        e.eval("var tf_long_arr = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, 3);" +
  89.123 -                "tf_long_arr[0] = -189009;" +
  89.124 -                "tf_long_arr[1] = 456;" +
  89.125 -                "tf_long_arr[2] = 600000001;" +
  89.126 -                "o.publicFinalLongArray = tf_long_arr;");
  89.127 -        // e.eval("o.publicIntArray = [-189009,456,600000001];");
  89.128 -        assertArrayEquals(new long[] { 1901733333333L, -2247355555L, 3977377777L }, o.publicFinalLongArray);
  89.129 -        e.eval("o.publicFinalLongArray[0] = 10;");
  89.130 -        assertEquals(10, o.publicFinalLongArray[0]);
  89.131 -    }
  89.132 -
  89.133 -    @Test
  89.134 -    public void accessStaticFinalFieldLong() throws ScriptException {
  89.135 -        e.eval("var psf_long = SharedObject.publicStaticFinalLong;");
  89.136 -        assertEquals(SharedObject.publicStaticFinalLong, e.get("psf_long"));
  89.137 -        e.eval("SharedObject.publicStaticFinalLong = 120;");
  89.138 -        assertEquals(8333333333333L, SharedObject.publicStaticFinalLong);
  89.139 -    }
  89.140 -
  89.141 -    @Test
  89.142 -    public void accessStaticFinalFieldLongArray() throws ScriptException {
  89.143 -        e.eval("var psf_long_array = SharedObject.publicStaticFinalLongArray;");
  89.144 -        assertEquals(SharedObject.publicStaticFinalLongArray[0], e.eval("SharedObject.publicStaticFinalLongArray[0];"));
  89.145 -        assertArrayEquals(SharedObject.publicStaticFinalLongArray, (long[])e.get("psf_long_array"));
  89.146 -        e.eval("var tsf_long_arr = java.lang.reflect.Array.newInstance(java.lang.Long.TYPE, 3);" +
  89.147 -                "tsf_long_arr[0] = -189009;" +
  89.148 -                "tsf_long_arr[1] = 456;" +
  89.149 -                "tsf_long_arr[2] = 600000001;" +
  89.150 -                "SharedObject.publicStaticFinalLongArray = tsf_long_arr;");
  89.151 -        // e.eval("o.publicIntArray = [-189009,456,600000001];");
  89.152 -        assertArrayEquals(new long[] { 19017383333L, -2247358L, 39773787L }, SharedObject.publicStaticFinalLongArray);
  89.153 -        e.eval("SharedObject.publicStaticFinalLongArray[0] = 10;");
  89.154 -        assertEquals(10, SharedObject.publicStaticFinalLongArray[0]);
  89.155 -    }
  89.156 -
  89.157 -    // --------------------------------int
  89.158 -    // tests------------------------------------
  89.159 -    @Test
  89.160 -    public void accessFieldInt() throws ScriptException {
  89.161 -        e.eval("var p_int = o.publicInt;");
  89.162 -        assertEquals(o.publicInt, e.get("p_int"));
  89.163 -        e.eval("o.publicInt = 14;");
  89.164 -        assertEquals(14, o.publicInt);
  89.165 -    }
  89.166 -
  89.167 -    @Test
  89.168 -    public void accessFieldIntArray() throws ScriptException {
  89.169 -        e.eval("var p_int_array = o.publicIntArray;");
  89.170 -        assertEquals(o.publicIntArray[0], e.eval("o.publicIntArray[0];"));
  89.171 -        assertArrayEquals(o.publicIntArray, (int[])e.get("p_int_array"));
  89.172 -        e.eval("var t_int_arr = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 3);" +
  89.173 -                "t_int_arr[0] = 4;" +
  89.174 -                "t_int_arr[1] = 5;" +
  89.175 -                "t_int_arr[2] = 6;" +
  89.176 -                "o.publicIntArray = t_int_arr;");
  89.177 -        assertArrayEquals(new int[] { 4, 5, 6 }, o.publicIntArray);
  89.178 -        e.eval("o.publicIntArray[0] = 100;");
  89.179 -        assertEquals(100, o.publicIntArray[0]);
  89.180 -    }
  89.181 -
  89.182 -    @Test
  89.183 -    public void accessStaticFieldInt() throws ScriptException {
  89.184 -        e.eval("var ps_int = SharedObject.publicStaticInt;");
  89.185 -        assertEquals(SharedObject.publicStaticInt, e.get("ps_int"));
  89.186 -        e.eval("SharedObject.publicStaticInt = 140;");
  89.187 -        assertEquals(140, SharedObject.publicStaticInt);
  89.188 -    }
  89.189 -
  89.190 -    @Test
  89.191 -    public void accessStaticFieldIntArray() throws ScriptException {
  89.192 -        e.eval("var ps_int_array = SharedObject.publicStaticIntArray;");
  89.193 -        assertEquals(SharedObject.publicStaticIntArray[0], e.eval("SharedObject.publicStaticIntArray[0];"));
  89.194 -        assertArrayEquals(SharedObject.publicStaticIntArray, (int[])e.get("ps_int_array"));
  89.195 -        e.eval("var ts_int_arr = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 3);" +
  89.196 -                "ts_int_arr[0] = 4;" +
  89.197 -                "ts_int_arr[1] = 5;" +
  89.198 -                "ts_int_arr[2] = 6;" +
  89.199 -                "SharedObject.publicStaticIntArray = ts_int_arr;");
  89.200 -        assertArrayEquals(new int[] { 4, 5, 6 }, SharedObject.publicStaticIntArray);
  89.201 -        e.eval("SharedObject.publicStaticIntArray[0] = 100;");
  89.202 -        assertEquals(100, SharedObject.publicStaticIntArray[0]);
  89.203 -    }
  89.204 -
  89.205 -    @Test
  89.206 -    public void accessFinalFieldInt() throws ScriptException {
  89.207 -        e.eval("var pf_int = o.publicFinalInt;");
  89.208 -        assertEquals(o.publicFinalInt, e.get("pf_int"));
  89.209 -
  89.210 -        e.eval("o.publicFinalInt = 10;");
  89.211 -        assertEquals(20712023, o.publicFinalInt);
  89.212 -    }
  89.213 -
  89.214 -    @Test
  89.215 -    public void accessFinalFieldIntArray() throws ScriptException {
  89.216 -        e.eval("var pf_int_array = o.publicFinalIntArray;");
  89.217 -        assertEquals(o.publicFinalIntArray[0], e.eval("o.publicFinalIntArray[0];"));
  89.218 -        assertArrayEquals(o.publicFinalIntArray, (int[])e.get("pf_int_array"));
  89.219 -        e.eval("var tf_int_arr = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 3);" +
  89.220 -                "tf_int_arr[0] = 4;" +
  89.221 -                "tf_int_arr[1] = 5;" +
  89.222 -                "tf_int_arr[2] = 6;" +
  89.223 -                "o.publicFinalIntArray = tf_int_arr;");
  89.224 -        assertArrayEquals(new int[] { 50, 80, 130, 210, 340 }, o.publicFinalIntArray);
  89.225 -        e.eval("o.publicFinalIntArray[0] = 100;");
  89.226 -        assertEquals(100, o.publicFinalIntArray[0]);
  89.227 -    }
  89.228 -
  89.229 -    @Test
  89.230 -    public void accessStaticFinalFieldInt() throws ScriptException {
  89.231 -        e.eval("var psf_int = SharedObject.publicStaticFinalInt;");
  89.232 -        assertEquals(SharedObject.publicStaticFinalInt, e.get("psf_int"));
  89.233 -        e.eval("SharedObject.publicStaticFinalInt = 140;");
  89.234 -        assertEquals(207182023, SharedObject.publicStaticFinalInt);
  89.235 -    }
  89.236 -
  89.237 -    @Test
  89.238 -    public void accessStaticFinalFieldIntArray() throws ScriptException {
  89.239 -        e.eval("var psf_int_array = SharedObject.publicStaticFinalIntArray;");
  89.240 -        assertEquals(SharedObject.publicStaticFinalIntArray[0], e.eval("SharedObject.publicStaticFinalIntArray[0];"));
  89.241 -        assertArrayEquals(SharedObject.publicStaticFinalIntArray, (int[])e.get("psf_int_array"));
  89.242 -        e.eval("var tsf_int_arr = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 3);" +
  89.243 -                "tsf_int_arr[0] = 4;" +
  89.244 -                "tsf_int_arr[1] = 5;" +
  89.245 -                "tsf_int_arr[2] = 6;" +
  89.246 -                "SharedObject.publicStaticFinalIntArray = tsf_int_arr;");
  89.247 -        assertArrayEquals(new int[] { 1308, 210, 340 }, SharedObject.publicStaticFinalIntArray);
  89.248 -        e.eval("SharedObject.publicStaticFinalIntArray[0] = 100;");
  89.249 -        assertEquals(100, SharedObject.publicStaticFinalIntArray[0]);
  89.250 -    }
  89.251 -
  89.252 -    // --------------------------------byte
  89.253 -    // tests------------------------------------
  89.254 -    @Test
  89.255 -    public void accessFieldByte() throws ScriptException {
  89.256 -        e.eval("var p_byte = o.publicByte;");
  89.257 -        assertEquals(o.publicByte, e.get("p_byte"));
  89.258 -        e.eval("o.publicByte = 16;");
  89.259 -        assertEquals(16, o.publicByte);
  89.260 -    }
  89.261 -
  89.262 -    @Test
  89.263 -    public void accessFieldByteArray() throws ScriptException {
  89.264 -        e.eval("var p_byte_array = o.publicByteArray;");
  89.265 -        assertEquals(o.publicByteArray[0], e.eval("o.publicByteArray[0];"));
  89.266 -        assertArrayEquals(o.publicByteArray, (byte[])e.get("p_byte_array"));
  89.267 -        e.eval("var t_byte_arr = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 3);" +
  89.268 -                "t_byte_arr[0] = -18;" +
  89.269 -                "t_byte_arr[1] = 56;" +
  89.270 -                "t_byte_arr[2] = 60;" +
  89.271 -                "o.publicByteArray = t_byte_arr;");
  89.272 -        assertArrayEquals(new byte[] { -18, 56, 60 }, o.publicByteArray);
  89.273 -        e.eval("o.publicByteArray[0] = 100;");
  89.274 -        assertEquals(100, o.publicByteArray[0]);
  89.275 -    }
  89.276 -
  89.277 -    @Test
  89.278 -    public void accessStaticFieldByte() throws ScriptException {
  89.279 -        e.eval("var ps_byte = SharedObject.publicStaticByte;");
  89.280 -        assertEquals(SharedObject.publicStaticByte, e.get("ps_byte"));
  89.281 -        e.eval("SharedObject.publicStaticByte = 16;");
  89.282 -        assertEquals(16, SharedObject.publicStaticByte);
  89.283 -    }
  89.284 -
  89.285 -    @Test
  89.286 -    public void accessStaticFieldByteArray() throws ScriptException {
  89.287 -        e.eval("var ps_byte_array = SharedObject.publicStaticByteArray;");
  89.288 -        assertEquals(SharedObject.publicStaticByteArray[0], e.eval("SharedObject.publicStaticByteArray[0];"));
  89.289 -        assertArrayEquals(SharedObject.publicStaticByteArray, (byte[])e.get("ps_byte_array"));
  89.290 -        e.eval("var ts_byte_arr = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 3);" +
  89.291 -                "ts_byte_arr[0] = -18;" +
  89.292 -                "ts_byte_arr[1] = 56;" +
  89.293 -                "ts_byte_arr[2] = 60;" +
  89.294 -                "SharedObject.publicStaticByteArray = ts_byte_arr;");
  89.295 -        assertArrayEquals(new byte[] { -18, 56, 60 }, SharedObject.publicStaticByteArray);
  89.296 -        e.eval("SharedObject.publicStaticByteArray[0] = -90;");
  89.297 -        assertEquals(-90, SharedObject.publicStaticByteArray[0]);
  89.298 -    }
  89.299 -
  89.300 -    @Test
  89.301 -    public void accessFinalFieldByte() throws ScriptException {
  89.302 -        e.eval("var pf_byte = o.publicFinalByte;");
  89.303 -        assertEquals(o.publicFinalByte, e.get("pf_byte"));
  89.304 -        e.eval("o.publicFinalByte = 16;");
  89.305 -        assertEquals(-7, o.publicFinalByte);
  89.306 -    }
  89.307 -
  89.308 -    @Test
  89.309 -    public void accessFinalFieldByteArray() throws ScriptException {
  89.310 -        e.eval("var pf_byte_array = o.publicFinalByteArray;");
  89.311 -        assertEquals(o.publicFinalByteArray[0], e.eval("o.publicFinalByteArray[0];"));
  89.312 -        assertArrayEquals(o.publicFinalByteArray, (byte[])e.get("pf_byte_array"));
  89.313 -        e.eval("var tf_byte_arr = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 3);" +
  89.314 -                "tf_byte_arr[0] = -18;" +
  89.315 -                "tf_byte_arr[1] = 56;" +
  89.316 -                "tf_byte_arr[2] = 60;" +
  89.317 -                "o.publicFinalByteArray = tf_byte_arr;");
  89.318 -        assertArrayEquals(new byte[] { 1, 3, 6, 17, -128 }, o.publicFinalByteArray);
  89.319 -        e.eval("o.publicFinalByteArray[0] = -90;");
  89.320 -        assertEquals(-90, o.publicFinalByteArray[0]);
  89.321 -    }
  89.322 -
  89.323 -    @Test
  89.324 -    public void accessStaticFinalFieldByte() throws ScriptException {
  89.325 -        e.eval("var psf_byte = SharedObject.publicStaticFinalByte;");
  89.326 -        assertEquals(SharedObject.publicStaticFinalByte, e.get("psf_byte"));
  89.327 -        e.eval("SharedObject.publicStaticFinalByte = 16;");
  89.328 -        assertEquals(-70, SharedObject.publicStaticFinalByte);
  89.329 -    }
  89.330 -
  89.331 -    @Test
  89.332 -    public void accessStaticFinalFieldByteArray() throws ScriptException {
  89.333 -        e.eval("var psf_byte_array = SharedObject.publicStaticFinalByteArray;");
  89.334 -        assertEquals(SharedObject.publicStaticFinalByteArray[0], e.eval("SharedObject.publicStaticFinalByteArray[0];"));
  89.335 -        assertArrayEquals(SharedObject.publicStaticFinalByteArray, (byte[])e.get("psf_byte_array"));
  89.336 -        e.eval("var tsf_byte_arr = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 3);" +
  89.337 -                "tsf_byte_arr[0] = -18;" +
  89.338 -                "tsf_byte_arr[1] = 56;" +
  89.339 -                "tsf_byte_arr[2] = 60;" +
  89.340 -                "SharedObject.publicStaticFinalByteArray = tsf_byte_arr;");
  89.341 -        assertArrayEquals(new byte[] { 17, -128, 81 }, SharedObject.publicStaticFinalByteArray);
  89.342 -        e.eval("SharedObject.publicStaticFinalByteArray[0] = -90;");
  89.343 -        assertEquals(-90, SharedObject.publicStaticFinalByteArray[0]);
  89.344 -    }
  89.345 -
  89.346 -    // --------------------------------short
  89.347 -    // tests------------------------------------
  89.348 -    @Test
  89.349 -    public void accessFieldShort() throws ScriptException {
  89.350 -        e.eval("var p_short = o.publicShort;");
  89.351 -        assertEquals(o.publicShort, e.get("p_short"));
  89.352 -        e.eval("o.publicShort = 18;");
  89.353 -        assertEquals(18, o.publicShort);
  89.354 -    }
  89.355 -
  89.356 -    @Test
  89.357 -    public void accessFieldShortArray() throws ScriptException {
  89.358 -        e.eval("var p_short_array = o.publicShortArray;");
  89.359 -        assertEquals(o.publicShortArray[0], e.eval("o.publicShortArray[0];"));
  89.360 -        assertArrayEquals(o.publicShortArray, (short[])e.get("p_short_array"));
  89.361 -        e.eval("var t_short_arr = java.lang.reflect.Array.newInstance(java.lang.Short.TYPE, 3);" +
  89.362 -                "t_short_arr[0] = 90;" +
  89.363 -                "t_short_arr[1] = 5;" +
  89.364 -                "t_short_arr[2] = -6000;" +
  89.365 -                "o.publicShortArray = t_short_arr;");
  89.366 -        assertArrayEquals(new short[] { 90, 5, -6000 }, o.publicShortArray);
  89.367 -        e.eval("o.publicShortArray[0] = -1000;");
  89.368 -        assertEquals(-1000, o.publicShortArray[0]);
  89.369 -    }
  89.370 -
  89.371 -    @Test
  89.372 -    public void accessStaticFieldShort() throws ScriptException {
  89.373 -        e.eval("var ps_short = SharedObject.publicStaticShort;");
  89.374 -        assertEquals(SharedObject.publicStaticShort, e.get("ps_short"));
  89.375 -        e.eval("SharedObject.publicStaticShort = 180;");
  89.376 -        assertEquals(180, SharedObject.publicStaticShort);
  89.377 -    }
  89.378 -
  89.379 -    @Test
  89.380 -    public void accessStaticFieldShortArray() throws ScriptException {
  89.381 -        e.eval("var ps_short_array = SharedObject.publicStaticShortArray;");
  89.382 -        assertEquals(SharedObject.publicStaticShortArray[0], e.eval("SharedObject.publicStaticShortArray[0];"));
  89.383 -        assertArrayEquals(SharedObject.publicStaticShortArray, (short[])e.get("ps_short_array"));
  89.384 -        e.eval("var ts_short_arr = java.lang.reflect.Array.newInstance(java.lang.Short.TYPE, 3);" +
  89.385 -                "ts_short_arr[0] = 90;" +
  89.386 -                "ts_short_arr[1] = 5;" +
  89.387 -                "ts_short_arr[2] = -6000;" +
  89.388 -                "SharedObject.publicStaticShortArray = ts_short_arr;");
  89.389 -        assertArrayEquals(new short[] { 90, 5, -6000 }, SharedObject.publicStaticShortArray);
  89.390 -        e.eval("SharedObject.publicStaticShortArray[0] = -1000;");
  89.391 -        assertEquals(-1000, SharedObject.publicStaticShortArray[0]);
  89.392 -    }
  89.393 -
  89.394 -    @Test
  89.395 -    public void accessFinalFieldShort() throws ScriptException {
  89.396 -        e.eval("var pf_short = o.publicFinalShort;");
  89.397 -        assertEquals(o.publicFinalShort, e.get("pf_short"));
  89.398 -        e.eval("o.publicFinalShort = 180;");
  89.399 -        assertEquals(31220, o.publicFinalShort);
  89.400 -    }
  89.401 -
  89.402 -    @Test
  89.403 -    public void accessFinalFieldShortArray() throws ScriptException {
  89.404 -        e.eval("var pf_short_array = o.publicFinalShortArray;");
  89.405 -        assertEquals(o.publicFinalShortArray[0], e.eval("o.publicFinalShortArray[0];"));
  89.406 -        assertArrayEquals(o.publicFinalShortArray, (short[])e.get("pf_short_array"));
  89.407 -        e.eval("var tf_short_arr = java.lang.reflect.Array.newInstance(java.lang.Short.TYPE, 3);" +
  89.408 -                "tf_short_arr[0] = 90;" +
  89.409 -                "tf_short_arr[1] = 5;" +
  89.410 -                "tf_short_arr[2] = -6000;" +
  89.411 -                "o.publicFinalShortArray = tf_short_arr;");
  89.412 -        assertArrayEquals(new short[] { 12240, 9200, -17289, 1200, 12 }, o.publicFinalShortArray);
  89.413 -        e.eval("o.publicFinalShortArray[0] = -1000;");
  89.414 -        assertEquals(-1000, o.publicFinalShortArray[0]);
  89.415 -    }
  89.416 -
  89.417 -    @Test
  89.418 -    public void accessStaticFinalFieldShort() throws ScriptException {
  89.419 -        e.eval("var psf_short = SharedObject.publicStaticFinalShort;");
  89.420 -        assertEquals(SharedObject.publicStaticFinalShort, e.get("psf_short"));
  89.421 -        e.eval("SharedObject.publicStaticFinalShort = 180;");
  89.422 -        assertEquals(8888, SharedObject.publicStaticFinalShort);
  89.423 -    }
  89.424 -
  89.425 -    @Test
  89.426 -    public void accessStaticFinalFieldShortArray() throws ScriptException {
  89.427 -        e.eval("var psf_short_array = SharedObject.publicStaticFinalShortArray;");
  89.428 -        assertEquals(SharedObject.publicStaticFinalShortArray[0], e.eval("SharedObject.publicStaticFinalShortArray[0];"));
  89.429 -        assertArrayEquals(SharedObject.publicStaticFinalShortArray, (short[])e.get("psf_short_array"));
  89.430 -        e.eval("var tsf_short_arr = java.lang.reflect.Array.newInstance(java.lang.Short.TYPE, 3);" +
  89.431 -                "tsf_short_arr[0] = 90;" +
  89.432 -                "tsf_short_arr[1] = 5;" +
  89.433 -                "tsf_short_arr[2] = -6000;" +
  89.434 -                "SharedObject.publicStaticFinalShortArray = tsf_short_arr;");
  89.435 -        assertArrayEquals(new short[] { 8240, 9280, -1289, 120, 812 }, SharedObject.publicStaticFinalShortArray);
  89.436 -        e.eval("SharedObject.publicStaticFinalShortArray[0] = -1000;");
  89.437 -        assertEquals(-1000, SharedObject.publicStaticFinalShortArray[0]);
  89.438 -    }
  89.439 -
  89.440 -    // --------------------------------char
  89.441 -    // tests------------------------------------
  89.442 -    @Test
  89.443 -    public void accessFieldChar() throws ScriptException {
  89.444 -        e.eval("var p_char = o.publicChar;");
  89.445 -        assertEquals(o.publicChar, e.get("p_char"));
  89.446 -        e.eval("o.publicChar = 'S';");
  89.447 -        assertEquals('S', o.publicChar);
  89.448 -        e.eval("o.publicChar = 10;");
  89.449 -        assertEquals(10, o.publicChar);
  89.450 -        e.eval("try {"
  89.451 -                + "    o.publicChar = 'Big string';" +
  89.452 -                "} catch(e) {" +
  89.453 -                "    var isThrown = true;" +
  89.454 -                "}");
  89.455 -        assertEquals("Exception thrown", true, e.get("isThrown"));
  89.456 -        assertEquals(10, o.publicChar);
  89.457 -    }
  89.458 -
  89.459 -    @Test
  89.460 -    public void accessFieldCharArray() throws ScriptException {
  89.461 -        e.eval("var p_char_array = o.publicCharArray;");
  89.462 -        assertEquals(o.publicCharArray[0], e.eval("o.publicCharArray[0];"));
  89.463 -        assertArrayEquals(o.publicCharArray, (char[])e.get("p_char_array"));
  89.464 -        e.eval("var t_char_arr = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 3);" +
  89.465 -                "t_char_arr[0] = 'F';" +
  89.466 -                "t_char_arr[1] = 'o';" +
  89.467 -                "t_char_arr[2] = 'o';" +
  89.468 -                "o.publicCharArray = t_char_arr;");
  89.469 -        assertArrayEquals("Foo".toCharArray(), o.publicCharArray);
  89.470 -        e.eval("o.publicCharArray[0] = 'Z';");
  89.471 -        assertEquals('Z', o.publicCharArray[0]);
  89.472 -    }
  89.473 -
  89.474 -    @Test
  89.475 -    public void accessStaticFieldChar() throws ScriptException {
  89.476 -        e.eval("var ps_char = SharedObject.publicStaticChar;");
  89.477 -        assertEquals(SharedObject.publicStaticChar, e.get("ps_char"));
  89.478 -        e.eval("SharedObject.publicStaticChar = 'Z';");
  89.479 -        assertEquals('Z', SharedObject.publicStaticChar);
  89.480 -    }
  89.481 -
  89.482 -    @Test
  89.483 -    public void accessStaticFieldCharArray() throws ScriptException {
  89.484 -        e.eval("var ps_char_array = SharedObject.publicStaticCharArray;");
  89.485 -        assertEquals(SharedObject.publicStaticCharArray[0], e.eval("SharedObject.publicStaticCharArray[0];"));
  89.486 -        assertArrayEquals(SharedObject.publicStaticCharArray, (char[])e.get("ps_char_array"));
  89.487 -        e.eval("var ts_char_arr = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 3);" +
  89.488 -                "ts_char_arr[0] = 'G';" +
  89.489 -                "ts_char_arr[1] = 'o';" +
  89.490 -                "ts_char_arr[2] = 'o';" +
  89.491 -                "SharedObject.publicStaticCharArray = ts_char_arr;");
  89.492 -        assertArrayEquals("Goo".toCharArray(), SharedObject.publicStaticCharArray);
  89.493 -        e.eval("SharedObject.publicStaticCharArray[0] = 'Z';");
  89.494 -        assertEquals('Z', SharedObject.publicStaticCharArray[0]);
  89.495 -    }
  89.496 -
  89.497 -    @Test
  89.498 -    public void accessFinalFieldChar() throws ScriptException {
  89.499 -        e.eval("var pf_char = o.publicFinalChar;");
  89.500 -        assertEquals(o.publicFinalChar, e.get("pf_char"));
  89.501 -        e.eval("o.publicFinalChar = 'S';");
  89.502 -        assertEquals('E', o.publicFinalChar);
  89.503 -    }
  89.504 -
  89.505 -    @Test
  89.506 -    public void accessFinalCharArray() throws ScriptException {
  89.507 -        e.eval("var pf_char_array = o.publicFinalCharArray;");
  89.508 -        assertEquals(o.publicFinalCharArray[0], e.eval("o.publicFinalCharArray[0];"));
  89.509 -        assertArrayEquals(o.publicFinalCharArray, (char[])e.get("pf_char_array"));
  89.510 -        e.eval("var tf_char_arr = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 3);" +
  89.511 -                "tf_char_arr[0] = 'F';" +
  89.512 -                "tf_char_arr[1] = 'o';" +
  89.513 -                "tf_char_arr[2] = 'o';" +
  89.514 -                "o.publicFinalCharArray = tf_char_arr;");
  89.515 -        assertArrayEquals("Nashorn hello".toCharArray(), o.publicFinalCharArray);
  89.516 -        e.eval("o.publicFinalCharArray[0] = 'Z';");
  89.517 -        assertEquals('Z', o.publicFinalCharArray[0]);
  89.518 -    }
  89.519 -
  89.520 -    @Test
  89.521 -    public void accessStaticFinalFieldChar() throws ScriptException {
  89.522 -        e.eval("var psf_char = SharedObject.publicStaticFinalChar;");
  89.523 -        assertEquals(SharedObject.publicStaticFinalChar, e.get("psf_char"));
  89.524 -        e.eval("SharedObject.publicStaticFinalChar = 'Z';");
  89.525 -        assertEquals('K', SharedObject.publicStaticFinalChar);
  89.526 -    }
  89.527 -
  89.528 -    @Test
  89.529 -    public void accessStaticFinalFieldCharArray() throws ScriptException {
  89.530 -        e.eval("var psf_char_array = SharedObject.publicStaticFinalCharArray;");
  89.531 -        assertEquals(SharedObject.publicStaticFinalCharArray[0], e.eval("SharedObject.publicStaticFinalCharArray[0];"));
  89.532 -        assertArrayEquals(SharedObject.publicStaticFinalCharArray, (char[])e.get("psf_char_array"));
  89.533 -        e.eval("var tsf_char_arr = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 3);" +
  89.534 -                "tsf_char_arr[0] = 'Z';" +
  89.535 -                "tsf_char_arr[1] = 'o';" +
  89.536 -                "tsf_char_arr[2] = 'o';" +
  89.537 -                "SharedObject.publicStaticFinalCharArray = tsf_char_arr;");
  89.538 -        assertArrayEquals("StaticString".toCharArray(), SharedObject.publicStaticFinalCharArray);
  89.539 -        e.eval("SharedObject.publicStaticFinalCharArray[0] = 'Z';");
  89.540 -        assertEquals('Z', SharedObject.publicStaticFinalCharArray[0]);
  89.541 -    }
  89.542 -
  89.543 -    // --------------------------------float
  89.544 -    // tests------------------------------------
  89.545 -    @Test
  89.546 -    public void accessFieldFloat() throws ScriptException {
  89.547 -        e.eval("var p_float = o.publicFloat;");
  89.548 -        assertEquals(o.publicFloat, e.get("p_float"));
  89.549 -        o.publicFloat = 0.0f / 0.0f;
  89.550 -        assertEquals(true, e.eval("isNaN(o.publicFloat)"));
  89.551 -        o.publicFloat = 1.0f / 0.0f;
  89.552 -        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === o.publicFloat"));
  89.553 -        o.publicFloat = -1.0f / 0.0f;
  89.554 -        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === o.publicFloat"));
  89.555 -        e.eval("o.publicFloat = 20;");
  89.556 -        assertEquals(20, o.publicFloat, 1e-10);
  89.557 -        e.eval("o.publicFloat = 0.0/0.0;");
  89.558 -        assertTrue(Float.isNaN(o.publicFloat));
  89.559 -        e.eval("o.publicFloat = 1.0/0.0;");
  89.560 -        assertEquals(Float.floatToIntBits(Float.POSITIVE_INFINITY), Float.floatToIntBits(o.publicFloat));
  89.561 -        e.eval("o.publicFloat = -1.0/0.0;");
  89.562 -        assertEquals(Float.NEGATIVE_INFINITY, o.publicFloat, 1e-10);
  89.563 -    }
  89.564 -
  89.565 -    @Test
  89.566 -    public void accessFieldFloatArray() throws ScriptException {
  89.567 -        e.eval("var p_float_array = o.publicFloatArray;");
  89.568 -        assertEquals(o.publicFloatArray[0], e.eval("o.publicFloatArray[0];"));
  89.569 -        assertArrayEquals(o.publicFloatArray, (float[])e.get("p_float_array"), 1e-10f);
  89.570 -        e.eval("var t_float_arr = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, 3);" +
  89.571 -                "t_float_arr[0] = 9.0;" +
  89.572 -                "t_float_arr[1] = 5.12345;" +
  89.573 -                "t_float_arr[2] = -60.03;" +
  89.574 -                "o.publicFloatArray = t_float_arr;");
  89.575 -        assertArrayEquals(new float[] { 9.0f, 5.12345f, -60.03f }, o.publicFloatArray, 1e-10f);
  89.576 -        e.eval("o.publicFloatArray[0] = -513.2;");
  89.577 -        assertArrayEquals(new float[] { -513.2f, 5.12345f, -60.03f }, o.publicFloatArray, 1e-10f);
  89.578 -    }
  89.579 -
  89.580 -    @Test
  89.581 -    public void accessStaticFieldFloat() throws ScriptException {
  89.582 -        e.eval("var ps_float = SharedObject.publicStaticFloat;");
  89.583 -        assertEquals(SharedObject.publicStaticFloat, e.get("ps_float"));
  89.584 -        SharedObject.publicStaticFloat = 0.0f / 0.0f;
  89.585 -        assertEquals(true, e.eval("isNaN(SharedObject.publicStaticFloat)"));
  89.586 -        SharedObject.publicStaticFloat = 1.0f / 0.0f;
  89.587 -        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === SharedObject.publicStaticFloat"));
  89.588 -        SharedObject.publicStaticFloat = -1.0f / 0.0f;
  89.589 -        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === SharedObject.publicStaticFloat"));
  89.590 -        e.eval("SharedObject.publicStaticFloat = 20.0;");
  89.591 -        assertEquals(20.0f, SharedObject.publicStaticFloat, 1e-10);
  89.592 -        e.eval("SharedObject.publicStaticFloat = 0.0/0.0;");
  89.593 -        assertTrue(Float.isNaN(SharedObject.publicStaticFloat));
  89.594 -        e.eval("SharedObject.publicStaticFloat = 1.0/0.0;");
  89.595 -        assertEquals(Float.floatToIntBits(Float.POSITIVE_INFINITY), Float.floatToIntBits(SharedObject.publicStaticFloat));
  89.596 -        e.eval("SharedObject.publicStaticFloat = -1.0/0.0;");
  89.597 -        assertEquals(Float.floatToIntBits(Float.NEGATIVE_INFINITY), Float.floatToIntBits(SharedObject.publicStaticFloat));
  89.598 -    }
  89.599 -
  89.600 -    @Test
  89.601 -    public void accessStaticFieldFloatArray() throws ScriptException {
  89.602 -        e.eval("var ps_float_array = SharedObject.publicStaticFloatArray;");
  89.603 -        assertEquals(SharedObject.publicStaticFloatArray[0], e.eval("SharedObject.publicStaticFloatArray[0];"));
  89.604 -        assertArrayEquals(SharedObject.publicStaticFloatArray, (float[])e.get("ps_float_array"), 1e-10f);
  89.605 -        e.eval("var ts_float_arr = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, 3);" +
  89.606 -                "ts_float_arr[0] = 9.0;" +
  89.607 -                "ts_float_arr[1] = 5.12345;" +
  89.608 -                "ts_float_arr[2] = -60.03;" +
  89.609 -                "SharedObject.publicStaticFloatArray = ts_float_arr;");
  89.610 -        assertArrayEquals(new float[] { 9.0f, 5.12345f, -60.03f }, SharedObject.publicStaticFloatArray, 1e-10f);
  89.611 -        e.eval("SharedObject.publicStaticFloatArray[0] = -513.2;");
  89.612 -        assertArrayEquals(new float[] { -513.2f, 5.12345f, -60.03f }, SharedObject.publicStaticFloatArray, 1e-10f);
  89.613 -    }
  89.614 -
  89.615 -    @Test
  89.616 -    public void accessFinalFloat() throws ScriptException {
  89.617 -        e.eval("var pf_float = o.publicFinalFloat;");
  89.618 -        assertEquals(o.publicFinalFloat, e.get("pf_float"));
  89.619 -        e.eval("o.publicFinalFloat = 20.0;");
  89.620 -        assertEquals(7.72e8f, o.publicFinalFloat, 1e-10);
  89.621 -    }
  89.622 -
  89.623 -    @Test
  89.624 -    public void accessFinalFloatArray() throws ScriptException {
  89.625 -        e.eval("var pf_float_array = o.publicFinalFloatArray;");
  89.626 -        assertEquals(o.publicFinalFloatArray[0], e.eval("o.publicFinalFloatArray[0];"));
  89.627 -        assertArrayEquals(o.publicFinalFloatArray, (float[])e.get("pf_float_array"), 1e-10f);
  89.628 -        e.eval("var tf_float_arr = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, 3);" +
  89.629 -                "tf_float_arr[0] = 9.0;" +
  89.630 -                "tf_float_arr[1] = 5.12345;" +
  89.631 -                "tf_float_arr[2] = -60.03;" +
  89.632 -                "o.publicFinalFloatArray = tf_float_arr;");
  89.633 -        assertArrayEquals(new float[] { -131.012f, 189.32f, -31.32e8f, 3.72f }, o.publicFinalFloatArray, 1e-10f);
  89.634 -        e.eval("o.publicFinalFloatArray[0] = -513.2;");
  89.635 -        assertEquals(-513.2f, o.publicFinalFloatArray[0], 1e-10f);
  89.636 -    }
  89.637 -
  89.638 -    @Test
  89.639 -    public void accessStaticFinalFieldFloat() throws ScriptException {
  89.640 -        e.eval("var psf_float = SharedObject.publicStaticFinalFloat;");
  89.641 -        assertEquals(SharedObject.publicStaticFinalFloat, e.get("psf_float"));
  89.642 -        e.eval("SharedObject.publicStaticFinalFloat = 20.0;");
  89.643 -        assertEquals(0.72e8f, SharedObject.publicStaticFinalFloat, 1e-10);
  89.644 -    }
  89.645 -
  89.646 -    @Test
  89.647 -    public void accessStaticFinalFieldFloatArray() throws ScriptException {
  89.648 -        e.eval("var psf_float_array = SharedObject.publicStaticFinalFloatArray;");
  89.649 -        assertEquals(SharedObject.publicStaticFinalFloatArray[0], e.eval("SharedObject.publicStaticFinalFloatArray[0];"));
  89.650 -        assertArrayEquals(SharedObject.publicStaticFinalFloatArray, (float[])e.get("psf_float_array"), 1e-10f);
  89.651 -        e.eval("var tsf_float_arr = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, 3);" +
  89.652 -                "tsf_float_arr[0] = 9.0;" +
  89.653 -                "tsf_float_arr[1] = 5.12345;" +
  89.654 -                "tsf_float_arr[2] = -60.03;" +
  89.655 -                "SharedObject.publicStaticFinalFloatArray = tsf_float_arr;");
  89.656 -        assertArrayEquals(new float[] { -8131.012f, 9.32f, -138.32e8f, 0.72f }, SharedObject.publicStaticFinalFloatArray, 1e-10f);
  89.657 -        e.eval("SharedObject.publicStaticFinalFloatArray[0] = -513.2;");
  89.658 -        assertEquals(-513.2f, SharedObject.publicStaticFinalFloatArray[0], 1e-10f);
  89.659 -    }
  89.660 -
  89.661 -    // --------------------------------double
  89.662 -    // tests------------------------------------
  89.663 -    @Test
  89.664 -    public void accessFieldDouble() throws ScriptException {
  89.665 -        e.eval("var p_double = o.publicDouble;");
  89.666 -        assertEquals(o.publicDouble, e.get("p_double"));
  89.667 -        o.publicDouble = 0.0 / 0.0;
  89.668 -        assertEquals(true, e.eval("isNaN(o.publicDouble)"));
  89.669 -        o.publicDouble = 1.0 / 0.0;
  89.670 -        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === o.publicDouble"));
  89.671 -        o.publicDouble = -1.0 / 0.0;
  89.672 -        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === o.publicDouble"));
  89.673 -        e.eval("o.publicDouble = 30;");
  89.674 -        assertEquals(Double.doubleToLongBits(30.0), Double.doubleToLongBits(o.publicDouble));
  89.675 -        e.eval("o.publicDouble = 0.0/0.0;");
  89.676 -        assertTrue(Double.isNaN(o.publicDouble));
  89.677 -        e.eval("o.publicDouble = 1.0/0.0;");
  89.678 -        assertEquals(Double.doubleToLongBits(Double.POSITIVE_INFINITY), Double.doubleToLongBits(o.publicDouble));
  89.679 -        e.eval("o.publicDouble = -1.0/0.0;");
  89.680 -        assertEquals(Double.doubleToLongBits(Double.NEGATIVE_INFINITY), Double.doubleToLongBits(o.publicDouble));
  89.681 -    }
  89.682 -
  89.683 -    @Test
  89.684 -    public void accessFieldDoubleArrayRead() throws ScriptException {
  89.685 -        e.eval("var p_double_array = o.publicDoubleArray;");
  89.686 -        assertEquals(o.publicDoubleArray[0], e.eval("o.publicDoubleArray[0];"));
  89.687 -        assertArrayEquals(o.publicDoubleArray, (double[])e.get("p_double_array"), 1e-10);
  89.688 -        e.eval("var t_double_arr = java.lang.reflect.Array.newInstance(java.lang.Double.TYPE, 3);" +
  89.689 -                "t_double_arr[0] = 9e10;" +
  89.690 -                "t_double_arr[1] = 0.677777;" +
  89.691 -                "t_double_arr[2] = -0.0000001;" +
  89.692 -                "o.publicDoubleArray = t_double_arr;");
  89.693 -        assertArrayEquals(new double[] { 9e10, 0.677777, -0.0000001 }, o.publicDoubleArray, 1e-10f);
  89.694 -        e.eval("o.publicDoubleArray[0] = -5.2e10;");
  89.695 -        assertEquals(-5.2e10, o.publicDoubleArray[0], 1e-10f);
  89.696 -    }
  89.697 -
  89.698 -    @Test
  89.699 -    public void accessStaticFieldDouble() throws ScriptException {
  89.700 -        e.eval("var ps_double = SharedObject.publicStaticDouble;");
  89.701 -        assertEquals(SharedObject.publicStaticDouble, e.get("ps_double"));
  89.702 -        SharedObject.publicStaticDouble = 0.0 / 0.0;
  89.703 -        assertEquals(true, e.eval("isNaN(SharedObject.publicStaticDouble)"));
  89.704 -        SharedObject.publicStaticDouble = 1.0 / 0.0;
  89.705 -        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === SharedObject.publicStaticDouble"));
  89.706 -        SharedObject.publicStaticDouble = -1.0 / 0.0;
  89.707 -        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === SharedObject.publicStaticDouble"));
  89.708 -        e.eval("SharedObject.publicStaticDouble = 40.0;");
  89.709 -        assertEquals(Double.doubleToLongBits(40.0), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  89.710 -        e.eval("SharedObject.publicStaticDouble = 0.0/0.0;");
  89.711 -        assertTrue(Double.isNaN(SharedObject.publicStaticDouble));
  89.712 -        e.eval("SharedObject.publicStaticDouble = 1.0/0.0;");
  89.713 -        assertEquals(Double.doubleToLongBits(Double.POSITIVE_INFINITY), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  89.714 -        e.eval("SharedObject.publicStaticDouble = -1.0/0.0;");
  89.715 -        assertEquals(Double.doubleToLongBits(Double.NEGATIVE_INFINITY), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  89.716 -    }
  89.717 -
  89.718 -    @Test
  89.719 -    public void accessStaticFieldDoubleArrayRead() throws ScriptException {
  89.720 -        e.eval("var ps_double_array = SharedObject.publicStaticDoubleArray;");
  89.721 -        assertEquals(SharedObject.publicStaticDoubleArray[0], e.eval("SharedObject.publicStaticDoubleArray[0];"));
  89.722 -        assertArrayEquals(SharedObject.publicStaticDoubleArray, (double[])e.get("ps_double_array"), 1e-10);
  89.723 -        e.eval("var ts_double_arr = java.lang.reflect.Array.newInstance(java.lang.Double.TYPE, 3);" +
  89.724 -                "ts_double_arr[0] = 9e10;" +
  89.725 -                "ts_double_arr[1] = 0.677777;" +
  89.726 -                "ts_double_arr[2] = -0.0000001;" +
  89.727 -                "SharedObject.publicStaticDoubleArray = ts_double_arr;");
  89.728 -        assertArrayEquals(new double[] { 9e10, 0.677777, -0.0000001 }, SharedObject.publicStaticDoubleArray, 1e-10f);
  89.729 -        e.eval("SharedObject.publicStaticDoubleArray[0] = -5.2e10;");
  89.730 -        assertEquals(-5.2e10, SharedObject.publicStaticDoubleArray[0], 1e-10f);
  89.731 -    }
  89.732 -
  89.733 -    @Test
  89.734 -    public void accessFinalFieldDouble() throws ScriptException {
  89.735 -        e.eval("var pf_double = o.publicFinalDouble;");
  89.736 -        assertEquals(o.publicFinalDouble, e.get("pf_double"));
  89.737 -        e.eval("o.publicFinalDouble = 30.0;");
  89.738 -        assertEquals(Double.doubleToLongBits(1.3412e20), Double.doubleToLongBits(o.publicFinalDouble));
  89.739 -    }
  89.740 -
  89.741 -    @Test
  89.742 -    public void accessFinalFieldDoubleArrayRead() throws ScriptException {
  89.743 -        e.eval("var pf_double_array = o.publicFinalDoubleArray;");
  89.744 -        assertEquals(o.publicFinalDoubleArray[0], e.eval("o.publicFinalDoubleArray[0];"));
  89.745 -        assertArrayEquals(o.publicFinalDoubleArray, (double[])e.get("pf_double_array"), 1e-10);
  89.746 -        e.eval("var tf_double_arr = java.lang.reflect.Array.newInstance(java.lang.Double.TYPE, 3);" +
  89.747 -                "tf_double_arr[0] = 9e10;" +
  89.748 -                "tf_double_arr[1] = 0.677777;" +
  89.749 -                "tf_double_arr[2] = -0.0000001;" +
  89.750 -                "o.publicFinalDoubleArray = tf_double_arr;");
  89.751 -        assertArrayEquals(new double[] { 0.725e80, 0.12e10, 8e-3, 1.00077 }, o.publicFinalDoubleArray, 1e-10f);
  89.752 -        e.eval("o.publicFinalDoubleArray[0] = -5.2e10;");
  89.753 -        assertEquals(-5.2e10, o.publicFinalDoubleArray[0], 1e-10f);
  89.754 -    }
  89.755 -
  89.756 -    @Test
  89.757 -    public void accessStaticFinalFieldDouble() throws ScriptException {
  89.758 -        e.eval("var psf_double = SharedObject.publicStaticFinalDouble;");
  89.759 -        assertEquals(SharedObject.publicStaticFinalDouble, e.get("psf_double"));
  89.760 -        e.eval("SharedObject.publicStaticFinalDouble = 40.0;");
  89.761 -        assertEquals(Double.doubleToLongBits(1.8e12), Double.doubleToLongBits(SharedObject.publicStaticFinalDouble));
  89.762 -    }
  89.763 -
  89.764 -    @Test
  89.765 -    public void accessStaticFinalFieldDoubleArrayRead() throws ScriptException {
  89.766 -        e.eval("var psf_double_array = SharedObject.publicStaticFinalDoubleArray;");
  89.767 -        assertEquals(SharedObject.publicStaticFinalDoubleArray[0], e.eval("SharedObject.publicStaticFinalDoubleArray[0];"));
  89.768 -        assertArrayEquals(SharedObject.publicStaticFinalDoubleArray, (double[])e.get("psf_double_array"), 1e-10);
  89.769 -        e.eval("var tsf_double_arr = java.lang.reflect.Array.newInstance(java.lang.Double.TYPE, 3);" +
  89.770 -                "tsf_double_arr[0] = 9e10;" +
  89.771 -                "tsf_double_arr[1] = 0.677777;" +
  89.772 -                "tsf_double_arr[2] = -0.0000001;" +
  89.773 -                "SharedObject.publicStaticFinalDoubleArray = tsf_double_arr;");
  89.774 -        assertArrayEquals(new double[] { 8.725e80, 0.82e10, 18e-3, 1.08077 }, SharedObject.publicStaticFinalDoubleArray, 1e-10f);
  89.775 -        e.eval("SharedObject.publicStaticFinalDoubleArray[0] = -5.2e10;");
  89.776 -        assertEquals(-5.2e10, SharedObject.publicStaticFinalDoubleArray[0], 1e-10f);
  89.777 -    }
  89.778 -
  89.779 -}
    90.1 --- a/test/src/jdk/nashorn/internal/access/NumberBoxingTest.java	Sat Feb 09 16:58:48 2013 +0100
    90.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.3 @@ -1,348 +0,0 @@
    90.4 -/*
    90.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    90.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    90.7 - *
    90.8 - * This code is free software; you can redistribute it and/or modify it
    90.9 - * under the terms of the GNU General Public License version 2 only, as
   90.10 - * published by the Free Software Foundation.  Oracle designates this
   90.11 - * particular file as subject to the "Classpath" exception as provided
   90.12 - * by Oracle in the LICENSE file that accompanied this code.
   90.13 - *
   90.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   90.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   90.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   90.17 - * version 2 for more details (a copy is included in the LICENSE file that
   90.18 - * accompanied this code).
   90.19 - *
   90.20 - * You should have received a copy of the GNU General Public License version
   90.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   90.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   90.23 - *
   90.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   90.25 - * or visit www.oracle.com if you need additional information or have any
   90.26 - * questions.
   90.27 - */
   90.28 -
   90.29 -package jdk.nashorn.internal.access;
   90.30 -
   90.31 -import static org.testng.AssertJUnit.assertEquals;
   90.32 -import static org.testng.AssertJUnit.assertTrue;
   90.33 -
   90.34 -import javax.script.ScriptEngine;
   90.35 -import javax.script.ScriptEngineManager;
   90.36 -import javax.script.ScriptException;
   90.37 -import org.testng.TestNG;
   90.38 -import org.testng.annotations.BeforeClass;
   90.39 -import org.testng.annotations.Test;
   90.40 -
   90.41 -public class NumberBoxingTest {
   90.42 -
   90.43 -    private static ScriptEngine e = null;
   90.44 -    private static SharedObject o = new SharedObject();
   90.45 -
   90.46 -    public static void main(final String[] args) {
   90.47 -        TestNG.main(args);
   90.48 -    }
   90.49 -
   90.50 -    @BeforeClass
   90.51 -    public static void setUpClass() throws ScriptException {
   90.52 -        final ScriptEngineManager m = new ScriptEngineManager();
   90.53 -        e = m.getEngineByName("nashorn");
   90.54 -        e.put("o", o);
   90.55 -        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   90.56 -    }
   90.57 -
   90.58 -    // --------------------------------long
   90.59 -    // tests------------------------------------
   90.60 -    @Test
   90.61 -    public void accessFieldLongBoxing() throws ScriptException {
   90.62 -        e.eval("var p_long = o.publicLongBox;");
   90.63 -        assertEquals(o.publicLongBox, e.get("p_long"));
   90.64 -        e.eval("o.publicLongBox = 12;");
   90.65 -        assertEquals(Long.valueOf(12), o.publicLongBox);
   90.66 -    }
   90.67 -
   90.68 -    @Test
   90.69 -    public void accessStaticFieldLongBoxing() throws ScriptException {
   90.70 -        e.eval("var ps_long = SharedObject.publicStaticLong;");
   90.71 -        assertEquals(SharedObject.publicStaticLong, e.get("ps_long"));
   90.72 -        e.eval("SharedObject.publicStaticLong = 120;");
   90.73 -        assertEquals(120, SharedObject.publicStaticLong);
   90.74 -    }
   90.75 -
   90.76 -    @Test
   90.77 -    public void accessFinalFieldLongBoxing() throws ScriptException {
   90.78 -        e.eval("var pf_long = o.publicFinalLongBox;");
   90.79 -        assertEquals(o.publicFinalLongBox, e.get("pf_long"));
   90.80 -        e.eval("o.publicFinalLongBox = 120;");
   90.81 -        assertEquals(Long.valueOf(9377333334L), o.publicFinalLongBox);
   90.82 -    }
   90.83 -
   90.84 -    @Test
   90.85 -    public void accessStaticFinalFieldLongBoxing() throws ScriptException {
   90.86 -        e.eval("var psf_long = SharedObject.publicStaticFinalLong;");
   90.87 -        assertEquals(SharedObject.publicStaticFinalLong, e.get("psf_long"));
   90.88 -        e.eval("SharedObject.publicStaticFinalLong = 120;");
   90.89 -        assertEquals(8333333333333L, SharedObject.publicStaticFinalLong);
   90.90 -    }
   90.91 -
   90.92 -    // --------------------------------int
   90.93 -    // tests------------------------------------
   90.94 -    @Test
   90.95 -    public void accessFieldIntBoxing() throws ScriptException {
   90.96 -        e.eval("var p_int = o.publicIntBox;");
   90.97 -        assertEquals(o.publicIntBox, e.get("p_int"));
   90.98 -        e.eval("o.publicIntBox = 14;");
   90.99 -        assertEquals(Integer.valueOf(14), o.publicIntBox);
  90.100 -    }
  90.101 -
  90.102 -    @Test
  90.103 -    public void accessStaticFieldIntBoxing() throws ScriptException {
  90.104 -        e.eval("var ps_int = SharedObject.publicStaticInt;");
  90.105 -        assertEquals(SharedObject.publicStaticInt, e.get("ps_int"));
  90.106 -        e.eval("SharedObject.publicStaticInt = 140;");
  90.107 -        assertEquals(140, SharedObject.publicStaticInt);
  90.108 -    }
  90.109 -
  90.110 -    @Test
  90.111 -    public void accessFinalFieldIntBoxing() throws ScriptException {
  90.112 -        e.eval("var pf_int = o.publicFinalIntBox;");
  90.113 -        assertEquals(o.publicFinalIntBox, e.get("pf_int"));
  90.114 -        e.eval("o.publicFinalIntBox = 10;");
  90.115 -        assertEquals(Integer.valueOf(207512301), o.publicFinalIntBox);
  90.116 -    }
  90.117 -
  90.118 -    @Test
  90.119 -    public void accessStaticFinalFieldIntBoxing() throws ScriptException {
  90.120 -        e.eval("var psf_int = SharedObject.publicStaticFinalInt;");
  90.121 -        assertEquals(SharedObject.publicStaticFinalInt, e.get("psf_int"));
  90.122 -        e.eval("SharedObject.publicStaticFinalInt = 140;");
  90.123 -        assertEquals(207182023, SharedObject.publicStaticFinalInt);
  90.124 -    }
  90.125 -
  90.126 -    // --------------------------------byte
  90.127 -    // tests------------------------------------
  90.128 -    @Test
  90.129 -    public void accessFieldByteBoxing() throws ScriptException {
  90.130 -        e.eval("var p_byte = o.publicByteBox;");
  90.131 -        assertEquals(o.publicByteBox, e.get("p_byte"));
  90.132 -        e.eval("o.publicByteBox = 16;");
  90.133 -        assertEquals(Byte.valueOf((byte)16), o.publicByteBox);
  90.134 -    }
  90.135 -
  90.136 -    @Test
  90.137 -    public void accessStaticFieldByteBoxing() throws ScriptException {
  90.138 -        e.eval("var ps_byte = SharedObject.publicStaticByte;");
  90.139 -        assertEquals(SharedObject.publicStaticByte, e.get("ps_byte"));
  90.140 -        e.eval("SharedObject.publicStaticByte = 16;");
  90.141 -        assertEquals(16, SharedObject.publicStaticByte);
  90.142 -    }
  90.143 -
  90.144 -    @Test
  90.145 -    public void accessFinalFieldByteBoxing() throws ScriptException {
  90.146 -        e.eval("var pf_byte = o.publicFinalByteBox;");
  90.147 -        assertEquals(o.publicFinalByteBox, e.get("pf_byte"));
  90.148 -        e.eval("o.publicFinalByteBox = 16;");
  90.149 -        assertEquals(Byte.valueOf((byte)19), o.publicFinalByteBox);
  90.150 -    }
  90.151 -
  90.152 -    @Test
  90.153 -    public void accessStaticFinalFieldByteBoxing() throws ScriptException {
  90.154 -        e.eval("var psf_byte = SharedObject.publicStaticFinalByte;");
  90.155 -        assertEquals(SharedObject.publicStaticFinalByte, e.get("psf_byte"));
  90.156 -        e.eval("SharedObject.publicStaticFinalByte = 16;");
  90.157 -        assertEquals(-70, SharedObject.publicStaticFinalByte);
  90.158 -    }
  90.159 -
  90.160 -    // --------------------------------short
  90.161 -    // tests------------------------------------
  90.162 -    @Test
  90.163 -    public void accessFieldShortBoxing() throws ScriptException {
  90.164 -        e.eval("var p_short = o.publicShortBox;");
  90.165 -        assertEquals(o.publicShortBox, e.get("p_short"));
  90.166 -        e.eval("o.publicShortBox = 18;");
  90.167 -        assertEquals(Short.valueOf((short)18), o.publicShortBox);
  90.168 -    }
  90.169 -
  90.170 -    @Test
  90.171 -    public void accessStaticFieldShortBoxing() throws ScriptException {
  90.172 -        e.eval("var ps_short = SharedObject.publicStaticShort;");
  90.173 -        assertEquals(SharedObject.publicStaticShort, e.get("ps_short"));
  90.174 -        e.eval("SharedObject.publicStaticShort = 180;");
  90.175 -        assertEquals(180, SharedObject.publicStaticShort);
  90.176 -    }
  90.177 -
  90.178 -    @Test
  90.179 -    public void accessFinalFieldShortBoxing() throws ScriptException {
  90.180 -        e.eval("var pf_short = o.publicFinalShortBox;");
  90.181 -        assertEquals(o.publicFinalShortBox, e.get("pf_short"));
  90.182 -        e.eval("o.publicFinalShortBox = 180;");
  90.183 -        assertEquals(Short.valueOf((short)-26777), o.publicFinalShortBox);
  90.184 -    }
  90.185 -
  90.186 -    @Test
  90.187 -    public void accessStaticFinalFieldShortBoxing() throws ScriptException {
  90.188 -        e.eval("var psf_short = SharedObject.publicStaticFinalShort;");
  90.189 -        assertEquals(SharedObject.publicStaticFinalShort, e.get("psf_short"));
  90.190 -        e.eval("SharedObject.publicStaticFinalShort = 180;");
  90.191 -        assertEquals(8888, SharedObject.publicStaticFinalShort);
  90.192 -    }
  90.193 -
  90.194 -    // --------------------------------char
  90.195 -    // tests------------------------------------
  90.196 -    @Test
  90.197 -    public void accessFieldCharBoxing() throws ScriptException {
  90.198 -        e.eval("var p_char = o.publicCharBox;");
  90.199 -        assertEquals(o.publicCharBox, e.get("p_char"));
  90.200 -        e.eval("o.publicCharBox = 'S';");
  90.201 -        assertEquals(Character.valueOf('S'), o.publicCharBox);
  90.202 -        e.eval("try {" +
  90.203 -                "    o.publicCharBox = 'Big string';" +
  90.204 -                "} catch(e) {" +
  90.205 -                "    var isThrown = true;" +
  90.206 -                "}");
  90.207 -        assertEquals("Exception thrown", true, e.get("isThrown"));
  90.208 -        assertEquals(Character.valueOf('S'), o.publicCharBox);
  90.209 -    }
  90.210 -
  90.211 -    @Test
  90.212 -    public void accessStaticFieldCharBoxing() throws ScriptException {
  90.213 -        e.eval("var ps_char = SharedObject.publicStaticChar;");
  90.214 -        assertEquals(SharedObject.publicStaticChar, e.get("ps_char"));
  90.215 -        e.eval("SharedObject.publicStaticChar = 'Z';");
  90.216 -        assertEquals('Z', SharedObject.publicStaticChar);
  90.217 -    }
  90.218 -
  90.219 -    @Test
  90.220 -    public void accessFinalFieldCharBoxing() throws ScriptException {
  90.221 -        e.eval("var pf_char = o.publicFinalCharBox;");
  90.222 -        assertEquals(o.publicFinalCharBox, e.get("pf_char"));
  90.223 -        e.eval("o.publicFinalCharBox = 'S';");
  90.224 -        assertEquals(Character.valueOf('F'), o.publicFinalCharBox);
  90.225 -    }
  90.226 -
  90.227 -    @Test
  90.228 -    public void accessStaticFinalFieldCharBoxing() throws ScriptException {
  90.229 -        e.eval("var psf_char = SharedObject.publicStaticFinalChar;");
  90.230 -        assertEquals(SharedObject.publicStaticFinalChar, e.get("psf_char"));
  90.231 -        e.eval("SharedObject.publicStaticFinalChar = 'Z';");
  90.232 -        assertEquals('K', SharedObject.publicStaticFinalChar);
  90.233 -    }
  90.234 -
  90.235 -    // --------------------------------float
  90.236 -    // tests------------------------------------
  90.237 -    @Test
  90.238 -    public void accessFieldFloatBoxing() throws ScriptException {
  90.239 -        e.eval("var p_float = o.publicFloatBox;");
  90.240 -        assertEquals(o.publicFloatBox, e.get("p_float"));
  90.241 -        o.publicFloatBox = 0.0f / 0.0f;
  90.242 -        assertEquals(true, e.eval("isNaN(o.publicFloatBox)"));
  90.243 -        o.publicFloatBox = 1.0f / 0.0f;
  90.244 -        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === o.publicFloatBox"));
  90.245 -        o.publicFloatBox = -1.0f / 0.0f;
  90.246 -        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === o.publicFloatBox"));
  90.247 -        e.eval("o.publicFloatBox = 20;");
  90.248 -        assertEquals(20, o.publicFloatBox, 1e-10);
  90.249 -        e.eval("o.publicFloatBox = 0.0/0.0;");
  90.250 -        assertTrue(Float.isNaN(o.publicFloatBox));
  90.251 -        e.eval("o.publicFloatBox = 1.0/0.0;");
  90.252 -        assertEquals(Float.floatToIntBits(Float.POSITIVE_INFINITY), Float.floatToIntBits(o.publicFloatBox));
  90.253 -        e.eval("o.publicFloatBox = -1.0/0.0;");
  90.254 -        assertEquals(Float.NEGATIVE_INFINITY, o.publicFloatBox, 1e-10);
  90.255 -    }
  90.256 -
  90.257 -    @Test
  90.258 -    public void accessStaticFieldFloatBoxing() throws ScriptException {
  90.259 -        e.eval("var ps_float = SharedObject.publicStaticFloat;");
  90.260 -        assertEquals(SharedObject.publicStaticFloat, e.get("ps_float"));
  90.261 -        SharedObject.publicStaticFloat = 0.0f / 0.0f;
  90.262 -        assertEquals(true, e.eval("isNaN(SharedObject.publicStaticFloat)"));
  90.263 -        SharedObject.publicStaticFloat = 1.0f / 0.0f;
  90.264 -        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === SharedObject.publicStaticFloat"));
  90.265 -        SharedObject.publicStaticFloat = -1.0f / 0.0f;
  90.266 -        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === SharedObject.publicStaticFloat"));
  90.267 -        e.eval("SharedObject.publicStaticFloat = 20.0;");
  90.268 -        assertEquals(20.0f, SharedObject.publicStaticFloat, 1e-10);
  90.269 -        e.eval("SharedObject.publicStaticFloat = 0.0/0.0;");
  90.270 -        assertTrue(Float.isNaN(SharedObject.publicStaticFloat));
  90.271 -        e.eval("SharedObject.publicStaticFloat = 1.0/0.0;");
  90.272 -        assertEquals(Float.floatToIntBits(Float.POSITIVE_INFINITY), Float.floatToIntBits(SharedObject.publicStaticFloat));
  90.273 -        e.eval("SharedObject.publicStaticFloat = -1.0/0.0;");
  90.274 -        assertEquals(Float.floatToIntBits(Float.NEGATIVE_INFINITY), Float.floatToIntBits(SharedObject.publicStaticFloat));
  90.275 -    }
  90.276 -
  90.277 -    @Test
  90.278 -    public void accessFinalFloatBoxing() throws ScriptException {
  90.279 -        e.eval("var pf_float = o.publicFinalFloatBox;");
  90.280 -        assertEquals(o.publicFinalFloatBox, e.get("pf_float"));
  90.281 -        e.eval("o.publicFinalFloatBox = 20.0;");
  90.282 -        assertEquals(1.372e4f, o.publicFinalFloatBox, 1e-10);
  90.283 -    }
  90.284 -
  90.285 -    @Test
  90.286 -    public void accessStaticFinalFieldFloatBoxing() throws ScriptException {
  90.287 -        e.eval("var psf_float = SharedObject.publicStaticFinalFloat;");
  90.288 -        assertEquals(SharedObject.publicStaticFinalFloat, e.get("psf_float"));
  90.289 -        e.eval("SharedObject.publicStaticFinalFloat = 20.0;");
  90.290 -        assertEquals(0.72e8f, SharedObject.publicStaticFinalFloat, 1e-10);
  90.291 -    }
  90.292 -
  90.293 -    // --------------------------------double
  90.294 -    // tests------------------------------------
  90.295 -    @Test
  90.296 -    public void accessFieldDoubleBoxing() throws ScriptException {
  90.297 -        e.eval("var p_double = o.publicDoubleBox;");
  90.298 -        assertEquals(o.publicDoubleBox, e.get("p_double"));
  90.299 -        o.publicDoubleBox = 0.0 / 0.0;
  90.300 -        assertEquals(true, e.eval("isNaN(o.publicDoubleBox)"));
  90.301 -        o.publicDoubleBox = 1.0 / 0.0;
  90.302 -        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === o.publicDoubleBox"));
  90.303 -        o.publicDoubleBox = -1.0 / 0.0;
  90.304 -        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === o.publicDoubleBox"));
  90.305 -        e.eval("o.publicDoubleBox = 30;");
  90.306 -        assertEquals(Double.doubleToLongBits(30.0), Double.doubleToLongBits(o.publicDoubleBox));
  90.307 -        e.eval("o.publicDoubleBox = 0.0/0.0;");
  90.308 -        assertTrue(Double.isNaN(o.publicDoubleBox));
  90.309 -        e.eval("o.publicDoubleBox = 1.0/0.0;");
  90.310 -        assertEquals(Double.doubleToLongBits(Double.POSITIVE_INFINITY), Double.doubleToLongBits(o.publicDoubleBox));
  90.311 -        e.eval("o.publicDoubleBox = -1.0/0.0;");
  90.312 -        assertEquals(Double.doubleToLongBits(Double.NEGATIVE_INFINITY), Double.doubleToLongBits(o.publicDoubleBox));
  90.313 -    }
  90.314 -
  90.315 -    @Test
  90.316 -    public void accessStaticFieldDoubleBoxing() throws ScriptException {
  90.317 -        e.eval("var ps_double = SharedObject.publicStaticDouble;");
  90.318 -        assertEquals(SharedObject.publicStaticDouble, e.get("ps_double"));
  90.319 -        SharedObject.publicStaticDouble = 0.0 / 0.0;
  90.320 -        assertEquals(true, e.eval("isNaN(SharedObject.publicStaticDouble)"));
  90.321 -        SharedObject.publicStaticDouble = 1.0 / 0.0;
  90.322 -        assertEquals(true, e.eval("Number.POSITIVE_INFINITY === SharedObject.publicStaticDouble"));
  90.323 -        SharedObject.publicStaticDouble = -1.0 / 0.0;
  90.324 -        assertEquals(true, e.eval("Number.NEGATIVE_INFINITY === SharedObject.publicStaticDouble"));
  90.325 -        e.eval("SharedObject.publicStaticDouble = 40.0;");
  90.326 -        assertEquals(Double.doubleToLongBits(40.0), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  90.327 -        e.eval("SharedObject.publicStaticDouble = 0.0/0.0;");
  90.328 -        assertTrue(Double.isNaN(SharedObject.publicStaticDouble));
  90.329 -        e.eval("SharedObject.publicStaticDouble = 1.0/0.0;");
  90.330 -        assertEquals(Double.doubleToLongBits(Double.POSITIVE_INFINITY), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  90.331 -        e.eval("SharedObject.publicStaticDouble = -1.0/0.0;");
  90.332 -        assertEquals(Double.doubleToLongBits(Double.NEGATIVE_INFINITY), Double.doubleToLongBits(SharedObject.publicStaticDouble));
  90.333 -    }
  90.334 -
  90.335 -    @Test
  90.336 -    public void accessFinalFieldDoubleBoxing() throws ScriptException {
  90.337 -        e.eval("var pf_double = o.publicFinalDoubleBox;");
  90.338 -        assertEquals(o.publicFinalDoubleBox, e.get("pf_double"));
  90.339 -        e.eval("o.publicFinalDoubleBox = 30.0;");
  90.340 -        assertEquals(Double.doubleToLongBits(1.412e-12), Double.doubleToLongBits(o.publicFinalDoubleBox));
  90.341 -    }
  90.342 -
  90.343 -    @Test
  90.344 -    public void accessStaticFinalFieldDoubleBoxing() throws ScriptException {
  90.345 -        e.eval("var psf_double = SharedObject.publicStaticFinalDouble;");
  90.346 -        assertEquals(SharedObject.publicStaticFinalDouble, e.get("psf_double"));
  90.347 -        e.eval("SharedObject.publicStaticFinalDouble = 40.0;");
  90.348 -        assertEquals(Double.doubleToLongBits(1.8e12), Double.doubleToLongBits(SharedObject.publicStaticFinalDouble));
  90.349 -    }
  90.350 -
  90.351 -}
    91.1 --- a/test/src/jdk/nashorn/internal/access/ObjectAccessTest.java	Sat Feb 09 16:58:48 2013 +0100
    91.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.3 @@ -1,152 +0,0 @@
    91.4 -/*
    91.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    91.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    91.7 - *
    91.8 - * This code is free software; you can redistribute it and/or modify it
    91.9 - * under the terms of the GNU General Public License version 2 only, as
   91.10 - * published by the Free Software Foundation.  Oracle designates this
   91.11 - * particular file as subject to the "Classpath" exception as provided
   91.12 - * by Oracle in the LICENSE file that accompanied this code.
   91.13 - *
   91.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   91.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   91.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   91.17 - * version 2 for more details (a copy is included in the LICENSE file that
   91.18 - * accompanied this code).
   91.19 - *
   91.20 - * You should have received a copy of the GNU General Public License version
   91.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   91.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   91.23 - *
   91.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   91.25 - * or visit www.oracle.com if you need additional information or have any
   91.26 - * questions.
   91.27 - */
   91.28 -
   91.29 -package jdk.nashorn.internal.access;
   91.30 -
   91.31 -import static org.testng.AssertJUnit.assertEquals;
   91.32 -import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
   91.33 -
   91.34 -import javax.script.ScriptEngine;
   91.35 -import javax.script.ScriptEngineManager;
   91.36 -import javax.script.ScriptException;
   91.37 -import org.testng.TestNG;
   91.38 -import org.testng.annotations.BeforeClass;
   91.39 -import org.testng.annotations.Test;
   91.40 -
   91.41 -public class ObjectAccessTest {
   91.42 -
   91.43 -    private static ScriptEngine e = null;
   91.44 -    private static SharedObject o = new SharedObject();
   91.45 -
   91.46 -    public static void main(final String[] args) {
   91.47 -        TestNG.main(args);
   91.48 -    }
   91.49 -
   91.50 -    @BeforeClass
   91.51 -    public static void setUpClass() throws ScriptException {
   91.52 -        final ScriptEngineManager m = new ScriptEngineManager();
   91.53 -        e = m.getEngineByName("nashorn");
   91.54 -        e.put("o", o);
   91.55 -        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   91.56 -        e.eval("var Person = Packages.jdk.nashorn.internal.access.Person;");
   91.57 -    }
   91.58 -
   91.59 -    @Test
   91.60 -    public void accessFieldObject() throws ScriptException {
   91.61 -        e.eval("var p_object = o.publicObject;");
   91.62 -        assertEquals(o.publicObject, e.get("p_object"));
   91.63 -        assertEquals("object", e.eval("typeof p_object;"));
   91.64 -        e.eval("o.publicObject = new Person(14);");
   91.65 -        assertEquals(new Person(14), o.publicObject);
   91.66 -    }
   91.67 -
   91.68 -    @Test
   91.69 -    public void accessFieldObjectArray() throws ScriptException {
   91.70 -        e.eval("var p_object_array = o.publicObjectArray;");
   91.71 -        assertEquals(o.publicObjectArray[0], e.eval("o.publicObjectArray[0]"));
   91.72 -        assertArrayEquals(o.publicObjectArray, (Object[])e.get("p_object_array"));
   91.73 -        e.eval("var t_object_arr = java.lang.reflect.Array.newInstance(Person.class, 3);" +
   91.74 -                "t_object_arr[0] = new Person(100);" +
   91.75 -                "t_object_arr[1] = new Person(120);" +
   91.76 -                "t_object_arr[2] = new Person(140);" +
   91.77 -                "o.publicObjectArray = t_object_arr;");
   91.78 -        assertArrayEquals(new Person[] { new Person(100), new Person(120), new Person(140) }, o.publicObjectArray);
   91.79 -        e.eval("o.publicObjectArray[0] = new Person(10);");
   91.80 -        assertEquals(new Person(10), o.publicObjectArray[0]);
   91.81 -    }
   91.82 -
   91.83 -    @Test
   91.84 -    public void accessStaticFieldObject() throws ScriptException {
   91.85 -        e.eval("var ps_object = SharedObject.publicStaticObject;");
   91.86 -        assertEquals(SharedObject.publicStaticObject, e.get("ps_object"));
   91.87 -        assertEquals("object", e.eval("typeof ps_object;"));
   91.88 -        e.eval("SharedObject.publicStaticObject = new Person(16);");
   91.89 -        assertEquals(new Person(16), SharedObject.publicStaticObject);
   91.90 -    }
   91.91 -
   91.92 -    @Test
   91.93 -    public void accessStaticFieldObjectArray() throws ScriptException {
   91.94 -        e.eval("var ps_object_array = SharedObject.publicStaticObjectArray;");
   91.95 -        assertEquals(SharedObject.publicStaticObjectArray[0], e.eval("SharedObject.publicStaticObjectArray[0]"));
   91.96 -        assertArrayEquals(SharedObject.publicStaticObjectArray, (Object[])e.get("ps_object_array"));
   91.97 -        e.eval("var ts_object_arr = java.lang.reflect.Array.newInstance(Person.class, 3);" +
   91.98 -                "ts_object_arr[0] = new Person(100);" +
   91.99 -                "ts_object_arr[1] = new Person(120);" +
  91.100 -                "ts_object_arr[2] = new Person(140);" +
  91.101 -                "SharedObject.publicStaticObjectArray = ts_object_arr;");
  91.102 -        assertArrayEquals(new Person[] { new Person(100), new Person(120), new Person(140) }, SharedObject.publicStaticObjectArray);
  91.103 -        e.eval("SharedObject.publicStaticObjectArray[0] = new Person(10);");
  91.104 -        assertEquals(new Person(10), SharedObject.publicStaticObjectArray[0]);
  91.105 -    }
  91.106 -
  91.107 -    @Test
  91.108 -    public void accessFinalFieldObject() throws ScriptException {
  91.109 -        e.eval("var pf_object = o.publicFinalObject;");
  91.110 -        assertEquals(o.publicFinalObject, e.get("pf_object"));
  91.111 -        assertEquals("object", e.eval("typeof pf_object;"));
  91.112 -        e.eval("o.publicFinalObject = new Person(-999);");
  91.113 -        assertEquals(new Person(1024), o.publicFinalObject);
  91.114 -    }
  91.115 -
  91.116 -    @Test
  91.117 -    public void accessFinalFieldObjectArray() throws ScriptException {
  91.118 -        e.eval("var pf_object_array = o.publicFinalObjectArray;");
  91.119 -        assertEquals(o.publicFinalObjectArray[0], e.eval("o.publicFinalObjectArray[0]"));
  91.120 -        assertArrayEquals(o.publicFinalObjectArray, (Object[])e.get("pf_object_array"));
  91.121 -        e.eval("var tf_object_arr = java.lang.reflect.Array.newInstance(Person.class, 3);" +
  91.122 -                "tf_object_arr[0] = new Person(100);" +
  91.123 -                "tf_object_arr[1] = new Person(120);" +
  91.124 -                "tf_object_arr[2] = new Person(140);" +
  91.125 -                "o.publicOFinalbjectArray = tf_object_arr;");
  91.126 -        assertArrayEquals(new Person[] { new Person(-900), new Person(1000), new Person(180) }, o.publicFinalObjectArray);
  91.127 -        e.eval("o.publicFinalObjectArray[0] = new Person(10);");
  91.128 -        assertEquals(new Person(10), o.publicFinalObjectArray[0]);
  91.129 -    }
  91.130 -
  91.131 -    @Test
  91.132 -    public void accessStaticFinalFieldObject() throws ScriptException {
  91.133 -        e.eval("var psf_object = SharedObject.publicStaticFinalObject;");
  91.134 -        assertEquals(SharedObject.publicStaticFinalObject, e.get("psf_object"));
  91.135 -        assertEquals("object", e.eval("typeof psf_object;"));
  91.136 -        e.eval("SharedObject.publicStaticFinalObject = new Person(6);");
  91.137 -        assertEquals(new Person(2048), SharedObject.publicStaticFinalObject);
  91.138 -    }
  91.139 -
  91.140 -    @Test
  91.141 -    public void accessStaticFinalFieldObjectArray() throws ScriptException {
  91.142 -        e.eval("var psf_object_array = SharedObject.publicStaticFinalObjectArray;");
  91.143 -        assertEquals(SharedObject.publicStaticFinalObjectArray[0], e.eval("SharedObject.publicStaticFinalObjectArray[0]"));
  91.144 -        assertArrayEquals(SharedObject.publicStaticFinalObjectArray, (Object[])e.get("psf_object_array"));
  91.145 -        e.eval("var tsf_object_arr = java.lang.reflect.Array.newInstance(Person.class, 3);" +
  91.146 -                "tsf_object_arr[0] = new Person(100);" +
  91.147 -                "tsf_object_arr[1] = new Person(120);" +
  91.148 -                "tsf_object_arr[2] = new Person(140);" +
  91.149 -                "SharedObject.publicStaticFinalObjectArray = tsf_object_arr;");
  91.150 -        assertArrayEquals(new Person[] { new Person(-9), new Person(110), new Person(Integer.MAX_VALUE) }, SharedObject.publicStaticFinalObjectArray);
  91.151 -        e.eval("SharedObject.publicStaticFinalObjectArray[0] = new Person(90);");
  91.152 -        assertEquals(new Person(90), SharedObject.publicStaticFinalObjectArray[0]);
  91.153 -    }
  91.154 -
  91.155 -}
    92.1 --- a/test/src/jdk/nashorn/internal/access/Person.java	Sat Feb 09 16:58:48 2013 +0100
    92.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.3 @@ -1,58 +0,0 @@
    92.4 -/*
    92.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    92.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    92.7 - *
    92.8 - * This code is free software; you can redistribute it and/or modify it
    92.9 - * under the terms of the GNU General Public License version 2 only, as
   92.10 - * published by the Free Software Foundation.  Oracle designates this
   92.11 - * particular file as subject to the "Classpath" exception as provided
   92.12 - * by Oracle in the LICENSE file that accompanied this code.
   92.13 - *
   92.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   92.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   92.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   92.17 - * version 2 for more details (a copy is included in the LICENSE file that
   92.18 - * accompanied this code).
   92.19 - *
   92.20 - * You should have received a copy of the GNU General Public License version
   92.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   92.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   92.23 - *
   92.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   92.25 - * or visit www.oracle.com if you need additional information or have any
   92.26 - * questions.
   92.27 - */
   92.28 -
   92.29 -package jdk.nashorn.internal.access;
   92.30 -
   92.31 -public class Person {
   92.32 -
   92.33 -    public int id = 0;
   92.34 -
   92.35 -    public Person() {
   92.36 -    }
   92.37 -
   92.38 -    public Person(final int code) {
   92.39 -        this.id = code;
   92.40 -    }
   92.41 -
   92.42 -    @Override
   92.43 -    public boolean equals(final Object obj) {
   92.44 -        if (obj != null && obj instanceof Person) {
   92.45 -            final Person o = (Person)obj;
   92.46 -            return this.id == o.id;
   92.47 -        }
   92.48 -        return false;
   92.49 -    }
   92.50 -
   92.51 -    @Override
   92.52 -    public int hashCode() {
   92.53 -        return id;
   92.54 -    }
   92.55 -
   92.56 -    @Override
   92.57 -    public String toString() {
   92.58 -        return "Person(" + id + ")";
   92.59 -    }
   92.60 -
   92.61 -}
    93.1 --- a/test/src/jdk/nashorn/internal/access/SharedObject.java	Sat Feb 09 16:58:48 2013 +0100
    93.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.3 @@ -1,466 +0,0 @@
    93.4 -/*
    93.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    93.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    93.7 - *
    93.8 - * This code is free software; you can redistribute it and/or modify it
    93.9 - * under the terms of the GNU General Public License version 2 only, as
   93.10 - * published by the Free Software Foundation.  Oracle designates this
   93.11 - * particular file as subject to the "Classpath" exception as provided
   93.12 - * by Oracle in the LICENSE file that accompanied this code.
   93.13 - *
   93.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   93.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   93.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   93.17 - * version 2 for more details (a copy is included in the LICENSE file that
   93.18 - * accompanied this code).
   93.19 - *
   93.20 - * You should have received a copy of the GNU General Public License version
   93.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   93.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   93.23 - *
   93.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   93.25 - * or visit www.oracle.com if you need additional information or have any
   93.26 - * questions.
   93.27 - */
   93.28 -
   93.29 -package jdk.nashorn.internal.access;
   93.30 -
   93.31 -import javax.script.Invocable;
   93.32 -import javax.script.ScriptEngine;
   93.33 -import javax.script.ScriptException;
   93.34 -
   93.35 -public class SharedObject {
   93.36 -
   93.37 -    // Public fields
   93.38 -    public String                 publicString                  = "PublicString";
   93.39 -    public String[]               publicStringArray             = { "ArrayString[0]", "ArrayString[1]", "ArrayString[2]", "ArrayString[3]" };
   93.40 -    public Person                 publicObject                  = new Person(256);
   93.41 -    public Person[]               publicObjectArray             = { new Person(4), new Person(-422), new Person(14) };
   93.42 -    public boolean                publicBoolean                 = true;
   93.43 -    public boolean[]              publicBooleanArray            = { true, false, false, true };
   93.44 -    public Boolean                publicBooleanBox              = true;
   93.45 -    public long                   publicLong                    = 933333333333333333L;
   93.46 -    public long[]                 publicLongArray               = { 99012333333333L, -124355555L, 89777777777L };
   93.47 -    public Long                   publicLongBox                 = 9333333333L;
   93.48 -    public int                    publicInt                     = 2076543123;
   93.49 -    public int[]                  publicIntArray                = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 };
   93.50 -    public Integer                publicIntBox                  = 20765123;
   93.51 -    public byte                   publicByte                    = -128;
   93.52 -    public byte[]                 publicByteArray               = { 1, 2, 4, 8, 16, 32, 64, 127, -128 };
   93.53 -    public Byte                   publicByteBox                 = 127;
   93.54 -    public short                  publicShort                   = 32000;
   93.55 -    public short[]                publicShortArray              = { 3240, 8900, -16789, 1, 12 };
   93.56 -    public Short                  publicShortBox                = Short.MIN_VALUE;
   93.57 -    public float                  publicFloat                   = 0.7e6f;
   93.58 -    public float[]                publicFloatArray              = { -32.01f, 89.3f, -1.3e8f, 3.1f };
   93.59 -    public Float                  publicFloatBox                = 1.377e4f;
   93.60 -    public double                 publicDouble                  = 1.34e20;
   93.61 -    public double[]               publicDoubleArray             = { 0.75e80, 8e-43, 1.000077, 0.123e10 };
   93.62 -    public Double                 publicDoubleBox               = 1.4e-19;
   93.63 -    public char                   publicChar                    = 'A';
   93.64 -    public char[]                 publicCharArray               = "Hello Nashorn".toCharArray();
   93.65 -    public Character              publicCharBox                 = 'B';
   93.66 -    // Public static fields
   93.67 -    public static String          publicStaticString            = "PublicStaticString";
   93.68 -    public static String[]        publicStaticStringArray       = { "StaticArrayString[0]", "StaticArrayString[1]", "StaticArrayString[2]", "StaticArrayString[3]" };
   93.69 -    public static Person          publicStaticObject            = new Person(512);
   93.70 -    public static Person[]        publicStaticObjectArray       = { new Person(40), new Person(-22), new Person(18) };
   93.71 -    public static boolean         publicStaticBoolean           = true;
   93.72 -    public static boolean[]       publicStaticBooleanArray      = { false, false, false, true };
   93.73 -    public static Boolean         publicStaticBooleanBox        = true;
   93.74 -    public static long            publicStaticLong              = 13333333333333333L;
   93.75 -    public static long[]          publicStaticLongArray         = { 19012333333333L, -224355555L, 39777777777L };
   93.76 -    public static Long            publicStaticLongBox           = 9333333334L;
   93.77 -    public static int             publicStaticInt               = 207654323;
   93.78 -    public static int[]           publicStaticIntArray          = { 5, 8, 13, 21, 34 };
   93.79 -    public static Integer         publicStaticIntBox            = 2075123;
   93.80 -    public static byte            publicStaticByte              = -12;
   93.81 -    public static byte[]          publicStaticByteArray         = { 16, 32, 64, 127, -128 };
   93.82 -    public static Byte            publicStaticByteBox           = 17;
   93.83 -    public static short           publicStaticShort             = 320;
   93.84 -    public static short[]         publicStaticShortArray        = { 1240, 900, -1789, 100, 12 };
   93.85 -    public static Short           publicStaticShortBox          = -16777;
   93.86 -    public static float           publicStaticFloat             = 7.7e8f;
   93.87 -    public static float[]         publicStaticFloatArray        = { -131.01f, 189.3f, -31.3e8f, 3.7f };
   93.88 -    public static Float           publicStaticFloatBox          = 1.37e4f;
   93.89 -    public static double          publicStaticDouble            = 1.341e20;
   93.90 -    public static double[]        publicStaticDoubleArray       = { 0.75e80, 0.123e10, 8e-43, 1.000077 };
   93.91 -    public static Double          publicStaticDoubleBox         = 1.41e-12;
   93.92 -    public static char            publicStaticChar              = 'C';
   93.93 -    public static char[]          publicStaticCharArray         = "Nashorn".toCharArray();
   93.94 -    public static Character       publicStaticCharBox           = 'D';
   93.95 -    // Public final fields
   93.96 -    public final String           publicFinalString             = "PublicFinalString";
   93.97 -    public final String[]         publicFinalStringArray        = { "FinalArrayString[0]", "FinalArrayString[1]", "FinalArrayString[2]", "FinalArrayString[3]" };
   93.98 -    public final Person           publicFinalObject             = new Person(1024);
   93.99 -    public final Person[]         publicFinalObjectArray        = { new Person(-900), new Person(1000), new Person(180) };
  93.100 -    public final boolean          publicFinalBoolean            = true;
  93.101 -    public final boolean[]        publicFinalBooleanArray       = { false, false, true, false };
  93.102 -    public final Boolean          publicFinalBooleanBox         = true;
  93.103 -    public final long             publicFinalLong               = 13353333333333333L;
  93.104 -    public final long[]           publicFinalLongArray          = { 1901733333333L, -2247355555L, 3977377777L };
  93.105 -    public final Long             publicFinalLongBox            = 9377333334L;
  93.106 -    public final int              publicFinalInt                = 20712023;
  93.107 -    public final int[]            publicFinalIntArray           = { 50, 80, 130, 210, 340 };
  93.108 -    public final Integer          publicFinalIntBox             = 207512301;
  93.109 -    public final byte             publicFinalByte               = -7;
  93.110 -    public final byte[]           publicFinalByteArray          = { 1, 3, 6, 17, -128 };
  93.111 -    public final Byte             publicFinalByteBox            = 19;
  93.112 -    public final short            publicFinalShort              = 31220;
  93.113 -    public final short[]          publicFinalShortArray         = { 12240, 9200, -17289, 1200, 12 };
  93.114 -    public final Short            publicFinalShortBox           = -26777;
  93.115 -    public final float            publicFinalFloat              = 7.72e8f;
  93.116 -    public final float[]          publicFinalFloatArray         = { -131.012f, 189.32f, -31.32e8f, 3.72f };
  93.117 -    public final Float            publicFinalFloatBox           = 1.372e4f;
  93.118 -    public final double           publicFinalDouble             = 1.3412e20;
  93.119 -    public final double[]         publicFinalDoubleArray        = { 0.725e80, 0.12e10, 8e-3, 1.00077 };
  93.120 -    public final Double           publicFinalDoubleBox          = 1.412e-12;
  93.121 -    public final char             publicFinalChar               = 'E';
  93.122 -    public final char[]           publicFinalCharArray          = "Nashorn hello".toCharArray();
  93.123 -    public final Character        publicFinalCharBox            = 'F';
  93.124 -    // Public static final fields
  93.125 -    public static final String    publicStaticFinalString       = "PublicStaticFinalString";
  93.126 -    public static final String[]  publicStaticFinalStringArray  = { "StaticFinalArrayString[0]", "StaticFinalArrayString[1]", "StaticFinalArrayString[2]", "StaticFinalArrayString[3]" };
  93.127 -    public static final Person    publicStaticFinalObject       = new Person(2048);
  93.128 -    public static final Person[]  publicStaticFinalObjectArray  = { new Person(-9), new Person(110), new Person(Integer.MAX_VALUE) };
  93.129 -    public static final boolean   publicStaticFinalBoolean      = true;
  93.130 -    public static final boolean[] publicStaticFinalBooleanArray = { false, true, false, false };
  93.131 -    public static final Boolean   publicStaticFinalBooleanBox   = true;
  93.132 -    public static final long      publicStaticFinalLong         = 8333333333333L;
  93.133 -    public static final long[]    publicStaticFinalLongArray    = { 19017383333L, -2247358L, 39773787L };
  93.134 -    public static final Long      publicStaticFinalLongBox      = 9377388334L;
  93.135 -    public static final int       publicStaticFinalInt          = 207182023;
  93.136 -    public static final int[]     publicStaticFinalIntArray     = { 1308, 210, 340 };
  93.137 -    public static final Integer   publicStaticFinalIntBox       = 2078301;
  93.138 -    public static final byte      publicStaticFinalByte         = -70;
  93.139 -    public static final byte[]    publicStaticFinalByteArray    = { 17, -128, 81 };
  93.140 -    public static final Byte      publicStaticFinalByteBox      = 91;
  93.141 -    public static final short     publicStaticFinalShort        = 8888;
  93.142 -    public static final short[]   publicStaticFinalShortArray   = { 8240, 9280, -1289, 120, 812 };
  93.143 -    public static final Short     publicStaticFinalShortBox     = -26;
  93.144 -    public static final float     publicStaticFinalFloat        = 0.72e8f;
  93.145 -    public static final float[]   publicStaticFinalFloatArray   = { -8131.012f, 9.32f, -138.32e8f, 0.72f };
  93.146 -    public static final Float     publicStaticFinalFloatBox     = 1.2e4f;
  93.147 -    public static final double    publicStaticFinalDouble       = 1.8e12;
  93.148 -    public static final double[]  publicStaticFinalDoubleArray  = { 8.725e80, 0.82e10, 18e-3, 1.08077 };
  93.149 -    public static final Double    publicStaticFinalDoubleBox    = 1.5612e-13;
  93.150 -    public static final char      publicStaticFinalChar         = 'K';
  93.151 -    public static final char[]    publicStaticFinalCharArray    = "StaticString".toCharArray();
  93.152 -    public static final Character publicStaticFinalCharBox      = 'L';
  93.153 -
  93.154 -    // Special vars
  93.155 -    public volatile boolean       volatileBoolean               = true;
  93.156 -    public transient boolean      transientBoolean              = true;
  93.157 -
  93.158 -    // For methods testing
  93.159 -    public boolean                isAccessed                    = false;
  93.160 -    public volatile boolean       isFinished                    = false;
  93.161 -
  93.162 -    private ScriptEngine engine;
  93.163 -
  93.164 -    public ScriptEngine getEngine() {
  93.165 -        return engine;
  93.166 -    }
  93.167 -
  93.168 -    public void setEngine(ScriptEngine engine) {
  93.169 -        this.engine = engine;
  93.170 -    }
  93.171 -
  93.172 -    public void voidMethod() {
  93.173 -        isAccessed = true;
  93.174 -    }
  93.175 -
  93.176 -    public boolean booleanMethod(final boolean arg) {
  93.177 -        return !arg;
  93.178 -    }
  93.179 -
  93.180 -    public Boolean booleanBoxingMethod(final Boolean arg) {
  93.181 -        return !arg.booleanValue();
  93.182 -    }
  93.183 -
  93.184 -    public boolean[] booleanArrayMethod(final boolean arg[]) {
  93.185 -        final boolean[] res = new boolean[arg.length];
  93.186 -        for (int i = 0; i < arg.length; i++) {
  93.187 -            res[i] = !arg[i];
  93.188 -        }
  93.189 -        return res;
  93.190 -    }
  93.191 -
  93.192 -    public int intMethod(final int arg) {
  93.193 -        return arg + arg;
  93.194 -    }
  93.195 -
  93.196 -    public Integer intBoxingMethod(final Integer arg) {
  93.197 -        return arg + arg;
  93.198 -    }
  93.199 -
  93.200 -    public int[] intArrayMethod(final int arg[]) {
  93.201 -        final int[] res = new int[arg.length];
  93.202 -        for (int i = 0; i < arg.length; i++) {
  93.203 -            res[i] = arg[i] * 2;
  93.204 -        }
  93.205 -        return res;
  93.206 -    }
  93.207 -
  93.208 -    public long longMethod(final long arg) {
  93.209 -        return arg + arg;
  93.210 -    }
  93.211 -
  93.212 -    public Long longBoxingMethod(final Long arg) {
  93.213 -        return arg + arg;
  93.214 -    }
  93.215 -
  93.216 -    public long[] longArrayMethod(final long[] arg) {
  93.217 -        final long[] res = new long[arg.length];
  93.218 -        for (int i = 0; i < arg.length; i++) {
  93.219 -            res[i] = arg[i] * 2;
  93.220 -        }
  93.221 -        return res;
  93.222 -    }
  93.223 -
  93.224 -    public byte byteMethod(final byte arg) {
  93.225 -        return (byte)(arg + arg);
  93.226 -    }
  93.227 -
  93.228 -    public Byte byteBoxingMethod(final Byte arg) {
  93.229 -        return (byte)(arg + arg);
  93.230 -    }
  93.231 -
  93.232 -    public byte[] byteArrayMethod(final byte[] arg) {
  93.233 -        final byte[] res = new byte[arg.length];
  93.234 -        for (int i = 0; i < arg.length; i++) {
  93.235 -            res[i] = (byte)(arg[i] * 2);
  93.236 -        }
  93.237 -        return res;
  93.238 -    }
  93.239 -
  93.240 -    public char charMethod(final char arg) {
  93.241 -        return Character.toUpperCase(arg);
  93.242 -    }
  93.243 -
  93.244 -    public Character charBoxingMethod(final Character arg) {
  93.245 -        return Character.toUpperCase(arg);
  93.246 -    }
  93.247 -
  93.248 -    public char[] charArrayMethod(final char[] arg) {
  93.249 -        final char[] res = new char[arg.length];
  93.250 -        for (int i = 0; i < arg.length; i++) {
  93.251 -            res[i] = Character.toUpperCase(arg[i]);
  93.252 -        }
  93.253 -        return res;
  93.254 -    }
  93.255 -
  93.256 -    public short shortMethod(final short arg) {
  93.257 -        return (short)(arg + arg);
  93.258 -    }
  93.259 -
  93.260 -    public Short shortBoxingMethod(final Short arg) {
  93.261 -        return (short)(arg + arg);
  93.262 -    }
  93.263 -
  93.264 -    public short[] shortArrayMethod(final short[] arg) {
  93.265 -        final short[] res = new short[arg.length];
  93.266 -        for (int i = 0; i < arg.length; i++) {
  93.267 -            res[i] = (short)(arg[i] * 2);
  93.268 -        }
  93.269 -        return res;
  93.270 -    }
  93.271 -
  93.272 -    public float floatMethod(final float arg) {
  93.273 -        return arg + arg;
  93.274 -    }
  93.275 -
  93.276 -    public Float floatBoxingMethod(final Float arg) {
  93.277 -        return arg + arg;
  93.278 -    }
  93.279 -
  93.280 -    public float[] floatArrayMethod(final float[] arg) {
  93.281 -        final float[] res = new float[arg.length];
  93.282 -        for (int i = 0; i < arg.length; i++) {
  93.283 -            res[i] = arg[i] * 2;
  93.284 -        }
  93.285 -        return res;
  93.286 -    }
  93.287 -
  93.288 -    public double doubleMethod(final double arg) {
  93.289 -        return arg + arg;
  93.290 -    }
  93.291 -
  93.292 -    public Double doubleBoxingMethod(final Double arg) {
  93.293 -        return arg + arg;
  93.294 -    }
  93.295 -
  93.296 -    public double[] doubleArrayMethod(final double[] arg) {
  93.297 -        final double[] res = new double[arg.length];
  93.298 -        for (int i = 0; i < arg.length; i++) {
  93.299 -            res[i] = arg[i] * 2;
  93.300 -        }
  93.301 -        return res;
  93.302 -    }
  93.303 -
  93.304 -    public String stringMethod(final String str) {
  93.305 -        return str + str;
  93.306 -    }
  93.307 -
  93.308 -    public String[] stringArrayMethod(final String[] arr) {
  93.309 -        final int l = arr.length;
  93.310 -        final String[] res = new String[l];
  93.311 -        for (int i = 0; i < l; i++) {
  93.312 -            res[i] = arr[l - i - 1];
  93.313 -        }
  93.314 -        return res;
  93.315 -    }
  93.316 -
  93.317 -    public Person[] objectArrayMethod(final Person[] arr) {
  93.318 -        final Person[] res = new Person[arr.length];
  93.319 -        for (int i = 0; i < arr.length; i++) {
  93.320 -            res[i] = new Person(i + 100);
  93.321 -        }
  93.322 -        return res;
  93.323 -    }
  93.324 -
  93.325 -    public Person objectMethod(final Person t) {
  93.326 -        t.id *= 2;
  93.327 -        return t;
  93.328 -    }
  93.329 -
  93.330 -    public int twoParamMethod(final long l, final double d) {
  93.331 -        return (int)(l + d);
  93.332 -    }
  93.333 -
  93.334 -    public int threeParamMethod(final short s, final long l, final char c) {
  93.335 -        return (int)(s + l + c);
  93.336 -    }
  93.337 -
  93.338 -    public Person[] twoObjectParamMethod(final Person arg1, final Person arg2) {
  93.339 -        return new Person[] { arg2, arg1 };
  93.340 -    }
  93.341 -
  93.342 -    public Person[] threeObjectParamMethod(final Person arg1, final Person arg2, final Person arg3) {
  93.343 -        return new Person[] { arg3, arg2, arg1 };
  93.344 -    }
  93.345 -
  93.346 -    public Person[] eightObjectParamMethod(final Person arg1, final Person arg2, final Person arg3, final Person arg4, final Person arg5, final Person arg6, final Person arg7, final Person arg8) {
  93.347 -        return new Person[] { arg8, arg7, arg6, arg5, arg4, arg3, arg2, arg1 };
  93.348 -    }
  93.349 -
  93.350 -    public Person[] nineObjectParamMethod(final Person arg1, final Person arg2, final Person arg3, final Person arg4, final Person arg5, final Person arg6, final Person arg7, final Person arg8, final Person arg9) {
  93.351 -        return new Person[] { arg9, arg8, arg7, arg6, arg5, arg4, arg3, arg2, arg1 };
  93.352 -    }
  93.353 -
  93.354 -    public Person[] methodObjectEllipsis(final Person... args) {
  93.355 -        final int l = args.length;
  93.356 -        final Person[] res = new Person[l];
  93.357 -        for (int i = 0; i < l; i++) {
  93.358 -            res[i] = args[l - i - 1];
  93.359 -        }
  93.360 -        return res;
  93.361 -    }
  93.362 -
  93.363 -    public Person[] methodPrimitiveEllipsis(final int... args) {
  93.364 -        final int l = args.length;
  93.365 -        final Person[] res = new Person[l];
  93.366 -        for (int i = 0; i < l; i++) {
  93.367 -            res[i] = new Person(args[i]);
  93.368 -        }
  93.369 -        return res;
  93.370 -    }
  93.371 -
  93.372 -    public Object[] methodMixedEllipsis(final Object... args) {
  93.373 -        return args;
  93.374 -    }
  93.375 -
  93.376 -    public Object[] methodObjectWithEllipsis(final String arg, final int... args) {
  93.377 -        final Object[] res = new Object[args.length + 1];
  93.378 -        res[0] = arg;
  93.379 -        for (int i = 0; i < args.length; i++) {
  93.380 -            res[i + 1] = args[i];
  93.381 -        }
  93.382 -        return res;
  93.383 -    }
  93.384 -
  93.385 -    public Object[] methodPrimitiveWithEllipsis(final int arg, final long... args) {
  93.386 -        final Object[] res = new Object[args.length + 1];
  93.387 -        res[0] = arg;
  93.388 -        for (int i = 0; i < args.length; i++) {
  93.389 -            res[i + 1] = args[i];
  93.390 -        }
  93.391 -        return res;
  93.392 -    }
  93.393 -
  93.394 -    public Object[] methodMixedWithEllipsis(final String arg1, final int arg2, final Object... args) {
  93.395 -        final Object[] res = new Object[args.length + 2];
  93.396 -        res[0] = arg1;
  93.397 -        res[1] = arg2;
  93.398 -        System.arraycopy(args, 0, res, 2, args.length);
  93.399 -        return res;
  93.400 -    }
  93.401 -
  93.402 -    public void methodStartsThread() {
  93.403 -        isFinished = false;
  93.404 -
  93.405 -        final Thread t = new Thread(new Runnable() {
  93.406 -            @Override
  93.407 -            public void run() {
  93.408 -                try {
  93.409 -                    Thread.sleep(1000);
  93.410 -                    isFinished = true;
  93.411 -                } catch (final InterruptedException e) {
  93.412 -                    e.printStackTrace();
  93.413 -                }
  93.414 -            }
  93.415 -        });
  93.416 -
  93.417 -        t.start();
  93.418 -    }
  93.419 -
  93.420 -    public String overloadedMethodDoubleVSint(int arg) {
  93.421 -        return "int";
  93.422 -    }
  93.423 -
  93.424 -    public String overloadedMethodDoubleVSint(double arg) {
  93.425 -        return "double";
  93.426 -    }
  93.427 -
  93.428 -    public int overloadedMethod(int arg) {
  93.429 -        return arg*2;
  93.430 -    }
  93.431 -
  93.432 -    public int overloadedMethod(String arg) {
  93.433 -        return arg.length();
  93.434 -    }
  93.435 -
  93.436 -    public int overloadedMethod(boolean arg) {
  93.437 -        return (arg) ? 1 : 0;
  93.438 -    }
  93.439 -
  93.440 -    public int overloadedMethod(Person arg) {
  93.441 -        return arg.id*2;
  93.442 -    }
  93.443 -
  93.444 -    public int firstLevelMethodInt(int arg) throws ScriptException, NoSuchMethodException {
  93.445 -        return (int) ((Invocable)engine).invokeFunction("secondLevelMethodInt", arg);
  93.446 -    }
  93.447 -
  93.448 -    public int thirdLevelMethodInt(int arg) {
  93.449 -        return arg*5;
  93.450 -    }
  93.451 -
  93.452 -    public int firstLevelMethodInteger(Integer arg) throws ScriptException, NoSuchMethodException {
  93.453 -        return (int) ((Invocable)engine).invokeFunction("secondLevelMethodInteger", arg);
  93.454 -    }
  93.455 -
  93.456 -    public int thirdLevelMethodInteger(Integer arg) {
  93.457 -        return arg*10;
  93.458 -    }
  93.459 -
  93.460 -    public Person firstLevelMethodObject(Person p) throws ScriptException, NoSuchMethodException {
  93.461 -        return (Person) ((Invocable)engine).invokeFunction("secondLevelMethodObject", p);
  93.462 -    }
  93.463 -
  93.464 -    public Person thirdLevelMethodObject(Person p) {
  93.465 -        p.id *= 10;
  93.466 -        return p;
  93.467 -    }
  93.468 -
  93.469 -}
    94.1 --- a/test/src/jdk/nashorn/internal/access/StringAccessTest.java	Sat Feb 09 16:58:48 2013 +0100
    94.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.3 @@ -1,155 +0,0 @@
    94.4 -/*
    94.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    94.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    94.7 - *
    94.8 - * This code is free software; you can redistribute it and/or modify it
    94.9 - * under the terms of the GNU General Public License version 2 only, as
   94.10 - * published by the Free Software Foundation.  Oracle designates this
   94.11 - * particular file as subject to the "Classpath" exception as provided
   94.12 - * by Oracle in the LICENSE file that accompanied this code.
   94.13 - *
   94.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   94.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   94.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   94.17 - * version 2 for more details (a copy is included in the LICENSE file that
   94.18 - * accompanied this code).
   94.19 - *
   94.20 - * You should have received a copy of the GNU General Public License version
   94.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   94.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   94.23 - *
   94.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   94.25 - * or visit www.oracle.com if you need additional information or have any
   94.26 - * questions.
   94.27 - */
   94.28 -
   94.29 -package jdk.nashorn.internal.access;
   94.30 -
   94.31 -import static org.testng.AssertJUnit.assertEquals;
   94.32 -import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
   94.33 -
   94.34 -import javax.script.ScriptEngine;
   94.35 -import javax.script.ScriptEngineManager;
   94.36 -import javax.script.ScriptException;
   94.37 -import org.testng.TestNG;
   94.38 -import org.testng.annotations.BeforeClass;
   94.39 -import org.testng.annotations.Test;
   94.40 -
   94.41 -public class StringAccessTest {
   94.42 -
   94.43 -    private static ScriptEngine e = null;
   94.44 -    private static SharedObject o = new SharedObject();
   94.45 -
   94.46 -    public static void main(final String[] args) {
   94.47 -        TestNG.main(args);
   94.48 -    }
   94.49 -
   94.50 -    @BeforeClass
   94.51 -    public static void setUpClass() throws ScriptException {
   94.52 -        final ScriptEngineManager m = new ScriptEngineManager();
   94.53 -        e = m.getEngineByName("nashorn");
   94.54 -        e.put("o", o);
   94.55 -        e.eval("var SharedObject = Packages.jdk.nashorn.internal.access.SharedObject;");
   94.56 -    }
   94.57 -
   94.58 -    @Test
   94.59 -    public void accessFieldString() throws ScriptException {
   94.60 -        e.eval("var p_string = o.publicString;");
   94.61 -        assertEquals(o.publicString, e.get("p_string"));
   94.62 -        assertEquals("string", e.eval("typeof p_string;"));
   94.63 -        e.eval("o.publicString = 'changedString';");
   94.64 -        assertEquals("changedString", o.publicString);
   94.65 -    }
   94.66 -
   94.67 -    @Test
   94.68 -    public void accessFieldStringArray() throws ScriptException {
   94.69 -        e.eval("var p_string_array = o.publicStringArray;");
   94.70 -        assertEquals(o.publicStringArray[0], e.eval("o.publicStringArray[0]"));
   94.71 -        assertArrayEquals(o.publicStringArray, (String[])e.get("p_string_array"));
   94.72 -        e.eval("var t_string_arr = java.lang.reflect.Array.newInstance(java.lang.String.class, 3);" +
   94.73 -                "t_string_arr[0] = 'abc';" +
   94.74 -                "t_string_arr[1] = '123';" +
   94.75 -                "t_string_arr[2] = 'xyzzzz';" +
   94.76 -                "o.publicStringArray = t_string_arr;");
   94.77 -        assertArrayEquals(new String[] { "abc", "123", "xyzzzz" }, o.publicStringArray);
   94.78 -        e.eval("o.publicStringArray[0] = 'nashorn';");
   94.79 -        assertEquals("nashorn", o.publicStringArray[0]);
   94.80 -    }
   94.81 -
   94.82 -    @Test
   94.83 -    public void accessStaticFieldString() throws ScriptException {
   94.84 -        e.eval("var ps_string = SharedObject.publicStaticString;");
   94.85 -        assertEquals(SharedObject.publicStaticString, e.get("ps_string"));
   94.86 -        assertEquals("string", e.eval("typeof ps_string;"));
   94.87 -        e.eval("SharedObject.publicStaticString = 'changedString';");
   94.88 -        assertEquals("changedString", SharedObject.publicStaticString);
   94.89 -    }
   94.90 -
   94.91 -    @Test
   94.92 -    public void accessStaticFieldStringArray() throws ScriptException {
   94.93 -        e.eval("var ps_string_array = SharedObject.publicStaticStringArray;");
   94.94 -        assertEquals(SharedObject.publicStaticStringArray[0], e.eval("SharedObject.publicStaticStringArray[0]"));
   94.95 -        assertArrayEquals(SharedObject.publicStaticStringArray, (String[])e.get("ps_string_array"));
   94.96 -        e.eval("var ts_string_arr = java.lang.reflect.Array.newInstance(java.lang.String.class, 3);" +
   94.97 -                "ts_string_arr[0] = 'abc';" +
   94.98 -                "ts_string_arr[1] = '123';" +
   94.99 -                "ts_string_arr[2] = 'xyzzzz';" +
  94.100 -                "SharedObject.publicStaticStringArray = ts_string_arr;");
  94.101 -        assertArrayEquals(new String[] { "abc", "123", "xyzzzz" }, SharedObject.publicStaticStringArray);
  94.102 -        e.eval("SharedObject.publicStaticStringArray[0] = 'nashorn';");
  94.103 -        assertEquals("nashorn", SharedObject.publicStaticStringArray[0]);
  94.104 -    }
  94.105 -
  94.106 -    @Test
  94.107 -    public void accessFinalFieldString() throws ScriptException {
  94.108 -        e.eval("var pf_string = o.publicFinalString;");
  94.109 -        assertEquals(o.publicFinalString, e.get("pf_string"));
  94.110 -        assertEquals("string", e.eval("typeof pf_string;"));
  94.111 -        e.eval("o.publicFinalString = 'changedString';");
  94.112 -        assertEquals("PublicFinalString", o.publicFinalString);
  94.113 -    }
  94.114 -
  94.115 -    @Test
  94.116 -    public void accessFinalFieldStringArray() throws ScriptException {
  94.117 -        e.eval("var pf_string_array = o.publicFinalStringArray;");
  94.118 -        assertEquals(o.publicFinalStringArray[0], e.eval("o.publicFinalStringArray[0]"));
  94.119 -        assertArrayEquals(o.publicFinalStringArray, (String[])e.get("pf_string_array"));
  94.120 -        e.eval("var tf_string_arr = java.lang.reflect.Array.newInstance(java.lang.String.class, 3);" +
  94.121 -                "tf_string_arr[0] = 'abc';" +
  94.122 -                "tf_string_arr[1] = '123';" +
  94.123 -                "tf_string_arr[2] = 'xyzzzz';" +
  94.124 -                "o.publicFinalStringArray = tf_string_arr;");
  94.125 -        assertArrayEquals(new String[] { "FinalArrayString[0]", "FinalArrayString[1]", "FinalArrayString[2]", "FinalArrayString[3]" }, o.publicFinalStringArray);
  94.126 -        e.eval("o.publicFinalStringArray[0] = 'nashorn';");
  94.127 -        assertEquals("nashorn", o.publicFinalStringArray[0]);
  94.128 -    }
  94.129 -
  94.130 -    @Test
  94.131 -    public void accessStaticFinalFieldString() throws ScriptException {
  94.132 -        e.eval("var psf_string = SharedObject.publicStaticFinalString;");
  94.133 -        assertEquals(SharedObject.publicStaticFinalString, e.get("psf_string"));
  94.134 -        assertEquals("string", e.eval("typeof psf_string;"));
  94.135 -        e.eval("SharedObject.publicStaticFinalString = 'changedString';");
  94.136 -        assertEquals("PublicStaticFinalString", SharedObject.publicStaticFinalString);
  94.137 -    }
  94.138 -
  94.139 -    @Test
  94.140 -    public void accessStaticFinalFieldStringArray() throws ScriptException {
  94.141 -        e.eval("var psf_string_array = SharedObject.publicStaticFinalStringArray;");
  94.142 -        assertEquals(SharedObject.publicStaticFinalStringArray[0], e.eval("SharedObject.publicStaticFinalStringArray[0]"));
  94.143 -        assertArrayEquals(SharedObject.publicStaticFinalStringArray, (String[])e.get("psf_string_array"));
  94.144 -        e.eval("var tsf_string_arr = java.lang.reflect.Array.newInstance(java.lang.String.class, 3);" +
  94.145 -                "tsf_string_arr[0] = 'abc';" +
  94.146 -                "tsf_string_arr[1] = '123';" +
  94.147 -                "tsf_string_arr[2] = 'xyzzzz';" +
  94.148 -                "SharedObject.publicStaticFinalStringArray = tsf_string_arr;");
  94.149 -        assertArrayEquals(new String[] { "StaticFinalArrayString[0]",
  94.150 -                    "StaticFinalArrayString[1]",
  94.151 -                    "StaticFinalArrayString[2]",
  94.152 -                    "StaticFinalArrayString[3]" },
  94.153 -                SharedObject.publicStaticFinalStringArray);
  94.154 -        e.eval("SharedObject.publicStaticFinalStringArray[0] = 'nashorn';");
  94.155 -        assertEquals("nashorn", SharedObject.publicStaticFinalStringArray[0]);
  94.156 -    }
  94.157 -
  94.158 -}
    95.1 --- a/test/src/jdk/nashorn/internal/codegen/CompilerAccess.java	Sat Feb 09 16:58:48 2013 +0100
    95.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.3 @@ -1,35 +0,0 @@
    95.4 -
    95.5 -package jdk.nashorn.internal.codegen;
    95.6 -
    95.7 -import java.lang.reflect.Field;
    95.8 -import jdk.nashorn.internal.ir.FunctionNode;
    95.9 -
   95.10 -/**
   95.11 - * Since Compiler class doesn't give us access to its private {@code functionNode} field, we use this reflection-based
   95.12 - * access-check disabling helper to get to it in compilation tests.
   95.13 - *
   95.14 - */
   95.15 -public class CompilerAccess {
   95.16 -    private static final Field FUNCTION_NODE_FIELD = getCompilerFunctionNodeField();
   95.17 -    static {
   95.18 -        FUNCTION_NODE_FIELD.setAccessible(true);
   95.19 -    }
   95.20 -
   95.21 -    /**
   95.22 -     * Given a compiler, return its {@code functionNode} field, representing the root function (i.e. the compiled script).
   95.23 -     * @param compiler the compiler that already run its {@link Compiler#compile()} method.
   95.24 -     * @return the root function node representing the compiled script.
   95.25 -     * @throws IllegalAccessException
   95.26 -     */
   95.27 -    public static FunctionNode getScriptNode(Compiler compiler) throws IllegalAccessException {
   95.28 -        return (FunctionNode)FUNCTION_NODE_FIELD.get(compiler);
   95.29 -    }
   95.30 -
   95.31 -    private static Field getCompilerFunctionNodeField() {
   95.32 -        try {
   95.33 -            return Compiler.class.getDeclaredField("functionNode");
   95.34 -        } catch (NoSuchFieldException e) {
   95.35 -            throw new AssertionError("", e);
   95.36 -        }
   95.37 -    }
   95.38 -}

mercurial