Merge jdk8u40-b23

Thu, 22 Jan 2015 14:08:54 -0800

author
lana
date
Thu, 22 Jan 2015 14:08:54 -0800
changeset 1185
6ca090832d30
parent 1180
f1c54e997f94
parent 1184
690acc40065e
child 1186
b2ce5df33715

Merge

     1.1 --- a/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java	Wed Jan 21 12:19:47 2015 -0800
     1.2 +++ b/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java	Thu Jan 22 14:08:54 2015 -0800
     1.3 @@ -491,8 +491,9 @@
     1.4  
     1.5                  // We want setters that conform to "Object(O, V)". Note, we aren't doing "R(O, V)" as it might not be
     1.6                  // valid for us to convert return values proactively. Also, since we don't know what setters will be
     1.7 -                // invoked, we'll conservatively presume Object return type.
     1.8 -                final MethodType type = callSiteDescriptor.getMethodType().changeReturnType(Object.class);
     1.9 +                // invoked, we'll conservatively presume Object return type. The one exception is void return.
    1.10 +                final MethodType origType = callSiteDescriptor.getMethodType();
    1.11 +                final MethodType type = origType.returnType() == void.class ? origType : origType.changeReturnType(Object.class);
    1.12  
    1.13                  // What's below is basically:
    1.14                  //   foldArguments(guardWithTest(isNotNull, invoke, null|nextComponent.invocation),
    1.15 @@ -508,7 +509,7 @@
    1.16                  // Bind property setter handle to the expected setter type and linker services. Type is
    1.17                  // MethodHandle(Object, String, Object)
    1.18                  final MethodHandle boundGetter = MethodHandles.insertArguments(getPropertySetterHandle, 0,
    1.19 -                        CallSiteDescriptorFactory.dropParameterTypes(callSiteDescriptor, 1, 2), linkerServices);
    1.20 +                        callSiteDescriptor.changeMethodType(setterType), linkerServices);
    1.21  
    1.22                  // Cast getter to MethodHandle(O, N, V)
    1.23                  final MethodHandle typedGetter = linkerServices.asType(boundGetter, type.changeReturnType(
     2.1 --- a/src/jdk/internal/dynalink/beans/OverloadedMethod.java	Wed Jan 21 12:19:47 2015 -0800
     2.2 +++ b/src/jdk/internal/dynalink/beans/OverloadedMethod.java	Thu Jan 22 14:08:54 2015 -0800
     2.3 @@ -123,7 +123,6 @@
     2.4          varArgMethods = new ArrayList<>(methodHandles.size());
     2.5          final int argNum = callSiteType.parameterCount();
     2.6          for(MethodHandle mh: methodHandles) {
     2.7 -            mh = mh.asType(mh.type().changeReturnType(commonRetType));
     2.8              if(mh.isVarargsCollector()) {
     2.9                  final MethodHandle asFixed = mh.asFixedArity();
    2.10                  if(argNum == asFixed.type().parameterCount()) {
     3.1 --- a/src/jdk/internal/dynalink/support/TypeUtilities.java	Wed Jan 21 12:19:47 2015 -0800
     3.2 +++ b/src/jdk/internal/dynalink/support/TypeUtilities.java	Thu Jan 22 14:08:54 2015 -0800
     3.3 @@ -118,17 +118,13 @@
     3.4      public static Class<?> getCommonLosslessConversionType(final Class<?> c1, final Class<?> c2) {
     3.5          if(c1 == c2) {
     3.6              return c1;
     3.7 +        } else if (c1 == void.class || c2 == void.class) {
     3.8 +            return Object.class;
     3.9          } else if(isConvertibleWithoutLoss(c2, c1)) {
    3.10              return c1;
    3.11          } else if(isConvertibleWithoutLoss(c1, c2)) {
    3.12              return c2;
    3.13 -        }
    3.14 -        if(c1 == void.class) {
    3.15 -            return c2;
    3.16 -        } else if(c2 == void.class) {
    3.17 -            return c1;
    3.18 -        }
    3.19 -        if(c1.isPrimitive() && c2.isPrimitive()) {
    3.20 +        } else if(c1.isPrimitive() && c2.isPrimitive()) {
    3.21              if((c1 == byte.class && c2 == char.class) || (c1 == char.class && c2 == byte.class)) {
    3.22                  // byte + char = int
    3.23                  return int.class;
    3.24 @@ -268,20 +264,24 @@
    3.25      }
    3.26  
    3.27      /**
    3.28 -     * Determines whether a type can be converted to another without losing any
    3.29 -     * precision.
    3.30 +     * Determines whether a type can be converted to another without losing any precision. As a special case,
    3.31 +     * void is considered convertible only to Object and void, while anything can be converted to void. This
    3.32 +     * is because a target type of void means we don't care about the value, so the conversion is always
    3.33 +     * permissible.
    3.34       *
    3.35       * @param sourceType the source type
    3.36       * @param targetType the target type
    3.37       * @return true if lossless conversion is possible
    3.38       */
    3.39      public static boolean isConvertibleWithoutLoss(final Class<?> sourceType, final Class<?> targetType) {
    3.40 -        if(targetType.isAssignableFrom(sourceType)) {
    3.41 +        if(targetType.isAssignableFrom(sourceType) || targetType == void.class) {
    3.42              return true;
    3.43          }
    3.44          if(sourceType.isPrimitive()) {
    3.45              if(sourceType == void.class) {
    3.46 -                return false; // Void can't be losslessly represented by any type
    3.47 +                // Void should be losslessly representable by Object, either as null or as a custom value that
    3.48 +                // can be set with DynamicLinkerFactory.setAutoConversionStrategy.
    3.49 +                return targetType == Object.class;
    3.50              }
    3.51              if(targetType.isPrimitive()) {
    3.52                  return isProperPrimitiveLosslessSubtype(sourceType, targetType);
     4.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Wed Jan 21 12:19:47 2015 -0800
     4.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Thu Jan 22 14:08:54 2015 -0800
     4.3 @@ -68,6 +68,8 @@
     4.4  
     4.5      private static final MethodHandleFunctionality MH = MethodHandleFactory.getFunctionality();
     4.6  
     4.7 +    private static final MethodHandle VOID_TO_OBJECT = MH.constant(Object.class, ScriptRuntime.UNDEFINED);
     4.8 +
     4.9      /**
    4.10       * The default dynalink relink threshold for megamorphisism is 8. In the case
    4.11       * of object fields only, it is fine. However, with dual fields, in order to get
    4.12 @@ -189,7 +191,7 @@
    4.13       * @return true if the obj is an instance of @FunctionalInterface interface
    4.14       */
    4.15      public static boolean isFunctionalInterfaceObject(final Object obj) {
    4.16 -        return !JSType.isPrimitive(obj) && (NashornBottomLinker.getFunctionalInterfaceMethod(obj.getClass()) != null);
    4.17 +        return !JSType.isPrimitive(obj) && (NashornBeansLinker.getFunctionalInterfaceMethod(obj.getClass()) != null);
    4.18      }
    4.19  
    4.20      /**
    4.21 @@ -481,14 +483,16 @@
    4.22      private static MethodHandle unboxReturnType(final MethodHandle target, final MethodType newType) {
    4.23          final MethodType targetType = target.type();
    4.24          final Class<?> oldReturnType = targetType.returnType();
    4.25 +        final Class<?> newReturnType = newType.returnType();
    4.26          if (TypeUtilities.isWrapperType(oldReturnType)) {
    4.27 -            final Class<?> newReturnType = newType.returnType();
    4.28              if (newReturnType.isPrimitive()) {
    4.29                  // The contract of setAutoConversionStrategy is such that the difference between newType and targetType
    4.30                  // can only be JLS method invocation conversions.
    4.31                  assert TypeUtilities.isMethodInvocationConvertible(oldReturnType, newReturnType);
    4.32                  return MethodHandles.explicitCastArguments(target, targetType.changeReturnType(newReturnType));
    4.33              }
    4.34 +        } else if (oldReturnType == void.class && newReturnType == Object.class) {
    4.35 +            return MethodHandles.filterReturnValue(target, VOID_TO_OBJECT);
    4.36          }
    4.37          return target;
    4.38      }
     5.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java	Wed Jan 21 12:19:47 2015 -0800
     5.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java	Thu Jan 22 14:08:54 2015 -0800
     5.3 @@ -25,20 +25,29 @@
     5.4  
     5.5  package jdk.nashorn.internal.runtime.linker;
     5.6  
     5.7 +import static jdk.nashorn.internal.lookup.Lookup.MH;
     5.8 +import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
     5.9 +
    5.10  import java.lang.invoke.MethodHandle;
    5.11  import java.lang.invoke.MethodHandles;
    5.12  import java.lang.invoke.MethodType;
    5.13 +import java.lang.reflect.Method;
    5.14 +import java.lang.reflect.Modifier;
    5.15 +import jdk.internal.dynalink.CallSiteDescriptor;
    5.16  import jdk.internal.dynalink.beans.BeansLinker;
    5.17  import jdk.internal.dynalink.linker.ConversionComparator.Comparison;
    5.18  import jdk.internal.dynalink.linker.GuardedInvocation;
    5.19  import jdk.internal.dynalink.linker.GuardingDynamicLinker;
    5.20  import jdk.internal.dynalink.linker.LinkRequest;
    5.21  import jdk.internal.dynalink.linker.LinkerServices;
    5.22 +import jdk.internal.dynalink.support.Guards;
    5.23  import jdk.internal.dynalink.support.Lookup;
    5.24  import jdk.nashorn.api.scripting.ScriptUtils;
    5.25  import jdk.nashorn.internal.objects.NativeArray;
    5.26  import jdk.nashorn.internal.runtime.ConsString;
    5.27 +import jdk.nashorn.internal.runtime.Context;
    5.28  import jdk.nashorn.internal.runtime.ScriptObject;
    5.29 +import jdk.nashorn.internal.runtime.ScriptRuntime;
    5.30  import jdk.nashorn.internal.runtime.options.Options;
    5.31  
    5.32  /**
    5.33 @@ -68,19 +77,49 @@
    5.34          FILTER_CONSSTRING    = lookup.findOwnStatic("consStringFilter", Object.class, Object.class);
    5.35      }
    5.36  
    5.37 +    // cache of @FunctionalInterface method of implementor classes
    5.38 +    private static final ClassValue<Method> FUNCTIONAL_IFACE_METHOD = new ClassValue<Method>() {
    5.39 +        @Override
    5.40 +        protected Method computeValue(final Class<?> type) {
    5.41 +            return findFunctionalInterfaceMethod(type);
    5.42 +        }
    5.43 +    };
    5.44 +
    5.45      private final BeansLinker beansLinker = new BeansLinker();
    5.46  
    5.47      @Override
    5.48      public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    5.49 -        if (linkRequest.getReceiver() instanceof ConsString) {
    5.50 +        final Object self = linkRequest.getReceiver();
    5.51 +        final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    5.52 +        if (self instanceof ConsString) {
    5.53              // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
    5.54              final Object[] arguments = linkRequest.getArguments();
    5.55              arguments[0] = "";
    5.56 -            final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(linkRequest.getCallSiteDescriptor(), arguments);
    5.57 +            final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
    5.58              final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
    5.59              // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
    5.60              return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    5.61          }
    5.62 +
    5.63 +        if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
    5.64 +            // Support dyn:call on any object that supports some @FunctionalInterface
    5.65 +            // annotated interface. This way Java method, constructor references or
    5.66 +            // implementations of java.util.function.* interfaces can be called as though
    5.67 +            // those are script functions.
    5.68 +            final Method m = getFunctionalInterfaceMethod(self.getClass());
    5.69 +            if (m != null) {
    5.70 +                final MethodType callType = desc.getMethodType();
    5.71 +                // 'callee' and 'thiz' passed from script + actual arguments
    5.72 +                if (callType.parameterCount() != m.getParameterCount() + 2) {
    5.73 +                    throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
    5.74 +                }
    5.75 +                return new GuardedInvocation(
    5.76 +                        // drop 'thiz' passed from the script.
    5.77 +                        MH.dropArguments(desc.getLookup().unreflect(m), 1, callType.parameterType(1)),
    5.78 +                        Guards.getInstanceOfGuard(m.getDeclaringClass())).asTypeSafeReturn(
    5.79 +                                new NashornBeansLinkerServices(linkerServices), callType);
    5.80 +            }
    5.81 +        }
    5.82          return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
    5.83      }
    5.84  
    5.85 @@ -137,6 +176,38 @@
    5.86          return arg instanceof ConsString ? arg.toString() : arg;
    5.87      }
    5.88  
    5.89 +    private static Method findFunctionalInterfaceMethod(final Class<?> clazz) {
    5.90 +        if (clazz == null) {
    5.91 +            return null;
    5.92 +        }
    5.93 +
    5.94 +        for (final Class<?> iface : clazz.getInterfaces()) {
    5.95 +            // check accessiblity up-front
    5.96 +            if (! Context.isAccessibleClass(iface)) {
    5.97 +                continue;
    5.98 +            }
    5.99 +
   5.100 +            // check for @FunctionalInterface
   5.101 +            if (iface.isAnnotationPresent(FunctionalInterface.class)) {
   5.102 +                // return the first abstract method
   5.103 +                for (final Method m : iface.getMethods()) {
   5.104 +                    if (Modifier.isAbstract(m.getModifiers())) {
   5.105 +                        return m;
   5.106 +                    }
   5.107 +                }
   5.108 +            }
   5.109 +        }
   5.110 +
   5.111 +        // did not find here, try super class
   5.112 +        return findFunctionalInterfaceMethod(clazz.getSuperclass());
   5.113 +    }
   5.114 +
   5.115 +    // Returns @FunctionalInterface annotated interface's single abstract
   5.116 +    // method. If not found, returns null.
   5.117 +    static Method getFunctionalInterfaceMethod(final Class<?> clazz) {
   5.118 +        return FUNCTIONAL_IFACE_METHOD.get(clazz);
   5.119 +    }
   5.120 +
   5.121      private static class NashornBeansLinkerServices implements LinkerServices {
   5.122          private final LinkerServices linkerServices;
   5.123  
     6.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java	Wed Jan 21 12:19:47 2015 -0800
     6.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java	Thu Jan 22 14:08:54 2015 -0800
     6.3 @@ -30,9 +30,6 @@
     6.4  import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
     6.5  
     6.6  import java.lang.invoke.MethodHandle;
     6.7 -import java.lang.invoke.MethodType;
     6.8 -import java.lang.reflect.Method;
     6.9 -import java.lang.reflect.Modifier;
    6.10  import java.util.HashMap;
    6.11  import java.util.Map;
    6.12  import jdk.internal.dynalink.CallSiteDescriptor;
    6.13 @@ -45,7 +42,6 @@
    6.14  import jdk.internal.dynalink.linker.LinkerServices;
    6.15  import jdk.internal.dynalink.support.Guards;
    6.16  import jdk.nashorn.internal.codegen.types.Type;
    6.17 -import jdk.nashorn.internal.runtime.Context;
    6.18  import jdk.nashorn.internal.runtime.JSType;
    6.19  import jdk.nashorn.internal.runtime.ScriptRuntime;
    6.20  import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
    6.21 @@ -95,22 +91,6 @@
    6.22              }
    6.23              throw typeError("not.a.function", ScriptRuntime.safeToString(self));
    6.24          case "call":
    6.25 -            // Support dyn:call on any object that supports some @FunctionalInterface
    6.26 -            // annotated interface. This way Java method, constructor references or
    6.27 -            // implementations of java.util.function.* interfaces can be called as though
    6.28 -            // those are script functions.
    6.29 -            final Method m = getFunctionalInterfaceMethod(self.getClass());
    6.30 -            if (m != null) {
    6.31 -                final MethodType callType = desc.getMethodType();
    6.32 -                // 'callee' and 'thiz' passed from script + actual arguments
    6.33 -                if (callType.parameterCount() != m.getParameterCount() + 2) {
    6.34 -                    throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
    6.35 -                }
    6.36 -                return Bootstrap.asTypeSafeReturn(new GuardedInvocation(
    6.37 -                        // drop 'thiz' passed from the script.
    6.38 -                        MH.dropArguments(desc.getLookup().unreflect(m), 1, callType.parameterType(1)),
    6.39 -                        Guards.getInstanceOfGuard(m.getDeclaringClass())), linkerServices, desc);
    6.40 -            }
    6.41              if(BeansLinker.isDynamicConstructor(self)) {
    6.42                  throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self));
    6.43              }
    6.44 @@ -218,44 +198,4 @@
    6.45          }
    6.46          return ScriptRuntime.safeToString(linkRequest.getArguments()[1]);
    6.47      }
    6.48 -
    6.49 -    // cache of @FunctionalInterface method of implementor classes
    6.50 -    private static final ClassValue<Method> FUNCTIONAL_IFACE_METHOD = new ClassValue<Method>() {
    6.51 -        @Override
    6.52 -        protected Method computeValue(final Class<?> type) {
    6.53 -            return findFunctionalInterfaceMethod(type);
    6.54 -        }
    6.55 -
    6.56 -        private Method findFunctionalInterfaceMethod(final Class<?> clazz) {
    6.57 -            if (clazz == null) {
    6.58 -                return null;
    6.59 -            }
    6.60 -
    6.61 -            for (final Class<?> iface : clazz.getInterfaces()) {
    6.62 -                // check accessiblity up-front
    6.63 -                if (! Context.isAccessibleClass(iface)) {
    6.64 -                    continue;
    6.65 -                }
    6.66 -
    6.67 -                // check for @FunctionalInterface
    6.68 -                if (iface.isAnnotationPresent(FunctionalInterface.class)) {
    6.69 -                    // return the first abstract method
    6.70 -                    for (final Method m : iface.getMethods()) {
    6.71 -                        if (Modifier.isAbstract(m.getModifiers())) {
    6.72 -                            return m;
    6.73 -                        }
    6.74 -                    }
    6.75 -                }
    6.76 -            }
    6.77 -
    6.78 -            // did not find here, try super class
    6.79 -            return findFunctionalInterfaceMethod(clazz.getSuperclass());
    6.80 -        }
    6.81 -    };
    6.82 -
    6.83 -    // Returns @FunctionalInterface annotated interface's single abstract
    6.84 -    // method. If not found, returns null.
    6.85 -    static Method getFunctionalInterfaceMethod(final Class<?> clazz) {
    6.86 -        return FUNCTIONAL_IFACE_METHOD.get(clazz);
    6.87 -    }
    6.88  }
     7.1 --- a/test/script/basic/JDK-8020324.js.EXPECTED	Wed Jan 21 12:19:47 2015 -0800
     7.2 +++ b/test/script/basic/JDK-8020324.js.EXPECTED	Thu Jan 22 14:08:54 2015 -0800
     7.3 @@ -17,7 +17,7 @@
     7.4  bean.readWrite = 18: 18
     7.5  obj1.readWrite: 18
     7.6  obj1.getReadWrite(): 18
     7.7 -obj1.setReadWrite(19): null
     7.8 +obj1.setReadWrite(19): undefined
     7.9  obj1.readWrite: 19
    7.10  bean.readWrite: 19
    7.11  
    7.12 @@ -52,7 +52,7 @@
    7.13  PropertyBind.staticReadWrite = 26: 26
    7.14  obj2.staticReadWrite: 26
    7.15  obj2.getStaticReadWrite(): 26
    7.16 -obj2.setStaticReadWrite(27): null
    7.17 +obj2.setStaticReadWrite(27): undefined
    7.18  obj2.staticReadWrite: 27
    7.19  PropertyBind.staticReadWrite: 27
    7.20  
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/script/basic/JDK-8068573.js	Thu Jan 22 14:08:54 2015 -0800
     8.3 @@ -0,0 +1,57 @@
     8.4 +/*
     8.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + * 
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.
    8.11 + * 
    8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.15 + * version 2 for more details (a copy is included in the LICENSE file that
    8.16 + * accompanied this code).
    8.17 + * 
    8.18 + * You should have received a copy of the GNU General Public License version
    8.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.21 + * 
    8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.23 + * or visit www.oracle.com if you need additional information or have any
    8.24 + * questions.
    8.25 + */
    8.26 +
    8.27 +/**
    8.28 + * JDK-8068573: POJO setter using [] syntax throws an exception
    8.29 + *
    8.30 + * @test
    8.31 + * @run
    8.32 + */
    8.33 +
    8.34 +// Invoke a setter using []. It's important that the setter returns void.
    8.35 +var pb = new (Java.type("jdk.nashorn.test.models.PropertyBind"))
    8.36 +var n = "writeOnly";
    8.37 +pb[n] = 2;
    8.38 +Assert.assertEquals(pb.peekWriteOnly(), 2);
    8.39 +
    8.40 +// Invoke an overloaded setter using []. It's important that one of the 
    8.41 +// overloads returns void.
    8.42 +var os = new (Java.type("jdk.nashorn.test.models.OverloadedSetter"))
    8.43 +var n2 = "color";
    8.44 +os[n2] = 3; // exercise int overload
    8.45 +Assert.assertEquals(os.peekColor(), "3");
    8.46 +os[n2] = "blue";  // exercise string overload
    8.47 +Assert.assertEquals(os.peekColor(), "blue");
    8.48 +for each(var x in [42, "42"]) {
    8.49 +  os[n2] = x; // exercise both overloads in the same call site
    8.50 +  Assert.assertEquals(os.peekColor(), "42");
    8.51 +}
    8.52 +
    8.53 +// Invoke an overloaded method using [], repeatedly in the same call 
    8.54 +// site. It's important that one of the overloads returns void.
    8.55 +var n3="foo";
    8.56 +var param=["xyz", 1, "zyx", 2];
    8.57 +var expected=["boo", void 0, "boo", void 0];
    8.58 +for(var i in param) {
    8.59 +  Assert.assertEquals(os[n3](param[i]), expected[i]);
    8.60 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/script/basic/JDK-8069002.js	Thu Jan 22 14:08:54 2015 -0800
     9.3 @@ -0,0 +1,35 @@
     9.4 +/*
     9.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + * 
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + * 
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + * 
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + * 
    9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.23 + * or visit www.oracle.com if you need additional information or have any
    9.24 + * questions.
    9.25 + */
    9.26 +
    9.27 +/**
    9.28 + * JDK-8069002: NPE on invoking null (8068889 regression)
    9.29 + *
    9.30 + * @test
    9.31 + * @run
    9.32 + */
    9.33 +
    9.34 +try {
    9.35 +    null();
    9.36 +} catch (e) {
    9.37 +    Assert.assertTrue(e instanceof TypeError);
    9.38 +}
    10.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Wed Jan 21 12:19:47 2015 -0800
    10.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Thu Jan 22 14:08:54 2015 -0800
    10.3 @@ -29,12 +29,16 @@
    10.4  import static org.testng.Assert.assertNotNull;
    10.5  import static org.testng.Assert.assertTrue;
    10.6  import static org.testng.Assert.fail;
    10.7 +
    10.8  import java.io.StringReader;
    10.9  import java.io.StringWriter;
   10.10  import java.lang.reflect.InvocationHandler;
   10.11  import java.lang.reflect.Method;
   10.12  import java.lang.reflect.Proxy;
   10.13  import java.util.concurrent.Callable;
   10.14 +import java.util.concurrent.atomic.AtomicBoolean;
   10.15 +import java.util.function.Consumer;
   10.16 +import java.util.function.Function;
   10.17  import javax.script.Compilable;
   10.18  import javax.script.CompiledScript;
   10.19  import javax.script.Invocable;
   10.20 @@ -668,6 +672,41 @@
   10.21          assertEquals("helloworld", inv.invokeMethod(ctx.get(), "join", ""));
   10.22      }
   10.23  
   10.24 +    // @bug JDK-8068889: ConsString arguments to a functional interface wasn't converted to string.
   10.25 +    @Test
   10.26 +    public void functionalInterfaceStringTest() throws Exception {
   10.27 +        final ScriptEngineManager manager = new ScriptEngineManager();
   10.28 +        final ScriptEngine e = manager.getEngineByName("nashorn");
   10.29 +        final AtomicBoolean invoked = new AtomicBoolean(false);
   10.30 +        e.put("f", new Function<String, String>() {
   10.31 +            @Override
   10.32 +            public String apply(String t) {
   10.33 +                invoked.set(true);
   10.34 +                return t;
   10.35 +            }
   10.36 +        });
   10.37 +        assertEquals(e.eval("var x = 'a'; x += 'b'; f(x)"), "ab");
   10.38 +        assertTrue(invoked.get());
   10.39 +    }
   10.40 +
   10.41 +    // @bug JDK-8068889: ScriptObject arguments to a functional interface wasn't converted to a mirror.
   10.42 +    @Test
   10.43 +    public void functionalInterfaceObjectTest() throws Exception {
   10.44 +        final ScriptEngineManager manager = new ScriptEngineManager();
   10.45 +        final ScriptEngine e = manager.getEngineByName("nashorn");
   10.46 +        final AtomicBoolean invoked = new AtomicBoolean(false);
   10.47 +        e.put("c", new Consumer<Object>() {
   10.48 +            @Override
   10.49 +            public void accept(Object t) {
   10.50 +                assertTrue(t instanceof ScriptObjectMirror);
   10.51 +                assertEquals(((ScriptObjectMirror)t).get("a"), "xyz");
   10.52 +                invoked.set(true);
   10.53 +            }
   10.54 +        });
   10.55 +        e.eval("var x = 'xy'; x += 'z';c({a:x})");
   10.56 +        assertTrue(invoked.get());
   10.57 +    }
   10.58 +
   10.59      private static void checkProperty(final ScriptEngine e, final String name)
   10.60          throws ScriptException {
   10.61          final String value = System.getProperty(name);
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/src/jdk/nashorn/test/models/OverloadedSetter.java	Thu Jan 22 14:08:54 2015 -0800
    11.3 @@ -0,0 +1,48 @@
    11.4 +/*
    11.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.  Oracle designates this
   11.11 + * particular file as subject to the "Classpath" exception as provided
   11.12 + * by Oracle in the LICENSE file that accompanied this code.
   11.13 + *
   11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.17 + * version 2 for more details (a copy is included in the LICENSE file that
   11.18 + * accompanied this code).
   11.19 + *
   11.20 + * You should have received a copy of the GNU General Public License version
   11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.23 + *
   11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.25 + * or visit www.oracle.com if you need additional information or have any
   11.26 + * questions.
   11.27 + */
   11.28 +package jdk.nashorn.test.models;
   11.29 +
   11.30 +public class OverloadedSetter {
   11.31 +    private String color;
   11.32 +
   11.33 +    public void setColor(final int x) {
   11.34 +        this.color = Integer.toString(x);
   11.35 +    }
   11.36 +
   11.37 +    public void setColor(final String x) {
   11.38 +        this.color = x;
   11.39 +    }
   11.40 +
   11.41 +    public String peekColor() {
   11.42 +        return color;
   11.43 +    }
   11.44 +
   11.45 +    public void foo(final int x) {
   11.46 +    }
   11.47 +
   11.48 +    public String foo(final String x) {
   11.49 +        return "boo";
   11.50 +    }
   11.51 +}

mercurial