# HG changeset patch # User jlaskey # Date 1366637878 10800 # Node ID 812e9cc70320543e1c88f963988e14892f73ba4d # Parent ead94bc579395cd325ace6359ef731df0f33504c 8012919: findMegaMorphicSetMethod should not cast result type Reviewed-by: attila, sundar Contributed-by: james.laskey@oracle.com diff -r ead94bc57939 -r 812e9cc70320 src/jdk/nashorn/internal/runtime/ScriptObject.java --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Apr 22 18:09:04 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Apr 22 10:37:58 2013 -0300 @@ -1892,7 +1892,7 @@ private static GuardedInvocation findMegaMorphicSetMethod(final CallSiteDescriptor desc, final String name) { final MethodType type = desc.getMethodType().insertParameterTypes(1, Object.class); - final GuardedInvocation inv = findSetIndexMethod(type, NashornCallSiteDescriptor.isStrict(desc)).asType(type); + final GuardedInvocation inv = findSetIndexMethod(type, NashornCallSiteDescriptor.isStrict(desc)); return inv.replaceMethods(MH.insertArguments(inv.getInvocation(), 1, name), inv.getGuard()); } diff -r ead94bc57939 -r 812e9cc70320 src/jdk/nashorn/internal/runtime/WithObject.java --- a/src/jdk/nashorn/internal/runtime/WithObject.java Mon Apr 22 18:09:04 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Mon Apr 22 10:37:58 2013 -0300 @@ -232,11 +232,18 @@ return (Scope) proto; } + private static GuardedInvocation fixReceiverType(final GuardedInvocation link, final MethodHandle filter) { + // The receiver may be an Object or a ScriptObject. + final MethodType invType = link.getInvocation().type(); + final MethodType newInvType = invType.changeParameterType(0, filter.type().returnType()); + return link.asType(newInvType); + } + private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) { // If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its // expression. if(!"getMethod".equals(desc.getFirstOperator())) { - return link.filterArguments(0, WITHEXPRESSIONFILTER); + return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER); } final MethodHandle linkInvocation = link.getInvocation(); @@ -252,10 +259,7 @@ } private static GuardedInvocation fixScopeCallSite(final GuardedInvocation link) { - // The receiver may be an object or a ScriptObject. - final MethodType invType = link.getInvocation().type(); - final MethodType newInvType = invType.changeParameterType(0, WITHSCOPEFILTER.type().returnType()); - final GuardedInvocation newLink = link.asType(newInvType); + final GuardedInvocation newLink = fixReceiverType(link, WITHSCOPEFILTER); return link.replaceMethods(filter(newLink.getInvocation(), WITHSCOPEFILTER), filterGuard(newLink, WITHSCOPEFILTER)); }