< prev index next >

buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java

Print this page

        

@@ -150,10 +150,11 @@
             // initialize data fields
             initDataFields(mi);
         }
 
         if (constructor != null) {
+            initPrototype(mi);
             final int arity = constructor.getArity();
             if (arity != MemberInfo.DEFAULT_ARITY) {
                 mi.loadThis();
                 mi.push(arity);
                 mi.invokeVirtual(SCRIPTFUNCTION_TYPE, SCRIPTFUNCTION_SETARITY,

@@ -191,10 +192,11 @@
 
         mi.invokeSpecial(superClass, INIT, superDesc);
     }
 
     private void initFunctionFields(final MethodGenerator mi) {
+        assert memberCount > 0;
         for (final MemberInfo memInfo : scriptClassInfo.getMembers()) {
             if (!memInfo.isConstructorFunction()) {
                 continue;
             }
             mi.loadThis();

@@ -202,10 +204,11 @@
             mi.putField(className, memInfo.getJavaName(), OBJECT_DESC);
         }
     }
 
     private void initDataFields(final MethodGenerator mi) {
+        assert memberCount > 0;
          for (final MemberInfo memInfo : scriptClassInfo.getMembers()) {
             if (!memInfo.isConstructorProperty() || memInfo.isFinal()) {
                 continue;
             }
             final Object value = memInfo.getValue();

@@ -220,12 +223,14 @@
                 mi.dup();
                 mi.invokeSpecial(clazz, INIT, DEFAULT_INIT_DESC);
                 mi.putField(className, memInfo.getJavaName(), memInfo.getJavaDesc());
             }
         }
+    }
 
-        if (constructor != null) {
+    private void initPrototype(final MethodGenerator mi) {
+        assert constructor != null;
             mi.loadThis();
             final String protoName = scriptClassInfo.getPrototypeClassName();
             mi.newObject(protoName);
             mi.dup();
             mi.invokeSpecial(protoName, INIT, DEFAULT_INIT_DESC);

@@ -233,11 +238,10 @@
             mi.loadThis();
             mi.invokeStatic(PROTOTYPEOBJECT_TYPE, PROTOTYPEOBJECT_SETCONSTRUCTOR,
                     PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC);
             mi.invokeVirtual(SCRIPTFUNCTION_TYPE, SCRIPTFUNCTION_SETPROTOTYPE, SCRIPTFUNCTION_SETPROTOTYPE_DESC);
         }
-    }
 
     /**
      * Entry point for ConstructorGenerator run separately as an application. Will display
      * usage. Takes one argument, a class name.
      * @param args args vector
< prev index next >