1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Oct 09 18:47:42 2012 -0700
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Oct 10 16:49:45 2012 -0700
1.3 @@ -118,22 +118,29 @@
1.4 out.append("\n this." + v.getName() + " = 0;");
1.5 }
1.6 }
1.7 - out.append("\n}");
1.8 + out.append("\n}\n\nfunction ").append(className).append("_proto() {");
1.9 + out.append("\n if (").append(className).
1.10 + append(".prototype.$instOf_").append(className).append(") {");
1.11 + out.append("\n return ").append(className).append(".prototype;");
1.12 + out.append("\n }");
1.13 ClassName sc = jc.getSuperClass();
1.14 if (sc != null) {
1.15 - out.append("\n").append(className)
1.16 + out.append("\n ").append(sc.getInternalName().replace('/', '_')).append("_proto();");
1.17 + out.append("\n ").append(className)
1.18 .append(".prototype = new ").append(sc.getInternalName().replace('/', '_')).append(';');
1.19 }
1.20 for (Method m : jc.getMethods()) {
1.21 if (!m.isStatic() && !m.isPrivate() && !m.getName().contains("<init>")) {
1.22 - compiler.generateMethodReference("\n" + className + ".prototype.", m);
1.23 + compiler.generateMethodReference("\n " + className + ".prototype.", m);
1.24 }
1.25 }
1.26 - out.append("\n" + className + ".prototype.$instOf_").append(className).append(" = true;");
1.27 + out.append("\n " + className + ".prototype.$instOf_").append(className).append(" = true;");
1.28 for (ClassName superInterface : jc.getInterfaces()) {
1.29 - out.append("\n" + className + ".prototype.$instOf_").append(superInterface.getInternalName().replace('/', '_')).append(" = true;");
1.30 + out.append("\n " + className + ".prototype.$instOf_").append(superInterface.getInternalName().replace('/', '_')).append(" = true;");
1.31 }
1.32 -
1.33 + out.append("\n return ").append(className).append(".prototype;");
1.34 + out.append("\n}");
1.35 + out.append("\n").append(className).append("_proto();");
1.36 StringBuilder sb = new StringBuilder();
1.37 for (String init : toInitilize) {
1.38 sb.append("\n").append(init).append("();");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSubTest.java Wed Oct 10 16:49:45 2012 -0700
2.3 @@ -0,0 +1,15 @@
2.4 +package org.apidesign.vm4brwsr;
2.5 +
2.6 +/** Checks if everything works OK, when we switch the
2.7 + * order of loaded classes.
2.8 + *
2.9 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.10 + */
2.11 +public class InstanceSubTest extends InstanceTest {
2.12 +
2.13 + @Override
2.14 + protected String startCompilationWith() {
2.15 + return "org/apidesign/vm4brwsr/InstanceSub";
2.16 + }
2.17 +
2.18 +}
3.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java Tue Oct 09 18:47:42 2012 -0700
3.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java Wed Oct 10 16:49:45 2012 -0700
3.3 @@ -102,11 +102,15 @@
3.4 );
3.5 }
3.6
3.7 - private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
3.8 + protected String startCompilationWith() {
3.9 + return "org/apidesign/vm4brwsr/Instance";
3.10 + }
3.11 +
3.12 + private void assertExec(
3.13 + String msg, String methodName, Object expRes, Object... args
3.14 + ) throws Exception {
3.15 StringBuilder sb = new StringBuilder();
3.16 - Invocable i = StaticMethodTest.compileClass(sb,
3.17 - "org/apidesign/vm4brwsr/Instance"
3.18 - );
3.19 + Invocable i = StaticMethodTest.compileClass(sb, startCompilationWith());
3.20
3.21 Object ret = null;
3.22 try {