nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java
changeset 31277 62097549ae94
parent 27099 eceb216332cb
child 31738 5ad3dfcf3507
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Tue Jun 23 11:16:48 2015 +0200
@@ -106,7 +106,9 @@
  * <li>
  * If the adapter being generated can have class-level overrides, constructors taking same arguments as the superclass
  * constructors are created. These constructors simply delegate to the superclass constructor. They are simply used to
- * create instances of the adapter class, with no instance-level overrides, as they don't have them.
+ * create instances of the adapter class, with no instance-level overrides, as they don't have them. If the original
+ * class' constructor was variable arity, the adapter constructor will also be variable arity. Protected constructors
+ * are exposed as public.
  * </li>
  * </ul>
  * </p><p>
@@ -190,7 +192,6 @@
     private static final int MAX_GENERATED_TYPE_NAME_LENGTH = 255;
 
     private static final String CLASS_INIT = "<clinit>";
-    static final String CONVERTER_INIT = "<converter-init>";
 
     // Method name prefix for invoking super-methods
     static final String SUPER_PREFIX = "super$";
@@ -494,7 +495,8 @@
         final Type[] argTypes = originalCtorType.getArgumentTypes();
 
         // All constructors must be public, even if in the superclass they were protected.
-        final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
+        final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC |
+                (ctor.isVarArgs() ? ACC_VARARGS : 0), INIT,
                 Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null));
 
         mv.visitCode();
@@ -543,7 +545,8 @@
         System.arraycopy(originalArgTypes, 0, newArgTypes, 0, argLen);
 
         // All constructors must be public, even if in the superclass they were protected.
-        // Existing super constructor <init>(this, args...) triggers generating <init>(this, scriptObj, args...).
+        // Existing super constructor <init>(this, args...) triggers generating <init>(this, args..., scriptObj).
+        // Any variable arity constructors become fixed-arity with explicit array arguments.
         final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
                 Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
 
@@ -593,7 +596,7 @@
         if (! fromFunction) {
             newArgTypes[argLen] = OBJECT_TYPE;
             final InstructionAdapter mv2 = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
-                Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
+                    Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
             generateOverridingConstructorWithObjectParam(mv2, ctor, originalCtorType.getDescriptor());
         }
     }