launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JsClassLoader.java
branchclassloader
changeset 1181 b703d9d71f25
parent 1179 2fee889b9830
     1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JsClassLoader.java	Mon Jun 17 17:40:30 2013 +0200
     1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JsClassLoader.java	Mon Jun 17 19:36:24 2013 +0200
     1.3 @@ -132,7 +132,7 @@
     1.4  
     1.5          @Override
     1.6          public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
     1.7 -            return new FindInMethod(name, desc,
     1.8 +            return new FindInMethod(access, name, desc,
     1.9                  super.visitMethod(access & (~Opcodes.ACC_NATIVE), name, desc, signature, exceptions)
    1.10              );
    1.11          }
    1.12 @@ -140,12 +140,14 @@
    1.13          private final class FindInMethod extends MethodVisitor {
    1.14              private final String name;
    1.15              private final String desc;
    1.16 +            private final int access;
    1.17              private List<String> args;
    1.18              private String body;
    1.19              private boolean bodyGenerated;
    1.20              
    1.21 -            public FindInMethod(String name, String desc, MethodVisitor mv) {
    1.22 +            public FindInMethod(int access, String name, String desc, MethodVisitor mv) {
    1.23                  super(Opcodes.ASM4, mv);
    1.24 +                this.access = access;
    1.25                  this.name = name;
    1.26                  this.desc = desc;
    1.27              }
    1.28 @@ -207,6 +209,16 @@
    1.29                  // end of Fn init
    1.30                  
    1.31                  super.visitLabel(ifNotNull);
    1.32 +                
    1.33 +                final int offset;
    1.34 +                if ((access & Opcodes.ACC_STATIC) == 0) {
    1.35 +                    offset = 1;
    1.36 +                    super.visitIntInsn(Opcodes.ALOAD, 0);
    1.37 +                } else {
    1.38 +                    offset = 0;
    1.39 +                    super.visitInsn(Opcodes.ACONST_NULL);
    1.40 +                }
    1.41 +                
    1.42                  super.visitIntInsn(Opcodes.SIPUSH, args.size());
    1.43                  super.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
    1.44                  
    1.45 @@ -228,7 +240,7 @@
    1.46                          }
    1.47                          FindInMethod.super.visitInsn(Opcodes.DUP);
    1.48                          FindInMethod.super.visitIntInsn(Opcodes.SIPUSH, index);
    1.49 -                        FindInMethod.super.visitVarInsn(t.getOpcode(Opcodes.ILOAD), index);
    1.50 +                        FindInMethod.super.visitVarInsn(t.getOpcode(Opcodes.ILOAD), index + offset);
    1.51                          String factory;
    1.52                          switch (descriptor) {
    1.53                          case 'I': factory = "java/lang/Integer"; break;
    1.54 @@ -256,7 +268,7 @@
    1.55                          }
    1.56                          FindInMethod.super.visitInsn(Opcodes.DUP);
    1.57                          FindInMethod.super.visitIntInsn(Opcodes.SIPUSH, index);
    1.58 -                        FindInMethod.super.visitVarInsn(Opcodes.ALOAD, index);
    1.59 +                        FindInMethod.super.visitVarInsn(Opcodes.ALOAD, index + offset);
    1.60                          FindInMethod.super.visitInsn(Opcodes.AASTORE);
    1.61                          index++;
    1.62                      }
    1.63 @@ -274,7 +286,7 @@
    1.64                  sr.accept(sv);
    1.65                  
    1.66                  super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, 
    1.67 -                    "org/apidesign/bck2brwsr/launcher/fximpl/Fn", "invoke", "([Ljava/lang/Object;)Ljava/lang/Object;"
    1.68 +                    "org/apidesign/bck2brwsr/launcher/fximpl/Fn", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"
    1.69                  );
    1.70                  switch (sv.returnType.getSort()) {
    1.71                  case Type.VOID: