Mon, 22 Apr 2013 10:37:58 -0300
8012919: findMegaMorphicSetMethod should not cast result type
Reviewed-by: attila, sundar
Contributed-by: james.laskey@oracle.com
src/jdk/nashorn/internal/runtime/ScriptObject.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/WithObject.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Apr 22 18:09:04 2013 +0530 1.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Apr 22 10:37:58 2013 -0300 1.3 @@ -1892,7 +1892,7 @@ 1.4 1.5 private static GuardedInvocation findMegaMorphicSetMethod(final CallSiteDescriptor desc, final String name) { 1.6 final MethodType type = desc.getMethodType().insertParameterTypes(1, Object.class); 1.7 - final GuardedInvocation inv = findSetIndexMethod(type, NashornCallSiteDescriptor.isStrict(desc)).asType(type); 1.8 + final GuardedInvocation inv = findSetIndexMethod(type, NashornCallSiteDescriptor.isStrict(desc)); 1.9 return inv.replaceMethods(MH.insertArguments(inv.getInvocation(), 1, name), inv.getGuard()); 1.10 } 1.11
2.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java Mon Apr 22 18:09:04 2013 +0530 2.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Mon Apr 22 10:37:58 2013 -0300 2.3 @@ -232,11 +232,18 @@ 2.4 return (Scope) proto; 2.5 } 2.6 2.7 + private static GuardedInvocation fixReceiverType(final GuardedInvocation link, final MethodHandle filter) { 2.8 + // The receiver may be an Object or a ScriptObject. 2.9 + final MethodType invType = link.getInvocation().type(); 2.10 + final MethodType newInvType = invType.changeParameterType(0, filter.type().returnType()); 2.11 + return link.asType(newInvType); 2.12 + } 2.13 + 2.14 private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) { 2.15 // If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its 2.16 // expression. 2.17 if(!"getMethod".equals(desc.getFirstOperator())) { 2.18 - return link.filterArguments(0, WITHEXPRESSIONFILTER); 2.19 + return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER); 2.20 } 2.21 2.22 final MethodHandle linkInvocation = link.getInvocation(); 2.23 @@ -252,10 +259,7 @@ 2.24 } 2.25 2.26 private static GuardedInvocation fixScopeCallSite(final GuardedInvocation link) { 2.27 - // The receiver may be an object or a ScriptObject. 2.28 - final MethodType invType = link.getInvocation().type(); 2.29 - final MethodType newInvType = invType.changeParameterType(0, WITHSCOPEFILTER.type().returnType()); 2.30 - final GuardedInvocation newLink = link.asType(newInvType); 2.31 + final GuardedInvocation newLink = fixReceiverType(link, WITHSCOPEFILTER); 2.32 return link.replaceMethods(filter(newLink.getInvocation(), WITHSCOPEFILTER), filterGuard(newLink, WITHSCOPEFILTER)); 2.33 } 2.34