8006570: This-value for non-strict functions should be converted to object

Tue, 22 Jan 2013 14:14:37 +0100

author
hannesw
date
Tue, 22 Jan 2013 14:14:37 +0100
changeset 42
935dcec38e9a
parent 41
8b3cc4ad1810
child 43
e43d1013d871

8006570: This-value for non-strict functions should be converted to object
Reviewed-by: jlaskey, lagergren, attila

src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeBoolean.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeFunction.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeNumber.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeString.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/GlobalObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptFunction.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptObject.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/SetMethodCreator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/NashornGuardedInvocation.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/NashornLinker.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8006570.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8006570.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Mon Jan 21 21:17:38 2013 +0530
     1.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Tue Jan 22 14:14:37 2013 +0100
     1.3 @@ -419,6 +419,18 @@
     1.4      }
     1.5  
     1.6      @Override
     1.7 +    public MethodHandle getWrapFilter(Object obj) {
     1.8 +        if (obj instanceof String || obj instanceof ConsString) {
     1.9 +            return NativeString.WRAPFILTER;
    1.10 +        } else if (obj instanceof Number) {
    1.11 +            return NativeNumber.WRAPFILTER;
    1.12 +        } else if (obj instanceof Boolean) {
    1.13 +            return NativeBoolean.WRAPFILTER;
    1.14 +        }
    1.15 +        throw new IllegalArgumentException("Unsupported primitive value: " + obj);
    1.16 +    }
    1.17 +
    1.18 +    @Override
    1.19      public GuardedInvocation numberLookup(final NashornCallSiteDescriptor callSite, final Number self) {
    1.20          return NativeNumber.lookupPrimitive(callSite, self);
    1.21      }
     2.1 --- a/src/jdk/nashorn/internal/objects/NativeBoolean.java	Mon Jan 21 21:17:38 2013 +0530
     2.2 +++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java	Tue Jan 22 14:14:37 2013 +0100
     2.3 @@ -50,7 +50,7 @@
     2.4  public final class NativeBoolean extends ScriptObject {
     2.5      private final boolean value;
     2.6  
     2.7 -    private final static MethodHandle WRAPFILTER = findWrapFilter();
     2.8 +    final static MethodHandle WRAPFILTER = findWrapFilter();
     2.9  
    2.10      NativeBoolean(final boolean value) {
    2.11          this(value, Global.instance().getBooleanPrototype());
     3.1 --- a/src/jdk/nashorn/internal/objects/NativeFunction.java	Mon Jan 21 21:17:38 2013 +0530
     3.2 +++ b/src/jdk/nashorn/internal/objects/NativeFunction.java	Tue Jan 22 14:14:37 2013 +0100
     3.3 @@ -67,7 +67,7 @@
     3.4      }
     3.5  
     3.6      private static Object convertThis(final ScriptFunction func, final Object thiz) {
     3.7 -        if (!(thiz instanceof ScriptObject) && !func.isStrict() && !func.isBuiltin()) {
     3.8 +        if (!(thiz instanceof ScriptObject) && func.isNonStrictFunction()) {
     3.9              if (thiz == UNDEFINED || thiz == null) {
    3.10                  return Global.instance();
    3.11              }
     4.1 --- a/src/jdk/nashorn/internal/objects/NativeNumber.java	Mon Jan 21 21:17:38 2013 +0530
     4.2 +++ b/src/jdk/nashorn/internal/objects/NativeNumber.java	Tue Jan 22 14:14:37 2013 +0100
     4.3 @@ -57,7 +57,7 @@
     4.4  @ScriptClass("Number")
     4.5  public final class NativeNumber extends ScriptObject {
     4.6  
     4.7 -    private static final MethodHandle WRAPFILTER = findWrapFilter();
     4.8 +    static final MethodHandle WRAPFILTER = findWrapFilter();
     4.9  
    4.10      /** ECMA 15.7.3.2 largest positive finite value */
    4.11      @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR)
     5.1 --- a/src/jdk/nashorn/internal/objects/NativeString.java	Mon Jan 21 21:17:38 2013 +0530
     5.2 +++ b/src/jdk/nashorn/internal/objects/NativeString.java	Tue Jan 22 14:14:37 2013 +0100
     5.3 @@ -68,7 +68,7 @@
     5.4  
     5.5      private final CharSequence value;
     5.6  
     5.7 -    private static final MethodHandle WRAPFILTER = findWrapFilter();
     5.8 +    static final MethodHandle WRAPFILTER = findWrapFilter();
     5.9  
    5.10      NativeString(final CharSequence value) {
    5.11          this(value, Global.instance().getStringPrototype());
     6.1 --- a/src/jdk/nashorn/internal/runtime/GlobalObject.java	Mon Jan 21 21:17:38 2013 +0530
     6.2 +++ b/src/jdk/nashorn/internal/runtime/GlobalObject.java	Tue Jan 22 14:14:37 2013 +0100
     6.3 @@ -68,6 +68,16 @@
     6.4       */
     6.5     public Object wrapAsObject(Object obj);
     6.6  
     6.7 +
     6.8 +    /**
     6.9 +     * Get a MethodHandle that converts the argument to its JavaScript object representation
    6.10 +     *
    6.11 +     * @param obj a JavaScript primitive object (String, Number, or Boolean)
    6.12 +     *
    6.13 +     * @return wrap filter methodhandle
    6.14 +     */
    6.15 +   public MethodHandle getWrapFilter(Object obj);
    6.16 +
    6.17      /**
    6.18       * Wrapper for {@link jdk.nashorn.internal.objects.Global#numberLookup(NashornCallSiteDescriptor, Number)}
    6.19       *
     7.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java	Mon Jan 21 21:17:38 2013 +0530
     7.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java	Tue Jan 22 14:14:37 2013 +0100
     7.3 @@ -40,6 +40,7 @@
     7.4  import jdk.nashorn.internal.parser.Token;
     7.5  import jdk.nashorn.internal.runtime.linker.MethodHandleFactory;
     7.6  import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
     7.7 +import jdk.nashorn.internal.runtime.linker.NashornGuardedInvocation;
     7.8  import jdk.nashorn.internal.runtime.linker.NashornGuards;
     7.9  import jdk.nashorn.internal.runtime.options.Options;
    7.10  import org.dynalang.dynalink.CallSiteDescriptor;
    7.11 @@ -329,6 +330,14 @@
    7.12      public abstract boolean isBuiltin();
    7.13  
    7.14      /**
    7.15 +     * Is this a non-strict (not built-in) script function?
    7.16 +     * @return true if neither strict nor built-in
    7.17 +     */
    7.18 +    public boolean isNonStrictFunction() {
    7.19 +        return !isStrict() && !isBuiltin();
    7.20 +    }
    7.21 +
    7.22 +    /**
    7.23       * Execute this script function.
    7.24       * @param self  Target object.
    7.25       * @param arguments  Call arguments.
    7.26 @@ -916,7 +925,7 @@
    7.27  
    7.28              if(NashornCallSiteDescriptor.isScope(desc)) {
    7.29                  // (this, callee, args...) => (callee, args...) => (callee, [this], args...)
    7.30 -                boundHandle = MH.bindTo(callHandle, isStrict() || isBuiltin()? ScriptRuntime.UNDEFINED : Context.getGlobal());
    7.31 +                boundHandle = MH.bindTo(callHandle, isNonStrictFunction() ? Context.getGlobal(): ScriptRuntime.UNDEFINED);
    7.32                  boundHandle = MH.dropArguments(boundHandle, 1, Object.class);
    7.33              } else {
    7.34                  // (this, callee, args...) permute => (callee, this, args...) which is what we get in
    7.35 @@ -934,7 +943,7 @@
    7.36              final MethodHandle callHandle = getBestSpecializedInvokeHandle(type.dropParameterTypes(0, 1));
    7.37  
    7.38              if(NashornCallSiteDescriptor.isScope(desc)) {
    7.39 -                boundHandle = MH.bindTo(callHandle, isStrict() || isBuiltin()? ScriptRuntime.UNDEFINED : Context.getGlobal());
    7.40 +                boundHandle = MH.bindTo(callHandle, isNonStrictFunction()? Context.getGlobal() : ScriptRuntime.UNDEFINED);
    7.41                  boundHandle = MH.dropArguments(boundHandle, 0, Object.class, Object.class);
    7.42              } else {
    7.43                  boundHandle = MH.dropArguments(callHandle, 0, Object.class);
    7.44 @@ -942,7 +951,7 @@
    7.45          }
    7.46  
    7.47          boundHandle = pairArguments(boundHandle, type);
    7.48 -        return new GuardedInvocation(boundHandle, NashornGuards.getFunctionGuard(this));
    7.49 +        return new NashornGuardedInvocation(boundHandle, null, NashornGuards.getFunctionGuard(this), isNonStrictFunction());
    7.50      }
    7.51  
    7.52      /**
     8.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Mon Jan 21 21:17:38 2013 +0530
     8.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Tue Jan 22 14:14:37 2013 +0100
     8.3 @@ -1643,16 +1643,14 @@
     8.4          // getMap() is fine as we have the prototype switchpoint depending on where the property was found
     8.5          final MethodHandle guard = NashornGuards.getMapGuard(getMap());
     8.6  
     8.7 -        int invokeFlags = 0;
     8.8 -
     8.9          if (methodHandle != null) {
    8.10              assert methodHandle.type().returnType().equals(returnType);
    8.11              final ScriptFunction getter = find.getGetterFunction();
    8.12 -            invokeFlags = (getter != null && getter.isStrict()) ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
    8.13 +            final boolean nonStrict = getter != null && getter.isNonStrictFunction();
    8.14              if (find.isSelf()) {
    8.15                  return new NashornGuardedInvocation(methodHandle, null, ObjectClassGenerator.OBJECT_FIELDS_ONLY &&
    8.16                          NashornCallSiteDescriptor.isFastScope(desc) && !property.canChangeType() ? null : guard,
    8.17 -                                invokeFlags);
    8.18 +                            nonStrict);
    8.19              }
    8.20  
    8.21              final ScriptObject prototype = find.getOwner();
    8.22 @@ -1660,11 +1658,11 @@
    8.23              if (!property.hasGetterFunction()) {
    8.24                  methodHandle = bindTo(methodHandle, prototype);
    8.25              }
    8.26 -            return new NashornGuardedInvocation(methodHandle, getMap().getProtoGetSwitchPoint(name), guard, invokeFlags);
    8.27 +            return new NashornGuardedInvocation(methodHandle, getMap().getProtoGetSwitchPoint(name), guard, nonStrict);
    8.28          }
    8.29  
    8.30          assert !NashornCallSiteDescriptor.isFastScope(desc);
    8.31 -        return new NashornGuardedInvocation(Lookup.emptyGetter(returnType), getMap().getProtoGetSwitchPoint(name), guard, invokeFlags);
    8.32 +        return new GuardedInvocation(Lookup.emptyGetter(returnType), getMap().getProtoGetSwitchPoint(name), guard);
    8.33      }
    8.34  
    8.35      private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name) {
    8.36 @@ -1855,7 +1853,6 @@
    8.37          final Class<?>   valueClass = callType.parameterType(2);
    8.38  
    8.39          MethodHandle methodHandle = findOwnMH("set", void.class, keyClass, valueClass, boolean.class);
    8.40 -        methodHandle = MH.asType(methodHandle, methodHandle.type().changeParameterType(0, Object.class));
    8.41          methodHandle = MH.insertArguments(methodHandle, 3, isStrict);
    8.42  
    8.43          return new GuardedInvocation(methodHandle, getScriptObjectGuard(callType));
     9.1 --- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java	Mon Jan 21 21:17:38 2013 +0530
     9.2 +++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java	Tue Jan 22 14:14:37 2013 +0100
     9.3 @@ -89,21 +89,19 @@
     9.4      private class SetMethod {
     9.5          private final MethodHandle methodHandle;
     9.6          private final Property property;
     9.7 -        private final int invokeFlags;
     9.8 +        private final boolean nonStrict;
     9.9  
    9.10          /**
    9.11           * Creates a new lookup result.
    9.12           * @param methodHandle the actual method handle
    9.13           * @param property the property object. Can be null in case we're creating a new property in the global object.
    9.14 -         * @param invokeFlags flags for the invocation. Normally either 0, or
    9.15 -         * {@link NashornCallSiteDescriptor#CALLSITE_STRICT} when an existing property with a strict function for a
    9.16 -         * property setter is discovered.
    9.17 +         * @param nonStrict True if an existing property with a non-strict function as property setter is discovered.
    9.18           */
    9.19 -        SetMethod(final MethodHandle methodHandle, final Property property, final int invokeFlags) {
    9.20 +        SetMethod(final MethodHandle methodHandle, final Property property, final boolean nonStrict) {
    9.21              assert methodHandle != null;
    9.22              this.methodHandle = methodHandle;
    9.23              this.property = property;
    9.24 -            this.invokeFlags = invokeFlags;
    9.25 +            this.nonStrict = nonStrict;
    9.26          }
    9.27  
    9.28          /**
    9.29 @@ -111,7 +109,7 @@
    9.30           * @return the composed guarded invocation that represents the dynamic setter method for the property.
    9.31           */
    9.32          GuardedInvocation createGuardedInvocation() {
    9.33 -            return new NashornGuardedInvocation(methodHandle, null, getGuard(), invokeFlags);
    9.34 +            return new NashornGuardedInvocation(methodHandle, null, getGuard(), nonStrict);
    9.35          }
    9.36  
    9.37          private MethodHandle getGuard() {
    9.38 @@ -164,20 +162,17 @@
    9.39          } else {
    9.40              boundHandle = methodHandle;
    9.41          }
    9.42 -        return new SetMethod(boundHandle, property, getExistingPropertySetterInvokeFlags());
    9.43 +        return new SetMethod(boundHandle, property, getExistingSetterNonStrictFlag());
    9.44      }
    9.45  
    9.46 -    private int getExistingPropertySetterInvokeFlags() {
    9.47 +    private boolean getExistingSetterNonStrictFlag() {
    9.48          final ScriptFunction setter = find.getSetterFunction();
    9.49 -        if (setter != null && setter.isStrict()) {
    9.50 -            return NashornCallSiteDescriptor.CALLSITE_STRICT;
    9.51 -        }
    9.52 -        return 0;
    9.53 +        return setter != null && setter.isNonStrictFunction();
    9.54      }
    9.55  
    9.56      private SetMethod createGlobalPropertySetter() {
    9.57          final ScriptObject global = Context.getGlobal();
    9.58 -        return new SetMethod(ScriptObject.bindTo(global.addSpill(getName()), global), null, 0);
    9.59 +        return new SetMethod(ScriptObject.bindTo(global.addSpill(getName()), global), null, false);
    9.60      }
    9.61  
    9.62      private SetMethod createNewPropertySetter() {
    9.63 @@ -197,7 +192,7 @@
    9.64          final int nextSpill = getMap().getSpillLength();
    9.65  
    9.66          final Property property = createSpillProperty(nextSpill);
    9.67 -        return new SetMethod(createSpillMethodHandle(nextSpill, property), property, 0);
    9.68 +        return new SetMethod(createSpillMethodHandle(nextSpill, property), property, false);
    9.69      }
    9.70  
    9.71      private Property createSpillProperty(final int nextSpill) {
    9.72 @@ -227,7 +222,7 @@
    9.73          final Property property = new SpillProperty(getName(), 0, nextEmbed, ScriptObject.GET_EMBED[nextEmbed], ScriptObject.SET_EMBED[nextEmbed]);
    9.74          //TODO specfields
    9.75          final MethodHandle methodHandle = MH.insertArguments(ScriptObject.SETEMBED, 0, desc, getMap(), getNewMap(property), property.getSetter(Object.class, getMap()), nextEmbed);
    9.76 -        return new SetMethod(methodHandle, property, 0);
    9.77 +        return new SetMethod(methodHandle, property, false);
    9.78      }
    9.79  
    9.80      private PropertyMap getNewMap(Property property) {
    10.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornGuardedInvocation.java	Mon Jan 21 21:17:38 2013 +0530
    10.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornGuardedInvocation.java	Tue Jan 22 14:14:37 2013 +0100
    10.3 @@ -33,7 +33,8 @@
    10.4   * Guarded invocation with Nashorn specific bits.
    10.5   */
    10.6  public class NashornGuardedInvocation extends GuardedInvocation {
    10.7 -    private final int flags;
    10.8 +
    10.9 +    private final boolean nonStrict;
   10.10  
   10.11      /**
   10.12       * Constructor
   10.13 @@ -41,28 +42,28 @@
   10.14       * @param invocation  invocation target
   10.15       * @param switchPoint SwitchPoint that will, when invalidated, require relinking callsite, null if no SwitchPoint
   10.16       * @param guard       guard that will, when failed, require relinking callsite, null if no guard
   10.17 -     * @param flags       callsite flags
   10.18 +     * @param nonStrict   non-strict invocation target flag
   10.19       */
   10.20 -    public NashornGuardedInvocation(final MethodHandle invocation, final SwitchPoint switchPoint, final MethodHandle guard, final int flags) {
   10.21 +    public NashornGuardedInvocation(final MethodHandle invocation, final SwitchPoint switchPoint, final MethodHandle guard, final boolean nonStrict) {
   10.22          super(invocation, switchPoint, guard);
   10.23 -        this.flags = flags;
   10.24 +        this.nonStrict = nonStrict;
   10.25  
   10.26      }
   10.27  
   10.28      /**
   10.29 -     * Is this invocation created from a callsite with strict semantics
   10.30 -     * @return true if strict
   10.31 +     * Is the target of this invocation a non-strict function?
   10.32 +     * @return true if invocation target is non-strict
   10.33       */
   10.34 -    public boolean isStrict() {
   10.35 -        return (flags & NashornCallSiteDescriptor.CALLSITE_STRICT) != 0;
   10.36 +    public boolean isNonStrict() {
   10.37 +        return nonStrict;
   10.38      }
   10.39  
   10.40      /**
   10.41 -     * Check whether a GuardedInvocation is created from a callsite with strict semantics
   10.42 +     * Check whether the target of this invocation is a non-strict script function.
   10.43       * @param inv guarded invocation
   10.44 -     * @return true if strict
   10.45 +     * @return true if invocation target is non-strict
   10.46       */
   10.47 -    public static boolean isStrict(final GuardedInvocation inv) {
   10.48 -        return (inv instanceof NashornGuardedInvocation)? ((NashornGuardedInvocation)inv).isStrict() : false;
   10.49 +    public static boolean isNonStrict(final GuardedInvocation inv) {
   10.50 +        return inv instanceof NashornGuardedInvocation && ((NashornGuardedInvocation)inv).isNonStrict();
   10.51      }
   10.52  }
    11.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornLinker.java	Mon Jan 21 21:17:38 2013 +0530
    11.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornLinker.java	Tue Jan 22 14:14:37 2013 +0100
    11.3 @@ -29,6 +29,10 @@
    11.4  
    11.5  import java.lang.invoke.MethodHandle;
    11.6  import java.lang.invoke.MethodHandles;
    11.7 +
    11.8 +import jdk.nashorn.internal.runtime.ConsString;
    11.9 +import jdk.nashorn.internal.runtime.Context;
   11.10 +import jdk.nashorn.internal.runtime.GlobalObject;
   11.11  import jdk.nashorn.internal.runtime.ScriptFunction;
   11.12  import jdk.nashorn.internal.runtime.ScriptObject;
   11.13  import jdk.nashorn.internal.runtime.Undefined;
   11.14 @@ -71,9 +75,23 @@
   11.15              return null;
   11.16          }
   11.17  
   11.18 -        final GuardedInvocation inv;
   11.19 +        GuardedInvocation inv;
   11.20          if (self instanceof ScriptObject) {
   11.21              inv = ((ScriptObject)self).lookup(desc, request.isCallSiteUnstable());
   11.22 +
   11.23 +            if (self instanceof ScriptFunction && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
   11.24 +
   11.25 +                // Add toObject wrapper for non-object self argument to non-strict functions
   11.26 +                assert request.getArguments().length >= 2 : "No self argument in script function callsite";
   11.27 +                Object thisObject = request.getArguments()[1];
   11.28 +                // Add wrapper filter for primitive this-object on non-strict functions
   11.29 +                if (NashornGuardedInvocation.isNonStrict(inv) && isPrimitive(thisObject)) {
   11.30 +                    MethodHandle wrapFilter = ((GlobalObject) Context.getGlobal()).getWrapFilter(thisObject);
   11.31 +                    MethodHandle invocation = MH.filterArguments(inv.getInvocation(), 1,
   11.32 +                            MH.asType(wrapFilter, wrapFilter.type().changeReturnType(Object.class)));
   11.33 +                    inv = new GuardedInvocation(invocation, inv.getSwitchPoint(), inv.getGuard());
   11.34 +                }
   11.35 +            }
   11.36          } else if (self instanceof Undefined) {
   11.37              inv = Undefined.lookup(desc);
   11.38          } else {
   11.39 @@ -135,6 +153,13 @@
   11.40                  JavaAdapterFactory.isAutoConvertibleFromFunction(clazz);
   11.41      }
   11.42  
   11.43 +    private static boolean isPrimitive(Object obj) {
   11.44 +        return obj instanceof Boolean ||
   11.45 +               obj instanceof Number ||
   11.46 +               obj instanceof String ||
   11.47 +               obj instanceof ConsString;
   11.48 +    }
   11.49 +
   11.50      @Override
   11.51      public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
   11.52          if(ScriptObject.class.isAssignableFrom(sourceType)) {
    12.1 --- a/src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java	Mon Jan 21 21:17:38 2013 +0530
    12.2 +++ b/src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java	Tue Jan 22 14:14:37 2013 +0100
    12.3 @@ -94,11 +94,11 @@
    12.4          final GuardedInvocation link = wrappedReceiver.lookup(desc);
    12.5          if (link != null) {
    12.6              MethodHandle method = link.getInvocation();
    12.7 -            if (!NashornGuardedInvocation.isStrict(link)) {
    12.8 +            final Class<?> receiverType = method.type().parameterType(0);
    12.9 +            if (receiverType != Object.class || NashornGuardedInvocation.isNonStrict(link)) {
   12.10                  final MethodType wrapType = wrapFilter.type();
   12.11 -                final Class<?> methodReceiverType = method.type().parameterType(0);
   12.12 -                assert methodReceiverType.isAssignableFrom(wrapType.returnType());
   12.13 -                method = MH.filterArguments(method, 0, MH.asType(wrapFilter, wrapType.changeReturnType(methodReceiverType)));
   12.14 +                assert receiverType.isAssignableFrom(wrapType.returnType());
   12.15 +                method = MH.filterArguments(method, 0, MH.asType(wrapFilter, wrapType.changeReturnType(receiverType)));
   12.16              }
   12.17              return new GuardedInvocation(method, guard, link.getSwitchPoint());
   12.18          }
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/script/basic/JDK-8006570.js	Tue Jan 22 14:14:37 2013 +0100
    13.3 @@ -0,0 +1,60 @@
    13.4 +/*
    13.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + * 
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.
   13.11 + * 
   13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.15 + * version 2 for more details (a copy is included in the LICENSE file that
   13.16 + * accompanied this code).
   13.17 + * 
   13.18 + * You should have received a copy of the GNU General Public License version
   13.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.21 + * 
   13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.23 + * or visit www.oracle.com if you need additional information or have any
   13.24 + * questions.
   13.25 + */
   13.26 +
   13.27 +/**
   13.28 + * JDK-8006570 : this-value for non-strict functions should be converted to object
   13.29 + *
   13.30 + * @test
   13.31 + * @run
   13.32 + */
   13.33 +
   13.34 +var strict, nonstrict;
   13.35 +
   13.36 +nonstrict = Object.prototype.nonstrict = function nonstrict() {
   13.37 +    print(typeof this, this instanceof Object);
   13.38 +};
   13.39 +
   13.40 +(function() {
   13.41 +    "use strict";
   13.42 +    strict = Object.prototype.strict = function strict() {
   13.43 +        print(typeof this, this instanceof Object);
   13.44 +    };
   13.45 +})();
   13.46 +
   13.47 +"foo".nonstrict();
   13.48 +(1).nonstrict();
   13.49 +true.nonstrict();
   13.50 +nonstrict();
   13.51 +nonstrict.call(null);
   13.52 +nonstrict.call("foo");
   13.53 +nonstrict.call(1);
   13.54 +nonstrict.call(true);
   13.55 +
   13.56 +"foo".strict();
   13.57 +(1).strict();
   13.58 +true.strict();
   13.59 +strict();
   13.60 +strict.call(null);
   13.61 +strict.call("foo");
   13.62 +strict.call(1);
   13.63 +strict.call(true);
   13.64 \ No newline at end of file
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/script/basic/JDK-8006570.js.EXPECTED	Tue Jan 22 14:14:37 2013 +0100
    14.3 @@ -0,0 +1,16 @@
    14.4 +object true
    14.5 +object true
    14.6 +object true
    14.7 +object true
    14.8 +object true
    14.9 +object true
   14.10 +object true
   14.11 +object true
   14.12 +string false
   14.13 +number false
   14.14 +boolean false
   14.15 +undefined false
   14.16 +object false
   14.17 +string false
   14.18 +number false
   14.19 +boolean false

mercurial