Merge jdk8-b117

Fri, 15 Nov 2013 07:16:05 -0800

author
lana
date
Fri, 15 Nov 2013 07:16:05 -0800
changeset 673
1db3d4e4d189
parent 661
774c63629870
parent 672
2f0f8d1d0753
child 674
8d014b039b44

Merge

     1.1 --- a/make/build.xml	Thu Nov 14 09:05:27 2013 -0800
     1.2 +++ b/make/build.xml	Fri Nov 15 07:16:05 2013 -0800
     1.3 @@ -372,6 +372,12 @@
     1.4      
     1.5      <copy file="${file.reference.jfxrt.jar}" todir="dist"/>
     1.6      
     1.7 +    <condition property="jfx.prism.order" value="-Dprism.order=j2d" else=" ">
     1.8 +		<not>
     1.9 +            <os family="mac"/>
    1.10 +        </not>
    1.11 +	</condition>
    1.12 +    
    1.13      <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
    1.14         verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
    1.15        <jvmarg line="${ext.class.path}"/>
    1.16 @@ -380,6 +386,7 @@
    1.17          <propertyref prefix="testjfx-test-sys-prop."/>
    1.18          <mapper from="testjfx-test-sys-prop.*" to="*" type="glob"/>
    1.19        </propertyset>
    1.20 +      <sysproperty key="test.fork.jvm.options" value="${testjfx-test-sys-prop.test.fork.jvm.options} ${jfx.prism.order}"/>
    1.21        <classpath>
    1.22            <pathelement path="${testjfx.run.test.classpath}"/>
    1.23        </classpath>
     2.1 --- a/make/project.properties	Thu Nov 14 09:05:27 2013 -0800
     2.2 +++ b/make/project.properties	Fri Nov 15 07:16:05 2013 -0800
     2.3 @@ -230,7 +230,7 @@
     2.4      ${file.reference.jemmyawtinput.jar}${path.separator}\
     2.5      ${file.reference.testng.jar}${path.separator}\
     2.6      ${nashorn.internal.tests.jar}${path.separator}\
     2.7 -    ${nashorn.api.tests.jar}    
     2.8 +    ${nashorn.api.tests.jar}
     2.9  
    2.10  # testjfx VM options for script tests with @fork option
    2.11  testjfx-test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} -cp ${testjfx.run.test.classpath}
     3.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Thu Nov 14 09:05:27 2013 -0800
     3.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Fri Nov 15 07:16:05 2013 -0800
     3.3 @@ -41,6 +41,7 @@
     3.4  import java.util.Set;
     3.5  import java.util.concurrent.Callable;
     3.6  import javax.script.Bindings;
     3.7 +import jdk.nashorn.internal.runtime.ConsString;
     3.8  import jdk.nashorn.internal.runtime.Context;
     3.9  import jdk.nashorn.internal.runtime.GlobalObject;
    3.10  import jdk.nashorn.internal.runtime.JSType;
    3.11 @@ -594,14 +595,35 @@
    3.12      }
    3.13  
    3.14      /**
    3.15 -     * Make a script object mirror on given object if needed.
    3.16 +     * Utilitity to convert this script object to the given type.
    3.17       *
    3.18 -     * @param obj object to be wrapped
    3.19 -     * @param homeGlobal global to which this object belongs
    3.20 -     * @return wrapped object
    3.21 +     * @param type destination type to convert to
    3.22 +     * @return converted object
    3.23       */
    3.24 -    public static Object wrap(final Object obj, final ScriptObject homeGlobal) {
    3.25 -        return (obj instanceof ScriptObject && homeGlobal != null) ? new ScriptObjectMirror((ScriptObject)obj, homeGlobal) : obj;
    3.26 +    public <T> T to(final Class<T> type) {
    3.27 +        return inGlobal(new Callable<T>() {
    3.28 +            @Override
    3.29 +            public T call() {
    3.30 +                return type.cast(ScriptUtils.convert(sobj, type));
    3.31 +            }
    3.32 +        });
    3.33 +    }
    3.34 +
    3.35 +    /**
    3.36 +     * Make a script object mirror on given object if needed. Also converts ConsString instances to Strings.
    3.37 +     *
    3.38 +     * @param obj object to be wrapped/converted
    3.39 +     * @param homeGlobal global to which this object belongs. Not used for ConsStrings.
    3.40 +     * @return wrapped/converted object
    3.41 +     */
    3.42 +    public static Object wrap(final Object obj, final Object homeGlobal) {
    3.43 +        if(obj instanceof ScriptObject) {
    3.44 +            return homeGlobal instanceof ScriptObject ? new ScriptObjectMirror((ScriptObject)obj, (ScriptObject)homeGlobal) : obj;
    3.45 +        }
    3.46 +        if(obj instanceof ConsString) {
    3.47 +            return obj.toString();
    3.48 +        }
    3.49 +        return obj;
    3.50      }
    3.51  
    3.52      /**
    3.53 @@ -611,7 +633,7 @@
    3.54       * @param homeGlobal global to which this object belongs
    3.55       * @return unwrapped object
    3.56       */
    3.57 -    public static Object unwrap(final Object obj, final ScriptObject homeGlobal) {
    3.58 +    public static Object unwrap(final Object obj, final Object homeGlobal) {
    3.59          if (obj instanceof ScriptObjectMirror) {
    3.60              final ScriptObjectMirror mirror = (ScriptObjectMirror)obj;
    3.61              return (mirror.global == homeGlobal)? mirror.sobj : obj;
    3.62 @@ -627,7 +649,7 @@
    3.63       * @param homeGlobal global to which this object belongs
    3.64       * @return wrapped array
    3.65       */
    3.66 -    public static Object[] wrapArray(final Object[] args, final ScriptObject homeGlobal) {
    3.67 +    public static Object[] wrapArray(final Object[] args, final Object homeGlobal) {
    3.68          if (args == null || args.length == 0) {
    3.69              return args;
    3.70          }
    3.71 @@ -648,7 +670,7 @@
    3.72       * @param homeGlobal global to which this object belongs
    3.73       * @return unwrapped array
    3.74       */
    3.75 -    public static Object[] unwrapArray(final Object[] args, final ScriptObject homeGlobal) {
    3.76 +    public static Object[] unwrapArray(final Object[] args, final Object homeGlobal) {
    3.77          if (args == null || args.length == 0) {
    3.78              return args;
    3.79          }
     4.1 --- a/src/jdk/nashorn/api/scripting/ScriptUtils.java	Thu Nov 14 09:05:27 2013 -0800
     4.2 +++ b/src/jdk/nashorn/api/scripting/ScriptUtils.java	Fri Nov 15 07:16:05 2013 -0800
     4.3 @@ -25,11 +25,17 @@
     4.4  
     4.5  package jdk.nashorn.api.scripting;
     4.6  
     4.7 +import java.lang.invoke.MethodHandle;
     4.8 +import jdk.internal.dynalink.beans.StaticClass;
     4.9 +import jdk.internal.dynalink.linker.LinkerServices;
    4.10 +import jdk.nashorn.internal.runtime.linker.Bootstrap;
    4.11 +import jdk.nashorn.internal.runtime.Context;
    4.12  import jdk.nashorn.internal.runtime.ScriptFunction;
    4.13 +import jdk.nashorn.internal.runtime.ScriptObject;
    4.14  import jdk.nashorn.internal.runtime.ScriptRuntime;
    4.15  
    4.16  /**
    4.17 - * Utilities that are to be called from script code
    4.18 + * Utilities that are to be called from script code.
    4.19   */
    4.20  public final class ScriptUtils {
    4.21      private ScriptUtils() {}
    4.22 @@ -71,4 +77,96 @@
    4.23          return func.makeSynchronizedFunction(sync);
    4.24      }
    4.25  
    4.26 +    /**
    4.27 +     * Make a script object mirror on given object if needed.
    4.28 +     *
    4.29 +     * @param obj object to be wrapped
    4.30 +     * @return wrapped object
    4.31 +     */
    4.32 +    public static Object wrap(final Object obj) {
    4.33 +        if (obj instanceof ScriptObject) {
    4.34 +            return ScriptObjectMirror.wrap(obj, Context.getGlobal());
    4.35 +        }
    4.36 +
    4.37 +        return obj;
    4.38 +    }
    4.39 +
    4.40 +    /**
    4.41 +     * Unwrap a script object mirror if needed.
    4.42 +     *
    4.43 +     * @param obj object to be unwrapped
    4.44 +     * @return unwrapped object
    4.45 +     */
    4.46 +    public static Object unwrap(final Object obj) {
    4.47 +        if (obj instanceof ScriptObjectMirror) {
    4.48 +            return ScriptObjectMirror.unwrap(obj, Context.getGlobal());
    4.49 +        }
    4.50 +
    4.51 +        return obj;
    4.52 +    }
    4.53 +
    4.54 +    /**
    4.55 +     * Wrap an array of object to script object mirrors if needed.
    4.56 +     *
    4.57 +     * @param args array to be unwrapped
    4.58 +     * @return wrapped array
    4.59 +     */
    4.60 +    public static Object[] wrapArray(final Object[] args) {
    4.61 +        if (args == null || args.length == 0) {
    4.62 +            return args;
    4.63 +        }
    4.64 +
    4.65 +        return ScriptObjectMirror.wrapArray(args, Context.getGlobal());
    4.66 +    }
    4.67 +
    4.68 +    /**
    4.69 +     * Unwrap an array of script object mirrors if needed.
    4.70 +     *
    4.71 +     * @param args array to be unwrapped
    4.72 +     * @return unwrapped array
    4.73 +     */
    4.74 +    public static Object[] unwrapArray(final Object[] args) {
    4.75 +        if (args == null || args.length == 0) {
    4.76 +            return args;
    4.77 +        }
    4.78 +
    4.79 +        return ScriptObjectMirror.unwrapArray(args, Context.getGlobal());
    4.80 +    }
    4.81 +
    4.82 +    /**
    4.83 +     * Convert the given object to the given type.
    4.84 +     *
    4.85 +     * @param obj object to be converted
    4.86 +     * @param type destination type to convert to
    4.87 +     * @return converted object
    4.88 +     */
    4.89 +    public static Object convert(final Object obj, final Object type) {
    4.90 +        if (obj == null) {
    4.91 +            return null;
    4.92 +        }
    4.93 +
    4.94 +        final Class<?> clazz;
    4.95 +        if (type instanceof Class) {
    4.96 +            clazz = (Class<?>)type;
    4.97 +        } else if (type instanceof StaticClass) {
    4.98 +            clazz = ((StaticClass)type).getRepresentedClass();
    4.99 +        } else {
   4.100 +            throw new IllegalArgumentException("type expected");
   4.101 +        }
   4.102 +
   4.103 +        final LinkerServices linker = Bootstrap.getLinkerServices();
   4.104 +        final MethodHandle converter = linker.getTypeConverter(obj.getClass(),  clazz);
   4.105 +        if (converter == null) {
   4.106 +            // no supported conversion!
   4.107 +            throw new UnsupportedOperationException("conversion not supported");
   4.108 +        }
   4.109 +
   4.110 +        try {
   4.111 +            return converter.invoke(obj);
   4.112 +        } catch (final RuntimeException | Error e) {
   4.113 +            throw e;
   4.114 +        } catch (final Throwable t) {
   4.115 +            throw new RuntimeException(t);
   4.116 +        }
   4.117 +    }
   4.118  }
     5.1 --- a/src/jdk/nashorn/internal/codegen/Attr.java	Thu Nov 14 09:05:27 2013 -0800
     5.2 +++ b/src/jdk/nashorn/internal/codegen/Attr.java	Fri Nov 15 07:16:05 2013 -0800
     5.3 @@ -271,6 +271,7 @@
     5.4                      functionNode.addDeclaredSymbol(symbol);
     5.5                      if (varNode.isFunctionDeclaration()) {
     5.6                          newType(symbol, FunctionNode.FUNCTION_TYPE);
     5.7 +                        symbol.setIsFunctionDeclaration();
     5.8                      }
     5.9                      return varNode.setName((IdentNode)ident.setSymbol(lc, symbol));
    5.10                  }
    5.11 @@ -1264,12 +1265,17 @@
    5.12  
    5.13      @Override
    5.14      public Node leaveCOMMARIGHT(final BinaryNode binaryNode) {
    5.15 -        return end(ensureSymbol(binaryNode.rhs().getType(), binaryNode));
    5.16 +        return leaveComma(binaryNode, binaryNode.rhs());
    5.17      }
    5.18  
    5.19      @Override
    5.20      public Node leaveCOMMALEFT(final BinaryNode binaryNode) {
    5.21 -        return end(ensureSymbol(binaryNode.lhs().getType(), binaryNode));
    5.22 +        return leaveComma(binaryNode, binaryNode.lhs());
    5.23 +    }
    5.24 +
    5.25 +    private Node leaveComma(final BinaryNode commaNode, final Expression effectiveExpr) {
    5.26 +        ensureTypeNotUnknown(effectiveExpr);
    5.27 +        return end(ensureSymbol(effectiveExpr.getType(), commaNode));
    5.28      }
    5.29  
    5.30      @Override
     6.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Thu Nov 14 09:05:27 2013 -0800
     6.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Fri Nov 15 07:16:05 2013 -0800
     6.3 @@ -412,6 +412,8 @@
     6.4              return method;
     6.5          }
     6.6  
     6.7 +        assert !type.isUnknown();
     6.8 +
     6.9          /*
    6.10           * The load may be of type IdentNode, e.g. "x", AccessNode, e.g. "x.y"
    6.11           * or IndexNode e.g. "x[y]". Both AccessNodes and IndexNodes are
     7.1 --- a/src/jdk/nashorn/internal/codegen/MapCreator.java	Thu Nov 14 09:05:27 2013 -0800
     7.2 +++ b/src/jdk/nashorn/internal/codegen/MapCreator.java	Fri Nov 15 07:16:05 2013 -0800
     7.3 @@ -134,6 +134,10 @@
     7.4              flags |= Property.CAN_BE_UNDEFINED;
     7.5          }
     7.6  
     7.7 +        if (symbol.isFunctionDeclaration()) {
     7.8 +            flags |= Property.IS_FUNCTION_DECLARATION;
     7.9 +        }
    7.10 +
    7.11          return flags;
    7.12      }
    7.13  
     8.1 --- a/src/jdk/nashorn/internal/ir/Symbol.java	Thu Nov 14 09:05:27 2013 -0800
     8.2 +++ b/src/jdk/nashorn/internal/ir/Symbol.java	Fri Nov 15 07:16:05 2013 -0800
     8.3 @@ -75,6 +75,8 @@
     8.4      public static final int IS_SPECIALIZED_PARAM = 1 << 13;
     8.5      /** Is this symbol a shared temporary? */
     8.6      public static final int IS_SHARED            = 1 << 14;
     8.7 +    /** Is this a function declaration? */
     8.8 +    public static final int IS_FUNCTION_DECLARATION = 1 << 15;
     8.9  
    8.10      /** Null or name identifying symbol. */
    8.11      private final String name;
    8.12 @@ -360,6 +362,14 @@
    8.13      }
    8.14  
    8.15      /**
    8.16 +     * Check if this symbol is a function declaration
    8.17 +     * @return true if a function declaration
    8.18 +     */
    8.19 +    public boolean isFunctionDeclaration() {
    8.20 +        return (flags & IS_FUNCTION_DECLARATION) == IS_FUNCTION_DECLARATION;
    8.21 +    }
    8.22 +
    8.23 +    /**
    8.24       * Creates an unshared copy of a symbol. The symbol must be currently shared.
    8.25       * @param newName the name for the new symbol.
    8.26       * @return a new, unshared symbol.
    8.27 @@ -396,6 +406,16 @@
    8.28  
    8.29  
    8.30      /**
    8.31 +     * Mark this symbol as a function declaration.
    8.32 +     */
    8.33 +    public void setIsFunctionDeclaration() {
    8.34 +        if (!isFunctionDeclaration()) {
    8.35 +            trace("SET IS FUNCTION DECLARATION");
    8.36 +            flags |= IS_FUNCTION_DECLARATION;
    8.37 +        }
    8.38 +    }
    8.39 +
    8.40 +    /**
    8.41       * Check if this symbol is a variable
    8.42       * @return true if variable
    8.43       */
     9.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Thu Nov 14 09:05:27 2013 -0800
     9.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Fri Nov 15 07:16:05 2013 -0800
     9.3 @@ -53,19 +53,19 @@
     9.4  import jdk.nashorn.internal.runtime.GlobalObject;
     9.5  import jdk.nashorn.internal.runtime.JSType;
     9.6  import jdk.nashorn.internal.runtime.NativeJavaPackage;
     9.7 +import jdk.nashorn.internal.runtime.PropertyDescriptor;
     9.8  import jdk.nashorn.internal.runtime.PropertyMap;
     9.9 +import jdk.nashorn.internal.runtime.Scope;
    9.10  import jdk.nashorn.internal.runtime.ScriptEnvironment;
    9.11 -import jdk.nashorn.internal.runtime.PropertyDescriptor;
    9.12 -import jdk.nashorn.internal.runtime.arrays.ArrayData;
    9.13 -import jdk.nashorn.internal.runtime.regexp.RegExpResult;
    9.14 -import jdk.nashorn.internal.runtime.Scope;
    9.15  import jdk.nashorn.internal.runtime.ScriptFunction;
    9.16  import jdk.nashorn.internal.runtime.ScriptObject;
    9.17  import jdk.nashorn.internal.runtime.ScriptRuntime;
    9.18  import jdk.nashorn.internal.runtime.ScriptingFunctions;
    9.19  import jdk.nashorn.internal.runtime.Source;
    9.20 +import jdk.nashorn.internal.runtime.arrays.ArrayData;
    9.21  import jdk.nashorn.internal.runtime.linker.Bootstrap;
    9.22  import jdk.nashorn.internal.runtime.linker.InvokeByName;
    9.23 +import jdk.nashorn.internal.runtime.regexp.RegExpResult;
    9.24  import jdk.nashorn.internal.scripts.JO;
    9.25  
    9.26  /**
    10.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java	Thu Nov 14 09:05:27 2013 -0800
    10.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java	Fri Nov 15 07:16:05 2013 -0800
    10.3 @@ -60,6 +60,7 @@
    10.4  import jdk.nashorn.internal.runtime.ScriptRuntime;
    10.5  import jdk.nashorn.internal.runtime.linker.Bootstrap;
    10.6  import jdk.nashorn.internal.runtime.linker.InvokeByName;
    10.7 +import jdk.nashorn.internal.runtime.linker.NashornBeansLinker;
    10.8  
    10.9  /**
   10.10   * ECMA 15.2 Object objects
   10.11 @@ -729,8 +730,7 @@
   10.12              final MethodType methodType, final Object source) {
   10.13          final GuardedInvocation inv;
   10.14          try {
   10.15 -            inv = linker.getGuardedInvocation(createLinkRequest(operation, methodType, source),
   10.16 -                Bootstrap.getLinkerServices());
   10.17 +            inv = NashornBeansLinker.getGuardedInvocation(linker, createLinkRequest(operation, methodType, source), Bootstrap.getLinkerServices());
   10.18              assert passesGuard(source, inv.getGuard());
   10.19          } catch(RuntimeException|Error e) {
   10.20              throw e;
    11.1 --- a/src/jdk/nashorn/internal/runtime/ConsString.java	Thu Nov 14 09:05:27 2013 -0800
    11.2 +++ b/src/jdk/nashorn/internal/runtime/ConsString.java	Fri Nov 15 07:16:05 2013 -0800
    11.3 @@ -57,10 +57,7 @@
    11.4  
    11.5      @Override
    11.6      public String toString() {
    11.7 -        if (!flat) {
    11.8 -            flatten();
    11.9 -        }
   11.10 -        return (String) left;
   11.11 +        return (String) flattened();
   11.12      }
   11.13  
   11.14      @Override
   11.15 @@ -70,18 +67,19 @@
   11.16  
   11.17      @Override
   11.18      public char charAt(final int index) {
   11.19 -        if (!flat) {
   11.20 -            flatten();
   11.21 -        }
   11.22 -        return left.charAt(index);
   11.23 +        return flattened().charAt(index);
   11.24      }
   11.25  
   11.26      @Override
   11.27      public CharSequence subSequence(final int start, final int end) {
   11.28 +        return flattened().subSequence(start, end);
   11.29 +    }
   11.30 +
   11.31 +    private CharSequence flattened() {
   11.32          if (!flat) {
   11.33              flatten();
   11.34          }
   11.35 -        return left.subSequence(start, end);
   11.36 +        return left;
   11.37      }
   11.38  
   11.39      private void flatten() {
    12.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java	Thu Nov 14 09:05:27 2013 -0800
    12.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java	Fri Nov 15 07:16:05 2013 -0800
    12.3 @@ -88,6 +88,9 @@
    12.4      /** JavaScript compliant conversion function from Object to number */
    12.5      public static final Call TO_NUMBER = staticCall(myLookup, JSType.class, "toNumber", double.class, Object.class);
    12.6  
    12.7 +    /** JavaScript compliant conversion function from Object to String */
    12.8 +    public static final Call TO_STRING = staticCall(myLookup, JSType.class, "toString", String.class, Object.class);
    12.9 +
   12.10      /** JavaScript compliant conversion function from Object to int32 */
   12.11      public static final Call TO_INT32 = staticCall(myLookup, JSType.class, "toInt32", int.class, Object.class);
   12.12  
   12.13 @@ -883,7 +886,7 @@
   12.14       */
   12.15      public static Object toJavaArray(final Object obj, final Class<?> componentType) {
   12.16          if (obj instanceof ScriptObject) {
   12.17 -            return convertArray(((ScriptObject)obj).getArray().asObjectArray(), componentType);
   12.18 +            return ((ScriptObject)obj).getArray().asArrayOfType(componentType);
   12.19          } else if (obj instanceof JSObject) {
   12.20              final ArrayLikeIterator<?> itr = ArrayLikeIterator.arrayLikeIterator(obj);
   12.21              final int len = (int) itr.getLength();
   12.22 @@ -908,6 +911,15 @@
   12.23       * @return converted Java array
   12.24       */
   12.25      public static Object convertArray(final Object[] src, final Class<?> componentType) {
   12.26 +        if(componentType == Object.class) {
   12.27 +            for(int i = 0; i < src.length; ++i) {
   12.28 +                final Object e = src[i];
   12.29 +                if(e instanceof ConsString) {
   12.30 +                    src[i] = e.toString();
   12.31 +                }
   12.32 +            }
   12.33 +        }
   12.34 +
   12.35          final int l = src.length;
   12.36          final Object dst = Array.newInstance(componentType, l);
   12.37          final MethodHandle converter = Bootstrap.getLinkerServices().getTypeConverter(Object.class, componentType);
    13.1 --- a/src/jdk/nashorn/internal/runtime/Property.java	Thu Nov 14 09:05:27 2013 -0800
    13.2 +++ b/src/jdk/nashorn/internal/runtime/Property.java	Fri Nov 15 07:16:05 2013 -0800
    13.3 @@ -56,33 +56,36 @@
    13.4      public static final int WRITABLE_ENUMERABLE_CONFIGURABLE = 0b0000_0000_0000;
    13.5  
    13.6      /** ECMA 8.6.1 - Is this property not writable? */
    13.7 -    public static final int NOT_WRITABLE     = 0b0000_0000_0001;
    13.8 +    public static final int NOT_WRITABLE     = 1 << 0;
    13.9  
   13.10      /** ECMA 8.6.1 - Is this property not enumerable? */
   13.11 -    public static final int NOT_ENUMERABLE   = 0b0000_0000_0010;
   13.12 +    public static final int NOT_ENUMERABLE   = 1 << 1;
   13.13  
   13.14      /** ECMA 8.6.1 - Is this property not configurable? */
   13.15 -    public static final int NOT_CONFIGURABLE = 0b0000_0000_0100;
   13.16 +    public static final int NOT_CONFIGURABLE = 1 << 2;
   13.17  
   13.18 -    private static final int MODIFY_MASK     = 0b0000_0000_1111;
   13.19 +    private static final int MODIFY_MASK     = (NOT_WRITABLE | NOT_ENUMERABLE | NOT_CONFIGURABLE);
   13.20  
   13.21      /** Is this a spill property? See {@link AccessorProperty} */
   13.22 -    public static final int IS_SPILL         = 0b0000_0001_0000;
   13.23 +    public static final int IS_SPILL         = 1 << 3;
   13.24  
   13.25      /** Is this a function parameter? */
   13.26 -    public static final int IS_PARAMETER     = 0b0000_0010_0000;
   13.27 +    public static final int IS_PARAMETER     = 1 << 4;
   13.28  
   13.29      /** Is parameter accessed thru arguments? */
   13.30 -    public static final int HAS_ARGUMENTS    = 0b0000_0100_0000;
   13.31 +    public static final int HAS_ARGUMENTS    = 1 << 5;
   13.32  
   13.33      /** Is this property always represented as an Object? See {@link ObjectClassGenerator} and dual fields flag. */
   13.34 -    public static final int IS_ALWAYS_OBJECT = 0b0000_1000_0000;
   13.35 +    public static final int IS_ALWAYS_OBJECT = 1 << 6;
   13.36  
   13.37      /** Can this property be primitive? */
   13.38 -    public static final int CAN_BE_PRIMITIVE = 0b0001_0000_0000;
   13.39 +    public static final int CAN_BE_PRIMITIVE = 1 << 7;
   13.40  
   13.41      /** Can this property be undefined? */
   13.42 -    public static final int CAN_BE_UNDEFINED = 0b0010_0000_0000;
   13.43 +    public static final int CAN_BE_UNDEFINED = 1 << 8;
   13.44 +
   13.45 +    /* Is this a function declaration property ? */
   13.46 +    public static final int IS_FUNCTION_DECLARATION = 1 << 9;
   13.47  
   13.48      /** Property key. */
   13.49      private final String key;
   13.50 @@ -522,4 +525,12 @@
   13.51      public boolean canBeUndefined() {
   13.52          return (flags & CAN_BE_UNDEFINED) == CAN_BE_UNDEFINED;
   13.53      }
   13.54 +
   13.55 +    /**
   13.56 +     * Check whether this property represents a function declaration.
   13.57 +     * @return whether this property is a function declaration or not.
   13.58 +     */
   13.59 +    public boolean isFunctionDeclaration() {
   13.60 +        return (flags & IS_FUNCTION_DECLARATION) == IS_FUNCTION_DECLARATION;
   13.61 +    }
   13.62  }
    14.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Nov 14 09:05:27 2013 -0800
    14.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Fri Nov 15 07:16:05 2013 -0800
    14.3 @@ -226,14 +226,23 @@
    14.4  
    14.5          for (final Property property : properties) {
    14.6              final String key = property.getKey();
    14.7 -
    14.8 -            if (newMap.findProperty(key) == null) {
    14.9 +            final Property oldProp = newMap.findProperty(key);
   14.10 +            if (oldProp == null) {
   14.11                  if (property instanceof UserAccessorProperty) {
   14.12                      final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source));
   14.13                      newMap = newMap.addProperty(prop);
   14.14                  } else {
   14.15                      newMap = newMap.addPropertyBind((AccessorProperty)property, source);
   14.16                  }
   14.17 +            } else {
   14.18 +                // See ECMA section 10.5 Declaration Binding Instantiation
   14.19 +                // step 5 processing each function declaration.
   14.20 +                if (property.isFunctionDeclaration() && !oldProp.isConfigurable()) {
   14.21 +                     if (oldProp instanceof UserAccessorProperty ||
   14.22 +                         !(oldProp.isWritable() && oldProp.isEnumerable())) {
   14.23 +                         throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
   14.24 +                     }
   14.25 +                }
   14.26              }
   14.27          }
   14.28  
    15.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Thu Nov 14 09:05:27 2013 -0800
    15.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Fri Nov 15 07:16:05 2013 -0800
    15.3 @@ -63,7 +63,7 @@
    15.4          final DynamicLinkerFactory factory = new DynamicLinkerFactory();
    15.5          factory.setPrioritizedLinkers(new NashornLinker(), new NashornPrimitiveLinker(), new NashornStaticClassLinker(),
    15.6                  new BoundDynamicMethodLinker(), new JavaSuperAdapterLinker(), new JSObjectLinker(), new ReflectionCheckLinker());
    15.7 -        factory.setFallbackLinkers(new BeansLinker(), new NashornBottomLinker());
    15.8 +        factory.setFallbackLinkers(new NashornBeansLinker(), new NashornBottomLinker());
    15.9          factory.setSyncOnRelink(true);
   15.10          final int relinkThreshold = Options.getIntProperty("nashorn.unstable.relink.threshold", -1);
   15.11          if (relinkThreshold > -1) {
    16.1 --- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java	Thu Nov 14 09:05:27 2013 -0800
    16.2 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java	Fri Nov 15 07:16:05 2013 -0800
    16.3 @@ -72,7 +72,7 @@
    16.4                  type.changeParameterType(0, dynamicMethodClass).changeParameterType(1, boundThis.getClass()));
    16.5  
    16.6          // Delegate to BeansLinker
    16.7 -        final GuardedInvocation inv = BeansLinker.getLinkerForClass(dynamicMethodClass).getGuardedInvocation(
    16.8 +        final GuardedInvocation inv = NashornBeansLinker.getGuardedInvocation(BeansLinker.getLinkerForClass(dynamicMethodClass),
    16.9                  linkRequest.replaceArguments(newDescriptor, args), linkerServices);
   16.10          if(inv == null) {
   16.11              return null;
    17.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java	Thu Nov 14 09:05:27 2013 -0800
    17.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java	Fri Nov 15 07:16:05 2013 -0800
    17.3 @@ -100,8 +100,9 @@
    17.4                  type.changeParameterType(0, adapterClass), 0);
    17.5  
    17.6          // Delegate to BeansLinker
    17.7 -        final GuardedInvocation guardedInv = BeansLinker.getLinkerForClass(adapterClass).getGuardedInvocation(
    17.8 -                linkRequest.replaceArguments(newDescriptor, args), linkerServices);
    17.9 +        final GuardedInvocation guardedInv = NashornBeansLinker.getGuardedInvocation(
   17.10 +                BeansLinker.getLinkerForClass(adapterClass), linkRequest.replaceArguments(newDescriptor, args),
   17.11 +                linkerServices);
   17.12  
   17.13          final MethodHandle guard = IS_ADAPTER_OF_CLASS.bindTo(adapterClass);
   17.14          if(guardedInv == null) {
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java	Fri Nov 15 07:16:05 2013 -0800
    18.3 @@ -0,0 +1,127 @@
    18.4 +/*
    18.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.7 + *
    18.8 + * This code is free software; you can redistribute it and/or modify it
    18.9 + * under the terms of the GNU General Public License version 2 only, as
   18.10 + * published by the Free Software Foundation.  Oracle designates this
   18.11 + * particular file as subject to the "Classpath" exception as provided
   18.12 + * by Oracle in the LICENSE file that accompanied this code.
   18.13 + *
   18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   18.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18.17 + * version 2 for more details (a copy is included in the LICENSE file that
   18.18 + * accompanied this code).
   18.19 + *
   18.20 + * You should have received a copy of the GNU General Public License version
   18.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18.23 + *
   18.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   18.25 + * or visit www.oracle.com if you need additional information or have any
   18.26 + * questions.
   18.27 + */
   18.28 +
   18.29 +package jdk.nashorn.internal.runtime.linker;
   18.30 +
   18.31 +import java.lang.invoke.MethodHandle;
   18.32 +import java.lang.invoke.MethodHandles;
   18.33 +import java.lang.invoke.MethodType;
   18.34 +import jdk.internal.dynalink.beans.BeansLinker;
   18.35 +import jdk.internal.dynalink.linker.ConversionComparator.Comparison;
   18.36 +import jdk.internal.dynalink.linker.GuardedInvocation;
   18.37 +import jdk.internal.dynalink.linker.GuardingDynamicLinker;
   18.38 +import jdk.internal.dynalink.linker.LinkRequest;
   18.39 +import jdk.internal.dynalink.linker.LinkerServices;
   18.40 +import jdk.internal.dynalink.support.Lookup;
   18.41 +import jdk.nashorn.internal.runtime.ConsString;
   18.42 +
   18.43 +/**
   18.44 + * This linker delegates to a {@code BeansLinker} but passes it a special linker services object that has a modified
   18.45 + * {@code asType} method that will ensure that we never pass internal engine objects that should not be externally
   18.46 + * observable (currently only ConsString) to Java APIs, but rather that we flatten it into a String. We can't just add
   18.47 + * this functionality as custom converters via {@code GuaardingTypeConverterFactory}, since they are not consulted when
   18.48 + * the target method handle parameter signature is {@code Object}.
   18.49 + */
   18.50 +public class NashornBeansLinker implements GuardingDynamicLinker {
   18.51 +    private static final MethodHandle EXPORT_ARGUMENT = new Lookup(MethodHandles.lookup()).findOwnStatic("exportArgument", Object.class, Object.class);
   18.52 +
   18.53 +    private final BeansLinker beansLinker = new BeansLinker();
   18.54 +
   18.55 +    @Override
   18.56 +    public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
   18.57 +        return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
   18.58 +    }
   18.59 +
   18.60 +    /**
   18.61 +     * Delegates to the specified linker but injects its linker services wrapper so that it will apply all special
   18.62 +     * conversions that this class does.
   18.63 +     * @param delegateLinker the linker to which the actual work is delegated to.
   18.64 +     * @param linkRequest the delegated link request
   18.65 +     * @param linkerServices the original link services that will be augmented with special conversions
   18.66 +     * @return the guarded invocation from the delegate, possibly augmented with special conversions
   18.67 +     * @throws Exception if the delegate throws an exception
   18.68 +     */
   18.69 +    public static GuardedInvocation getGuardedInvocation(final GuardingDynamicLinker delegateLinker, final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
   18.70 +        return delegateLinker.getGuardedInvocation(linkRequest, new NashornBeansLinkerServices(linkerServices));
   18.71 +    }
   18.72 +
   18.73 +    @SuppressWarnings("unused")
   18.74 +    private static Object exportArgument(final Object arg) {
   18.75 +        return arg instanceof ConsString ? arg.toString() : arg;
   18.76 +    }
   18.77 +
   18.78 +    private static class NashornBeansLinkerServices implements LinkerServices {
   18.79 +        private final LinkerServices linkerServices;
   18.80 +
   18.81 +        NashornBeansLinkerServices(final LinkerServices linkerServices) {
   18.82 +            this.linkerServices = linkerServices;
   18.83 +        }
   18.84 +
   18.85 +        @Override
   18.86 +        public MethodHandle asType(final MethodHandle handle, final MethodType fromType) {
   18.87 +            final MethodHandle typed = linkerServices.asType(handle, fromType);
   18.88 +
   18.89 +            final MethodType handleType = handle.type();
   18.90 +            final int paramCount = handleType.parameterCount();
   18.91 +            assert fromType.parameterCount() == handleType.parameterCount();
   18.92 +
   18.93 +            MethodHandle[] filters = null;
   18.94 +            for(int i = 0; i < paramCount; ++i) {
   18.95 +                if(shouldConvert(handleType.parameterType(i), fromType.parameterType(i))) {
   18.96 +                    if(filters == null) {
   18.97 +                        filters = new MethodHandle[paramCount];
   18.98 +                    }
   18.99 +                    filters[i] = EXPORT_ARGUMENT;
  18.100 +                }
  18.101 +            }
  18.102 +
  18.103 +            return filters != null ? MethodHandles.filterArguments(typed, 0, filters) : typed;
  18.104 +        }
  18.105 +
  18.106 +        private static boolean shouldConvert(final Class<?> handleType, final Class<?> fromType) {
  18.107 +            return handleType == Object.class && fromType == Object.class;
  18.108 +        }
  18.109 +
  18.110 +        @Override
  18.111 +        public MethodHandle getTypeConverter(final Class<?> sourceType, final Class<?> targetType) {
  18.112 +            return linkerServices.getTypeConverter(sourceType, targetType);
  18.113 +        }
  18.114 +
  18.115 +        @Override
  18.116 +        public boolean canConvert(final Class<?> from, final Class<?> to) {
  18.117 +            return linkerServices.canConvert(from, to);
  18.118 +        }
  18.119 +
  18.120 +        @Override
  18.121 +        public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest) throws Exception {
  18.122 +            return linkerServices.getGuardedInvocation(linkRequest);
  18.123 +        }
  18.124 +
  18.125 +        @Override
  18.126 +        public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
  18.127 +            return linkerServices.compareConversion(sourceType, targetType1, targetType2);
  18.128 +        }
  18.129 +    }
  18.130 +}
    19.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java	Thu Nov 14 09:05:27 2013 -0800
    19.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java	Fri Nov 15 07:16:05 2013 -0800
    19.3 @@ -33,14 +33,18 @@
    19.4  import java.lang.invoke.MethodType;
    19.5  import java.lang.reflect.Method;
    19.6  import java.lang.reflect.Modifier;
    19.7 +import java.util.Map;
    19.8 +import java.util.HashMap;
    19.9  import jdk.internal.dynalink.CallSiteDescriptor;
   19.10  import jdk.internal.dynalink.beans.BeansLinker;
   19.11  import jdk.internal.dynalink.linker.GuardedInvocation;
   19.12  import jdk.internal.dynalink.linker.GuardingDynamicLinker;
   19.13 +import jdk.internal.dynalink.linker.GuardingTypeConverterFactory;
   19.14  import jdk.internal.dynalink.linker.LinkRequest;
   19.15  import jdk.internal.dynalink.linker.LinkerServices;
   19.16  import jdk.internal.dynalink.support.Guards;
   19.17  import jdk.nashorn.internal.runtime.Context;
   19.18 +import jdk.nashorn.internal.runtime.JSType;
   19.19  import jdk.nashorn.internal.runtime.ScriptRuntime;
   19.20  
   19.21  /**
   19.22 @@ -50,7 +54,7 @@
   19.23   * setters for Java objects that couldn't be linked by any other linker, and throw appropriate ECMAScript errors for
   19.24   * attempts to invoke arbitrary Java objects as functions or constructors.
   19.25   */
   19.26 -final class NashornBottomLinker implements GuardingDynamicLinker {
   19.27 +final class NashornBottomLinker implements GuardingDynamicLinker, GuardingTypeConverterFactory {
   19.28  
   19.29      @Override
   19.30      public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)
   19.31 @@ -129,6 +133,29 @@
   19.32          throw new AssertionError("unknown call type " + desc);
   19.33      }
   19.34  
   19.35 +    @Override
   19.36 +    public GuardedInvocation convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
   19.37 +        final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
   19.38 +        return gi == null ? null : gi.asType(MH.type(targetType, sourceType));
   19.39 +    }
   19.40 +
   19.41 +    /**
   19.42 +     * Main part of the implementation of {@link GuardingTypeConverterFactory#convertToType(Class, Class)} that doesn't
   19.43 +     * care about adapting the method signature; that's done by the invoking method. Returns conversion from Object to String/number/boolean (JS primitive types).
   19.44 +     * @param sourceType the source type
   19.45 +     * @param targetType the target type
   19.46 +     * @return a guarded invocation that converts from the source type to the target type.
   19.47 +     * @throws Exception if something goes wrong
   19.48 +     */
   19.49 +    private static GuardedInvocation convertToTypeNoCast(final Class<?> sourceType, final Class<?> targetType) throws Exception {
   19.50 +        final MethodHandle mh = CONVERTERS.get(targetType);
   19.51 +        if (mh != null) {
   19.52 +            return new GuardedInvocation(mh, null);
   19.53 +        }
   19.54 +
   19.55 +        return null;
   19.56 +    }
   19.57 +
   19.58      private static GuardedInvocation getInvocation(final MethodHandle handle, final Object self, final LinkerServices linkerServices, final CallSiteDescriptor desc) {
   19.59          return Bootstrap.asType(new GuardedInvocation(handle, Guards.getClassGuard(self.getClass())), linkerServices, desc);
   19.60      }
   19.61 @@ -161,6 +188,15 @@
   19.62          throw new AssertionError("unknown call type " + desc);
   19.63      }
   19.64  
   19.65 +    private static final Map<Class<?>, MethodHandle> CONVERTERS = new HashMap<>();
   19.66 +    static {
   19.67 +        CONVERTERS.put(boolean.class, JSType.TO_BOOLEAN.methodHandle());
   19.68 +        CONVERTERS.put(double.class, JSType.TO_NUMBER.methodHandle());
   19.69 +        CONVERTERS.put(int.class, JSType.TO_INTEGER.methodHandle());
   19.70 +        CONVERTERS.put(long.class, JSType.TO_LONG.methodHandle());
   19.71 +        CONVERTERS.put(String.class, JSType.TO_STRING.methodHandle());
   19.72 +    }
   19.73 +
   19.74      private static String getArgument(final LinkRequest linkRequest) {
   19.75          final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
   19.76          if (desc.getNameTokenCount() > 2) {
    20.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornLinker.java	Thu Nov 14 09:05:27 2013 -0800
    20.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornLinker.java	Fri Nov 15 07:16:05 2013 -0800
    20.3 @@ -32,6 +32,8 @@
    20.4  import java.lang.reflect.Modifier;
    20.5  import java.util.Deque;
    20.6  import java.util.List;
    20.7 +import java.util.Map;
    20.8 +import javax.script.Bindings;
    20.9  import jdk.internal.dynalink.CallSiteDescriptor;
   20.10  import jdk.internal.dynalink.linker.ConversionComparator;
   20.11  import jdk.internal.dynalink.linker.GuardedInvocation;
   20.12 @@ -40,7 +42,11 @@
   20.13  import jdk.internal.dynalink.linker.LinkerServices;
   20.14  import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
   20.15  import jdk.internal.dynalink.support.Guards;
   20.16 +import jdk.nashorn.api.scripting.JSObject;
   20.17 +import jdk.nashorn.api.scripting.ScriptObjectMirror;
   20.18 +import jdk.nashorn.api.scripting.ScriptUtils;
   20.19  import jdk.nashorn.internal.objects.NativeArray;
   20.20 +import jdk.nashorn.internal.runtime.Context;
   20.21  import jdk.nashorn.internal.runtime.JSType;
   20.22  import jdk.nashorn.internal.runtime.ScriptFunction;
   20.23  import jdk.nashorn.internal.runtime.ScriptObject;
   20.24 @@ -115,9 +121,14 @@
   20.25              return new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : IS_NASHORN_OR_UNDEFINED_TYPE);
   20.26          }
   20.27  
   20.28 -        GuardedInvocation inv = getArrayConverter(sourceType, targetType);
   20.29 -        if(inv != null) {
   20.30 -            return inv;
   20.31 +        final GuardedInvocation arrayConverter = getArrayConverter(sourceType, targetType);
   20.32 +        if(arrayConverter != null) {
   20.33 +            return arrayConverter;
   20.34 +        }
   20.35 +
   20.36 +        final GuardedInvocation mirrorConverter = getMirrorConverter(sourceType, targetType);
   20.37 +        if(mirrorConverter != null) {
   20.38 +            return mirrorConverter;
   20.39          }
   20.40  
   20.41          return getSamTypeConverter(sourceType, targetType);
   20.42 @@ -181,6 +192,18 @@
   20.43          return MH.asType(converter, converter.type().changeReturnType(type));
   20.44      }
   20.45  
   20.46 +    private static GuardedInvocation getMirrorConverter(Class<?> sourceType, Class<?> targetType) {
   20.47 +        // Could've also used (targetType.isAssignableFrom(ScriptObjectMirror.class) && targetType != Object.class) but
   20.48 +        // it's probably better to explicitly spell out the supported target types
   20.49 +        if (targetType == Map.class || targetType == Bindings.class || targetType == JSObject.class || targetType == ScriptObjectMirror.class) {
   20.50 +            if(ScriptObject.class.isAssignableFrom(sourceType)) {
   20.51 +                return new GuardedInvocation(CREATE_MIRROR, null);
   20.52 +            }
   20.53 +            return new GuardedInvocation(CREATE_MIRROR, IS_SCRIPT_OBJECT);
   20.54 +        }
   20.55 +        return null;
   20.56 +    }
   20.57 +
   20.58      private static boolean isAutoConvertibleFromFunction(final Class<?> clazz) {
   20.59          return isAbstractClass(clazz) && !ScriptObject.class.isAssignableFrom(clazz) &&
   20.60                  JavaAdapterFactory.isAutoConvertibleFromFunction(clazz);
   20.61 @@ -235,17 +258,23 @@
   20.62          return clazz == List.class || clazz == Deque.class;
   20.63      }
   20.64  
   20.65 +    private static final MethodHandle IS_SCRIPT_OBJECT = Guards.isInstance(ScriptObject.class, MH.type(Boolean.TYPE, Object.class));
   20.66      private static final MethodHandle IS_SCRIPT_FUNCTION = Guards.isInstance(ScriptFunction.class, MH.type(Boolean.TYPE, Object.class));
   20.67      private static final MethodHandle IS_NATIVE_ARRAY = Guards.isOfClass(NativeArray.class, MH.type(Boolean.TYPE, Object.class));
   20.68  
   20.69 -    private static final MethodHandle IS_NASHORN_OR_UNDEFINED_TYPE = findOwnMH("isNashornTypeOrUndefined",
   20.70 -            Boolean.TYPE, Object.class);
   20.71 +    private static final MethodHandle IS_NASHORN_OR_UNDEFINED_TYPE = findOwnMH("isNashornTypeOrUndefined", Boolean.TYPE, Object.class);
   20.72 +    private static final MethodHandle CREATE_MIRROR = findOwnMH("createMirror", Object.class, Object.class);
   20.73  
   20.74      @SuppressWarnings("unused")
   20.75      private static boolean isNashornTypeOrUndefined(final Object obj) {
   20.76          return obj instanceof ScriptObject || obj instanceof Undefined;
   20.77      }
   20.78  
   20.79 +    @SuppressWarnings("unused")
   20.80 +    private static Object createMirror(final Object obj) {
   20.81 +        return ScriptUtils.wrap(obj);
   20.82 +    }
   20.83 +
   20.84      private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
   20.85          return MH.findStatic(MethodHandles.lookup(), NashornLinker.class, name, MH.type(rtype, types));
   20.86      }
    21.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java	Thu Nov 14 09:05:27 2013 -0800
    21.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java	Fri Nov 15 07:16:05 2013 -0800
    21.3 @@ -93,7 +93,7 @@
    21.4      }
    21.5  
    21.6      private static GuardedInvocation delegate(LinkerServices linkerServices, final LinkRequest request) throws Exception {
    21.7 -        return staticClassLinker.getGuardedInvocation(request, linkerServices);
    21.8 +        return NashornBeansLinker.getGuardedInvocation(staticClassLinker, request, linkerServices);
    21.9      }
   21.10  
   21.11      private static GuardedInvocation checkNullConstructor(final GuardedInvocation ctorInvocation, final Class<?> receiverClass) {
    22.1 --- a/test/script/basic/JDK-8015355.js	Thu Nov 14 09:05:27 2013 -0800
    22.2 +++ b/test/script/basic/JDK-8015355.js	Fri Nov 15 07:16:05 2013 -0800
    22.3 @@ -28,10 +28,6 @@
    22.4   * @run
    22.5   */
    22.6  
    22.7 -function fail(msg) {
    22.8 -    print(msg);
    22.9 -}
   22.10 -
   22.11  function check(callback) {
   22.12      try {
   22.13          callback();
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/test/script/basic/JDK-8027236.js	Fri Nov 15 07:16:05 2013 -0800
    23.3 @@ -0,0 +1,37 @@
    23.4 +/*
    23.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.7 + * 
    23.8 + * This code is free software; you can redistribute it and/or modify it
    23.9 + * under the terms of the GNU General Public License version 2 only, as
   23.10 + * published by the Free Software Foundation.
   23.11 + * 
   23.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   23.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   23.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   23.15 + * version 2 for more details (a copy is included in the LICENSE file that
   23.16 + * accompanied this code).
   23.17 + * 
   23.18 + * You should have received a copy of the GNU General Public License version
   23.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   23.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   23.21 + * 
   23.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   23.23 + * or visit www.oracle.com if you need additional information or have any
   23.24 + * questions.
   23.25 + */
   23.26 +
   23.27 +/**
   23.28 + * JDK-8027236: Ensure ScriptObject and ConsString aren't visible to Java
   23.29 + *
   23.30 + * @test
   23.31 + * @run
   23.32 + */
   23.33 +
   23.34 +// Check that ConsString is flattened
   23.35 +var m = new java.util.HashMap()
   23.36 +var x = "f"
   23.37 +x += "oo"
   23.38 +m.put(x, "bar")
   23.39 +print(m.get("foo"))
   23.40 +// Note: many more tests are run by the JavaExportImportTest TestNG class.
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/test/script/basic/JDK-8027236.js.EXPECTED	Fri Nov 15 07:16:05 2013 -0800
    24.3 @@ -0,0 +1,1 @@
    24.4 +bar
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/test/script/basic/JDK-8027700.js	Fri Nov 15 07:16:05 2013 -0800
    25.3 @@ -0,0 +1,54 @@
    25.4 +/*
    25.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    25.7 + * 
    25.8 + * This code is free software; you can redistribute it and/or modify it
    25.9 + * under the terms of the GNU General Public License version 2 only, as
   25.10 + * published by the Free Software Foundation.
   25.11 + * 
   25.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   25.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   25.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   25.15 + * version 2 for more details (a copy is included in the LICENSE file that
   25.16 + * accompanied this code).
   25.17 + * 
   25.18 + * You should have received a copy of the GNU General Public License version
   25.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   25.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   25.21 + * 
   25.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   25.23 + * or visit www.oracle.com if you need additional information or have any
   25.24 + * questions.
   25.25 + */
   25.26 +
   25.27 +/**
   25.28 + * JDK-8027700: function redeclaration checks missing for declaration binding instantiation
   25.29 + *
   25.30 + * @test
   25.31 + * @run
   25.32 + */
   25.33 +
   25.34 +Object.defineProperty(this,"x", {
   25.35 +        value:0,
   25.36 +        writable:true,
   25.37 +        enumerable:false
   25.38 +})
   25.39 +
   25.40 +try {
   25.41 +    eval("function x() {}");
   25.42 +    fail("should have thrown TypeError");
   25.43 +} catch (e) {
   25.44 +    if (! (e instanceof TypeError)) {
   25.45 +        fail("TypeError expected but got " + e);
   25.46 +    }
   25.47 +}
   25.48 +
   25.49 +Object.defineProperty(this, "foo", { value:0 }) 
   25.50 +try {
   25.51 +    eval("function foo() {}");
   25.52 +    fail("should have thrown TypeError");
   25.53 +} catch (e) {
   25.54 +    if (! (e instanceof TypeError)) {
   25.55 +        fail("TypeError expected but got " + e);
   25.56 +    }
   25.57 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/test/script/basic/JDK-8027753.js	Fri Nov 15 07:16:05 2013 -0800
    26.3 @@ -0,0 +1,50 @@
    26.4 +/*
    26.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    26.7 + * 
    26.8 + * This code is free software; you can redistribute it and/or modify it
    26.9 + * under the terms of the GNU General Public License version 2 only, as
   26.10 + * published by the Free Software Foundation.
   26.11 + * 
   26.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   26.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   26.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   26.15 + * version 2 for more details (a copy is included in the LICENSE file that
   26.16 + * accompanied this code).
   26.17 + * 
   26.18 + * You should have received a copy of the GNU General Public License version
   26.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   26.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   26.21 + * 
   26.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   26.23 + * or visit www.oracle.com if you need additional information or have any
   26.24 + * questions.
   26.25 + */
   26.26 +
   26.27 +/**
   26.28 + * JDK-8027753: Support ScriptObject to JSObject, ScriptObjectMirror, Map, Bindings auto-conversion as well as explicit wrap, unwrap
   26.29 + *
   26.30 + * @test
   26.31 + * @run
   26.32 + */
   26.33 +
   26.34 +var ScriptUtils = Java.type("jdk.nashorn.api.scripting.ScriptUtils");
   26.35 +var ScriptObjectMirror = Java.type("jdk.nashorn.api.scripting.ScriptObjectMirror");
   26.36 +
   26.37 +var obj = { foo: 34, bar: 'hello' };
   26.38 +
   26.39 +var wrapped = ScriptUtils.wrap(obj);
   26.40 +if (! (wrapped instanceof ScriptObjectMirror)) {
   26.41 +    fail("ScriptUtils.wrap does not return a ScriptObjectMirror");
   26.42 +}
   26.43 +
   26.44 +print("wrapped.foo = " + wrapped.foo);
   26.45 +print("wrapped.bar = " + wrapped.bar);
   26.46 +
   26.47 +var unwrapped = ScriptUtils.unwrap(wrapped);
   26.48 +if (! (unwrapped instanceof Object)) {
   26.49 +    fail("ScriptUtils.unwrap does not return a ScriptObject");
   26.50 +}
   26.51 +
   26.52 +// same object unwrapped?
   26.53 +print(unwrapped === obj);
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/test/script/basic/JDK-8027753.js.EXPECTED	Fri Nov 15 07:16:05 2013 -0800
    27.3 @@ -0,0 +1,3 @@
    27.4 +wrapped.foo = 34
    27.5 +wrapped.bar = hello
    27.6 +true
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/test/script/basic/JDK-8027828.js	Fri Nov 15 07:16:05 2013 -0800
    28.3 @@ -0,0 +1,35 @@
    28.4 +/*
    28.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    28.7 + * 
    28.8 + * This code is free software; you can redistribute it and/or modify it
    28.9 + * under the terms of the GNU General Public License version 2 only, as
   28.10 + * published by the Free Software Foundation.
   28.11 + * 
   28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   28.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   28.15 + * version 2 for more details (a copy is included in the LICENSE file that
   28.16 + * accompanied this code).
   28.17 + * 
   28.18 + * You should have received a copy of the GNU General Public License version
   28.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   28.21 + * 
   28.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   28.23 + * or visit www.oracle.com if you need additional information or have any
   28.24 + * questions.
   28.25 + */
   28.26 +
   28.27 +/**
   28.28 + * JDK-8027828: ClassCastException when converting return value of a Java method to boolean
   28.29 + *
   28.30 + * @test
   28.31 + * @run
   28.32 + */
   28.33 +
   28.34 +var x = new java.util.HashMap()
   28.35 +x.put('test', new java.io.File('test'))
   28.36 +if (x.get("test")) {
   28.37 +  print('Found!')
   28.38 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/test/script/basic/JDK-8027828.js.EXPECTED	Fri Nov 15 07:16:05 2013 -0800
    29.3 @@ -0,0 +1,1 @@
    29.4 +Found!
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/test/script/basic/JDK-8028020.js	Fri Nov 15 07:16:05 2013 -0800
    30.3 @@ -0,0 +1,40 @@
    30.4 +/*
    30.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    30.7 + * 
    30.8 + * This code is free software; you can redistribute it and/or modify it
    30.9 + * under the terms of the GNU General Public License version 2 only, as
   30.10 + * published by the Free Software Foundation.
   30.11 + * 
   30.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   30.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   30.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   30.15 + * version 2 for more details (a copy is included in the LICENSE file that
   30.16 + * accompanied this code).
   30.17 + * 
   30.18 + * You should have received a copy of the GNU General Public License version
   30.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   30.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   30.21 + * 
   30.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   30.23 + * or visit www.oracle.com if you need additional information or have any
   30.24 + * questions.
   30.25 + */
   30.26 +
   30.27 +/**
   30.28 + * JDK-8028020: Function parameter as last expression in comma in return value causes bad type calculation
   30.29 + *
   30.30 + * @test
   30.31 + * @run
   30.32 + */
   30.33 +
   30.34 +function f(x) {
   30.35 +    return 1, x
   30.36 +}
   30.37 +
   30.38 +function g(x, y) {
   30.39 +    return x, y
   30.40 +}
   30.41 +
   30.42 +print(f("'1, x' works."))
   30.43 +print(g(42, "'x, y' works too."))
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/test/script/basic/JDK-8028020.js.EXPECTED	Fri Nov 15 07:16:05 2013 -0800
    31.3 @@ -0,0 +1,2 @@
    31.4 +'1, x' works.
    31.5 +'x, y' works too.
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/test/script/basic/convert.js	Fri Nov 15 07:16:05 2013 -0800
    32.3 @@ -0,0 +1,61 @@
    32.4 +/*
    32.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    32.7 + * 
    32.8 + * This code is free software; you can redistribute it and/or modify it
    32.9 + * under the terms of the GNU General Public License version 2 only, as
   32.10 + * published by the Free Software Foundation.
   32.11 + * 
   32.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   32.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   32.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   32.15 + * version 2 for more details (a copy is included in the LICENSE file that
   32.16 + * accompanied this code).
   32.17 + * 
   32.18 + * You should have received a copy of the GNU General Public License version
   32.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   32.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   32.21 + * 
   32.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   32.23 + * or visit www.oracle.com if you need additional information or have any
   32.24 + * questions.
   32.25 + */
   32.26 +
   32.27 +/**
   32.28 + * Tests for convert method of ScriptUtils.
   32.29 + *
   32.30 + * @test
   32.31 + * @run
   32.32 + */
   32.33 +
   32.34 +var ScriptUtils = Java.type("jdk.nashorn.api.scripting.ScriptUtils");
   32.35 +obj = { valueOf: function() { print("hello"); return 43.3; } };
   32.36 +
   32.37 +// object to double
   32.38 +print(ScriptUtils.convert(obj, java.lang.Number.class));
   32.39 +
   32.40 +// array to List
   32.41 +var arr = [3, 44, 23, 33];
   32.42 +var list = ScriptUtils.convert(arr, java.util.List.class);
   32.43 +print(list instanceof java.util.List)
   32.44 +print(list);
   32.45 +
   32.46 +// object to Map
   32.47 +obj = { foo: 333, bar: 'hello'};
   32.48 +var map = ScriptUtils.convert(obj, java.util.Map.class);
   32.49 +print(map instanceof java.util.Map);
   32.50 +for (m in map) {
   32.51 +   print(m + " " + map[m]);
   32.52 +}
   32.53 +
   32.54 +// object to String
   32.55 +obj = { toString: function() { print("in toString"); return "foo" } };
   32.56 +print(ScriptUtils.convert(obj, java.lang.String.class));
   32.57 +
   32.58 +// array to Java array
   32.59 +var jarr = ScriptUtils.convert(arr, Java.type("int[]"));
   32.60 +print(jarr instanceof Java.type("int[]"));
   32.61 +for (i in jarr) {
   32.62 +    print(jarr[i]);
   32.63 +}
   32.64 +
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/test/script/basic/convert.js.EXPECTED	Fri Nov 15 07:16:05 2013 -0800
    33.3 @@ -0,0 +1,14 @@
    33.4 +hello
    33.5 +43.3
    33.6 +true
    33.7 +[3, 44, 23, 33]
    33.8 +true
    33.9 +foo 333
   33.10 +bar hello
   33.11 +in toString
   33.12 +foo
   33.13 +true
   33.14 +3
   33.15 +44
   33.16 +23
   33.17 +33
    34.1 --- a/test/script/jfx.js	Thu Nov 14 09:05:27 2013 -0800
    34.2 +++ b/test/script/jfx.js	Fri Nov 15 07:16:05 2013 -0800
    34.3 @@ -37,13 +37,24 @@
    34.4  var Scene                = Java.type("javafx.scene.Scene");
    34.5  var Stage                = Java.type("javafx.stage.Stage");
    34.6  var File                 = Java.type("java.io.File");
    34.7 -var Timer                = Java.type("java.util.Timer");
    34.8 -var TimerTask            = Java.type("java.util.TimerTask");
    34.9  var OSInfo               = Java.type("sun.awt.OSInfo");
   34.10  var OSType               = Java.type("sun.awt.OSInfo.OSType");
   34.11  var StringBuffer         = Java.type("java.lang.StringBuffer");
   34.12 +var Paint                = Java.type("javafx.scene.paint.Paint");
   34.13 +var Color                = Java.type("javafx.scene.paint.Color");
   34.14 +var Image                = Java.type("javafx.scene.image.Image");
   34.15 +var Canvas               = Java.type("javafx.scene.canvas.Canvas");
   34.16 +var BorderPane           = Java.type("javafx.scene.layout.BorderPane");
   34.17 +var StackPane            = Java.type("javafx.scene.layout.StackPane");
   34.18 +var StrokeLineCap        = Java.type("javafx.scene.shape.StrokeLineCap");
   34.19 +var Platform             = Java.type("javafx.application.Platform");
   34.20 +var Runnable             = Java.type("java.lang.Runnable");
   34.21 +var RunnableExtend       = Java.extend(Runnable);
   34.22 +var AnimationTimer       = Java.type("javafx.animation.AnimationTimer");
   34.23 +var AnimationTimerExtend = Java.extend(AnimationTimer);
   34.24 +var Timer                = Java.type("java.util.Timer");
   34.25 +var TimerTask            = Java.type("java.util.TimerTask");
   34.26  
   34.27 -var WAIT = 2000;
   34.28  var TESTNAME = "test";
   34.29  var fsep = System.getProperty("file.separator");
   34.30  
   34.31 @@ -53,14 +64,16 @@
   34.32          run: function run() {
   34.33              var tmpdir = System.getProperty("java.io.tmpdir");
   34.34              var timenow = (new Date()).getTime();
   34.35 -            makeScreenShot(tmpdir + fsep + "screenshot" + timenow +".png");
   34.36 -            var dupImg = isDuplicateImages(tmpdir + fsep + "screenshot" + timenow +".png", __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden");
   34.37 -            (new File(mpdir + fsep + "screenshot" + timenow +".png")).delete();
   34.38 -            if (!dupImg) System.err.println("ERROR: screenshot does not match golden image");
   34.39 +            var scrShotTmp = tmpdir + fsep + "screenshot" + timenow +".png";
   34.40 +            var goldenImageDir = __DIR__ + "jfx" + fsep + TESTNAME + fsep + "golden";
   34.41 +            makeScreenShot(scrShotTmp);
   34.42 +            var dupImg = isDuplicateImages(scrShotTmp, goldenImageDir);
   34.43 +            (new File(scrShotTmp)).delete();
   34.44 +            if (!dupImg) System.err.println("ERROR: screenshot does not match the golden image");
   34.45              exit(0);
   34.46          }
   34.47      };
   34.48 -    raceTimer.schedule(timerTask, WAIT);
   34.49 +    raceTimer.schedule(timerTask, 100);
   34.50  }
   34.51  
   34.52  function makeScreenShot(shootToImg) {
   34.53 @@ -70,10 +83,10 @@
   34.54     imageJemmy.save(shootToImg);
   34.55  }
   34.56  
   34.57 -function isDuplicateImages(file1, file2) {
   34.58 -    var f1 = new File(file1);
   34.59 +function isDuplicateImages(screenShot, goldenDir) {
   34.60 +    var f1 = new File(screenShot);
   34.61      var f2;
   34.62 -    var sb = new StringBuffer(file2);
   34.63 +    var sb = new StringBuffer(goldenDir);
   34.64      if (OSInfo.getOSType() == OSType.WINDOWS) {
   34.65          f2 = new File(sb.append(fsep + "windows.png").toString());
   34.66      } else if (OSInfo.getOSType() == OSType.LINUX) {
   34.67 @@ -81,8 +94,6 @@
   34.68      } else if (OSInfo.getOSType() == OSType.MACOSX) {
   34.69          f2 = new File(sb.append(fsep + "macosx.png").toString());
   34.70      }
   34.71 -    print(f1.getAbsolutePath());
   34.72 -    print(f2.getAbsolutePath());
   34.73      if (f1.exists() && f2.exists()) {
   34.74          var image1 = new AWTImage(PNGDecoder.decode(f1.getAbsolutePath()));
   34.75          var image2 = new AWTImage(PNGDecoder.decode(f2.getAbsolutePath()));
    35.1 --- a/test/script/jfx/flyingimage.js	Thu Nov 14 09:05:27 2013 -0800
    35.2 +++ b/test/script/jfx/flyingimage.js	Fri Nov 15 07:16:05 2013 -0800
    35.3 @@ -31,15 +31,6 @@
    35.4  
    35.5  TESTNAME = "flyingimage";
    35.6  
    35.7 -var Image                = Java.type("javafx.scene.image.Image");
    35.8 -var Color                = Java.type("javafx.scene.paint.Color");
    35.9 -var Canvas               = Java.type("javafx.scene.canvas.Canvas");
   35.10 -var BorderPane           = Java.type("javafx.scene.layout.BorderPane");
   35.11 -var StackPane            = Java.type("javafx.scene.layout.StackPane");
   35.12 -var Font                 = Java.type("javafx.scene.text.Font");
   35.13 -var FontSmoothingType    = Java.type("javafx.scene.text.FontSmoothingType");
   35.14 -var Text                 = Java.type("javafx.scene.text.Text");
   35.15 -
   35.16  var WIDTH = 800;
   35.17  var HEIGHT = 600;
   35.18  var canvas = new Canvas(WIDTH, HEIGHT);
   35.19 @@ -48,10 +39,9 @@
   35.20  }
   35.21  var imageUrl = fileToURL(__DIR__ + "flyingimage/flyingimage.png");
   35.22  var img = new Image(imageUrl);
   35.23 -var font = new Font("Arial", 16);
   35.24 -var t = 0;
   35.25  var isFrameRendered = false;
   35.26  function renderFrame() {
   35.27 +    var t = frame;
   35.28      var gc = canvas.graphicsContext2D;
   35.29      gc.setFill(Color.web("#cccccc"));
   35.30      gc.fillRect(0, 0, WIDTH, HEIGHT);
   35.31 @@ -61,7 +51,7 @@
   35.32      var c = 200;
   35.33      var msc= 0.5 * HEIGHT / img.height;
   35.34      var sp0 = 0.003;
   35.35 -    for (var h = 0; h < c; h++, t++) {
   35.36 +    for (var h = 0; h < c; h++) {
   35.37          gc.setTransform(1, 0, 0, 1, 0, 0);
   35.38          var yh = h / (c - 1);
   35.39          gc.translate((0.5 + Math.sin(t * sp0 + h * 0.1) / 3) * WIDTH, 25 + (HEIGHT * 3 / 4 - 40) * (yh * yh));
   35.40 @@ -69,15 +59,26 @@
   35.41          gc.rotate(90 * Math.sin(t * sp0 + h * 0.1 + Math.PI));
   35.42          gc.scale(sc, sc);
   35.43          gc.drawImage(img, -img.width / 2, -img.height / 2);
   35.44 -     }
   35.45 +    }
   35.46      gc.setTransform(1, 0, 0, 1, 0, 0);
   35.47      isFrameRendered = true;
   35.48  }
   35.49  var stack = new StackPane();
   35.50  var pane = new BorderPane();
   35.51 -
   35.52  pane.setCenter(canvas);
   35.53  stack.getChildren().add(pane);
   35.54  $STAGE.scene = new Scene(stack);
   35.55 -renderFrame();
   35.56 -checkImageAndExit();
   35.57 +var frame = 0;
   35.58 +var timer = new AnimationTimerExtend() {
   35.59 +    handle: function handle(now) {
   35.60 +        if (frame < 200) {
   35.61 +            renderFrame();
   35.62 +            frame++;
   35.63 +        } else {
   35.64 +            checkImageAndExit();        
   35.65 +            timer.stop();
   35.66 +        }
   35.67 +    }
   35.68 +};
   35.69 +timer.start();
   35.70 + 
    36.1 Binary file test/script/jfx/flyingimage/flyingimage.png has changed
    37.1 Binary file test/script/jfx/flyingimage/golden/linux.png has changed
    38.1 Binary file test/script/jfx/flyingimage/golden/macosx.png has changed
    39.1 Binary file test/script/jfx/flyingimage/golden/windows.png has changed
    40.1 --- a/test/script/jfx/kaleidoscope.js	Thu Nov 14 09:05:27 2013 -0800
    40.2 +++ b/test/script/jfx/kaleidoscope.js	Fri Nov 15 07:16:05 2013 -0800
    40.3 @@ -30,13 +30,6 @@
    40.4   */
    40.5  
    40.6  TESTNAME = "kaleidoscope";
    40.7 -WAIT = 4000;
    40.8 -
    40.9 -var Paint                = Java.type("javafx.scene.paint.Paint");
   40.10 -var Canvas               = Java.type("javafx.scene.canvas.Canvas");
   40.11 -var BorderPane           = Java.type("javafx.scene.layout.BorderPane");
   40.12 -var StackPane            = Java.type("javafx.scene.layout.StackPane");
   40.13 -var StrokeLineCap        = Java.type("javafx.scene.shape.StrokeLineCap");
   40.14          
   40.15  var WIDTH = 800;
   40.16  var HEIGHT = 600;
   40.17 @@ -56,26 +49,28 @@
   40.18  var r,e;
   40.19  var fade;
   40.20  var prv_x,prv_y,prv_x2,prv_y2;
   40.21 +var isFrameRendered = false;
   40.22  
   40.23  function renderFrame() {
   40.24 -	a=0.2*angle;
   40.25 -	b=0.7*angle;
   40.26 -	r=0;
   40.27 -	fade=32;
   40.28 -	for(var i=0;i<6;i++)
   40.29 -		{
   40.30 -		c[i]=1.0/(i+1)/2;
   40.31 -		d[i]=1.0/(i+1)/2;
   40.32 -		}
   40.33 -	radius=Math.round((WIDTH+HEIGHT)/8);
   40.34 -	e=radius*0.2;
   40.35 -	p_x=Math.round(WIDTH/2);
   40.36 -	p_y=Math.round(HEIGHT/2);
   40.37 -	x=(radius*c[0])*Math.cos(a*d[1])+(radius*c[2])*Math.sin(a*d[3])+(radius*c[4])*Math.sin(a*d[5]);
   40.38 -	y=(radius*c[5])*Math.sin(a*d[4])+(radius*c[3])*Math.cos(a*d[2])+(radius*c[1])*Math.cos(a*d[0]);
   40.39 -    for (i = 0; i < 800; i++) {
   40.40 -        anim();
   40.41 +	if (!isFrameRendered) {
   40.42 +        a=0.2*angle;
   40.43 +		b=0.7*angle;
   40.44 +		r=0;
   40.45 +		fade=32;
   40.46 +		for(var i=0;i<6;i++)
   40.47 +			{
   40.48 +			c[i]=1.0/(i+1)/2;
   40.49 +			d[i]=1.0/(i+1)/2;
   40.50 +			}
   40.51 +		radius=Math.round((WIDTH+HEIGHT)/8);
   40.52 +		e=radius*0.2;
   40.53 +		p_x=Math.round(WIDTH/2);
   40.54 +		p_y=Math.round(HEIGHT/2);
   40.55 +		x=(radius*c[0])*Math.cos(a*d[1])+(radius*c[2])*Math.sin(a*d[3])+(radius*c[4])*Math.sin(a*d[5]);
   40.56 +		y=(radius*c[5])*Math.sin(a*d[4])+(radius*c[3])*Math.cos(a*d[2])+(radius*c[1])*Math.cos(a*d[0]);
   40.57 +        isFrameRendered = true;
   40.58      }
   40.59 +    anim();
   40.60  }
   40.61  
   40.62  function anim() {
   40.63 @@ -154,9 +149,19 @@
   40.64  
   40.65  var stack = new StackPane();
   40.66  var pane = new BorderPane();
   40.67 -
   40.68  pane.setCenter(canvas);
   40.69  stack.getChildren().add(pane);
   40.70  $STAGE.scene = new Scene(stack);
   40.71 -renderFrame();
   40.72 -checkImageAndExit();
   40.73 \ No newline at end of file
   40.74 +var frame = 0;
   40.75 +var timer = new AnimationTimerExtend() {
   40.76 +    handle: function handle(now) {
   40.77 +        if (frame < 800) {
   40.78 +            renderFrame();
   40.79 +            frame++;
   40.80 +        } else {
   40.81 +            checkImageAndExit();
   40.82 +            timer.stop();
   40.83 +        }
   40.84 +    }
   40.85 +};
   40.86 +timer.start();
    41.1 Binary file test/script/jfx/kaleidoscope/golden/linux.png has changed
    42.1 Binary file test/script/jfx/kaleidoscope/golden/macosx.png has changed
    43.1 Binary file test/script/jfx/kaleidoscope/golden/windows.png has changed
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/test/script/jfx/spread.js	Fri Nov 15 07:16:05 2013 -0800
    44.3 @@ -0,0 +1,222 @@
    44.4 +/*
    44.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    44.7 + * 
    44.8 + * This code is free software; you can redistribute it and/or modify it
    44.9 + * under the terms of the GNU General Public License version 2 only, as
   44.10 + * published by the Free Software Foundation.
   44.11 + * 
   44.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   44.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   44.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   44.15 + * version 2 for more details (a copy is included in the LICENSE file that
   44.16 + * accompanied this code).
   44.17 + * 
   44.18 + * You should have received a copy of the GNU General Public License version
   44.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   44.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   44.21 + * 
   44.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   44.23 + * or visit www.oracle.com if you need additional information or have any
   44.24 + * questions.
   44.25 + */
   44.26 +
   44.27 +/**
   44.28 + * Testing JavaFX canvas run by Nashorn.
   44.29 + *
   44.30 + * @test/nocompare
   44.31 + * @run
   44.32 + * @fork
   44.33 + */
   44.34 + 
   44.35 +TESTNAME = "spread";
   44.36 +
   44.37 +var WIDTH = 800;
   44.38 +var HEIGHT = 600;
   44.39 +var canvas = new Canvas(WIDTH, HEIGHT);
   44.40 +var context = canvas.graphicsContext2D;
   44.41 +
   44.42 +/* "Spread" tech demo of canvas by Tom Theisen
   44.43 + *
   44.44 + * This will animate a sequence of branch structures in a canvas element.
   44.45 + * Each frame, a new direction is calculated, similar to the last frame.
   44.46 + */
   44.47 +
   44.48 +var start_width = 20;           // starting width of each branch
   44.49 +var frame_time = 30;            // milliseconds per frame
   44.50 +var straighten_factor = 0.95;   // value from 0 to 1, factor applied to direction_offset every frame
   44.51 +var curviness = 0.2;            // amount of random direction change each frame
   44.52 +
   44.53 +var color_speed = 0.03;     // speed at which colors change when cycling is enabled
   44.54 +var branch_shrink = 0.95;   // factor by which branches shrink every frame
   44.55 +var min_width = 1;          // minimum WIDTH for branch, after which they are discontinued
   44.56 +var branch_opacity = 0.4;   // opacity of lines drawn
   44.57 +var branch_count = 3;       // branch count per tree
   44.58 +var branch_bud_size = 0.5;  // ratio of original branch size at which branch will split
   44.59 +var branch_bud_angle = 1;   // angle offset for split branch;
   44.60 +
   44.61 +var paper;                  // reference to graphics context
   44.62 +var branches = Object();    // linked list of active branches
   44.63 +var color_styles = [];      // pre-computed list of colors as styles. format: (r,g,b,a)    
   44.64 +var direction_offset = 0;   // current direction offset in radians.  this is applied to all branches.
   44.65 +var frame = 0;              // frame counter
   44.66 +var timespent = 0;          // total time spent so far, used to calculate average frame render duration
   44.67 +var frameratespan;          // html span element for updating performance number
   44.68 +
   44.69 +// preferences object, contains an attribute for each user setting
   44.70 +var prefs = {
   44.71 +    wrap: true,             // causes branches reaching edge of viewable area to appear on opposite side
   44.72 +    fade: false,             // fade existing graphics on each frame
   44.73 +    cycle: true,            // gradually change colors each frame
   44.74 +    new_branch_frames: 20    // number of frames elapsed between each auto-generated tree
   44.75 +};
   44.76 +
   44.77 +// create tree at the specified position with number of branches
   44.78 +function create_tree(branches, start_width, position, branch_count) {
   44.79 +    var angle_offset = Math.PI * 2 / branch_count;
   44.80 +    for (var i = 0; i < branch_count; ++i) {
   44.81 +        branch_add(branches, new Branch(position, angle_offset * i, start_width));
   44.82 +    }
   44.83 +}
   44.84 +
   44.85 +// add branch to collection
   44.86 +function branch_add(branches, branch) {
   44.87 +    branch.next = branches.next;
   44.88 +    branches.next = branch;
   44.89 +}
   44.90 +
   44.91 +// get the coordinates for the position of a new tree
   44.92 +// use the center of the canvas
   44.93 +function get_new_tree_center(width, height) {
   44.94 +    return {
   44.95 +        x: 0.5 * width, 
   44.96 +        y: 0.5 * height 
   44.97 +    };
   44.98 +}
   44.99 +
  44.100 +// Branch constructor
  44.101 +// position has x and y properties
  44.102 +// direction is in radians
  44.103 +function Branch(position, direction, width) {
  44.104 +    this.x = position.x;
  44.105 +    this.y = position.y;
  44.106 +    this.width = width;
  44.107 +    this.original_width = width;
  44.108 +    this.direction = direction;
  44.109 +}
  44.110 +
  44.111 +// update position, direction and width of a particular branch
  44.112 +function branch_update(branches, branch, paper) {
  44.113 +    paper.beginPath();
  44.114 +    paper.lineWidth = branch.width;
  44.115 +    paper.moveTo(branch.x, branch.y);
  44.116 +    
  44.117 +    branch.width *= branch_shrink;
  44.118 +    branch.direction += direction_offset;
  44.119 +    branch.x += Math.cos(branch.direction) * branch.width;
  44.120 +    branch.y += Math.sin(branch.direction) * branch.width;
  44.121 +    
  44.122 +    paper.lineTo(branch.x, branch.y);
  44.123 +    paper.stroke();
  44.124 +    
  44.125 +    if (prefs.wrap) wrap_branch(branch, WIDTH, HEIGHT);
  44.126 +
  44.127 +    if (branch.width < branch.original_width * branch_bud_size) {
  44.128 +        branch.original_width *= branch_bud_size;
  44.129 +        branch_add(branches, new Branch(branch, branch.direction + 1, branch.original_width));
  44.130 +    }
  44.131 +}
  44.132 +
  44.133 +function draw_frame() {
  44.134 +    if (prefs.fade) {
  44.135 +        paper.fillRect(0, 0, WIDTH, HEIGHT);
  44.136 +    }
  44.137 +
  44.138 +    if (prefs.cycle) {
  44.139 +        paper.setStroke(Paint.valueOf(color_styles[frame % color_styles.length]));
  44.140 +    }
  44.141 +
  44.142 +    if (frame++ % prefs.new_branch_frames == 0) {
  44.143 +        create_tree(branches, start_width, get_new_tree_center(WIDTH, HEIGHT), branch_count);
  44.144 +    }
  44.145 +    
  44.146 +    direction_offset += (0.35 + (frame % 200) * 0.0015) * curviness - curviness / 2;
  44.147 +    direction_offset *= straighten_factor;
  44.148 +    
  44.149 +    var branch = branches;
  44.150 +    var prev_branch = branches;
  44.151 +    while (branch = branch.next) {
  44.152 +        branch_update(branches, branch, paper);
  44.153 +        
  44.154 +        if (branch.width < min_width) {
  44.155 +            // remove branch from list
  44.156 +            prev_branch.next = branch.next;
  44.157 +        }
  44.158 +        
  44.159 +        prev_branch = branch;
  44.160 +    }
  44.161 +}
  44.162 +
  44.163 +// constrain branch position to visible area by "wrapping" from edge to edge
  44.164 +function wrap_branch(branch, WIDTH, HEIGHT) {
  44.165 +    branch.x = positive_mod(branch.x, WIDTH);
  44.166 +    branch.y = positive_mod(branch.y, HEIGHT);
  44.167 +}
  44.168 +
  44.169 +// for a < 0, b > 0, javascript returns a negative number for a % b
  44.170 +// this is a variant of the % operator that adds b to the result in this case
  44.171 +function positive_mod(a, b) {
  44.172 +    // ECMA 262 11.5.3: Applying the % Operator 
  44.173 +    // remainder operator does not convert operands to integers,
  44.174 +    // although negative results are possible
  44.175 +
  44.176 +    return ((a % b) + b) % b;
  44.177 +}
  44.178 +
  44.179 +// pre-compute color styles that will be used for color cycling
  44.180 +function populate_colors(color_speed, color_styles, branch_opacity) {
  44.181 +    // used in calculation of RGB values
  44.182 +    var two_thirds_pi = Math.PI * 2 / 3;
  44.183 +    var four_thirds_pi = Math.PI * 4 / 3;
  44.184 +    var two_pi = Math.PI * 2;
  44.185 +
  44.186 +    // hue does represent hue, but not in the conventional HSL scheme
  44.187 +    for(var hue = 0; hue < two_pi; hue += color_speed) {
  44.188 +        var r = Math.floor(Math.sin(hue) * 128 + 128);
  44.189 +        var g = Math.floor(Math.sin(hue + two_thirds_pi) * 128 + 128);
  44.190 +        var b = Math.floor(Math.sin(hue + four_thirds_pi) * 128 + 128);
  44.191 +        color = "rgba(" + [r, g, b, branch_opacity].join() + ")";
  44.192 +
  44.193 +        color_styles.push(color);
  44.194 +    }
  44.195 +}
  44.196 +
  44.197 +// apply initial settings to canvas object
  44.198 +function setup_canvas() {
  44.199 +    paper = canvas.graphicsContext2D;
  44.200 +    paper.setFill(Paint.valueOf('rgb(0, 0, 0)'));
  44.201 +    paper.fillRect(0, 0, WIDTH, HEIGHT);
  44.202 +    paper.setFill(Paint.valueOf("rgba(0, 0, 0, 0.005)"));
  44.203 +    paper.setStroke(Paint.valueOf("rgba(128, 128, 64, " + String(branch_opacity) + ")"));
  44.204 +}
  44.205 +
  44.206 +populate_colors(color_speed, color_styles, branch_opacity);
  44.207 +setup_canvas();
  44.208 +
  44.209 +var stack = new StackPane();
  44.210 +var pane = new BorderPane();
  44.211 +pane.setCenter(canvas);
  44.212 +stack.getChildren().add(pane);
  44.213 +$STAGE.scene = new Scene(stack);
  44.214 +var timer = new AnimationTimerExtend() {
  44.215 +    handle: function handle(now) {
  44.216 +        if (frame < 200) {
  44.217 +		    draw_frame();
  44.218 +        } else {
  44.219 +            checkImageAndExit();
  44.220 +            timer.stop();
  44.221 +        }
  44.222 +    }
  44.223 +};
  44.224 +timer.start();
  44.225 +
    45.1 Binary file test/script/jfx/spread/golden/linux.png has changed
    46.1 Binary file test/script/jfx/spread/golden/macosx.png has changed
    47.1 Binary file test/script/jfx/spread/golden/windows.png has changed
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/test/src/jdk/nashorn/api/javaaccess/ConsStringTest.java	Fri Nov 15 07:16:05 2013 -0800
    48.3 @@ -0,0 +1,99 @@
    48.4 +/*
    48.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    48.7 + *
    48.8 + * This code is free software; you can redistribute it and/or modify it
    48.9 + * under the terms of the GNU General Public License version 2 only, as
   48.10 + * published by the Free Software Foundation.  Oracle designates this
   48.11 + * particular file as subject to the "Classpath" exception as provided
   48.12 + * by Oracle in the LICENSE file that accompanied this code.
   48.13 + *
   48.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   48.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   48.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   48.17 + * version 2 for more details (a copy is included in the LICENSE file that
   48.18 + * accompanied this code).
   48.19 + *
   48.20 + * You should have received a copy of the GNU General Public License version
   48.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   48.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   48.23 + *
   48.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   48.25 + * or visit www.oracle.com if you need additional information or have any
   48.26 + * questions.
   48.27 + */
   48.28 +
   48.29 +package jdk.nashorn.api.javaaccess;
   48.30 +
   48.31 +import static org.testng.AssertJUnit.assertEquals;
   48.32 +
   48.33 +import java.util.HashMap;
   48.34 +import java.util.Map;
   48.35 +import javax.script.Bindings;
   48.36 +import javax.script.ScriptContext;
   48.37 +import javax.script.ScriptEngine;
   48.38 +import javax.script.ScriptEngineManager;
   48.39 +import javax.script.ScriptException;
   48.40 +import jdk.nashorn.api.scripting.JSObject;
   48.41 +import org.testng.TestNG;
   48.42 +import org.testng.annotations.AfterClass;
   48.43 +import org.testng.annotations.BeforeClass;
   48.44 +import org.testng.annotations.Test;
   48.45 +
   48.46 +public class ConsStringTest {
   48.47 +    private static ScriptEngine e = null;
   48.48 +
   48.49 +    public static void main(final String[] args) {
   48.50 +        TestNG.main(args);
   48.51 +    }
   48.52 +
   48.53 +    @BeforeClass
   48.54 +    public static void setUpClass() throws ScriptException {
   48.55 +        e = new ScriptEngineManager().getEngineByName("nashorn");
   48.56 +    }
   48.57 +
   48.58 +    @AfterClass
   48.59 +    public static void tearDownClass() {
   48.60 +        e = null;
   48.61 +    }
   48.62 +
   48.63 +    @Test
   48.64 +    public void testConsStringFlattening() throws ScriptException {
   48.65 +        final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
   48.66 +        final Map<Object, Object> m = new HashMap<>();
   48.67 +        b.put("m", m);
   48.68 +        e.eval("var x = 'f'; x += 'oo'; var y = 'b'; y += 'ar'; m.put(x, y)");
   48.69 +        assertEquals("bar", m.get("foo"));
   48.70 +    }
   48.71 +
   48.72 +    @Test
   48.73 +    public void testConsStringFromMirror() throws ScriptException {
   48.74 +        final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
   48.75 +        final Map<Object, Object> m = new HashMap<>();
   48.76 +        e.eval("var x = 'f'; x += 'oo'; var obj = {x: x};");
   48.77 +        assertEquals("foo", ((JSObject)b.get("obj")).getMember("x"));
   48.78 +    }
   48.79 +
   48.80 +    @Test
   48.81 +    public void testArrayConsString() throws ScriptException {
   48.82 +        final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
   48.83 +        final ArrayHolder h = new ArrayHolder();
   48.84 +        b.put("h", h);
   48.85 +        e.eval("var x = 'f'; x += 'oo'; h.array = [x];");
   48.86 +        assertEquals(1, h.array.length);
   48.87 +        assertEquals("foo", h.array[0]);
   48.88 +    }
   48.89 +
   48.90 +
   48.91 +    public static class ArrayHolder {
   48.92 +        private Object[] array;
   48.93 +
   48.94 +        public void setArray(Object[] array) {
   48.95 +            this.array = array;
   48.96 +        }
   48.97 +
   48.98 +        public Object[] getArray() {
   48.99 +            return array;
  48.100 +        }
  48.101 +    }
  48.102 +}
    49.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Thu Nov 14 09:05:27 2013 -0800
    49.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Fri Nov 15 07:16:05 2013 -0800
    49.3 @@ -523,6 +523,18 @@
    49.4          assertEquals(sw.toString(), println("34 true hello"));
    49.5      }
    49.6  
    49.7 +    @Test
    49.8 +    public void scriptObjectAutoConversionTest() throws ScriptException {
    49.9 +        final ScriptEngineManager m = new ScriptEngineManager();
   49.10 +        final ScriptEngine e = m.getEngineByName("nashorn");
   49.11 +        e.eval("obj = { foo: 'hello' }");
   49.12 +        e.put("Window", e.eval("Packages.jdk.nashorn.api.scripting.Window"));
   49.13 +        assertEquals(e.eval("Window.funcJSObject(obj)"), "hello");
   49.14 +        assertEquals(e.eval("Window.funcScriptObjectMirror(obj)"), "hello");
   49.15 +        assertEquals(e.eval("Window.funcMap(obj)"), "hello");
   49.16 +        assertEquals(e.eval("Window.funcJSObject(obj)"), "hello");
   49.17 +    }
   49.18 +
   49.19      private static final String LINE_SEPARATOR = System.getProperty("line.separator");
   49.20  
   49.21      // Returns String that would be the result of calling PrintWriter.println
    50.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java	Thu Nov 14 09:05:27 2013 -0800
    50.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java	Fri Nov 15 07:16:05 2013 -0800
    50.3 @@ -26,6 +26,7 @@
    50.4  package jdk.nashorn.api.scripting;
    50.5  
    50.6  import java.util.HashMap;
    50.7 +import java.util.List;
    50.8  import java.util.Map;
    50.9  import javax.script.ScriptEngine;
   50.10  import javax.script.ScriptEngineManager;
   50.11 @@ -227,4 +228,28 @@
   50.12          final Object newObj = ((ScriptObjectMirror)e2obj.getMember("foo")).newObject();
   50.13          assertTrue(newObj instanceof ScriptObjectMirror);
   50.14      }
   50.15 +
   50.16 +    @Test
   50.17 +    public void conversionTest() throws ScriptException {
   50.18 +        final ScriptEngineManager m = new ScriptEngineManager();
   50.19 +        final ScriptEngine e = m.getEngineByName("nashorn");
   50.20 +        final ScriptObjectMirror arr = (ScriptObjectMirror)e.eval("[33, 45, 23]");
   50.21 +        final int[] intArr = arr.to(int[].class);
   50.22 +        assertEquals(intArr[0], 33);
   50.23 +        assertEquals(intArr[1], 45);
   50.24 +        assertEquals(intArr[2], 23);
   50.25 +
   50.26 +        final List<?> list = arr.to(List.class);
   50.27 +        assertEquals(list.get(0), 33);
   50.28 +        assertEquals(list.get(1), 45);
   50.29 +        assertEquals(list.get(2), 23);
   50.30 +
   50.31 +        ScriptObjectMirror obj = (ScriptObjectMirror)e.eval(
   50.32 +            "({ valueOf: function() { return 42 } })");
   50.33 +        assertEquals(Double.valueOf(42.0), obj.to(Double.class));
   50.34 +
   50.35 +        obj = (ScriptObjectMirror)e.eval(
   50.36 +            "({ toString: function() { return 'foo' } })");
   50.37 +        assertEquals("foo", obj.to(String.class));
   50.38 +    }
   50.39  }
    51.1 --- a/test/src/jdk/nashorn/api/scripting/Window.java	Thu Nov 14 09:05:27 2013 -0800
    51.2 +++ b/test/src/jdk/nashorn/api/scripting/Window.java	Fri Nov 15 07:16:05 2013 -0800
    51.3 @@ -25,6 +25,9 @@
    51.4  
    51.5  package jdk.nashorn.api.scripting;
    51.6  
    51.7 +import java.util.Map;
    51.8 +import javax.script.Bindings;
    51.9 +
   51.10  public class Window {
   51.11  
   51.12      private String location = "http://localhost:8080/window";
   51.13 @@ -63,4 +66,20 @@
   51.14          System.out.println("window.setTimeout: " + delay + ", code: " + code);
   51.15          return 0;
   51.16      }
   51.17 +
   51.18 +    public static Object funcJSObject(final JSObject jsobj) {
   51.19 +        return jsobj.getMember("foo");
   51.20 +    }
   51.21 +
   51.22 +    public static Object funcScriptObjectMirror(final ScriptObjectMirror sobj) {
   51.23 +        return sobj.get("foo");
   51.24 +    }
   51.25 +
   51.26 +    public static Object funcMap(final Map<?,?> map) {
   51.27 +        return map.get("foo");
   51.28 +    }
   51.29 +
   51.30 +    public static Object funcBindings(final Bindings bindings) {
   51.31 +        return bindings.get("foo");
   51.32 +    }
   51.33  }

mercurial