8012919: findMegaMorphicSetMethod should not cast result type
authorjlaskey
Mon, 22 Apr 2013 10:37:58 -0300
changeset 17236 75779a53c6a9
parent 17235 b08e7199633f
child 17237 08e9feb60a83
8012919: findMegaMorphicSetMethod should not cast result type Reviewed-by: attila, sundar Contributed-by: james.laskey@oracle.com
nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java
nashorn/src/jdk/nashorn/internal/runtime/WithObject.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Mon Apr 22 18:09:04 2013 +0530
+++ b/nashorn/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());
     }
 
--- a/nashorn/src/jdk/nashorn/internal/runtime/WithObject.java	Mon Apr 22 18:09:04 2013 +0530
+++ b/nashorn/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));
     }