Static methods needs to be in the prototype, as the bytecode can refer to them as being in a subclass
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 11 Oct 2012 10:03:21 -0700
changeset 1022354255a1844
parent 101 ff3f0de0b8a2
child 103 e8438996d406
Static methods needs to be in the prototype, as the bytecode can refer to them as being in a subclass
htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java
htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java
vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
vm/src/test/java/org/apidesign/vm4brwsr/InstanceSub.java
vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java
     1.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java	Thu Oct 11 06:16:00 2012 -0700
     1.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java	Thu Oct 11 10:03:21 2012 -0700
     1.3 @@ -31,10 +31,10 @@
     1.4      }
     1.5      
     1.6      public void setAutocomplete(boolean state) {
     1.7 -        Element.setAttribute(this, "autocomplete", state);
     1.8 +        setAttribute(this, "autocomplete", state);
     1.9      }
    1.10      
    1.11      public final String getValue() {
    1.12 -        return (String)Element.getAttribute(this, "value");
    1.13 +        return (String)getAttribute(this, "value");
    1.14      }
    1.15  }
     2.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java	Thu Oct 11 06:16:00 2012 -0700
     2.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java	Thu Oct 11 10:03:21 2012 -0700
     2.3 @@ -31,6 +31,6 @@
     2.4      }
     2.5      
     2.6      public final void setText(String text) {
     2.7 -        Element.setAttribute(this, "innerHTML", text);
     2.8 +        setAttribute(this, "innerHTML", text);
     2.9      }
    2.10  }
     3.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Thu Oct 11 06:16:00 2012 -0700
     3.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Thu Oct 11 10:03:21 2012 -0700
     3.3 @@ -130,7 +130,7 @@
     3.4                 .append(".prototype = new ").append(sc.getInternalName().replace('/', '_')).append(';');
     3.5          }
     3.6          for (Method m : jc.getMethods()) {
     3.7 -            if (!m.isStatic() && !m.isPrivate() && !m.getName().contains("<init>")) {
     3.8 +            if (!m.getName().contains("<init>") && !m.getName().contains("<cinit>")) {
     3.9                  compiler.generateMethodReference("\n  " + className + ".prototype.", m);
    3.10              }
    3.11          }
    3.12 @@ -828,7 +828,11 @@
    3.13          }
    3.14          final String in = mi.getClassName().getInternalName();
    3.15          out.append(in.replace('/', '_'));
    3.16 -        out.append('_');
    3.17 +        if (isStatic) {
    3.18 +            out.append(".prototype.");
    3.19 +        } else {
    3.20 +            out.append('_');
    3.21 +        }
    3.22          out.append(mn);
    3.23          out.append('(');
    3.24          String sep = "";
     4.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSub.java	Thu Oct 11 06:16:00 2012 -0700
     4.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSub.java	Thu Oct 11 10:03:21 2012 -0700
     4.3 @@ -30,4 +30,8 @@
     4.4      public void setByte(byte b) {
     4.5          super.setByte((byte) (b + 1));
     4.6      }
     4.7 +    
     4.8 +    public static double recallDbl() {
     4.9 +        return defaultDblValue();
    4.10 +    }
    4.11  }
     5.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java	Thu Oct 11 06:16:00 2012 -0700
     5.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java	Thu Oct 11 10:03:21 2012 -0700
     5.3 @@ -34,6 +34,13 @@
     5.4              Double.valueOf(0)
     5.5          );
     5.6      }
     5.7 +    @Test public void verifyStaticMethodCall() throws Exception {
     5.8 +        assertExec(
     5.9 +            "Will be zero",
    5.10 +            "org_apidesign_vm4brwsr_InstanceSub_recallDblD",
    5.11 +            Double.valueOf(0)
    5.12 +        );
    5.13 +    }
    5.14      @Test public void verifyAssignedByteValue() throws Exception {
    5.15          assertExec(
    5.16              "Will one thirty one",